Author: cziegeler
Date: Sat Aug  5 09:47:24 2017
New Revision: 1804183

URL: http://svn.apache.org/viewvc?rev=1804183&view=rev
Log:
Move tasks impls to separate package, add content package scanner

Added:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
      - copied, changed from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundleExportsImports.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
      - copied, changed from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForInitialContent.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
      - copied, changed from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForResources.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
      - copied, changed from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckRequirementsCapabilities.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptor.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
   (with props)
Removed:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundleExportsImports.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForInitialContent.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForResources.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckRequirementsCapabilities.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ArtifactScanner.java
Modified:
    sling/whiteboard/cziegeler/feature-analyser/pom.xml
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactDescriptor.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleDescriptor.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Scanner.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ExtensionScanner.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
    
sling/whiteboard/cziegeler/feature-analyser/src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask

Modified: sling/whiteboard/cziegeler/feature-analyser/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/pom.xml?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/pom.xml (original)
+++ sling/whiteboard/cziegeler/feature-analyser/pom.xml Sat Aug  5 09:47:24 2017
@@ -78,6 +78,7 @@
                 <configuration>
                     <excludes>
                         
<exclude>src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask</exclude>
+                        
<exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.ExtensionScanner</exclude>
                         
<exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.FrameworkScanner</exclude>
                     </excludes>
                 </configuration>

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactDescriptor.java?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactDescriptor.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactDescriptor.java
 Sat Aug  5 09:47:24 2017
@@ -17,7 +17,6 @@
 package org.apache.sling.feature.analyser;
 
 import java.io.File;
-import java.util.jar.Manifest;
 
 import org.apache.sling.feature.Artifact;
 
@@ -37,10 +36,4 @@ public abstract class ArtifactDescriptor
      * @return The artifact
      */
     public abstract Artifact getArtifact();
-
-    /**
-     * If the artifact has a manifest, return it
-     * @return The manifest or {@code null}
-     */
-    public abstract Manifest getManifest();
 }
\ No newline at end of file

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleDescriptor.java?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleDescriptor.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleDescriptor.java
 Sat Aug  5 09:47:24 2017
@@ -16,6 +16,8 @@
  */
 package org.apache.sling.feature.analyser;
 
+import java.util.jar.Manifest;
+
 import org.apache.sling.feature.analyser.impl.BundleDescriptorImpl;
 import org.apache.sling.feature.support.util.PackageInfo;
 
@@ -42,6 +44,12 @@ public abstract class BundleDescriptor e
      */
     public abstract int getBundleStartLevel();
 
