ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1514679 - in /ace/trunk/org.apache.ace.agent.launcher: ./ resources/ resources/META-INF/ src/org/apache/ace/agent/launcher/
Date Fri, 16 Aug 2013 12:37:36 GMT
Author: bramk
Date: Fri Aug 16 12:37:36 2013
New Revision: 1514679

URL: http://svn.apache.org/r1514679
Log:
ACE-347 Split out base and added bundle dir support

Added:
    ace/trunk/org.apache.ace.agent.launcher/base.bnd
    ace/trunk/org.apache.ace.agent.launcher/felix.bnd
    ace/trunk/org.apache.ace.agent.launcher/resources/org.apache.ace.agent.launcher.BundleProvider
      - copied, changed from r1514625, ace/trunk/org.apache.ace.agent.launcher/resources/META-INF/services/org.apache.ace.agent.launcher.BundleProvider
    ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleDirBundleProvider.java
    ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java
      - copied, changed from r1514625, ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java
Removed:
    ace/trunk/org.apache.ace.agent.launcher/resources/META-INF/
    ace/trunk/org.apache.ace.agent.launcher/resources/felix-defaults.properties
Modified:
    ace/trunk/org.apache.ace.agent.launcher/.classpath
    ace/trunk/org.apache.ace.agent.launcher/bnd.bnd
    ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/AgentBundleProvider.java
    ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java

Modified: ace/trunk/org.apache.ace.agent.launcher/.classpath
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/.classpath?rev=1514679&r1=1514678&r2=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/.classpath (original)
+++ ace/trunk/org.apache.ace.agent.launcher/.classpath Fri Aug 16 12:37:36 2013
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" output="bin" path="src"/>
-	<classpathentry kind="src" path="resources"/>
 	<classpathentry kind="src" output="bin_test" path="test"/>
 	<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

