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

maven: Compute extension from packaging type #5309

Merged
merged 2 commits into from Jul 5, 2022
Merged
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-baseline-maven-plugin/pom.xml
Expand Up @@ -11,8 +11,8 @@
</parent>

<artifactId>bnd-baseline-maven-plugin</artifactId>
<description>This maven plugin is used to baseline OSGi bundles.</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd baseline maven plugin is used to baseline OSGi bundles.</description>
<name>Bnd Baseline Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-export-maven-plugin/pom.xml
Expand Up @@ -9,8 +9,8 @@
<relativePath>../bnd-plugin-parent</relativePath>
</parent>
<artifactId>bnd-export-maven-plugin</artifactId>
<description>Resolve and Export OSGi applications.</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd export maven plugin can be used to export OSGi applications.</description>
<name>Bnd Export Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-indexer-maven-plugin/pom.xml
Expand Up @@ -11,8 +11,8 @@
</parent>

<artifactId>bnd-indexer-maven-plugin</artifactId>
<description>This maven plugin is used to make OSGi indexes from lists of maven dependencies.</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd indexer maven plugin is used to make OSGi indexes from lists of maven dependencies.</description>
<name>Bnd Indexer Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-maven-plugin/pom.xml
Expand Up @@ -11,8 +11,8 @@
</parent>

<artifactId>bnd-maven-plugin</artifactId>
<description>This maven plugin is used to build OSGi bundles using the bnd tool for generating MANIFEST.MF and other OSGi-specific artifacts.</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd maven plugin is used to build OSGi bundles using bnd for generating MANIFEST.MF and other OSGi-specific artifacts.</description>
<name>Bnd Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
Expand Up @@ -40,6 +40,8 @@
import java.util.zip.ZipFile;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.model.Developer;
import org.apache.maven.model.License;
Expand Down Expand Up @@ -80,6 +82,9 @@
import aQute.lib.utf8properties.UTF8Properties;
import aQute.service.reporter.Report.Location;

