You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/08/11 14:19:11 UTC
[sling-maven-plugin] 01/01: SLING-11524 Always retrieve bundle file from project artifact's
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/use-attached-artifacts
in repository https://gitbox.apache.org/repos/asf/sling-maven-plugin.git
commit 14e2c8c312ddaaed11d2d9e2b8cd34e28457a238
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Aug 11 16:19:06 2022 +0200
SLING-11524 Always retrieve bundle file from project artifact's
---
.../bundlesupport/AbstractBundleRequestMojo.java | 19 +++---------
.../maven/bundlesupport/BundleInstallMojo.java | 34 +++++++++++++++-------
2 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleRequestMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleRequestMojo.java
index d92083f..8203640 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleRequestMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleRequestMojo.java
@@ -41,6 +41,7 @@ import org.apache.hc.core5.util.Timeout;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Parameter;
+import org.osgi.framework.Constants;
abstract class AbstractBundleRequestMojo extends AbstractMojo {
@@ -117,9 +118,7 @@ abstract class AbstractBundleRequestMojo extends AbstractMojo {
return null;
}
- JarFile jaf = null;
- try {
- jaf = new JarFile(jarFile);
+ try (JarFile jaf = new JarFile(jarFile)) {
Manifest manif = jaf.getManifest();
if (manif == null) {
getLog().debug(
@@ -127,8 +126,7 @@ abstract class AbstractBundleRequestMojo extends AbstractMojo {
return null;
}
- String symbName = manif.getMainAttributes().getValue(
- "Bundle-SymbolicName");
+ String symbName = manif.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
if (symbName == null) {
getLog().debug(
"getBundleSymbolicName: No Bundle-SymbolicName in "
@@ -140,16 +138,7 @@ abstract class AbstractBundleRequestMojo extends AbstractMojo {
} catch (IOException ioe) {
getLog().warn("getBundleSymbolicName: Problem checking " + jarFile,
ioe);
- } finally {
- if (jaf != null) {
- try {
- jaf.close();
- } catch (IOException ignore) {
- // don't care
- }
- }
- }
-
+ }
// fall back to not being a bundle
return null;
}
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
index 6ecc098..fbd636e 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
@@ -19,13 +19,15 @@ package org.apache.sling.maven.bundlesupport;
import java.io.File;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
/**
- * Install a local OSGi bundle file to a running Sling instance.
+ * Install the project's artifact to a running Sling instance (in case it is an OSGi bundle).
+ * It uses the first valid OSGi bundle file for deployment from the primary artifact and all secondary ones.
* For details refer to <a href="bundle-installation.html">Bundle Installation</a>.
*/
@Mojo(name = "install", defaultPhase = LifecyclePhase.INSTALL)
@@ -37,12 +39,6 @@ public class BundleInstallMojo extends AbstractBundleInstallMojo {
*/
@Parameter(property = "sling.install.skip", defaultValue = "false", required = true)
private boolean skip;
-
- /**
- * The path of the bundle file to install.
- */
- @Parameter(property = "sling.file", defaultValue = "${project.build.directory}/${project.build.finalName}.jar", required = true)
- private File bundleFileName;
@Override
public void execute() throws MojoExecutionException {
@@ -51,12 +47,30 @@ public class BundleInstallMojo extends AbstractBundleInstallMojo {
getLog().debug("Skipping bundle installation as instructed");
return;
}
-
super.execute();
}
-
+
@Override
protected File getBundleFileName() {
- return bundleFileName;
+ File file = project.getArtifact().getFile();
+ if (isBundleFile(file)) {
+ return file;
+ } else {
+ getLog().debug("No bundle found in primary artifact " + file + ", checking secondary ones...");
+ for (Artifact artifact : project.getAttachedArtifacts()) {
+ if (isBundleFile(artifact.getFile())) {
+ return file;
+ }
+ getLog().debug("No bundle found in secondary artifact " + file);
+ }
+ }
+ return null;
+ }
+
+ private boolean isBundleFile(File file) {
+ if (file == null) {
+ return false;
+ }
+ return getBundleSymbolicName(file) != null;
}
}
\ No newline at end of file