Added: ace/trunk/org.apache.ace.agent.launcher/base.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/base.bnd?rev=1514679&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/base.bnd (added)
+++ ace/trunk/org.apache.ace.agent.launcher/base.bnd Fri Aug 16 12:37:36 2013
@@ -0,0 +1,14 @@
+
+# The Jar Main-Class header
+Main-Class: org.apache.ace.agent.launcher.Launcher
+Bundle-Version: 1.0.0
+Bundle-Name: Apache ACE Agent launcher
+Bundle-Description: Standalone launcher that start an OSGi framework with an embedded ACE
Agent
+
+# Include the felix defaults
+Include-Resource: ${repo;org.apache.ace.agent;latest},\
+	META-INF/services/org.apache.ace.agent.launcher.BundleProvider=resources/org.apache.ace.agent.launcher.BundleProvider
+  
+Private-Package: org.apache.ace.agent.launcher,\
+	org.apache.commons.cli,\
+	org.apache.ace.agent;-split-package:=merge-first
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.agent.launcher/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/bnd.bnd?rev=1514679&r1=1514678&r2=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.agent.launcher/bnd.bnd Fri Aug 16 12:37:36 2013
@@ -1,22 +1,9 @@
-# The Jar Main-Class header
-Main-Class: org.apache.ace.agent.launcher.Launcher
-Bundle-Version: 1.0.0
-Bundle-Name: Apache ACE Agent launcher
-Bundle-Description: Standalone laucher that start an Apache Felix framework with an embedded
ACE Agent
-
-# Include the felix defaults
-Include-Resource: @${repo;org.apache.felix.framework;4.0.3}!/default.properties,\
-    @${repo;org.apache.felix.framework;4.0.3}!/META-INF/services/*,\
-    @${repo;org.apache.felix.framework;4.0.3}!/org/*,\
-	${repo;org.apache.ace.agent;latest},\
-	resources/META-INF/services/org.apache.ace.agent.launcher.BundleProvider==META-INF/services/org.apache.ace.agent.launcher.BundleProvider
-  
-Private-Package: org.apache.ace.agent.launcher,\
-	org.apache.commons.cli,\
-	org.apache.ace.agent;-split-package:=merge-first
-
 -buildpath: osgi.core;version='[4.3,5)',\
 	org.apache.commons.cli,\
 	org.apache.ace.agent;version=latest,\
-	org.apache.ace.test;version=latest
+	org.apache.ace.test;version=latest,\
+	org.apache.felix.gogo.command,\
+	org.apache.felix.gogo.runtime,\
+	org.apache.felix.gogo.shell
 -sources: false
+-sub: *.bnd

Added: ace/trunk/org.apache.ace.agent.launcher/felix.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/felix.bnd?rev=1514679&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/felix.bnd (added)
+++ ace/trunk/org.apache.ace.agent.launcher/felix.bnd Fri Aug 16 12:37:36 2013
@@ -0,0 +1,18 @@
+
+# The Jar Main-Class header
+Main-Class: org.apache.ace.agent.launcher.Launcher
+Bundle-Version: 1.0.0
+Bundle-Name: Apache ACE Agent Felix launcher
+Bundle-Description: Standalone launcher that start a Felix framework with an embedded ACE
Agent
+
+# Include the felix defaults
+felix.version=4.0.3
+Include-Resource: @${repo;org.apache.felix.framework;${felix.version}}!/default.properties,\
+    @${repo;org.apache.felix.framework;${felix.version}}!/META-INF/services/*,\
+    @${repo;org.apache.felix.framework;${felix.version}}!/org/*,\
+	${repo;org.apache.ace.agent;latest},\
+	META-INF/services/org.apache.ace.agent.launcher.BundleProvider=resources/org.apache.ace.agent.launcher.BundleProvider
+  
+Private-Package: org.apache.ace.agent.launcher,\
+	org.apache.commons.cli,\
+	org.apache.ace.agent;-split-package:=merge-first
\ No newline at end of file

Copied: ace/trunk/org.apache.ace.agent.launcher/resources/org.apache.ace.agent.launcher.BundleProvider
(from r1514625, ace/trunk/org.apache.ace.agent.launcher/resources/META-INF/services/org.apache.ace.agent.launcher.BundleProvider)
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/resources/org.apache.ace.agent.launcher.BundleProvider?p2=ace/trunk/org.apache.ace.agent.launcher/resources/org.apache.ace.agent.launcher.BundleProvider&p1=ace/trunk/org.apache.ace.agent.launcher/resources/META-INF/services/org.apache.ace.agent.launcher.BundleProvider&r1=1514625&r2=1514679&rev=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/resources/META-INF/services/org.apache.ace.agent.launcher.BundleProvider
(original)
+++ ace/trunk/org.apache.ace.agent.launcher/resources/org.apache.ace.agent.launcher.BundleProvider
Fri Aug 16 12:37:36 2013
@@ -1 +1,2 @@
 org.apache.ace.agent.launcher.AgentBundleProvider
+org.apache.ace.agent.launcher.BundleDirBundleProvider

Modified: ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/AgentBundleProvider.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/AgentBundleProvider.java?rev=1514679&r1=1514678&r2=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/AgentBundleProvider.java
(original)
+++ ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/AgentBundleProvider.java
Fri Aug 16 12:37:36 2013
@@ -29,12 +29,13 @@ import java.io.InputStream;
 public class AgentBundleProvider implements BundleProvider {
 
     @Override
-    public String getLocation() {
-        return "org.apache.ace.agent.jar";
+    public String[] getBundleNames() {
+        return new String[] { "org.apache.ace.agent" };
     }
 
     @Override
-    public InputStream getInputStream() {
-        return getClass().getClassLoader().getResourceAsStream("org.apache.ace.agent.jar");
+    public InputStream getInputStream(String name) {
+        return getClass().getClassLoader().getResourceAsStream(
+            "org.apache.ace.agent.jar");
     }
 }

Added: ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleDirBundleProvider.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleDirBundleProvider.java?rev=1514679&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleDirBundleProvider.java
(added)
+++ ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleDirBundleProvider.java
Fri Aug 16 12:37:36 2013
@@ -0,0 +1,55 @@
+package org.apache.ace.agent.launcher;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * {@link BundleProvider} that loads bundles from a directory.
+ * 
+ * @see META-INF/services/org.apache.ace.agent.launcher.BundleProvider
+ * 
+ */
+public class BundleDirBundleProvider implements BundleProvider {
+
+    public static final String BUNDLE_DIR_PROPERTY = "agent.bundles.dir";
+    public static final String BUNDLE_DIR_DEFAULT = "bundles";
+
+    @Override
+    public String[] getBundleNames() {
+        File dir = getDir();
+        if (!dir.exists() || !dir.canRead()) {
+            return new String[] {};
+        }
+
+        File[] bundles = dir.listFiles();
+        List<String> names = new ArrayList<String>();
+        for (File bundle : bundles) {
+            names.add(bundle.getName());
+        }
+        return names.toArray(new String[names.size()]);
+    }
+
+    @Override
+    public InputStream getInputStream(String bundleName) throws IOException {
+        File dir = getDir();
+        if (!dir.exists() || !dir.canRead()) {
+            throw new IOException("No such bundle in dir " + dir.getAbsolutePath());
+        }
+        File bundle = new File(dir, bundleName);
+        if (!bundle.exists() || !bundle.canRead()) {
+            throw new IOException("No such bundle in dir " + dir.getAbsolutePath());
+        }
+        return new FileInputStream(bundle);
+    }
+
+    private File getDir() {
+        String dir = System.getProperty(BUNDLE_DIR_PROPERTY);
+        if (dir != null)
+            return new File(dir);
+        return new File(BUNDLE_DIR_DEFAULT);
+    }
+}