+    /**
+     * If the artifact has a manifest, return it
+     * @return The manifest
+     */
+    public abstract Manifest getManifest();
+
     public boolean isExportingPackage(final String packageName) {
         if ( getExportedPackages() != null ) {
             for(final PackageInfo i : getExportedPackages()) {

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Scanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Scanner.java?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Scanner.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/Scanner.java
 Sat Aug  5 09:47:24 2017
@@ -32,7 +32,6 @@ import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.analyser.impl.ApplicationDescriptorImpl;
 import org.apache.sling.feature.analyser.impl.BundleDescriptorImpl;
 import org.apache.sling.feature.analyser.impl.FeatureDescriptorImpl;
-import org.apache.sling.feature.scanner.ArtifactScanner;
 import org.apache.sling.feature.scanner.ExtensionScanner;
 import org.apache.sling.feature.scanner.FrameworkScanner;
 import org.apache.sling.feature.support.ArtifactManager;
@@ -54,8 +53,6 @@ public class Scanner {
 
     private final ArtifactManager artifactManager;
 
-    private final List<ArtifactScanner> artifactScanners;
-
     private final List<ExtensionScanner> extensionScanners;
 
     private final List<FrameworkScanner> frameworkScanners;
@@ -70,12 +67,10 @@ public class Scanner {
      * @throws IOException If something goes wrong
      */
     public Scanner(final ArtifactManagerConfig amConfig,
-            final List<ArtifactScanner> artifactScanners,
             final List<ExtensionScanner> extensionScanners,
             final List<FrameworkScanner> frameworkScanners)
     throws IOException {
         this.artifactManager = ArtifactManager.getArtifactManager(amConfig);
-        this.artifactScanners = artifactScanners == null ? 
getServices(ArtifactScanner.class) : artifactScanners;
         this.extensionScanners = extensionScanners == null ? 
getServices(ExtensionScanner.class) : extensionScanners;
         this.frameworkScanners = frameworkScanners == null ? 
getServices(FrameworkScanner.class) : frameworkScanners;
     }
@@ -88,7 +83,7 @@ public class Scanner {
      */
     public Scanner(final ArtifactManagerConfig amConfig)
     throws IOException {
-        this(amConfig, null, null, null);
+        this(amConfig, null, null);
     }
 
     /**
@@ -107,36 +102,6 @@ public class Scanner {
     }
 
     /**
-     * Scan an artifact.
-     *
-     * @param artifact The artifact
-     * @return The artifact descriptor.
-     * @throws IOException If something goes wrong or no scanner could handle 
the artifact
-     */
-    public ArtifactDescriptor 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());
-        }
-
-        ArtifactDescriptor info = null;
-
-        for(final ArtifactScanner scanner : this.artifactScanners ) {
-            info = scanner.scan(artifact, file);
-            if ( info != null ) {
-                break;
-            }
-        }
-
-        if ( info == null ) {
-            throw new IOException("No artifact scanner found for " + 
artifact.getId().toMvnId());
-        }
-        info.lock();
-
-        return info;
-    }
-
-    /**
      * Scan a bundle
      *
      * @param bundle The bundle artifact
@@ -174,7 +139,7 @@ public class Scanner {
         for(final Extension ext : extensions) {
             ContainerDescriptor extDesc = null;
             for(final ExtensionScanner scanner : this.extensionScanners) {
-                extDesc = scanner.scan(ext, this, this.artifactManager);
+                extDesc = scanner.scan(ext, this.artifactManager);
                 if ( extDesc != null ) {
                     break;
                 }

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
 (from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundleExportsImports.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundleExportsImports.java&r1=1804182&r2=1804183&rev=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundleExportsImports.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
 Sat Aug  5 09:47:24 2017
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.feature.analyser.impl;
+package org.apache.sling.feature.analyser.task.impl;
 
 import java.io.IOException;
 import java.util.ArrayList;

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
 (from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForInitialContent.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForInitialContent.java&r1=1804182&r2=1804183&rev=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForInitialContent.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
 Sat Aug  5 09:47:24 2017
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.feature.analyser.impl;
+package org.apache.sling.feature.analyser.task.impl;
 
 import org.apache.sling.commons.osgi.ManifestHeader;
 import org.apache.sling.feature.analyser.BundleDescriptor;

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
 (from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForResources.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForResources.java&r1=1804182&r2=1804183&rev=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckBundlesForResources.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
 Sat Aug  5 09:47:24 2017
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.feature.analyser.impl;
+package org.apache.sling.feature.analyser.task.impl;
 
 import org.apache.sling.commons.osgi.ManifestHeader;
 import org.apache.sling.feature.analyser.BundleDescriptor;

Copied: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
 (from r1804182, 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckRequirementsCapabilities.java)
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java?p2=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java&p1=sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckRequirementsCapabilities.java&r1=1804182&r2=1804183&rev=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/CheckRequirementsCapabilities.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
 Sat Aug  5 09:47:24 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.impl;
+package org.apache.sling.feature.analyser.task.impl;
 
 import java.util.ArrayList;
 import java.util.List;

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ExtensionScanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ExtensionScanner.java?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ExtensionScanner.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/ExtensionScanner.java
 Sat Aug  5 09:47:24 2017
@@ -20,7 +20,6 @@ import java.io.IOException;
 
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.analyser.ContainerDescriptor;
-import org.apache.sling.feature.analyser.Scanner;
 import org.apache.sling.feature.support.ArtifactManager;
 
 /**
@@ -38,12 +37,10 @@ public interface ExtensionScanner  {
      * Try to scan the extension and return a descriptor
      *
      * @param extension The extension
-     * @param scanner The scanner to scan included artifacts
      * @param manager Artifact manager
      * @return The descriptor or {@code null} if the scanner does not know the 
extension
      * @throws IOException If an error occurs while scanning the extension or 
the extension is invalid
      */
     ContainerDescriptor scan(Extension extension,
-            Scanner scanner,
             ArtifactManager manager) throws IOException;
 }
\ No newline at end of file

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptor.java?rev=1804183&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptor.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptor.java
 Sat Aug  5 09:47:24 2017
@@ -0,0 +1,142 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.Configuration;
+import org.apache.sling.feature.analyser.ArtifactDescriptor;
+import org.apache.sling.feature.analyser.BundleDescriptor;
+
+/**
+ * Information about a content package.
+ */
+public class ContentPackageDescriptor extends ArtifactDescriptor {
+
+    /** The content package name. */
+    private String name;
+
+    /** Bundles in the content package. */
+    public final List<BundleDescriptor> bundles = new ArrayList<>();
+
+    /** Configurations in the content package. */
+    public final List<Configuration> configs = new ArrayList<>();
+
+    private File artifactFile;
+
+    private Artifact artifact;
+
+    /**
+     * Get the artifact file
+     * @return The artifact file
+     */
+    @Override
+    public File getArtifactFile() {
+        return artifactFile;
+    }
+
+    /**
+     * Get the artifact
+     * @return The artifact
+     */
+    @Override
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+    /**
+     * Set the artifact
+     * @param artifact The artifact
+     */
+    public void setArtifact(Artifact artifact) {
+        checkLocked();
+        this.artifact = artifact;
+    }
+
+    /**
+     * Set the artifact file
+     * @param artifactFile The artifact file
+     */
+    public void setArtifactFile(File artifactFile) {
+        checkLocked();
+        this.artifactFile = artifactFile;
+    }
+
+    /** Optional: the artifact of the content package. */
+    private Artifact contentPackage;
+
+    /** Optional: the path inside of the content package. */
+    private String contentPath;
+
+    /**
+     * Get the content package
+     * @return The content package or {@code null}
+     */
+    public Artifact getContentPackage() {
+        return contentPackage;
+    }
+
+    /**
+     * Get the content path
+     * @return The content path or {@code null}
+     */
+    public String getContentPath() {
+        return this.contentPath;
+    }
+
+    /**
+     * Whether this artifact is embedded in a content package
+     * @return {@code true} if embedded.
+     */
+    public boolean isEmbeddedInContentPackage() {
+        return this.contentPath != null;
+    }
+
+    /**
+     * Set the information about the content package containing this artifact
+     * @param artifact The package
+     * @param path The path inside the package
+     */
+    public void setContentPackageInfo(final Artifact artifact, final String 
path) {
+        checkLocked();
+        this.contentPackage = artifact;
+        this.contentPath = path;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(final String value) {
+        checkLocked();
+        this.name = value;
+    }
+
+
+    public boolean hasEmbeddedArtifacts() {
+        return !this.bundles.isEmpty() || !this.configs.isEmpty();
+    }
+
+    @Override
+    public String toString() {
+        return "ContentPackage [" + name + "]";
+    }
+}
+

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

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

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java?rev=1804183&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
 Sat Aug  5 09:47:24 2017
@@ -0,0 +1,358 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Configuration;
+import org.apache.sling.feature.analyser.BundleDescriptor;
+import org.apache.sling.feature.analyser.impl.BundleDescriptorImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ContentPackageScanner {
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    private final byte[] buffer = new byte[65536];
+
+    private enum FileType {
+        BUNDLE,
+        CONFIG,
+        PACKAGE
+    }
+
+    public Set<ContentPackageDescriptor> scan(final Artifact desc, final File 
file) throws IOException {
+        if (!file.getName().endsWith(".zip") ) {
+            throw new IOException("Artifact seems to be no content package 
(not a zip file): " + desc.getId().toMvnId());
+        }
+
+        final Set<ContentPackageDescriptor> contentPackages = new HashSet<>();
+        final ContentPackageDescriptor cp = new ContentPackageDescriptor();
+        final int lastDot = file.getName().lastIndexOf(".");
+        cp.setName(file.getName().substring(0, lastDot));
+        cp.setArtifact(desc);
+        cp.setArtifactFile(file);
+
+        extractContentPackage(cp, contentPackages, file);
+
+        contentPackages.add(cp);
+        cp.lock();
+
+        return contentPackages;
+    }
+
+    private void extractContentPackage(final ContentPackageDescriptor cp,
+            final Set<ContentPackageDescriptor> infos,
+            final File archive)
+    throws IOException {
+        logger.info("Analyzing Content Package {}", archive.getName());
+
+        final File tempDir = Files.createTempDirectory(null).toFile();
+        try {
+            final File toDir = new File(tempDir, archive.getName());
+            toDir.mkdirs();
+
+            final List<File> toProcess = new ArrayList<>();
+
+            try (final ZipInputStream zis = new ZipInputStream(new 
FileInputStream(archive)) ) {
+                boolean done = false;
+                while ( !done ) {
+                    final ZipEntry entry = zis.getNextEntry();
+                    if ( entry == null ) {
+                        done = true;
+                    } else {
+                        final String entryName = entry.getName();
+                        if ( !entryName.endsWith("/") && 
entryName.startsWith("jcr_root/") ) {
+                            final String contentPath = entryName.substring(8);
+
+                            FileType fileType = null;
+
+                            if ( entryName.endsWith(".zip") ) {
+                                // embedded content package
+                                fileType = FileType.PACKAGE;
+
+                                // check for libs or apps
+                            } else if ( entryName.startsWith("jcr_root/libs/") 
|| entryName.startsWith("jcr_root/apps/") ) {
+
+                                // check if this is an install folder (I)
+                                // install folders are either named:
+                                // "install" or
+                                // "install.{runmode}"
+                                boolean isInstall = 
entryName.indexOf("/install/") != -1;
+                                if ( !isInstall ) {
+                                    final int pos = 
entryName.indexOf("/install.");
+                                    if ( pos != -1 ) {
+                                        final int endSlashPos = 
entryName.indexOf('/', pos + 1);
+                                        if ( endSlashPos != -1 ) {
+                                            isInstall = true;
+                                        }
+                                    }
+                                }
+                                if ( !isInstall ) {
+                                    // check if this is an install folder (II)
+                                    // config folders are either named:
+                                    // "config" or
+                                    // "config.{runmode}"
+                                    isInstall = entryName.indexOf("/config/") 
!= -1;
+                                    if ( !isInstall ) {
+                                        final int pos = 
entryName.indexOf("/config.");
+                                        if ( pos != -1 ) {
+                                            final int endSlashPos = 
entryName.indexOf('/', pos + 1);
+                                            if ( endSlashPos != -1 ) {
+                                                isInstall = true;
+                                            }
+                                        }
+                                    }
+                                }
+
+                                if (isInstall ) {
+
+                                   if ( entryName.endsWith(".jar") ) {
+                                       fileType = FileType.BUNDLE;
+                                   } else if ( entryName.endsWith(".xml") || 
entryName.endsWith(".config") ) {
+                                       fileType = FileType.CONFIG;
+                                   }
+                                }
+                            }
+
+                            if ( fileType != null ) {
+                                logger.debug("- extracting : {}", entryName);
+                                final File newFile = new File(toDir, 
entryName.replace('/', File.separatorChar));
+                                newFile.getParentFile().mkdirs();
+
+                                try (final FileOutputStream fos = new 
FileOutputStream(newFile)) {
+                                    int len;
+                                    while ((len = zis.read(buffer)) > -1) {
+                                        fos.write(buffer, 0, len);
+                                    }
+                                }
+
+                                if ( fileType == FileType.BUNDLE ) {
+                                    int startLevel = 20;
+                                    final int lastSlash = 
contentPath.lastIndexOf('/');
+                                    final int nextSlash = 
contentPath.lastIndexOf('/', lastSlash - 1);
+                                    final String part = 
contentPath.substring(nextSlash + 1, lastSlash);
+                                    try {
+                                        startLevel = Integer.valueOf(part);
+                                    } catch ( final NumberFormatException 
ignore ) {
+                                        // ignore
+                                    }
+
+                                    final Artifact bundle = new 
Artifact(extractArtifactId(tempDir, newFile));
+                                    final BundleDescriptor info = new 
BundleDescriptorImpl(bundle, newFile, startLevel);
+                                    
bundle.getMetadata().put("content-package", cp.getArtifact().getId().toMvnId());
+                                    bundle.getMetadata().put("content-path", 
contentPath);
+
+                                    cp.bundles.add(info);
+
+                                } else if ( fileType == FileType.CONFIG ) {
+
+                                    final Configuration configEntry = 
this.process(newFile, cp.getArtifact(), contentPath);
+                                    if ( configEntry != null ) {
+
+                                        cp.configs.add(configEntry);
+                                    }
+
+                                } else if ( fileType == FileType.PACKAGE ) {
+                                    toProcess.add(newFile);
+                                }
+
+                            }
+
+                        }
+                        zis.closeEntry();
+                    }
+                }
+
+            }
+
+            for(final File f : toProcess) {
+                extractContentPackage(cp, infos, f);
+                final ContentPackageDescriptor i = new 
ContentPackageDescriptor();
+                final int lastDot = f.getName().lastIndexOf(".");
+                i.setName(f.getName().substring(0, lastDot));
+                i.setArtifactFile(f);
+                i.setContentPackageInfo(cp.getArtifact(), f.getName());
+                infos.add(i);
+
+                i.lock();
+            }
+        } finally {
+            if ( tempDir.exists() ) {
+                tempDir.delete();
+            }
+        }
+    }
+
+    private ArtifactId extractArtifactId(final File tempDir, final File 
bundleFile)
+    throws IOException {
+        logger.debug("Extracting Bundle {}", bundleFile.getName());
+
+        final File toDir = new File(tempDir, bundleFile.getName());
+        toDir.mkdirs();
+
+        try (final ZipInputStream zis = new ZipInputStream(new 
FileInputStream(bundleFile)) ) {
+            boolean done = false;
+            while ( !done ) {
+                final ZipEntry entry = zis.getNextEntry();
+                if ( entry == null ) {
+                    done = true;
+                } else {
+                    final String entryName = entry.getName();
+                    if ( !entryName.endsWith("/") && 
entryName.startsWith("META-INF/maven/") && 
entryName.endsWith("/pom.properties")) {
+                        logger.debug("- extracting : {}", entryName);
+                        final File newFile = new File(toDir, 
entryName.replace('/', File.separatorChar));
+                        newFile.getParentFile().mkdirs();
+
+                        try (final FileOutputStream fos = new 
FileOutputStream(newFile)) {
+                            int len;
+                            while ((len = zis.read(buffer)) > -1) {
+                                fos.write(buffer, 0, len);
+                            }
+                        }
+
+                    }
+                    zis.closeEntry();
+                }
+            }
+
+        }
+
+        // check for maven
+
+        final File metaInfDir = new File(toDir, "META-INF");
+        if ( metaInfDir.exists() ) {
+            final File mavenDir = new File(metaInfDir, "maven");
+            if ( mavenDir.exists() ) {
+                File groupDir = null;
+                for(final File d : mavenDir.listFiles()) {
+                    if ( d.isDirectory() && !d.getName().startsWith(".") ) {
+                        groupDir = d;
+                        break;
+                    }
+                }
+                if ( groupDir != null ) {
+                    File artifactDir = null;
+                    for(final File d : groupDir.listFiles()) {
+                        if ( d.isDirectory() && !d.getName().startsWith(".") ) 
{
+                            artifactDir = d;
+                            break;
+                        }
+                    }
+                    if ( artifactDir != null ) {
+                        final File propsFile = new File(artifactDir, 
"pom.properties");
+                        if ( propsFile.exists() ) {
+                            final Properties props = new Properties();
+                            try ( final Reader r = new FileReader(propsFile) ) 
{
+                                props.load(r);
+                            }
+                            String groupId = props.getProperty("groupId");
+                            String artifactId = 
props.getProperty("artifactId");
+                            String version = props.getProperty("version");
+                            String classifier = null;
+
+                            // Capture classifier
+                            final int pos = 
bundleFile.getName().indexOf(version) + version.length();
+                            if ( bundleFile.getName().charAt(pos) == '-') {
+                                classifier = 
bundleFile.getName().substring(pos + 1, bundleFile.getName().lastIndexOf('.'));
+                            }
+
+                            final String parts[] = version.split("\\.");
+                            if ( parts.length == 4 ) {
+                                final int lastDot = version.lastIndexOf('.');
+                                version = version.substring(0, lastDot) + '-' 
+ version.substring(lastDot + 1);
+                            }
+
+                            if ( groupId != null && artifactId != null && 
version != null ) {
+                                return new ArtifactId(groupId,
+                                        artifactId,
+                                        version, classifier, null);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        throw new IOException(bundleFile.getName() + " has no maven 
coordinates!");
+    }
+
+    private Configuration process(final File configFile,
+            final Artifact packageArtifact,
+            final String contentPath)
+    throws IOException {
+
+        boolean isConfig = true;
+        if ( configFile.getName().endsWith(".xml") ) {
+            final String contents = 
Files.readAllLines(configFile.toPath()).toString();
+            if ( contents.indexOf("jcr:primaryType=\"sling:OsgiConfig\"") == 
-1 ) {
+                isConfig = false;
+            }
+        }
+
+        if ( isConfig ) {
+            final String id;
+            if ( ".content.xml".equals(configFile.getName()) ) {
+                final int lastSlash = contentPath.lastIndexOf('/');
+                final int previousSlash = contentPath.lastIndexOf('/', 
lastSlash - 1);
+                id = contentPath.substring(previousSlash + 1, lastSlash);
+            } else {
+                final int lastDot = configFile.getName().lastIndexOf('.');
+                id = configFile.getName().substring(0, lastDot);
+            }
+
+            final String pid, factoryPid;
+            final int slashPos = id.indexOf('-');
+            if ( slashPos == -1 ) {
+                pid = id;
+                factoryPid = null;
+            } else {
+                pid = id.substring(slashPos + 1);
+                factoryPid = id.substring(0, slashPos);
+            }
+
+            final Configuration cfg;
+            if ( factoryPid != null ) {
+                cfg = new Configuration(factoryPid, pid);
+            } else {
+                cfg = new Configuration(pid);
+            }
+            cfg.getProperties().put("content-path", contentPath);
+            cfg.getProperties().put("content-package", 
packageArtifact.getId().toMvnId());
+
+            return cfg;
+        }
+
+        return null;
+    }
+}

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

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

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java?rev=1804183&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
 Sat Aug  5 09:47:24 2017
@@ -0,0 +1,73 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.analyser.ContainerDescriptor;
+import org.apache.sling.feature.scanner.ExtensionScanner;
+import org.apache.sling.feature.support.ArtifactManager;
+
+public class ContentPackagesExtensionScanner implements ExtensionScanner {
+
+    @Override
+    public String getId() {
+        return "content-packages";
+    }
+
+    @Override
+    public String getName() {
+        return "Content Packages Scanner";
+    }
+
+    @Override
+    public ContainerDescriptor scan(final Extension extension,
+            final ArtifactManager artifactManager)
+    throws IOException {
+        if (!Extension.NAME_CONTENT_PACKAGES.equals(extension.getName()) ) {
+            return null;
+        }
+        if ( extension.getType() != ExtensionType.ARTIFACTS ) {
+            return null;
+        }
+
+        final ContentPackageScanner scanner = new ContentPackageScanner();
+        final ContainerDescriptor cd = new ContainerDescriptor() {};
+
+        for(final Artifact a : extension.getArtifacts()) {
+            final File file = 
artifactManager.getArtifactHandler(a.getId().toMvnUrl()).getFile();
+            if ( file == null ) {
+                throw new IOException("Unable to find file for " + a.getId());
+            }
+
+            final Set<ContentPackageDescriptor> pcks = scanner.scan(a, file);
+            for(final ContentPackageDescriptor desc : pcks) {
+                cd.getArtifactDescriptors().add(desc);
+                cd.getBundleDescriptors().addAll(desc.bundles);
+            }
+        }
+
+        cd.lock();
+
+        return cd;
+    }
+}

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

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

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
 Sat Aug  5 09:47:24 2017
@@ -90,7 +90,7 @@ public class FelixFrameworkScanner imple
 
             @Override
             public Manifest getManifest() {
-                return null;
+                return new Manifest();
             }
         };
         d.getCapabilities().addAll(capabilities);

Modified: 
sling/whiteboard/cziegeler/feature-analyser/src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask?rev=1804183&r1=1804182&r2=1804183&view=diff
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask
 (original)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask
 Sat Aug  5 09:47:24 2017
@@ -1,5 +1,5 @@
-org.apache.sling.feature.analyser.impl.CheckBundleExportsImports
-org.apache.sling.feature.analyser.impl.CheckBundlesForInitialContent
-org.apache.sling.feature.analyser.impl.CheckBundlesForResources
-org.apache.sling.feature.analyser.impl.CheckRequirementsCapabilities
+org.apache.sling.feature.analyser.task.impl.CheckBundleExportsImports
+org.apache.sling.feature.analyser.task.impl.CheckBundlesForInitialContent
+org.apache.sling.feature.analyser.task.impl.CheckBundlesForResources
+org.apache.sling.feature.analyser.task.impl.CheckRequirementsCapabilities
 


Reply via email to