sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1797033 - in /sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl: FeatureProcessor.java artifacts/ArtifactManager.java launchers/FrameworkLauncher.java
Date Wed, 31 May 2017 13:15:08 GMT
Author: cziegeler
Date: Wed May 31 13:15:08 2017
New Revision: 1797033

URL: http://svn.apache.org/viewvc?rev=1797033&view=rev
Log:
Add framework handling

Modified:
    sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
    sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/artifacts/ArtifactManager.java
    sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java

Modified: sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java?rev=1797033&r1=1797032&r2=1797033&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
(original)
+++ sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
Wed May 31 13:15:08 2017
@@ -17,10 +17,9 @@
 package org.apache.sling.feature.launcher.impl;
 
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -43,6 +42,9 @@ import org.apache.sling.feature.process.
 
 public class FeatureProcessor {
 
+    // Framework extension
+    private static final String EXT_NAME = "framework";
+
     /**
      * Initialize the launcher
      * Read the features and prepare the application
@@ -70,12 +72,47 @@ public class FeatureProcessor {
         final Application app = ApplicationBuilder.assemble(new FeatureProvider() {
 
             @Override
-            public Feature provide(ArtifactId id) {
-                // TODO Auto-generated method stub
+            public Feature provide(final ArtifactId id) {
+                try {
+                    final ArtifactHandler handler = artifactManager.getArtifactHandler("mvn:"
+ id.toMvnPath());
+                    try (final FileReader r = new FileReader(handler.getArtifact())) {
+                        final Feature f = FeatureJSONReader.read(r, handler.getArtifactUrl());
+                        return f;
+                    }
+
+                } catch (final IOException e) {
+                    // ignore
+                }
                 return null;
             }
         }, features.toArray(new Feature[features.size()]));
 
+        // search for framework extension
+        Extension fwk = null;
+        for(final Extension e : app.getExtensions()) {
+            if ( e.getName().equals(EXT_NAME) ) {
+                fwk = e;
+            }
+        }
+        if ( fwk != null ) {
+            if ( fwk.getType() != ExtensionType.ARTIFACTS ) {
+                Logger.LOG.error("Extension " + EXT_NAME + " is of wrong type: " + fwk.getType());
+                System.exit(1);
+            }
+            if ( fwk.getArtifacts().size() != 1 ) {
+                Logger.LOG.error("Extension " + EXT_NAME + " must have exactly one artifact:
" + fwk.getArtifacts().size());
+                System.exit(1);
+            }
+            app.setFramework(fwk.getArtifacts().get(0).getId());
+            app.getExtensions().remove(fwk);
+        } else {
+            // use hard coded Apache Felix
+            app.setFramework(new ArtifactId("org.apache.felix",
+                    "org.apache.felix.framework",
+                    "5.6.4", null, null));
+        }
+
+        // write application back
         final File file = new File(config.getHomeDirectory(), "resources" + File.separatorChar
+ "provisioning" + File.separatorChar + "feature.txt");
         file.getParentFile().mkdirs();
 
@@ -110,8 +147,8 @@ public class FeatureProcessor {
         }
         Logger.LOG.log("- reading feature {0}", featureArtifact.getArtifactUrl());
 
-        try (final FileInputStream is = new FileInputStream(featureArtifact.getArtifact()))
{
-            final Feature f = FeatureJSONReader.read(new InputStreamReader(is, "UTF-8"),
featureArtifact.getArtifactUrl());
+        try (final FileReader r = new FileReader(featureArtifact.getArtifact())) {
+            final Feature f = FeatureJSONReader.read(r, featureArtifact.getArtifactUrl());
             return f;
         }
     }

Modified: sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/artifacts/ArtifactManager.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/artifacts/ArtifactManager.java?rev=1797033&r1=1797032&r2=1797033&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/artifacts/ArtifactManager.java
(original)
+++ sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/artifacts/ArtifactManager.java
Wed May 31 13:15:08 2017
@@ -115,9 +115,9 @@ public class ArtifactManager {
     }
 
     /**
-     * Get the full artifact url for an artifact.
+     * Get the full artifact url and file for an artifact.
      * @param url Artifact url or relative path.
-     * @return Absolute url.
+     * @return Absolute url and file in the form of a handler.
      * @throws IOException If something goes wrong.
      */
     public ArtifactHandler getArtifactHandler(final String url) throws IOException {

Modified: sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java?rev=1797033&r1=1797032&r2=1797033&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java
(original)
+++ sling/whiteboard/cziegeler/feature-launcher/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java
Wed May 31 13:15:08 2017
@@ -21,8 +21,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.feature.Application;
-import org.apache.sling.feature.Extension;
-import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.launcher.spi.Launcher;
 import org.apache.sling.feature.launcher.spi.LauncherPrepareContext;
 import org.apache.sling.feature.launcher.spi.LauncherRunContext;
@@ -32,28 +30,10 @@ import org.apache.sling.feature.launcher
  */
 public class FrameworkLauncher implements Launcher {
 
-    private static final String EXT_NAME = "framework";
 
     @Override
     public void prepare(final LauncherPrepareContext context, final Application app) throws
Exception {
-        // search for framework extension
-        Extension fwk = null;
-        for(final Extension e : app.getExtensions()) {
-            if ( e.getName().equals(EXT_NAME) ) {
-                fwk = e;
-            }
-        }
-        if ( fwk == null ) {
-            throw new Exception("No " + EXT_NAME + " extension for framework found.");
-        }
-        if ( fwk.getType() != ExtensionType.ARTIFACTS ) {
-            throw new Exception("Extension " + EXT_NAME + " is of wrong type: " + fwk.getType());
-        }
-        if ( fwk.getArtifacts().size() != 1 ) {
-            throw new Exception("Extension " + EXT_NAME + " must have exactly one artifact:
" + fwk.getArtifacts().size());
-        }
-        // add the framework to the classpath
-        context.addAppJar(context.getArtifactFile(fwk.getArtifacts().get(0).getId()));
+        context.addAppJar(context.getArtifactFile(app.getFramework()));
     }
 
     /**



Mime
View raw message