Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP:[maven] use outputDir and waroutputDir correctly #5176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions maven/bnd-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ The `jar` goal is not executed by default, therefore at least one explicit execu
|`classifier` | A string added to the artifact indicating a supplemental artifact produced by the project. If no value is provided it indicates the main artifact produced by the project. _Defaults to no value_.||`manifestPath` | Specify the path to a manifest file to use. _Defaults to `${project.build.outputDirectory}/META-INF/MANIFEST.MF`._|
|`classesDir` | The directory where the `maven-compiler-plugin` places its output. _Defaults to `${project.build.outputDirectory}`._|
|`includeClassesDir` | Include the entire contents of `classesDir` in the bundle. *Defaults to `true`*. |
|`outputDir` | The directory where the `bnd-maven-plugin` will extract it's contents. _Defaults to `${project.build.outputDirectory}`._|
|`warOutputDir` | The directory where the `bnd-maven-plugin` will extract it's contents when packaging is `war`. _Defaults to `${project.build.directory}/${project.build.finalName}`._|
|`outputDir` | The directory where the `bnd-maven-plugin` will place the jar when packaging. _Defaults to `${project.build.directory}`._|
|`warOutputDir` | The directory where the `bnd-maven-plugin` will place the war when packaging is `war`. _Defaults to `${project.build.directory}`._|
|`packagingTypes` | The list of maven packaging types for which the plugin will execute. *Defaults to `jar,war`*. Override with property `bnd.packagingTypes`. |
|`skip` | Skip the project. _Defaults to `false`._ Override with property `bnd.skip`.|
|`skipIfEmpty` | Skip processing if `includeClassesDir` is `true` and the `${project.build.outputDirectory}` is empty. _Defaults to `false`._ Override with property `bnd.skipIfEmpty`.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (wabProperty == null) {
builder.setProperty(Constants.WAB, "");
}
outputDir = warOutputDir;
outputDir = getWarOutputDir();
logger
.info("WAB mode enabled. Bnd output will be expanded into the 'maven-war-plugin' <webappDirectory>:"
+ outputDir);
Expand Down Expand Up @@ -508,14 +508,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// Add META-INF/maven metadata to jar
addMavenMetadataToJar(bndJar);
// Write the jar directly and attach it to the project
attachArtifactToProject(bndJar);
attachArtifactToProject(bndJar, outputDir);
} else {
throw new MojoExecutionException(String.format(
"In order to use the bnd-maven-plugin packaging goal %s, <extensions>true</extensions> must be set on the plugin",
goal));
}
} else {
// Expand Jar into target/classes
// Expand Jar into outputDir
expandJar(bndJar, outputDir);
}
} else {
Expand All @@ -531,6 +531,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

protected File getWarOutputDir() {
return warOutputDir;
}

/**
* If a mojo needs to tweak the builder for any particular reason, do it
* here.
Expand Down Expand Up @@ -569,9 +573,8 @@ private static StringBuilder addHeaderAttribute(StringBuilder builder, String ke
return builder;
}

private void attachArtifactToProject(Jar bndJar) throws Exception {
File artifactFile = createArtifactFile();
File outputDir = artifactFile.getParentFile();
private void attachArtifactToProject(Jar bndJar, File outputDir) throws Exception {
File artifactFile = createArtifactFile(outputDir);

if (!outputDir.exists()) {
IO.mkdirs(outputDir);
Expand Down Expand Up @@ -617,8 +620,8 @@ private void addMavenMetadataToJar(Jar bndJar) throws IOException {
bndJar.putResource(pomProperties.getWhere(), pomProperties);
}

private File createArtifactFile() {
return new File(targetDir, project.getBuild()
private File createArtifactFile(File outputDir) {
return new File(outputDir, project.getBuild()
.getFinalName()
+ getClassifier().map("-"::concat)
.orElse("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aQute.bnd.maven.plugin;

import java.io.File;
import java.util.Optional;

import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -13,6 +14,22 @@ public class BndMavenPackagingPlugin extends BndMavenPlugin {
@Parameter
private String classifier;

@Parameter(defaultValue = "${project.build.directory}")
private File outputDir;

@Parameter(defaultValue = "${project.build.directory}")
private File warOutputDir;

@Override
public File getOutputDir() {
return outputDir;
}

@Override
protected File getWarOutputDir() {
return warOutputDir;
}

@Override
public Optional<String> getClassifier() {
return Optional.ofNullable(classifier)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aQute.bnd.maven.plugin;

import java.io.File;
import java.util.Optional;

import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -13,6 +14,14 @@ public class BndMavenPackagingTestsPlugin extends BndMavenTestsPlugin {
@Parameter(defaultValue = "tests")
private String classifier;

@Parameter(defaultValue = "${project.build.directory}")
private File outputDir;

@Override
public File getOutputDir() {
return outputDir;
}

@Override
public Optional<String> getClassifier() {
return Optional.ofNullable(classifier)
Expand Down