Author: bdelacretaz
Date: Mon Dec 21 16:20:50 2015
New Revision: 1721206

URL: http://svn.apache.org/viewvc?rev=1721206&view=rev
Log:
SLING-5379 - add BSNRenamer

Added:
    
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
Modified:
    
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
    
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java

Added: 
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java?rev=1721206&view=auto
==============================================================================
--- 
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
 (added)
+++ 
sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
 Mon Dec 21 16:20:50 2015
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.osgi;
+
+import java.io.File;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/** Processes a bundle file by changing its Bundle-SymbolicName.
+ *  The original BSN is copied to a an {@link #X_ORIG_BSN} header,
+ *  to allow users to find out what happened.
+ * @since 2.4
+ */
+public class BSNRenamer extends BundleFileProcessor {
+    private final String newBSN;
+    public static final String BUNDLE_SYMBOLIC_NAME = "Bundle-SymbolicName";
+    public static final String X_ORIG_BSN = "X-Original-Bundle-SymbolicName"; 
+    public static final String BUNDLE_VERSION = "Bundle-Version"; 
+    
+    public BSNRenamer(File input, File outputFolder, String newBSN) {
+        super(input, outputFolder);
+        this.newBSN = newBSN;
+    }
+    
+    protected Manifest processManifest(Manifest inputMF) {
+        Attributes inputAttrs = inputMF.getMainAttributes();
+        String orgBSN = inputAttrs.getValue(BUNDLE_SYMBOLIC_NAME);
+        Manifest newMF = new Manifest(inputMF);
+        Attributes outputAttrs = newMF.getMainAttributes();
+        outputAttrs.putValue(BUNDLE_SYMBOLIC_NAME, newBSN);
+        outputAttrs.putValue(X_ORIG_BSN, orgBSN);
+        return newMF;
+    }
+    
+    protected String getTargetFilename(Manifest inputJarManifest) {
+        String bver = 
inputJarManifest.getMainAttributes().getValue(BUNDLE_VERSION);
+        if (bver == null) {
+            bver = "0.0.0";
+        }
+        return newBSN + "-" + bver + ".jar";
+    }
+}

Modified: 
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java?rev=1721206&r1=1721205&r2=1721206&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
 (original)
+++ 
sling/trunk/bundles/commons/osgi/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
 Mon Dec 21 16:20:50 2015
@@ -46,33 +46,6 @@ public class BundleFileProcessorTest {
         }
     }
     
-    static class BSNRenamer extends BundleFileProcessor {
-        private final String newBSN;
-        
-        BSNRenamer(File input, File outputFolder, String newBSN) {
-            super(input, outputFolder);
-            this.newBSN = newBSN;
-        }
-        
-        protected Manifest processManifest(Manifest inputMF) {
-            Attributes inputAttrs = inputMF.getMainAttributes();
-            String orgBSN = inputAttrs.getValue("Bundle-SymbolicName");
-            Manifest newMF = new Manifest(inputMF);
-            Attributes outputAttrs = newMF.getMainAttributes();
-            outputAttrs.putValue("Bundle-SymbolicName", newBSN);
-            outputAttrs.putValue("X-Original-Bundle-SymbolicName", orgBSN);
-            return newMF;
-        }
-        
-        protected String getTargetFilename(Manifest inputJarManifest) {
-            String bver = 
inputJarManifest.getMainAttributes().getValue("Bundle-Version");
-            if (bver == null) {
-                bver = "0.0.0";
-            }
-            return newBSN + "-" + bver + ".jar";
-        }
-    }
-    
     @Test
     public void testBSNRenaming() throws IOException {
         File tempDir = new File(System.getProperty("java.io.tmpdir"));

Modified: 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java?rev=1721206&r1=1721205&r2=1721206&view=diff
==============================================================================
--- 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
 (original)
+++ 
sling/trunk/tooling/maven/slingstart-maven-plugin/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
 Mon Dec 21 16:20:50 2015
@@ -48,7 +48,7 @@ import org.apache.maven.plugins.annotati
 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.BundleFileProcessor;
+import org.apache.sling.commons.osgi.BSNRenamer;
 import org.apache.sling.provisioning.model.ArtifactGroup;
 import org.apache.sling.provisioning.model.Configuration;
 import org.apache.sling.provisioning.model.Feature;
@@ -87,34 +87,6 @@ public class PreparePackageMojo extends
 
     private static final String PROPERTIES_FILE = "sling_install.properties";
 
-    /** BundleFileProcessor that can change the bundle symbolic name */ 
-    static class BSNRenamer extends BundleFileProcessor {
-        private final String newBSN;
-        
-        BSNRenamer(File input, File outputFolder, String newBSN) {
-            super(input, outputFolder);
-            this.newBSN = newBSN;
-        }
-        
-        protected Manifest processManifest(Manifest inputMF) {
-            Attributes inputAttrs = inputMF.getMainAttributes();
-            String orgBSN = inputAttrs.getValue("Bundle-SymbolicName");
-            Manifest newMF = new Manifest(inputMF);
-            Attributes outputAttrs = newMF.getMainAttributes();
-            outputAttrs.putValue("Bundle-SymbolicName", newBSN);
-            outputAttrs.putValue("X-Original-Bundle-SymbolicName", orgBSN);
-            return newMF;
-        }
-        
-        protected String getTargetFilename(Manifest inputJarManifest) {
-            String bver = 
inputJarManifest.getMainAttributes().getValue("Bundle-Version");
-            if (bver == null) {
-                bver = "0.0.0";
-            }
-            return newBSN + "-" + bver + ".jar";
-        }
-    }
-
     /**
      * To look up Archiver/UnArchiver implementations
      */


Reply via email to