/**
* Abstract base class for all bnd-maven-plugin mojos.
*/
public abstract class AbstractBndMavenPlugin extends AbstractMojo {
protected final Logger logger = LoggerFactory.getLogger(getClass());
static final String MANIFEST_LAST_MODIFIED = "aQute.bnd.maven.plugin.BndMavenPlugin.manifestLastModified";
Expand All @@ -90,11 +95,18 @@ public abstract class AbstractBndMavenPlugin extends AbstractMojo {
static final String SNAPSHOT = "SNAPSHOT";

@Parameter(defaultValue = "${project.build.directory}", readonly = true)
File targetDir;
File buildDir;

/**
* Whether to include the contents of the {@code classesDir} directory
* in the generated bundle.
*/
@Parameter(defaultValue = "true")
boolean includeClassesDir;

/**
* The directory where this plugin will store its output when packaging is {@code war}.
*/
@Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}")
File warOutputDir;

Expand All @@ -107,14 +119,27 @@ public abstract class AbstractBndMavenPlugin extends AbstractMojo {
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
MojoExecution mojoExecution;

/**
* The list of maven packaging types for which the plugin will execute.
*/
@Parameter(property = "bnd.packagingTypes", defaultValue = PACKAGING_JAR + "," + PACKAGING_WAR)
List<String> packagingTypes;

/**
* Skip processing if {@link #includeClassesDir} is {@code true} and the
* {@code classesDir} directory is empty.
*/
@Parameter(property = "bnd.skipIfEmpty", defaultValue = "false")
boolean skipIfEmpty;

/**
* If set, the generated output will be reproducible.
*
* @see <a href="https://maven.apache.org/guides/mini/guide-reproducible-builds.html">Configuring
* for Reproducible Builds</a>
*/
@Parameter(defaultValue = "${project.build.outputTimestamp}")
private String outputTimestamp;
String outputTimestamp;

/**
* File path to a bnd file containing bnd instructions for this project.
Expand Down Expand Up @@ -149,6 +174,9 @@ public abstract class AbstractBndMavenPlugin extends AbstractMojo {
@Component
MavenProjectHelper projectHelper;

@Component
private ArtifactHandlerManager artifactHandlerManager;

File propertiesFile;

public abstract File getSourceDir();
Expand Down Expand Up @@ -208,7 +236,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

builder.setBase(project.getBasedir());
propertiesFile = loadProperties(builder);
builder.setProperty("project.output", targetDir.getCanonicalPath());
builder.setProperty("project.output", buildDir.getCanonicalPath());

// If no bundle to be built, we have nothing to do
if (Processor.isTrue(builder.getProperty(Constants.NOBUNDLES))) {
Expand All @@ -225,12 +253,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// always add the outputDirectory to the classpath, but
// handle projects with no output directory, like
// 'test-wrapper-bundle'
if (getClassesDir().isDirectory()) {
builder.addClasspath(getClassesDir());
if (classesDir.isDirectory()) {
builder.addClasspath(classesDir);

Jar classesDirJar;
if (includeClassesDir) {
classesDirJar = new Jar(project.getName(), getClassesDir());
classesDirJar = new Jar(project.getName(), classesDir);
} else {
classesDirJar = new Jar(project.getName()); // empty jar
}
Expand Down Expand Up @@ -574,10 +602,10 @@ private static StringBuilder addHeaderAttribute(StringBuilder builder, String ke

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

if (!outputDir.exists()) {
IO.mkdirs(outputDir);
if (!parent.exists()) {
IO.mkdirs(parent);
}

try (OutputStream os = buildContext.newFileOutputStream(artifactFile)) {
Expand Down Expand Up @@ -621,11 +649,19 @@ private void addMavenMetadataToJar(Jar bndJar) throws IOException {
}

private File createArtifactFile() {
return new File(targetDir, project.getBuild()
return new File(buildDir, project.getBuild()
.getFinalName()
+ getClassifier().map("-"::concat)
.orElse("")
+ "." + project.getPackaging());
+ "." + getExtension(project.getPackaging()));
}

private String getExtension(String type) {
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(type);
if (artifactHandler != null) {
type = artifactHandler.getExtension();
}
return type;
}

private String createArtifactName(Artifact artifact) {
Expand Down
Expand Up @@ -7,9 +7,18 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* Generate OSGi metadata for the target classes and
* package into a jar.
* <p>
* This goal has the default phase of "package".
*/
@Mojo(name = "jar", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class BndMavenPackagingPlugin extends BndMavenPlugin {

/**
* The classifier to use for the generated artifact.
*/
@Parameter
private String classifier;

Expand Down
Expand Up @@ -7,9 +7,18 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* Generate OSGi metadata for the test target classes and
* package into a jar.
* <p>
* This goal has the default phase of "package".
*/
@Mojo(name = "test-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class BndMavenPackagingTestsPlugin extends BndMavenTestsPlugin {

/**
* The classifier to use for the generated artifact.
*/
@Parameter(defaultValue = "tests")
private String classifier;

Expand Down
Expand Up @@ -9,6 +9,11 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* Processes the target classes to generate OSGi metadata.
* <p>
* This goal has the default phase of "process-classes".
*/
@Mojo(name = "bnd-process", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class BndMavenPlugin extends AbstractBndMavenPlugin {

Expand All @@ -18,15 +23,27 @@ public class BndMavenPlugin extends AbstractBndMavenPlugin {
@Parameter(defaultValue = "${project.build.resources}", readonly = true)
private List<org.apache.maven.model.Resource> resources;

/**
* The directory where the {@code maven-compiler-plugin} places its output.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}")
private File classesDir;

/**
* The directory where this plugin will store its output.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}")
private File outputDir;

/**
* Specify the path to store the generated manifest file.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}/META-INF/MANIFEST.MF")
File manifestPath;

/**
* Skip this goal.
*/
@Parameter(property = "bnd.skip", defaultValue = "false")
boolean skip;

Expand Down
Expand Up @@ -29,10 +29,17 @@
import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Constants;

/**
* Processes the test target classes to generate OSGi metadata.
* <p>
* This goal has the default phase of "process-test-classes".
*/
@Mojo(name = "bnd-process-tests", defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
public class BndMavenTestsPlugin extends AbstractBndMavenPlugin {

/**
* Whether the test artifact is an OSGi fragment.
* <p>
* If true, make the tests artifact a fragment using
* <code>$&#123;project.artifactId&#125;</code> as the {@code Fragment-Host}
* header and setting the {@code Bundle-SymbolicName} of the tests artifact
Expand All @@ -42,6 +49,9 @@ public class BndMavenTestsPlugin extends AbstractBndMavenPlugin {
private boolean artifactFragment;

/**
* The test case types to generate into the {@code Test-Cases}
* manifest header.
* <p>
* Possible values are {@link TestCases#junit3 junit3},
* {@link TestCases#junit4 junit4}, {@link TestCases#junit5 junit5},
* {@link TestCases#all all}, {@link TestCases#testng testng}, and
Expand All @@ -56,21 +66,41 @@ public class BndMavenTestsPlugin extends AbstractBndMavenPlugin {
@Parameter(defaultValue = "${project.build.testResources}", readonly = true)
private List<org.apache.maven.model.Resource> resources;

@Parameter(defaultValue = "${project.build.outputDirectory}", readonly = true, required = false)
/**
* The directory where the {@code maven-compiler-plugin} placed the main output.
*/
@Parameter(defaultValue = "${project.build.outputDirectory}")
private File mainClassesDir;

@Parameter(defaultValue = "${project.build.testOutputDirectory}", readonly = true)
/**
* The directory where the {@code maven-compiler-plugin} places its output.
*/
@Parameter(defaultValue = "${project.build.testOutputDirectory}")
private File classesDir;

@Parameter(defaultValue = "${project.build.testOutputDirectory}", readonly = true)
/**
* The directory where this plugin will store its output.
*/
@Parameter(defaultValue = "${project.build.testOutputDirectory}")
private File outputDir;

@Parameter(defaultValue = "${project.build.testOutputDirectory}/META-INF/MANIFEST.MF", readonly = true)
/**
* Specify the path to store the generated manifest file.
*/
@Parameter(defaultValue = "${project.build.testOutputDirectory}/META-INF/MANIFEST.MF")
private File manifestPath;

/**
* Skip this goal. The goal can also be skipped with the {@link #skipGoal}
* configuration.
*/
@Parameter(property = "maven.test.skip", defaultValue = "false")
private boolean skip;

/**
* Skip this goal. The goal can also be skipped with the {@link #skip}
* configuration.
*/
@Parameter(property = "bnd-tests.skip", defaultValue = "false")
private boolean skipGoal;

Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-reporter-maven-plugin/pom.xml
Expand Up @@ -9,8 +9,8 @@
<relativePath>../bnd-plugin-parent</relativePath>
</parent>
<artifactId>bnd-reporter-maven-plugin</artifactId>
<description>Generates and exports reports of projects</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd reporter maven plugin generates and exports reports of projects.</description>
<name>Bnd Reporter Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>http://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-resolver-maven-plugin/pom.xml
Expand Up @@ -9,8 +9,8 @@
<relativePath>../bnd-plugin-parent</relativePath>
</parent>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<description>Resolves the -runbundles for an OSGi bndrun file</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd resolver maven plugin resolves the -runbundles for a bndrun file.</description>
<name>Bnd Resolver Maven Plugins</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-run-maven-plugin/pom.xml
Expand Up @@ -9,8 +9,8 @@
<relativePath>../bnd-plugin-parent</relativePath>
</parent>
<artifactId>bnd-run-maven-plugin</artifactId>
<description>Run an OSGi bndrun file</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd run maven plugin is used to run a bndrun file.</description>
<name>Bnd Run Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down
4 changes: 2 additions & 2 deletions maven/bnd-testing-maven-plugin/pom.xml
Expand Up @@ -9,8 +9,8 @@
<relativePath>../bnd-plugin-parent</relativePath>
</parent>
<artifactId>bnd-testing-maven-plugin</artifactId>
<description>Run the tests from an OSGi bndrun file</description>
<name>${project.groupId}:${project.artifactId}</name>
<description>The bnd testing maven plugin is used to run the tests from a bndrun file.</description>
<name>Bnd Testing Maven Plugin</name>
<packaging>maven-plugin</packaging>
<url>https://bnd.bndtools.org/</url>
<scm>
Expand Down