You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/05/29 15:04:24 UTC

svn commit: r1796643 - in /sling/whiteboard/cziegeler/provisioning-model: ./ src/main/java/org/apache/sling/feature/analyser/ src/main/java/org/apache/sling/feature/process/

Author: cziegeler
Date: Mon May 29 15:04:24 2017
New Revision: 1796643

URL: http://svn.apache.org/viewvc?rev=1796643&view=rev
Log:
Start analyser framework and application builder

Added:
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java   (with props)
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java   (with props)
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java   (with props)
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java   (with props)
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java   (with props)
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java   (with props)
Modified:
    sling/whiteboard/cziegeler/provisioning-model/pom.xml
    sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java

Modified: sling/whiteboard/cziegeler/provisioning-model/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/pom.xml?rev=1796643&r1=1796642&r2=1796643&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/pom.xml (original)
+++ sling/whiteboard/cziegeler/provisioning-model/pom.xml Mon May 29 15:04:24 2017
@@ -72,6 +72,12 @@
             <version>0.0.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.4.0</version>
+            <scope>provided</scope>
+        </dependency>
       <!-- Testing -->
         <dependency>
         	<groupId>junit</groupId>

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java Mon May 29 15:04:24 2017
@@ -0,0 +1,25 @@
+/*
+ * 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.analyser;
+
+public interface AnalyserTask {
+
+    String getName();
+
+    void execute(AnalyserTaskContext ctx);
+}
+

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

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

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java Mon May 29 15:04:24 2017
@@ -0,0 +1,40 @@
+/*
+ * 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.analyser;
+
+import java.util.List;
+
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.KeyValueMap;
+
+public interface AnalyserTaskContext {
+
+    Application getApplication();
+
+    KeyValueMap<String> getDefaultFrameworkProperties();
+
+    List<PackageInfo> getSystemPackages();
+
+    List<BundleInfo> getBundleInfos();
+
+    List<ArtifactInfo> getArtifactInfos();
+
+    void addWarning(String message);
+
+    void addError(String message);
+}
+

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

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

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java Mon May 29 15:04:24 2017
@@ -0,0 +1,200 @@
+/*
+ * 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.analyser;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.feature.Artifact;
+import org.osgi.framework.Constants;
+
+/**
+ * Information about an artifact
+ */
+public class ArtifactInfo  {
+
+    /** The physical file for analysing. */
+    private final File artifactFile;
+
+    /** The corresponding artifact from the feature. */
+    private final Artifact artifact;
+
+    /** Information about exported packages. */
+    private final List<PackageInfo> exportedPackages = new ArrayList<>();
+
+    /** Information about imported packages. */
+    private final List<PackageInfo> importedPackages = new ArrayList<>();
+
+    /** Information about dynamic imported packages. */
+    private final List<PackageInfo> dynamicImportedPackages = new ArrayList<>();
+
+    public ArtifactInfo(final Artifact a,
+            final File file) throws IOException {
+        this.artifact = a;
+        this.artifactFile = file;
+
+        this.analyze();
+    }
+
+    /**
+     * Get the artifact file
+     * @return The artifact file
+     */
+    public File getArtifactFile() {
+        return artifactFile;
+    }
+
+    /**
+     * Get the artifact
+     * @return The artifact
+     */
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+    public List<PackageInfo> getExportedPackages() {
+        return Collections.unmodifiableList(this.exportedPackages);
+    }
+
+    public boolean isExportingPackage(final String packageName) {
+        if ( getExportedPackages() != null ) {
+            for(final PackageInfo i : getExportedPackages()) {
+                if ( i.getName().equals(packageName) ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public boolean isExportingPackage(final PackageInfo info) {
+        if ( getExportedPackages() != null ) {
+            for(final PackageInfo i : getExportedPackages()) {
+                if ( i.getName().equals(info.getName())
+                     && (info.getVersion() == null || info.getPackageVersionRange().includes(i.getPackageVersion()))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public List<PackageInfo> getImportedPackages() {
+        return Collections.unmodifiableList(this.importedPackages);
+    }
+
+    public List<PackageInfo> getDynamicImportedPackages() {
+        return Collections.unmodifiableList(this.dynamicImportedPackages);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( obj instanceof ArtifactInfo ) {
+            return this.getArtifact().getId().toMvnId().equals(((ArtifactInfo)obj).getArtifact().getId().toMvnId());
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return this.getArtifact().getId().toMvnId().hashCode();
+
+    }
+
+    @Override
+    public String toString() {
+        return "ArtifactInfo [artifact=" + this.getArtifact().getId().toMvnId() + "]";
+    }
+
+    private void analyze() throws IOException {
+        final Manifest m = getManifest(this.artifactFile);
+        if (m != null ) {
+
+            doAnalyze(m);
+
+        } else {
+            throw new IOException("Unable to get manifest from artifact " + getArtifact().getId().toMvnId());
+        }
+    }
+
+    protected void doAnalyze(final Manifest m) throws IOException {
+        extractExportedPackages(m);
+        extractDynamicImportedPackages(m);
+        extractImportedPackages(m);
+    }
+
+    /**
+     * Get the manifest from the artifact.
+     * @param artifact The artifact
+     * @throws IOException If the manifest can't be read
+     */
+    private static Manifest getManifest(final File artifact) throws IOException {
+        try (final JarFile file = new JarFile(artifact) ) {
+            return file.getManifest();
+        }
+    }
+
+    private void extractExportedPackages(final Manifest m) {
+        final String exportedPackages = m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
+        if (exportedPackages != null) {
+            final ManifestHeader header = ManifestHeader.parse(exportedPackages);
+            for(final ManifestHeader.Entry entry : header.getEntries()) {
+                String version = entry.getAttributeValue("version");
+                if ( version == null ) {
+                    version = "0.0.0";
+                }
+                final PackageInfo pck = new PackageInfo(entry.getValue(),
+                        version,
+                        false);
+                this.exportedPackages.add(pck);
+            }
+        }
+    }
+
+    private void extractImportedPackages(final Manifest m) {
+        final String importedPackages = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
+        if (importedPackages != null) {
+            final ManifestHeader header = ManifestHeader.parse(importedPackages);
+            for(final ManifestHeader.Entry entry : header.getEntries()) {
+                final String resolution = entry.getDirectiveValue("resolution");
+                final PackageInfo pck = new PackageInfo(entry.getValue(),
+                        entry.getAttributeValue("version"),
+                        "optional".equalsIgnoreCase(resolution));
+                this.importedPackages.add(pck);
+            }
+        }
+    }
+
+    private void extractDynamicImportedPackages(final Manifest m) {
+        final String importedPackages = m.getMainAttributes().getValue(Constants.DYNAMICIMPORT_PACKAGE);
+        if (importedPackages != null) {
+            final ManifestHeader header = ManifestHeader.parse(importedPackages);
+            for(final ManifestHeader.Entry entry : header.getEntries()) {
+                final PackageInfo pck = new PackageInfo(entry.getValue(),
+                        entry.getAttributeValue("version"),
+                        false);
+                this.dynamicImportedPackages.add(pck);
+            }
+        }
+    }
+}
\ No newline at end of file

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

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

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java Mon May 29 15:04: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.analyser;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.jar.Manifest;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.feature.Artifact;
+import org.osgi.framework.Constants;
+
+/**
+ * Information about a bundle
+ */
+public class BundleInfo extends ArtifactInfo  {
+
+    /** The manifest header to specify initial content to be loaded. */
+    private static final String CONTENT_HEADER = "Sling-Initial-Content";
+
+    /**
+     * The path directive specifying the target node where initial content will
+     * be loaded.
+     */
+    private static final String PATH_DIRECTIVE = "path";
+
+    /** The bundle symbolic name. */
+    private String symbolicName;
+
+    /** The bundle version. */
+    private String bundleVersion;
+
+    /** The start level of this artifact. */
+    private final int startLevel;
+
+    /** Initial content */
+    private final List<String> initialContent = new ArrayList<>();
+
+    public BundleInfo(final Artifact a,
+            final File file,
+            final int startLevel) throws IOException  {
+        super(a, file);
+        this.startLevel = startLevel;
+    }
+
+    public String getBundleSymbolicName() {
+        return symbolicName;
+    }
+
+    public String getBundleVersion() {
+        return bundleVersion;
+    }
+
+    /**
+     * Get the start level
+     * @return The start level or {@code 0} for the default.
+     */
+    public int getBundleStartLevel() {
+        return startLevel;
+    }
+
+    public List<String> getInitialContent() {
+        return Collections.unmodifiableList(this.initialContent);
+    }
+
+    @Override
+    protected void doAnalyze(final Manifest m) throws IOException {
+        final String name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+        if ( name != null ) {
+            final String version = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+            if ( version == null ) {
+                throw new IOException("Unable to get bundle version from artifact " + getArtifact().getId().toMvnId());
+            }
+            this.symbolicName = name;
+            this.bundleVersion = version;
+            final String newBundleName = this.getArtifact().getMetadata().get("bundle:rename-bsn");
+            if (newBundleName != null) {
+                this.symbolicName = newBundleName;
+            }
+
+            extractInitialContent(m);
+
+            super.doAnalyze(m);
+        } else {
+            throw new IOException("Unable to get bundle symbolic name from artifact " + getArtifact().getId().toMvnId());
+        }
+    }
+
+    private void extractInitialContent(final Manifest m) {
+        final String root =  m.getMainAttributes().getValue(CONTENT_HEADER);
+        if (root != null) {
+            final ManifestHeader header = ManifestHeader.parse(root);
+            for (final ManifestHeader.Entry entry : header.getEntries()) {
+
+                String path = entry.getDirectiveValue(PATH_DIRECTIVE);
+                if (path == null) {
+                    path = "/";
+                } else if (!path.startsWith("/")) {
+                    // make relative path absolute
+                    path = "/" + path;
+                }
+                this.initialContent.add(path);
+            }
+        }
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( obj instanceof BundleInfo ) {
+            return this.symbolicName.equals(((BundleInfo)obj).symbolicName) && this.bundleVersion.equals(((BundleInfo)obj).bundleVersion);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return (this.symbolicName + ':' + this.bundleVersion).hashCode();
+
+    }
+
+    @Override
+    public String toString() {
+        return "BundleInfo [symbolicName=" + symbolicName + ", version=" + this.bundleVersion + "]";
+    }
+}
\ No newline at end of file

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

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

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java Mon May 29 15:04:24 2017
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.feature.analyser;
+
+import org.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
+
+public class PackageInfo {
+
+    private final boolean optional;
+    private final String name;
+    private final String version;
+
+    public PackageInfo(final String name, final String version, final boolean optional) {
+        this.name = name;
+        this.version = version;
+        this.optional = optional;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public boolean isOptional() {
+        return optional;
+    }
+
+    public Version getPackageVersion() {
+        return new Version(this.version);
+    }
+
+    public VersionRange getPackageVersionRange() {
+        return new VersionRange(this.version);
+    }
+
+    @Override
+    public String toString() {
+        return "Package " + name + ";version=" + version;
+    }
+}

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

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

Added: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java?rev=1796643&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java (added)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java Mon May 29 15:04:24 2017
@@ -0,0 +1,78 @@
+/*
+ * 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.process;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+
+/**
+ * Build an application based on features.
+ */
+public class ApplicationBuilder {
+
+    /**
+     *
+     * @param provider
+     * @param featureIds
+     * @return
+     * throws IllegalArgumentException If provider or featureIds is {@code null}
+     * throws IllegalStateException If the provided ids are invalid, or the feature can't be provided
+     */
+    public static Application assemble(final FeatureProvider provider,
+            final String...featureIds) {
+        if ( featureIds == null || provider == null ) {
+            throw new IllegalArgumentException("Features and/or provider must not be null");
+        }
+
+        final Feature[] features = new Feature[featureIds.length];
+        int index = 0;
+        for(final String id : featureIds) {
+            features[index] = provider.provide(ArtifactId.fromMvnId(id));
+            if ( features[index] == null ) {
+                throw new IllegalStateException("Unable to find included feature " + id);
+            }
+            index++;
+        }
+        return assemble(provider, features);
+    }
+
+    public static Application assemble(final FeatureProvider provider,
+            final Feature...features) {
+        if ( features == null || provider == null ) {
+            throw new IllegalArgumentException("Features and/or provider must not be null");
+        }
+
+        final Application app = new Application();
+        final List<Feature> sortedFeatureList = new ArrayList<>();
+        for(final Feature f : features) {
+            app.getFeatureIds().add(f.getId());
+            sortedFeatureList.add(f);
+        }
+        Collections.sort(sortedFeatureList);
+
+        for(final Feature f : sortedFeatureList) {
+            final Feature assembled = FeatureBuilder.assemble(f, provider);
+            // TODO add feature to application
+        }
+        return app;
+    }
+}

Propchange: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java?rev=1796643&r1=1796642&r2=1796643&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java (original)
+++ sling/whiteboard/cziegeler/provisioning-model/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java Mon May 29 15:04:24 2017
@@ -23,9 +23,11 @@ import java.util.Map;
 
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Capability;
 import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.Include;
+import org.apache.sling.feature.Requirement;
 
 public class FeatureBuilder {
 
@@ -149,6 +151,16 @@ public class FeatureBuilder {
         // framework properties
         target.getFrameworkProperties().putAll(source.getFrameworkProperties());
 
-        // TODO - capabilities, requirements, extensions
+        // requirements
+        for(final Requirement req : source.getRequirements()) {
+            target.getRequirements().add(req);
+        }
+
+        // capabilities
+        for(final Capability cap : source.getCapabilities()) {
+            target.getCapabilities().add(cap);
+        }
+
+        // TODO - extensions
     }
 }