Author: cziegeler
Date: Wed Jul  5 13:19:15 2017
New Revision: 1800872

URL: http://svn.apache.org/viewvc?rev=1800872&view=rev
Log:
Create scanner and resolver package

Added:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactInfo.java
      - copied, changed from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/BundleInfo.java
      - copied, changed from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ManifestUtil.java
      - copied, changed from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ManifestUtil.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
      - copied, changed from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
   (with props)
Removed:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ManifestUtil.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
Modified:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Analyser.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundleExportsImports.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForInitialContent.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForResources.java

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Analyser.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Analyser.java?rev=1800872&r1=1800871&r2=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Analyser.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Analyser.java
 Wed Jul  5 13:19:15 2017
@@ -16,30 +16,23 @@
  */
 package org.apache.sling.feature.analyser;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.ServiceLoader;
 import java.util.Set;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
 
-import org.apache.sling.commons.osgi.ManifestHeader;
 import org.apache.sling.feature.Application;
-import org.apache.sling.feature.Artifact;
-import org.apache.sling.feature.Extension;
-import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.KeyValueMap;
+import org.apache.sling.feature.scanner.ArtifactInfo;
+import org.apache.sling.feature.scanner.BundleInfo;
+import org.apache.sling.feature.scanner.PackageInfo;
+import org.apache.sling.feature.scanner.Scanner;
 import org.apache.sling.feature.support.ArtifactManager;
 import org.apache.sling.feature.support.ArtifactManagerConfig;
