You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:25:35 UTC
[sling-org-apache-sling-commons-osgi] 09/19: SLING-5379 - add
BSNRenamer
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.commons.osgi-2.4.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-osgi.git
commit ad893b85cf3584bcf7ca5c8fbb81ce0d07eb066e
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Dec 21 16:20:50 2015 +0000
SLING-5379 - add BSNRenamer
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi@1721206 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/commons/osgi/BSNRenamer.java | 58 ++++++++++++++++++++++
.../commons/osgi/BundleFileProcessorTest.java | 27 ----------
2 files changed, 58 insertions(+), 27 deletions(-)
diff --git a/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java b/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
new file mode 100644
index 0000000..faf6730
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/osgi/BSNRenamer.java
@@ -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";
+ }
+}
diff --git a/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java b/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
index c8d67b4..09822b9 100644
--- a/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
+++ b/src/test/java/org/apache/sling/commons/osgi/BundleFileProcessorTest.java
@@ -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"));
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.