You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2019/05/14 15:16:31 UTC

[sling-org-apache-sling-feature-cpconverter] branch master updated: Took the Bundle Name extraction outside of the loop and adjusted the variable names

This is an automated email from the ASF dual-hosted git repository.

andysch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new 08f3db8  Took the Bundle Name extraction outside of the loop and adjusted the variable names
08f3db8 is described below

commit 08f3db85033521229d19b3b75a9466473af29981
Author: Andreas Schaefer <ac...@Andreass-iMac.local>
AuthorDate: Tue May 14 08:16:17 2019 -0700

    Took the Bundle Name extraction outside of the loop and adjusted the variable names
---
 .../cpconverter/handlers/BundleEntryHandler.java   | 37 +++++++++++-----------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
index 3135a7b..63b9533 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
@@ -116,15 +116,27 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
     }
 
     // method visibility set to 'protected' fot testing purposes
-    protected Properties readGav(String bundleName, JarInputStream jarInput) throws IOException {
+    protected Properties readGav(String entryName, JarInputStream jarInput) throws IOException {
         Properties properties = new Properties();
 
+        String bundleName = entryName;
+        // Remove the leading path
+        int idx = bundleName.lastIndexOf('/');
+        if (idx >= 0) {
+            bundleName = bundleName.substring(idx + 1);
+        }
+        // Remove the extension
+        int edx = bundleName.lastIndexOf('.');
+        if (edx > 0) {
+            bundleName = bundleName.substring(0, edx);
+        }
+
         JarEntry jarEntry;
         dance : while ((jarEntry = jarInput.getNextJarEntry()) != null) {
-            String entryName = jarEntry.getName();
+            String nextEntryName = jarEntry.getName();
 
-            if (pomPropertiesPattern.matcher(entryName).matches()) {
-                logger.info("Reading '{}' bundle GAV from {}...", bundleName, entryName);
+            if (pomPropertiesPattern.matcher(nextEntryName).matches()) {
+                logger.info("Reading '{}' bundle GAV from {}...", bundleName, nextEntryName);
 
                 properties.load(jarInput);
 
@@ -135,26 +147,15 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
                     continue;
                 }
 
-                String currentName = bundleName;
-                int idx = currentName.lastIndexOf('/');
-                if (idx >= 0) {
-                    currentName = currentName.substring(idx + 1);
-                }
-
-                int edx = currentName.lastIndexOf('.');
-                if (edx > 0) {
-                    currentName = currentName.substring(0, edx);
-                }
-
                 // bundleName is now the bare name without extension
                 String synthesized = artifactId + "-" + version;
 
                 // it was the pom.properties  we were looking for
-                if (currentName.startsWith(synthesized)) {
+                if (bundleName.startsWith(synthesized)) {
 
                     // check the artifact has a classifier in the bundle file name
-                    if (synthesized.length() < currentName.length()) {
-                        String suffix = currentName.substring(synthesized.length());
+                    if (synthesized.length() < bundleName.length()) {
+                        String suffix = bundleName.substring(synthesized.length());
                         if (suffix.length() > 1 && suffix.startsWith("-")) {
                             String classifier = suffix.substring(1);
                             logger.info("Inferred classifier of '"