Skip to content

Commit

Permalink
Merge pull request #8 from zmeggyesi/modular-projects
Browse files Browse the repository at this point in the history
Modular projects, closes #5
  • Loading branch information
zmeggyesi authored Dec 9, 2016
2 parents 4faa35c + f6aca86 commit 94dacc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ Used to generate a Bazel-compatible listing of all dependencies transitively. Pr

## Preparation

- Clone the repo and run `mvn install` to install the plugin in your local repo before running
Clone the repo and run `mvn install` to install the plugin in your local repo before running.

If you're looking to build a specific version, first you'll need to check out the appropriate tag/commit, and change the version number in the POM plugin declaration!

## Injecting

```
<plugin>
<groupId>hu.skawa</groupId>
<artifactId>migrator-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</plugin>
```

Expand All @@ -21,8 +23,8 @@ Used to generate a Bazel-compatible listing of all dependencies transitively. Pr
- Global
- `outputFilePrefix[String]`: Determines the prefix of the output files. If set, console output is suppressed and directed to the selected files.
- Dependency Export
- `outputDirectives[Boolean:true|false]`: Instructs the Migrator to output the `WORKSPACE` directives into a file named `${outputFilePrefix}-directives`
- `outputReferences[Boolean:true|false]`: Instructs the Migrator to output the `BUILD` directives into a file named `${outputFilePrefix}-references`
- `outputDirectives[Boolean:true|false]`: Instructs the Migrator to output the `WORKSPACE` directives into a file named `${outputFilePrefix}-${projectName}-directives`
- `outputReferences[Boolean:true|false]`: Instructs the Migrator to output the `BUILD` directives into a file named `${outputFilePrefix}-${projectName}-references`. Defaults to false.
- `addHashes[Boolean:true|false]`: Instructs the Migrator to add SHA1 hashes of each artifact to the `WORKSPACE` directives. Defaults to false.
- `addServers[Boolean:true|false]`: Instructs the Migrator to add the last server where the artifact was downloaded from. Uses only the JAR server, not the POM server, as Bazel only seems to care where the JAR can be downloaded from.

Expand All @@ -34,4 +36,10 @@ The export assumes that your personal/global settings are in their default place

## Use

Run the plugin by executing `mvn hu.skawa:migrator-maven-plugin:${GOAL}`, optionally adding the above parameters
Run the plugin by executing `mvn hu.skawa:migrator-maven-plugin:${GOAL}`, optionally adding the above parameters.

If you have a modular project, the build *will* invoke the reactor, and the plugin is executed for each project in turn. This will result in multiple output files, each prefixed by your chosen prefix and the project name.

## Known issues

- The plugin relies on the presence of the Aether `_remote.repositories` file beside the artifacts to determine the latest server it was resolved from. If not found, a warning is emitted and the server name will be empty.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

<name>Maven-Bazel Migration Plugin</name>
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/hu/skawa/migrator_maven_plugin/DependencyExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class DependencyExport extends AbstractMojo {
@Parameter(property = "outputDirectives")
private Boolean outputDirectives;

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

@Parameter(property = "addHashes", defaultValue = "false")
Expand All @@ -66,8 +66,7 @@ public class DependencyExport extends AbstractMojo {

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 @@ -82,8 +81,7 @@ public void execute() throws MojoExecutionException {
} catch (IOException e) {
throw new MojoExecutionException("Dependency could not be hashed!", e);
}
InternalDependency id = new InternalDependency(arti.getGroupId(), arti
.getArtifactId(), arti.getVersion(), hash);
InternalDependency id = new InternalDependency(arti.getGroupId(), arti.getArtifactId(), arti.getVersion(), hash);
File remotes = new File(file.getParent() + File.separator + "_remote.repositories");
try {
String remoteDescriptorContent = Files.toString(remotes, StandardCharsets.UTF_8);
Expand All @@ -105,13 +103,12 @@ public void execute() throws MojoExecutionException {
}

if (outputFilePrefix != null) {
File directives = new File(outputFilePrefix + "-directives");
File references = new File(outputFilePrefix + "-references");
File directives = new File(outputFilePrefix + "-" + project.getName() + "-directives");
File references = new File(outputFilePrefix + "-" + project.getName() + "-references");

try (
try (
FileWriter directiveWriter = new FileWriter(directives);
FileWriter referenceWriter = new FileWriter(references);
) {
FileWriter referenceWriter = new FileWriter(references);) {
for (InternalDependency dep : allDependencies) {
if (outputDirectives) {
directiveWriter.append(dep.toBazelDirective(addHashes, addServers));
Expand All @@ -124,7 +121,7 @@ public void execute() throws MojoExecutionException {
}
} catch (IOException e) {
getLog().error(e);
}
}
} else {
for (InternalDependency dep : allDependencies) {
getLog().info(dep.toBazelDirective(addHashes, addServers));
Expand Down

0 comments on commit 94dacc2

Please sign in to comment.