This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag slingstart-maven-plugin-1.4.0 in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git
commit f6075f8eb62c6234fdd2b0caa9656aa1aaf92248 Author: Bertrand Delacretaz <[email protected]> AuthorDate: Mon Dec 21 15:11:26 2015 +0000 SLING-5379 - support renaming of bundles in maven-slingstart-plugin. Contributed by David Bosschaert, thanks! git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/slingstart-maven-plugin@1721185 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 13 ++-- .../sling/maven/slingstart/PreparePackageMojo.java | 17 ++++- .../maven/slingstart/PreparePackageMojoTest.java | 87 +++++++++++++++++++++- 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 1d30ec8..acac9db 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.provisioning.model</artifactId> - <version>1.4.0</version> + <version>1.4.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> @@ -169,6 +169,11 @@ </exclusions> </dependency> <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.osgi</artifactId> + <version>2.3.1-SNAPSHOT</version> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> @@ -208,12 +213,6 @@ </dependency> <dependency> <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.osgi</artifactId> - <version>2.3.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.commons.threads</artifactId> <version>3.2.0</version> <scope>test</scope> diff --git a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java index 3871246..c845bab 100644 --- a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java +++ b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java @@ -48,6 +48,7 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.sling.commons.osgi.BundleUtil; import org.apache.sling.provisioning.model.ArtifactGroup; import org.apache.sling.provisioning.model.Configuration; import org.apache.sling.provisioning.model.Feature; @@ -231,7 +232,18 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { for(final org.apache.sling.provisioning.model.Artifact a : group) { final Artifact artifact = ModelUtils.getArtifact(this.project, this.mavenSession, this.artifactHandlerManager, this.resolver, a.getGroupId(), a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier()); - final File artifactFile = artifact.getFile(); + File artifactFile = artifact.getFile(); + + String newBSN = a.getMetadata().get("bundle:rename-bsn"); + if (newBSN != null) { + try { + getTmpDir().mkdirs(); + artifactFile = BundleUtil.renameBSN(artifactFile, newBSN, getTmpDir()); + } catch (IOException e) { + throw new MojoExecutionException("Unable to rename bundle BSN to " + newBSN + " for " + artifactFile, e); + } + } + contentsMap.put(getPathForArtifact(group.getStartLevel(), artifactFile.getName(), runMode, isBoot), artifactFile); } } @@ -264,7 +276,6 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { } } - private File createSubsystemBaseFile(Feature feature, AtomicInteger startLevelHolder) throws MojoExecutionException { File subsystemFile = new File(getTmpDir(), feature.getName() + ".subsystem-base"); if (subsystemFile.exists()) { @@ -354,7 +365,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo { attrs.putValue("Manifest-Version", "1.0"); // Manifest does not work without this value attrs.putValue("About-This-Manifest", "This is not a real manifest, it is used as information when this archive is transformed into a real subsystem .esa file"); for (Map.Entry<String, StringBuilder> entry : runModes.entrySet()) { - attrs.putValue(entry.getKey(), entry.getValue().toString()); + attrs.putValue(entry.getKey().replace(':', '_'), entry.getValue().toString()); } return mf; } diff --git a/src/test/java/org/apache/sling/maven/slingstart/PreparePackageMojoTest.java b/src/test/java/org/apache/sling/maven/slingstart/PreparePackageMojoTest.java index 4f8a427..353f74c 100644 --- a/src/test/java/org/apache/sling/maven/slingstart/PreparePackageMojoTest.java +++ b/src/test/java/org/apache/sling/maven/slingstart/PreparePackageMojoTest.java @@ -17,6 +17,7 @@ package org.apache.sling.maven.slingstart; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.StringReader; @@ -27,7 +28,9 @@ import java.nio.file.Path; import java.util.HashSet; import java.util.Set; import java.util.jar.Attributes; +import java.util.jar.JarEntry; import java.util.jar.JarFile; +import java.util.jar.JarInputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; @@ -52,7 +55,87 @@ import static org.junit.Assert.assertEquals; public class PreparePackageMojoTest { @Test - public void testSubsystemBaseGeneration1() throws Exception { + public void testBSNRenaming() throws Exception { + // Provide the system with some artifacts that are known to be in the local .m2 repo + // These are explicitly included in the test section of the pom.xml + PreparePackageMojo ppm = getMojoUnderTest( + "org.apache.sling/org.apache.sling.commons.classloader/1.3.2", + "org.apache.sling/org.apache.sling.commons.classloader/1.3.2/app", + "org.apache.sling/org.apache.sling.commons.json/2.0.12"); + try { + String modelTxt = "[feature name=:launchpad]\n" + + "[artifacts]\n" + + " org.apache.sling/org.apache.sling.commons.classloader/1.3.2\n" + + "" + + "[feature name=rename_test]\n" + + " org.apache.sling/org.apache.sling.commons.json/2.0.12 [bundle:rename-bsn=r-foo.bar.renamed.sling.commons.json]\n"; + + Model model = ModelReader.read(new StringReader(modelTxt), null); + ppm.execute(model); + + File orgJar = getMavenArtifactFile(getMavenRepoRoot(), "org.apache.sling", "org.apache.sling.commons.json", "2.0.12"); + File generatedJar = new File(ppm.getTmpDir() + "/r-foo.bar.renamed.sling.commons.json-2.0.12.jar"); + + compareJarContents(orgJar, generatedJar); + + try (JarFile jfOrg = new JarFile(orgJar); + JarFile jfNew = new JarFile(generatedJar)) { + Manifest mfOrg = jfOrg.getManifest(); + Manifest mfNew = jfNew.getManifest(); + + Attributes orgAttrs = mfOrg.getMainAttributes(); + Attributes newAttrs = mfNew.getMainAttributes(); + for (Object key : orgAttrs.keySet()) { + String orgVal = orgAttrs.getValue(key.toString()); + String newVal = newAttrs.getValue(key.toString()); + + if ("Bundle-SymbolicName".equals(key.toString())) { + assertEquals("Should have recorded the original Bundle-SymbolicName", + orgVal, newAttrs.getValue("X-Original-Bundle-SymbolicName")); + + assertEquals("r-foo.bar.renamed.sling.commons.json", newVal); + } else { + assertEquals("Different keys: " + key, orgVal, newVal); + } + } + } + } finally { + FileUtils.deleteDirectory(new File(ppm.project.getBuild().getDirectory())); + } + } + + private static void compareJarContents(File orgJar, File actualJar) throws IOException { + try (JarInputStream jis1 = new JarInputStream(new FileInputStream(orgJar)); + JarInputStream jis2 = new JarInputStream(new FileInputStream(actualJar))) { + JarEntry je1 = null; + while ((je1 = jis1.getNextJarEntry()) != null) { + if (je1.isDirectory()) + continue; + + JarEntry je2 = null; + while((je2 = jis2.getNextJarEntry()) != null) { + if (!je2.isDirectory()) + break; + } + + assertEquals(je1.getName(), je2.getName()); + assertEquals(je1.getSize(), je2.getSize()); + + try { + byte[] buf1 = IOUtils.toByteArray(jis1); + byte[] buf2 = IOUtils.toByteArray(jis2); + + assertArrayEquals("Contents not equal: " + je1.getName(), buf1, buf2); + } finally { + jis1.closeEntry(); + jis2.closeEntry(); + } + } + } + } + + @Test + public void testSubsystemBaseGeneration() throws Exception { // Provide the system with some artifacts that are known to be in the local .m2 repo // These are explicitly included in the test section of the pom.xml PreparePackageMojo ppm = getMojoUnderTest( @@ -84,7 +167,7 @@ public class PreparePackageMojoTest { " org.apache.sling/org.apache.sling.commons.json/2.0.12\n" + " org.apache.sling/org.apache.sling.commons.mime/2.1.8\n" + "" + - "[artifacts startLevel=20 runModes=foo,bar]\n" + + "[artifacts startLevel=20 runModes=foo,bar,:blah]\n" + " org.apache.sling/org.apache.sling.commons.threads/3.2.0\n" + "" + "[artifacts startLevel=100 runModes=bar]\n" + -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