Copied: ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java
(from r1514625, ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java)
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java?p2=ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java&p1=ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java&r1=1514625&r2=1514679&rev=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java
(original)
+++ ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/BundleProvider.java
Fri Aug 16 12:37:36 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.ace.agent.launcher;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ServiceLoader;
 
@@ -28,16 +29,16 @@ import java.util.ServiceLoader;
 public interface BundleProvider {
 
     /**
-     * The bundle location.
+     * Return the bundle names.
      * 
-     * @return The location
+     * @return The names
      */
-    String getLocation();
+    String[] getBundleNames();
 
     /**
-     * The bundle input stream
+     * Return a bundle input stream
      * 
      * @return The input
      */
-    InputStream getInputStream();
+    InputStream getInputStream(String bundleName) throws IOException;
 }

Modified: ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java?rev=1514679&r1=1514678&r2=1514679&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java
(original)
+++ ace/trunk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java
Fri Aug 16 12:37:36 2013
@@ -43,6 +43,7 @@ import org.apache.commons.cli.HelpFormat
 import org.apache.commons.cli.Options;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
 import org.osgi.framework.launch.Framework;
@@ -99,7 +100,8 @@ public class Launcher {
 
         // // overwrite with user args
         // if (command.hasOption("a")) {
-        // configuration.put(CONFIG_IDENTIFICATION_KEY, command.getOptionValue("a"));
+        // configuration.put(CONFIG_IDENTIFICATION_KEY,
+        // command.getOptionValue("a"));
         // }
         // if (command.hasOption("s")) {
         // configuration.put(CONFIG_SERVERURL_KEY, command.getOptionValue("s"));
@@ -124,9 +126,12 @@ public class Launcher {
 
     private static void printHelp(Options options) {
         HelpFormatter formatter = new HelpFormatter();
-        formatter.printHelp(120, "java -jar org.apache.ace.agent.launcher [options] [configurationfile]",
-            "\nApache ACE AgentLauncher\n\n", options,
-            "\n\nConfiguration file options\n\nTODO", false);
+        formatter
+            .printHelp(
+                120,
+                "java -jar org.apache.ace.agent.launcher [options] [configurationfile]",
+                "\nApache ACE AgentLauncher\n\n", options,
+                "\n\nConfiguration file options\n\nTODO", false);
     }
 
     private static Properties loadDefaultProperties() throws IOException {
@@ -143,9 +148,11 @@ public class Launcher {
         }
     }
 
-    private static Properties loadUserProperties(String configFileArgument) throws IOException
{
+    private static Properties loadUserProperties(String configFileArgument)
+        throws IOException {
         File configFile = new File(configFileArgument);
-        if (!configFile.exists() || !configFile.isFile() || !configFile.canRead()) {
+        if (!configFile.exists() || !configFile.isFile()
+            || !configFile.canRead()) {
             System.err.println("Can not acces configuration file : " + configFileArgument);
             return null;
         }
@@ -172,7 +179,8 @@ public class Launcher {
      * Main execution logic of the launcher; Start a framework, install bundles and pass
configuration to the
      * {@link AgentFactory}.
      * 
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     public void run() throws Exception {
 
@@ -180,43 +188,18 @@ public class Launcher {
             FrameworkFactory frameworkFactory = loadFrameworkFactory();
             Map<String, String> frameworkProperties = createFrameworkProperties();
             if (m_verbose)
-                System.out.println("Launching OSGI framework\n factory\t: " + frameworkFactory.getClass().getName()
+ "\n properties\t: " + frameworkProperties);
+                System.out.println("Launching OSGI framework\n factory\t: "
+                    + frameworkFactory.getClass().getName()
+                    + "\n properties\t: " + frameworkProperties);
 
             Framework framework = frameworkFactory.newFramework(frameworkProperties);
             BundleContext context = null;
             framework.init();
             context = framework.getBundleContext();
 
-            BundleProvider[] bundleFactories = loadBundleProviders();
-            if (bundleFactories != null) {
-                for (BundleProvider bundleFactory : bundleFactories) {
-                    if (m_verbose)
-                        System.out.println(" bundle\t: " + bundleFactory.getLocation());
-                    InputStream inputStream = bundleFactory.getInputStream();
-                    try {
-                        Bundle bundle = context.installBundle(bundleFactory.getLocation(),
inputStream);
-                        bundle.start();
-                    }
-                    finally {
-                        inputStream.close();
-                    }
-                }
-            }
-
-            File[] bundleFiles = loadBundleFiles();
-            if (bundleFiles != null) {
-                for (File bundleFile : bundleFiles) {
-                    if (m_verbose)
-                        System.out.println(" bundle\t: " + bundleFile.getAbsolutePath());
-                    InputStream inputStream = new FileInputStream(bundleFile);
-                    try {
-                        Bundle bundle = context.installBundle(bundleFile.getAbsolutePath(),
inputStream);
-                        bundle.start();
-                    }
-                    finally {
-                        inputStream.close();
-                    }
-                }
+            BundleProvider[] bundleProviders = loadBundleProviders();
+            for (BundleProvider bundleProvider : bundleProviders) {
+                installBundles(context, bundleProvider);
             }
 
             framework.start();
@@ -233,11 +216,33 @@ public class Launcher {
         System.exit(0);
     }
 
+    private Bundle[] installBundles(BundleContext context, BundleProvider extensionProvider)
throws BundleException, IOException {
+        List<Bundle> bundles = new ArrayList<Bundle>();
+        for (String bundleName : extensionProvider.getBundleNames()) {
+            if (m_verbose)
+                System.out.println("Installing bundle\t: " + bundleName);
+            InputStream inputStream = null;
+            try {
+                inputStream = extensionProvider.getInputStream(bundleName);
+                bundles.add(context.installBundle(bundleName, inputStream));
+            }
+            finally {
+                if (inputStream != null)
+                    inputStream.close();
+            }
+        }
+        for (Bundle bundle : bundles) {
+            bundle.start();
+        }
+        return bundles.toArray(new Bundle[bundles.size()]);
+    }
+
     /**
      * Load {@link FrameworkFactory} through the {@link ServiceLoader}.
      * 
      * @return the first factory
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     private FrameworkFactory loadFrameworkFactory() throws Exception {
         ServiceLoader<FrameworkFactory> frameworkFactoryLoader = ServiceLoader.load(FrameworkFactory.class);
@@ -249,33 +254,11 @@ public class Launcher {
     }
 
     /**
-     * Load bundle file specified through configuration.
-     * 
-     * @return list of files
-     * @throws Exception on failure
-     */
-    private File[] loadBundleFiles() throws Exception {
-        List<File> bundleFiles = new ArrayList<File>();
-        String bundleFileConfig = m_configuration.get("system.bundles");
-        if (bundleFileConfig != null && !bundleFileConfig.trim().equals("")) {
-            String[] bundleFileNames = bundleFileConfig.trim().split(",");
-            int i = 0;
-            for (String bundleFileName : bundleFileNames) {
-                File bundleFile = new File(bundleFileName);
-                if (!bundleFile.exists() || !bundleFile.isFile() || !bundleFile.canRead())
{
-                    throw new IllegalArgumentException("Can not access configured file: "
+ bundleFile.getAbsolutePath());
-                }
-                bundleFiles.add(bundleFile);
-            }
-        }
-        return bundleFiles.toArray(new File[bundleFiles.size()]);
-    }
-
-    /**
      * Load {@link BundleProvider}s through the {@link ServiceLoader}.
      * 
      * @return list of providers
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     private BundleProvider[] loadBundleProviders() throws Exception {
         ServiceLoader<BundleProvider> bundleFactoryLoader = ServiceLoader.load(BundleProvider.class);
@@ -291,7 +274,8 @@ public class Launcher {
      * Build the framework launch properties.
      * 
      * @return the launch properties
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     private Map<String, String> createFrameworkProperties() throws Exception {
         Map<String, String> frameworkProperties = new HashMap<String, String>();
@@ -309,7 +293,6 @@ public class Launcher {
         }
         else {
             frameworkProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, extraPackage
+ "," + getAgentApiPackageSpec());
-
         }
         return frameworkProperties;
     }
@@ -318,10 +301,10 @@ public class Launcher {
      * Determines the export clause for the agent API package.
      * 
      * @return the export clause
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     private String getAgentApiPackageSpec() throws IOException {
-
         String apiPackage = AgentControl.class.getPackage().getName();
         String apiVersion = Version.emptyVersion.toString();
         InputStream packageInfoStream = null;



Mime
View raw message