-import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,6 +42,8 @@ public class Analyser {
 
     private final ArtifactManager artifactManager;
 
+    private final Scanner scanner;
+
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     public Analyser(final ArtifactManagerConfig amConfig,
@@ -56,37 +51,33 @@ public class Analyser {
     throws IOException {
         this.tasks = tasks;
         this.artifactManager = ArtifactManager.getArtifactManager(amConfig);
+        this.scanner = new Scanner(amConfig);
     }
 
     public Analyser(final ArtifactManagerConfig amConfig,
             final String... taskIds)
     throws IOException {
-        this.artifactManager = ArtifactManager.getArtifactManager(amConfig);
-        final ServiceLoader<AnalyserTask> loader = 
ServiceLoader.load(AnalyserTask.class);
-        final Set<String> ids = new HashSet<>(Arrays.asList(taskIds));
-        this.tasks = new AnalyserTask[ids.size()];
-        int index = 0;
-        for(final AnalyserTask task : loader) {
-            if ( ids.contains(task.getId())) {
-                ids.remove(task.getId());
-                this.tasks[index] = task;
-                index++;
-            }
-        }
-        if ( ids.isEmpty() ) {
-            throw new IOException("Couldn't find tasks " + ids);
+        this(amConfig, getTasks(taskIds));
+        if ( this.tasks.length != taskIds.length ) {
+            throw new IOException("Couldn't find all tasks " + taskIds);
         }
     }
 
     public Analyser(final ArtifactManagerConfig amConfig)
     throws IOException {
-        this.artifactManager = ArtifactManager.getArtifactManager(amConfig);
+        this(amConfig, getTasks((String[])null));
+    }
+
+    private static AnalyserTask[] getTasks(final String... taskIds) {
+        final Set<String> ids = taskIds == null ? null : new 
HashSet<>(Arrays.asList(taskIds));
         final ServiceLoader<AnalyserTask> loader = 
ServiceLoader.load(AnalyserTask.class);
         final List<AnalyserTask> list = new ArrayList<>();
         for(final AnalyserTask task : loader) {
-            list.add(task);
+            if ( ids == null || ids.contains(task.getId()) ) {
+                list.add(task);
+            }
         }
-        this.tasks = list.toArray(new AnalyserTask[list.size()]);
+        return list.toArray(new AnalyserTask[list.size()]);
     }
 
     public void analyse(final Application app)
@@ -94,17 +85,17 @@ public class Analyser {
         logger.info("Starting application analyzer...");
 
         // get framework properties and update application
-        final KeyValueMap frameworkProps = getFrameworkProperties(app);
+        final KeyValueMap frameworkProps = scanner.getFrameworkProperties(app);
         for(final Map.Entry<String, String>entry : frameworkProps) {
             if ( app.getFrameworkProperties().get(entry.getKey()) == null ) {
                 app.getFrameworkProperties().put(entry.getKey(), 
entry.getValue());
             }
         }
 
-        final List<PackageInfo> systemPackages = calculateSystemPackages(app);
+        final List<PackageInfo> systemPackages = 
scanner.calculateSystemPackages(app);
 
-        final List<BundleInfo> bundleInfos = getBundleInfos(app);
-        final List<ArtifactInfo> artifactInfos = getArtifactInfos(app);
+        final List<BundleInfo> bundleInfos = scanner.getBundleInfos(app);
+        final List<ArtifactInfo> artifactInfos = scanner.getArtifactInfos(app);
 
         final List<String> warnings = new ArrayList<>();
         final List<String> errors = new ArrayList<>();
@@ -159,233 +150,4 @@ public class Analyser {
 
         logger.info("Provisioning model analyzer finished");
     }
-
-    private List<BundleInfo> getBundleInfos(final Application app)  throws 
Exception {
-        final List<BundleInfo> bundleInfos = new ArrayList<>();
-
-        for(final Map.Entry<Integer, List<Artifact>> entry : 
app.getBundles().getBundlesByStartLevel().entrySet()) {
-            for(final Artifact bundle : entry.getValue() ) {
-                final File file = 
artifactManager.getArtifactHandler(bundle.getId().toMvnUrl()).getFile();
-                if ( file == null ) {
-                    throw new Exception("Unable to find file for " + 
bundle.getId());
-                }
-                final BundleInfo info = new BundleInfo(bundle, file, 
entry.getKey());
-                bundleInfos.add(info);
-            }
-        }
-
-        return bundleInfos;
-    }
-
-    private List<ArtifactInfo> getArtifactInfos(final Application app)  throws 
Exception {
-        final List<ArtifactInfo> artifactInfos = new ArrayList<>();
-
-        for(final Extension ext : app.getExtensions()) {
-            if ( ext.getType() == ExtensionType.ARTIFACTS ) {
-                for(final Artifact artifact : ext.getArtifacts()) {
-                    final File file = 
artifactManager.getArtifactHandler(artifact.getId().toMvnUrl()).getFile();
-                    if ( file == null ) {
-                        throw new Exception("Unable to find file for " + 
artifact.getId());
-                    }
-                    final ArtifactInfo info = new ArtifactInfo(artifact, file);
-                    artifactInfos.add(info);
-                }
-            }
-        }
-
-        return artifactInfos;
-    }
-
-    private List<PackageInfo> calculateSystemPackages(final Application app) {
-        final String system = 
app.getFrameworkProperties().get(Constants.FRAMEWORK_SYSTEMPACKAGES);
-        final String extra = 
app.getFrameworkProperties().get(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
-        final List<PackageInfo> packages = new ArrayList<>();
-        for(int i=0;i<2;i++) {
-            final String value = (i == 0 ? system : extra);
-            if ( value != null ) {
-                final ManifestHeader header = ManifestHeader.parse(value);
-                for(final ManifestHeader.Entry entry : header.getEntries()) {
-                    String version = entry.getAttributeValue("version");
-                    if ( version == null ) {
-                        version = "0.0.0";
-                    }
-
-                    final PackageInfo exportedPackageInfo = new 
PackageInfo(entry.getValue(),
-                            version, false);
-                    packages.add(exportedPackageInfo);
-                }
-            }
-        }
-        return packages;
-    }
-
-    private static final String DEFAULT_PROPERTIES = "default.properties";
-
-    private KeyValueMap getFrameworkProperties(final Application app)
-    throws IOException {
-        final File framework = 
this.artifactManager.getArtifactHandler(app.getFramework().toMvnUrl()).getFile();
-
-        final Map<String, Properties> propsMap = new HashMap<>();
-        try (final ZipInputStream zis = new ZipInputStream(new 
FileInputStream(framework)) ) {
-            boolean done = false;
-            while ( !done ) {
-                final ZipEntry entry = zis.getNextEntry();
-                if ( entry == null ) {
-                    done = true;
-                } else {
-                    final String entryName = entry.getName();
-                    if ( entryName.endsWith(".properties") ) {
-                        final Properties props = new Properties();
-                        props.load(zis);
-
-                        propsMap.put(entryName, props);
-                    }
-                    zis.closeEntry();
-                }
-            }
-        }
-
-        final Properties defaultMap = propsMap.get(DEFAULT_PROPERTIES);
-        if ( defaultMap == null ) {
-            throw new IOException("Unable to find " + DEFAULT_PROPERTIES + " 
in framework " + app.getFramework());
-        }
-
-        final KeyValueMap frameworkProps = new KeyValueMap();
-        // replace variables
-        defaultMap.put("java.specification.version",
-                System.getProperty("java.specification.version", "1.8"));
-        for(final Object name : defaultMap.keySet()) {
-            final String value = (String)defaultMap.get(name);
-            final String substValue = substVars(value, name.toString(), null, 
defaultMap);
-            frameworkProps.put(name.toString(), substValue);
-        }
-
-        return frameworkProps;
-    }
-
-    private static final String DELIM_START = "${";
-    private static final String DELIM_STOP  = "}";
-
-    /**
-     * <p>
-     * This method performs property variable substitution on the
-     * specified value. If the specified value contains the syntax
-     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
-     * refers to either a configuration property or a system property,
-     * then the corresponding property value is substituted for the variable
-     * placeholder. Multiple variable place holders may exist in the
-     * specified value as well as nested variable place holders, which
-     * are substituted from inner most to outer most. Configuration
-     * properties override system properties.
-     * </p>
-     * @param val The string on which to perform property substitution.
-     * @param currentKey The key of the property being evaluated used to
-     *        detect cycles.
-     * @param cycleMap Map of variable references used to detect nested cycles.
-     * @param configProps Set of configuration properties.
-     * @return The value of the specified string after system property 
substitution.
-     * @throws IllegalArgumentException If there was a syntax error in the
-     *         property placeholder syntax or a recursive variable reference.
-    **/
-    public static String substVars(String val, String currentKey,
-        Map<String, String> cycleMap, Properties configProps)
-        throws IllegalArgumentException
-    {
-        // If there is currently no cycle map, then create
-        // one for detecting cycles for this invocation.
-        if (cycleMap == null)
-        {
-            cycleMap = new HashMap<>();
-        }
-
-        // Put the current key in the cycle map.
-        cycleMap.put(currentKey, currentKey);
-
-        // Assume we have a value that is something like:
-        // "leading ${foo.${bar}} middle ${baz} trailing"
-
-        // Find the first ending '}' variable delimiter, which
-        // will correspond to the first deepest nested variable
-        // placeholder.
-        int stopDelim = -1;
-        int startDelim = -1;
-
-        do
-        {
-            stopDelim = val.indexOf(DELIM_STOP, stopDelim + 1);
-            // If there is no stopping delimiter, then just return
-            // the value since there is no variable declared.
-            if (stopDelim < 0)
-            {
-                return val;
-            }
-            // Try to find the matching start delimiter by
-            // looping until we find a start delimiter that is
-            // greater than the stop delimiter we have found.
-            startDelim = val.indexOf(DELIM_START);
-            // If there is no starting delimiter, then just return
-            // the value since there is no variable declared.
-            if (startDelim < 0)
-            {
-                return val;
-            }
-            while (stopDelim >= 0)
-            {
-                int idx = val.indexOf(DELIM_START, startDelim + 
DELIM_START.length());
-                if ((idx < 0) || (idx > stopDelim))
-                {
-                    break;
-                }
-                else if (idx < stopDelim)
-                {
-                    startDelim = idx;
-                }
-            }
-        }
-        while ((startDelim > stopDelim) && (stopDelim >= 0));
-
-        // At this point, we have found a variable placeholder so
-        // we must perform a variable substitution on it.
-        // Using the start and stop delimiter indices, extract
-        // the first, deepest nested variable placeholder.
-        String variable =
-            val.substring(startDelim + DELIM_START.length(), stopDelim);
-
-        // Verify that this is not a recursive variable reference.
-        if (cycleMap.get(variable) != null)
-        {
-            throw new IllegalArgumentException(
-                "recursive variable reference: " + variable);
-        }
-
-        // Get the value of the deepest nested variable placeholder.
-        // Try to configuration properties first.
-        String substValue = (configProps != null)
-            ? configProps.getProperty(variable, null)
-            : null;
-        if (substValue == null)
-        {
-            // Ignore unknown property values.
-            substValue = System.getProperty(variable, "");
-        }
-
-        // Remove the found variable from the cycle map, since
-        // it may appear more than once in the value and we don't
-        // want such situations to appear as a recursive reference.
-        cycleMap.remove(variable);
-
-        // Append the leading characters, the substituted value of
-        // the variable, and the trailing characters to get the new
-        // value.
-        val = val.substring(0, startDelim)
-            + substValue
-            + val.substring(stopDelim + DELIM_STOP.length(), val.length());
-
-        // Now perform substitution again, since there could still
-        // be substitutions to make.
-        val = substVars(val, currentKey, cycleMap, configProps);
-
-        // Return the value.
-        return val;
-    }
 }

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java?rev=1800872&r1=1800871&r2=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
 Wed Jul  5 13:19:15 2017
@@ -19,6 +19,9 @@ package org.apache.sling.feature.analyse
 import java.util.List;
 
 import org.apache.sling.feature.Application;
+import org.apache.sling.feature.scanner.ArtifactInfo;
+import org.apache.sling.feature.scanner.BundleInfo;
+import org.apache.sling.feature.scanner.PackageInfo;
 
 public interface AnalyserTaskContext {
 

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundleExportsImports.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundleExportsImports.java?rev=1800872&r1=1800871&r2=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundleExportsImports.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundleExportsImports.java
 Wed Jul  5 13:19:15 2017
@@ -29,8 +29,8 @@ import java.util.TreeMap;
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.analyser.AnalyserTask;
 import org.apache.sling.feature.analyser.AnalyserTaskContext;
-import org.apache.sling.feature.analyser.BundleInfo;
-import org.apache.sling.feature.analyser.PackageInfo;
+import org.apache.sling.feature.scanner.BundleInfo;
+import org.apache.sling.feature.scanner.PackageInfo;
 import org.osgi.framework.Version;
 
 public class CheckBundleExportsImports implements AnalyserTask {

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForInitialContent.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForInitialContent.java?rev=1800872&r1=1800871&r2=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForInitialContent.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForInitialContent.java
 Wed Jul  5 13:19:15 2017
@@ -20,7 +20,7 @@ package org.apache.sling.feature.analyse
 
 import org.apache.sling.feature.analyser.AnalyserTask;
 import org.apache.sling.feature.analyser.AnalyserTaskContext;
-import org.apache.sling.feature.analyser.BundleInfo;
+import org.apache.sling.feature.scanner.BundleInfo;
 
 public class CheckBundlesForInitialContent implements AnalyserTask {
 

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForResources.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForResources.java?rev=1800872&r1=1800871&r2=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForResources.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/tasks/CheckBundlesForResources.java
 Wed Jul  5 13:19:15 2017
@@ -20,7 +20,7 @@ package org.apache.sling.feature.analyse
 
 import org.apache.sling.feature.analyser.AnalyserTask;
 import org.apache.sling.feature.analyser.AnalyserTaskContext;
-import org.apache.sling.feature.analyser.BundleInfo;
+import org.apache.sling.feature.scanner.BundleInfo;
 
 public class CheckBundlesForResources implements AnalyserTask {
 

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java?rev=1800872&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
 Wed Jul  5 13:19:15 2017
@@ -0,0 +1,32 @@
+/*
+ * 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.feature.resolver;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.feature.Feature;
+
+public class Resolver {
+
+    public List<Feature> resolve(final ResolverContext ctx) {
+        final List<Feature> result = new 
ArrayList<>(ctx.getRequiredFeatures());
+
+        return result;
+    }
+}
+

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/Resolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java?rev=1800872&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
 Wed Jul  5 13:19:15 2017
@@ -0,0 +1,46 @@
+/*
+ * 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.feature.resolver;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.feature.Feature;
+
+public class ResolverContext {
+
+    private final List<Feature> requiredFeatures = new ArrayList<>();
+
+    private final List<Feature> optionalFeatures = new ArrayList<>();
+
+    public List<Feature> getRequiredFeatures() {
+        return requiredFeatures;
+    }
+
+    public List<Feature> getOptionalFeatures() {
+        return optionalFeatures;
+    }
+
+    public void addRequiredFeatures(final List<Feature> features) {
+        this.requiredFeatures.addAll(features);
+    }
+
+    public void addOptionalFeatures(final List<Feature> features) {
+        this.optionalFeatures.addAll(features);
+    }
+}
+

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/ResolverContext.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java?rev=1800872&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
 Wed Jul  5 13:19:15 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
[email protected]("1.0.0")
+package org.apache.sling.feature.resolver;
+
+

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/resolver/package-info.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactInfo.java
 (from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactInfo.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactInfo.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java&r1=1800871&r2=1800872&rev=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactInfo.java
 Wed Jul  5 13:19:15 2017
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.analyser;
+package org.apache.sling.feature.scanner;
 
 import java.io.File;
 import java.io.IOException;

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/BundleInfo.java
 (from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/BundleInfo.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/BundleInfo.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java&r1=1800871&r2=1800872&rev=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/BundleInfo.java
 Wed Jul  5 13:19:15 2017
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.analyser;
+package org.apache.sling.feature.scanner;
 
 import java.io.File;
 import java.io.IOException;
@@ -78,6 +78,9 @@ public class BundleInfo extends Artifact
         this.startLevel = startLevel;
 
         this.manifest = ManifestUtil.getManifest(file);
+        if ( this.manifest == null ) {
+            throw new IOException("File has no manifest");
+        }
         this.analyze();
     }
 

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ManifestUtil.java
 (from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ManifestUtil.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ManifestUtil.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ManifestUtil.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ManifestUtil.java&r1=1800871&r2=1800872&rev=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ManifestUtil.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ManifestUtil.java
 Wed Jul  5 13:19:15 2017
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.analyser;
+package org.apache.sling.feature.scanner;
 
 import java.io.File;
 import java.io.IOException;

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
 (from r1800871, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java&r1=1800871&r2=1800872&rev=1800872&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
 Wed Jul  5 13:19:15 2017
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.feature.analyser;
+package org.apache.sling.feature.scanner;
 
 import org.osgi.framework.Version;
 import org.osgi.framework.VersionRange;

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java?rev=1800872&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
 Wed Jul  5 13:19:15 2017
@@ -0,0 +1,289 @@
+/*
+ * 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.feature.scanner;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.KeyValueMap;
+import org.apache.sling.feature.support.ArtifactManager;
+import org.apache.sling.feature.support.ArtifactManagerConfig;
+import org.osgi.framework.Constants;
+
+public class Scanner {
+
+    private final ArtifactManager artifactManager;
+
+    public Scanner(final ArtifactManagerConfig amConfig)
+    throws IOException {
+        this.artifactManager = ArtifactManager.getArtifactManager(amConfig);
+    }
+
+    public ArtifactInfo scan(final Artifact artifact) throws IOException {
+        final File file = 
artifactManager.getArtifactHandler(artifact.getId().toMvnUrl()).getFile();
+        if ( file == null ) {
+            throw new IOException("Unable to find file for " + 
artifact.getId());
+        }
+
+        ArtifactInfo info = null;
+
+        info = new ArtifactInfo(artifact, file);
+
+        return info;
+    }
+
+    public BundleInfo scanBundle(final Artifact artifact, final int 
startLevel) throws IOException {
+        final File file = 
artifactManager.getArtifactHandler(artifact.getId().toMvnUrl()).getFile();
+        if ( file == null ) {
+            throw new IOException("Unable to find file for " + 
artifact.getId());
+        }
+
+        return new BundleInfo(artifact, file, startLevel);
+    }
+
+    public List<BundleInfo> getBundleInfos(final Application app)  throws 
Exception {
+        final List<BundleInfo> bundleInfos = new ArrayList<>();
+
+        for(final Map.Entry<Integer, List<Artifact>> entry : 
app.getBundles().getBundlesByStartLevel().entrySet()) {
+            for(final Artifact bundle : entry.getValue() ) {
+                bundleInfos.add(scanBundle(bundle, entry.getKey()));
+            }
+        }
+
+        return bundleInfos;
+    }
+
+    public List<ArtifactInfo> getArtifactInfos(final Application app)  throws 
Exception {
+        final List<ArtifactInfo> artifactInfos = new ArrayList<>();
+
+        for(final Extension ext : app.getExtensions()) {
+            if ( ext.getType() == ExtensionType.ARTIFACTS ) {
+                for(final Artifact artifact : ext.getArtifacts()) {
+                    artifactInfos.add(scan(artifact));
+                }
+            }
+        }
+
+        return artifactInfos;
+    }
+
+    public List<PackageInfo> calculateSystemPackages(final Application app) {
+        final String system = 
app.getFrameworkProperties().get(Constants.FRAMEWORK_SYSTEMPACKAGES);
+        final String extra = 
app.getFrameworkProperties().get(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
+        final List<PackageInfo> packages = new ArrayList<>();
+        for(int i=0;i<2;i++) {
+            final String value = (i == 0 ? system : extra);
+            if ( value != null ) {
+                final ManifestHeader header = ManifestHeader.parse(value);
+                for(final ManifestHeader.Entry entry : header.getEntries()) {
+                    String version = entry.getAttributeValue("version");
+                    if ( version == null ) {
+                        version = "0.0.0";
+                    }
+
+                    final PackageInfo exportedPackageInfo = new 
PackageInfo(entry.getValue(),
+                            version, false);
+                    packages.add(exportedPackageInfo);
+                }
+            }
+        }
+        return packages;
+    }
+
+    private static final String DEFAULT_PROPERTIES = "default.properties";
+
+    public KeyValueMap getFrameworkProperties(final Application app)
+    throws IOException {
+        final File framework = 
this.artifactManager.getArtifactHandler(app.getFramework().toMvnUrl()).getFile();
+
+        final Map<String, Properties> propsMap = new HashMap<>();
+        try (final ZipInputStream zis = new ZipInputStream(new 
FileInputStream(framework)) ) {
+            boolean done = false;
+            while ( !done ) {
+                final ZipEntry entry = zis.getNextEntry();
+                if ( entry == null ) {
+                    done = true;
+                } else {
+                    final String entryName = entry.getName();
+                    if ( entryName.endsWith(".properties") ) {
+                        final Properties props = new Properties();
+                        props.load(zis);
+
+                        propsMap.put(entryName, props);
+                    }
+                    zis.closeEntry();
+                }
+            }
+        }
+
+        final Properties defaultMap = propsMap.get(DEFAULT_PROPERTIES);
+        if ( defaultMap == null ) {
+            throw new IOException("Unable to find " + DEFAULT_PROPERTIES + " 
in framework " + app.getFramework());
+        }
+
+        final KeyValueMap frameworkProps = new KeyValueMap();
+        // replace variables
+        defaultMap.put("java.specification.version",
+                System.getProperty("java.specification.version", "1.8"));
+        for(final Object name : defaultMap.keySet()) {
+            final String value = (String)defaultMap.get(name);
+            final String substValue = substVars(value, name.toString(), null, 
defaultMap);
+            frameworkProps.put(name.toString(), substValue);
+        }
+
+        return frameworkProps;
+    }
+
+    private static final String DELIM_START = "${";
+    private static final String DELIM_STOP  = "}";
+
+    /**
+     * <p>
+     * This method performs property variable substitution on the
+     * specified value. If the specified value contains the syntax
+     * <tt>${&lt;prop-name&gt;}</tt>, where <tt>&lt;prop-name&gt;</tt>
+     * refers to either a configuration property or a system property,
+     * then the corresponding property value is substituted for the variable
+     * placeholder. Multiple variable place holders may exist in the
+     * specified value as well as nested variable place holders, which
+     * are substituted from inner most to outer most. Configuration
+     * properties override system properties.
+     * </p>
+     * @param val The string on which to perform property substitution.
+     * @param currentKey The key of the property being evaluated used to
+     *        detect cycles.
+     * @param cycleMap Map of variable references used to detect nested cycles.
+     * @param configProps Set of configuration properties.
+     * @return The value of the specified string after system property 
substitution.
+     * @throws IllegalArgumentException If there was a syntax error in the
+     *         property placeholder syntax or a recursive variable reference.
+    **/
+    public static String substVars(String val, String currentKey,
+        Map<String, String> cycleMap, Properties configProps)
+        throws IllegalArgumentException
+    {
+        // If there is currently no cycle map, then create
+        // one for detecting cycles for this invocation.
+        if (cycleMap == null)
+        {
+            cycleMap = new HashMap<>();
+        }
+
+        // Put the current key in the cycle map.
+        cycleMap.put(currentKey, currentKey);
+
+        // Assume we have a value that is something like:
+        // "leading ${foo.${bar}} middle ${baz} trailing"
+
+        // Find the first ending '}' variable delimiter, which
+        // will correspond to the first deepest nested variable
+        // placeholder.
+        int stopDelim = -1;
+        int startDelim = -1;
+
+        do
+        {
+            stopDelim = val.indexOf(DELIM_STOP, stopDelim + 1);
+            // If there is no stopping delimiter, then just return
+            // the value since there is no variable declared.
+            if (stopDelim < 0)
+            {
+                return val;
+            }
+            // Try to find the matching start delimiter by
+            // looping until we find a start delimiter that is
+            // greater than the stop delimiter we have found.
+            startDelim = val.indexOf(DELIM_START);
+            // If there is no starting delimiter, then just return
+            // the value since there is no variable declared.
+            if (startDelim < 0)
+            {
+                return val;
+            }
+            while (stopDelim >= 0)
+            {
+                int idx = val.indexOf(DELIM_START, startDelim + 
DELIM_START.length());
+                if ((idx < 0) || (idx > stopDelim))
+                {
+                    break;
+                }
+                else if (idx < stopDelim)
+                {
+                    startDelim = idx;
+                }
+            }
+        }
+        while ((startDelim > stopDelim) && (stopDelim >= 0));
+
+        // At this point, we have found a variable placeholder so
+        // we must perform a variable substitution on it.
+        // Using the start and stop delimiter indices, extract
+        // the first, deepest nested variable placeholder.
+        String variable =
+            val.substring(startDelim + DELIM_START.length(), stopDelim);
+
+        // Verify that this is not a recursive variable reference.
+        if (cycleMap.get(variable) != null)
+        {
+            throw new IllegalArgumentException(
+                "recursive variable reference: " + variable);
+        }
+
+        // Get the value of the deepest nested variable placeholder.
+        // Try to configuration properties first.
+        String substValue = (configProps != null)
+            ? configProps.getProperty(variable, null)
+            : null;
+        if (substValue == null)
+        {
+            // Ignore unknown property values.
+            substValue = System.getProperty(variable, "");
+        }
+
+        // Remove the found variable from the cycle map, since
+        // it may appear more than once in the value and we don't
+        // want such situations to appear as a recursive reference.
+        cycleMap.remove(variable);
+
+        // Append the leading characters, the substituted value of
+        // the variable, and the trailing characters to get the new
+        // value.
+        val = val.substring(0, startDelim)
+            + substValue
+            + val.substring(stopDelim + DELIM_STOP.length(), val.length());
+
+        // Now perform substitution again, since there could still
+        // be substitutions to make.
+        val = substVars(val, currentKey, cycleMap, configProps);
+
+        // Return the value.
+        return val;
+    }
+}

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/Scanner.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java?rev=1800872&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
 Wed Jul  5 13:19:15 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
[email protected]("1.0.0")
+package org.apache.sling.feature.scanner;
+
+

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/package-info.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url


Reply via email to