Skip to content

Commit

Permalink
Merge pull request #7 from zmeggyesi/modular-projects
Browse files Browse the repository at this point in the history
Modular projects
  • Loading branch information
zmeggyesi authored Dec 6, 2016
2 parents ce04bef + 562859a commit 491f9b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

<groupId>hu.skawa</groupId>
<artifactId>migrator-maven-plugin</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>maven-plugin</packaging>

<name>Maven-Bazel Migration Plugin</name>

<url>https://zmeggyesi.github.io/migrator-maven-plugin/</url>
<inceptionYear>2016</inceptionYear>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
Expand Down
63 changes: 33 additions & 30 deletions src/main/java/hu/skawa/migrator_maven_plugin/DependencyExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public class DependencyExport extends AbstractMojo {

@Parameter(property = "addServers", defaultValue = "false")
private Boolean addServers;

private List<InternalDependency> allDependencies = new ArrayList<InternalDependency>();

private Pattern jarPattern = Pattern.compile("^.+?\\.[^javadoc]\\.jar\\>(.+?)\\=$", Pattern.MULTILINE);

private Pattern jarPattern =
Pattern.compile("^.+?\\.[^javadoc]\\.jar\\>(.+?)\\=$", Pattern.MULTILINE);
@SuppressWarnings("unused")
private Pattern pomPattern = Pattern.compile("^.+?pom\\>(.+?)\\=$", Pattern.MULTILINE);

Expand All @@ -87,45 +88,47 @@ public void execute() throws MojoExecutionException {
try {
String remoteDescriptorContent = Files.toString(remotes, StandardCharsets.UTF_8);
getLog().debug(remoteDescriptorContent);
Matcher jarServerMatcher = jarPattern.matcher(remoteDescriptorContent);
while (jarServerMatcher.find()) {
String server = jarServerMatcher.group(1);
if (server != null) {
id.setJarServer(server);
} else {
id.setJarServer("");
}
Matcher jarServerMatcher = jarPattern.matcher(remoteDescriptorContent);
while (jarServerMatcher.find()) {
String server = jarServerMatcher.group(1);
if (server != null) {
id.setJarServer(server);
} else {
id.setJarServer("");
}
}
} catch (IOException e) {
getLog().warn("Could not locate repo");
getLog().warn("Could not locate repository file for " + arti.getArtifactId() + ", setting to empty!");
id.setJarServer("");
}
allDependencies.add(id);
}

try {
for (InternalDependency dep : allDependencies) {
if (outputFilePrefix != null) {
if (outputFilePrefix != null) {
File directives = new File(outputFilePrefix + "-directives");
File references = new File(outputFilePrefix + "-references");

try (
FileWriter directiveWriter = new FileWriter(directives);
FileWriter referenceWriter = new FileWriter(references);
) {
for (InternalDependency dep : allDependencies) {
if (outputDirectives) {
File directives = new File(outputFilePrefix + "-directives");
FileWriter directiveWriter = new FileWriter(directives);
directiveWriter.write(dep.toBazelDirective(addHashes, addServers));
directiveWriter.write("\n");
directiveWriter.close();
directiveWriter.append(dep.toBazelDirective(addHashes, addServers));
directiveWriter.append("\n");
}
if (outputReferences) {
File references = new File(outputFilePrefix + "-references");
FileWriter referenceWriter = new FileWriter(references);
referenceWriter
.write(dep.getArtifactId() + ": @" + dep.getBazelName() + "//jar");
referenceWriter.write("\n");
referenceWriter.close();
referenceWriter.append(dep.getArtifactId() + ": @" + dep.getBazelName() + "//jar");
referenceWriter.append("\n");
}
} else {
getLog().info(dep.toBazelDirective(addHashes, addServers));
}
} catch (IOException e) {
getLog().error(e);
}
} else {
for (InternalDependency dep : allDependencies) {
getLog().info(dep.toBazelDirective(addHashes, addServers));
}
} catch (IOException e) {
getLog().error(e);
}
}
}

0 comments on commit 491f9b7

Please sign in to comment.