Return-Path: X-Original-To: apmail-ace-commits-archive@www.apache.org Delivered-To: apmail-ace-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 45085107F6 for ; Fri, 3 May 2013 10:36:07 +0000 (UTC) Received: (qmail 67521 invoked by uid 500); 3 May 2013 10:36:06 -0000 Delivered-To: apmail-ace-commits-archive@ace.apache.org Received: (qmail 67482 invoked by uid 500); 3 May 2013 10:36:06 -0000 Mailing-List: contact commits-help@ace.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ace.apache.org Delivered-To: mailing list commits@ace.apache.org Received: (qmail 67455 invoked by uid 99); 3 May 2013 10:36:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 May 2013 10:36:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 May 2013 10:36:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 010E62388994; Fri, 3 May 2013 10:35:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1478717 - in /ace/trunk: org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java run-target/target.bndrun Date: Fri, 03 May 2013 10:35:38 -0000 To: commits@ace.apache.org From: bramk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130503103539.010E62388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bramk Date: Fri May 3 10:35:38 2013 New Revision: 1478717 URL: http://svn.apache.org/r1478717 Log: ACE-323 Formatting / License header Modified: ace/trunk/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java ace/trunk/org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java ace/trunk/run-target/target.bndrun Modified: ace/trunk/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java?rev=1478717&r1=1478716&r2=1478717&view=diff ============================================================================== --- ace/trunk/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java (original) +++ ace/trunk/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java Fri May 3 10:35:38 2013 @@ -42,47 +42,48 @@ import org.osgi.framework.launch.Framewo */ public class Main { - private static class AdditionalBundlesOption extends KeyValueArgument { + private static class AdditionalBundlesOption extends KeyValueArgument { private final List m_additionalBundleActivators; - - public AdditionalBundlesOption() { - super("bundle"); - - m_additionalBundleActivators = new ArrayList(); - } - - /** - * @return the additionalBundleActivators - */ - public List getAdditionalBundleActivators() { - return new ArrayList(m_additionalBundleActivators); - } - - @Override - public String getDescription() { - return "bundle: adds an additional bundle to be started with this management agent: bundle=my.fully.qualified.BundleActivator"; - } - - @Override - protected void doHandle(String value) { - if (!"".equals(value.trim()) && !m_additionalBundleActivators.contains(value)) { - m_additionalBundleActivators.add(value); - } - } + + public AdditionalBundlesOption() { + super("bundle"); + + m_additionalBundleActivators = new ArrayList(); + } + + /** + * @return the additionalBundleActivators + */ + public List getAdditionalBundleActivators() { + return new ArrayList(m_additionalBundleActivators); + } + + @Override + public String getDescription() { + return "bundle: adds an additional bundle to be started with this management agent: bundle=my.fully.qualified.BundleActivator"; + } + + @Override + protected void doHandle(String value) { + if (!"".equals(value.trim()) && !m_additionalBundleActivators.contains(value)) { + m_additionalBundleActivators.add(value); + } + } } private interface Argument { String getDescription(); + void handle(String argument); } - + private static class FrameworkOption extends KeyValueArgument { - private Properties m_properties = new Properties(); - - public FrameworkOption() { - super("fwOption"); - } - + private Properties m_properties = new Properties(); + + public FrameworkOption() { + super("fwOption"); + } + public String getDescription() { return "fwOption: sets framework options for the OSGi framework to be created. This argument may be repeated"; } @@ -103,12 +104,12 @@ public class Main { } private static abstract class KeyValueArgument implements Argument { - protected final String m_key; - - public KeyValueArgument(String key) { - m_key = key; - } - + protected final String m_key; + + public KeyValueArgument(String key) { + m_key = key; + } + public void handle(String argument) { Pattern pattern = Pattern.compile(m_key + "=(.*)"); Matcher m = pattern.matcher(argument); @@ -121,60 +122,63 @@ public class Main { } private static class SystemPropertyArgument extends KeyValueArgument { - private final String m_description; - - public SystemPropertyArgument(String key, String description) { - super(key); - m_description = description; - } - - @Override - public String getDescription() { - return m_key + ": " + m_description; - } - - @Override - protected void doHandle(String value) { - System.setProperty(m_key, value); - } + private final String m_description; + + public SystemPropertyArgument(String key, String description) { + super(key); + m_description = description; + } + + @Override + public String getDescription() { + return m_key + ": " + m_description; + } + + @Override + protected void doHandle(String value) { + System.setProperty(m_key, value); + } } private static final boolean m_quiet = Boolean.parseBoolean(System.getProperty("quiet", "false")); - /** + /** * MAIN ENTRY POINT * - * @param args the command line arguments, never null. - * @throws Exception in case of errors. + * @param args + * the command line arguments, never null. + * @throws Exception + * in case of errors. */ public static void main(String[] args) throws Exception { new Main(args).run(); } - + private final FrameworkOption m_fwOptionHandler; private final AdditionalBundlesOption m_additionalBundleHandler; - /** + /** * Creates a new {@link Main} instance. * - * @param args the command line arguments, never null. + * @param args + * the command line arguments, never null. */ public Main(String[] args) { - m_additionalBundleHandler = new AdditionalBundlesOption(); - m_fwOptionHandler = new FrameworkOption(); - + m_additionalBundleHandler = new AdditionalBundlesOption(); + m_fwOptionHandler = new FrameworkOption(); + final List arguments = new ArrayList(); - Argument agents = new SystemPropertyArgument("agents", "configures multiple management agents: agent-id,identification,discovery[;agent-id,identification,discovery]*"); + Argument agents = new SystemPropertyArgument("agents", "configures multiple management agents: agent-id,identification,discovery[;agent-id,identification,discovery]*"); Argument auth = new SystemPropertyArgument("auth", "point to the properties file containing the authentication credentials for a certain subsystem: "); Argument discovery = new SystemPropertyArgument("discovery", "sets the ACE server to connect to"); Argument identification = new SystemPropertyArgument("id(?:entification)?", "sets the target ID to use") { - @Override - protected void doHandle(String value) { - System.setProperty("identification", value); - } + @Override + protected void doHandle(String value) { + System.setProperty("identification", value); + } }; - Argument help = new Argument() { + Argument help = new Argument() { public String getDescription() { return "help: prints this help message"; } @@ -188,29 +192,30 @@ public class Main { }; arguments.addAll(Arrays.asList(agents, auth, discovery, identification, m_additionalBundleHandler, m_fwOptionHandler, help)); - + for (String arg : args) { for (Argument argument : arguments) { argument.handle(arg); } } } - + public void run() throws Exception { Map frameworkProperties = createFrameworkProperties(); FrameworkFactory factory = createFrameworkFactory(); - + Framework framework = factory.newFramework(frameworkProperties); - framework.start(); + framework.start(); - try { - framework.waitForStop(0); - } finally { - System.exit(0); - } + try { + framework.waitForStop(0); + } + finally { + System.exit(0); + } } - + /** * @param extraSystemPackages * @return @@ -235,20 +240,21 @@ public class Main { * @return */ private FrameworkFactory createFrameworkFactory() { - try { - Class clazz = Class.forName("org.apache.felix.framework.FrameworkFactory"); - return (FrameworkFactory) clazz.newInstance(); - } catch (Exception e) { - throw new RuntimeException("Failed to create framework factory?!", e); - } + try { + Class clazz = Class.forName("org.apache.felix.framework.FrameworkFactory"); + return (FrameworkFactory) clazz.newInstance(); + } + catch (Exception e) { + throw new RuntimeException("Failed to create framework factory?!", e); + } } /** - * @return - * @throws Exception - */ - private Map createFrameworkProperties() throws Exception { - String[] extraSystemPackageArray = { + * @return + * @throws Exception + */ + private Map createFrameworkProperties() throws Exception { + String[] extraSystemPackageArray = { "org.osgi.service.deploymentadmin;version=\"1.0\"", "org.osgi.service.deploymentadmin.spi;version=\"1.0\"", "org.osgi.service.cm;version=\"1.3\"", @@ -266,66 +272,68 @@ public class Main { frameworkProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, getExtraSystemPackages(extraSystemPackageArray)); frameworkProperties.putAll(m_fwOptionHandler.getProperties()); - return frameworkProperties; - } - + return frameworkProperties; + } + /** - * @return - * @throws IOException - */ - private List getAdditionalBundleActivators() throws IOException { - List bundleActivators = m_additionalBundleHandler.getAdditionalBundleActivators(); - - // The actual management agent itself... - bundleActivators.add(0, "org.apache.ace.managementagent.Activator"); - - // Pull in all the additional mentioned bundles on the classpath... - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - Enumeration resources = cl.getResources("META-INF/MANIFEST.MF"); - while (resources.hasMoreElements()) { - URL resource = resources.nextElement(); - try { - Manifest mf = new Manifest(resource.openStream()); - String bundleActivator = mf.getMainAttributes().getValue(Constants.BUNDLE_ACTIVATOR); - if (bundleActivator != null) { - bundleActivators.add(bundleActivator); - } - } catch (Exception e) { - System.err.println("Failed to read resource: " + resource + "!\nPossible reason: " + e); - } - } - return bundleActivators; - } - + * @return + * @throws IOException + */ + private List getAdditionalBundleActivators() throws IOException { + List bundleActivators = m_additionalBundleHandler.getAdditionalBundleActivators(); + + // The actual management agent itself... + bundleActivators.add(0, "org.apache.ace.managementagent.Activator"); + + // Pull in all the additional mentioned bundles on the classpath... + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + Enumeration resources = cl.getResources("META-INF/MANIFEST.MF"); + while (resources.hasMoreElements()) { + URL resource = resources.nextElement(); + try { + Manifest mf = new Manifest(resource.openStream()); + String bundleActivator = mf.getMainAttributes().getValue(Constants.BUNDLE_ACTIVATOR); + if (bundleActivator != null) { + bundleActivators.add(bundleActivator); + } + } + catch (Exception e) { + System.err.println("Failed to read resource: " + resource + "!\nPossible reason: " + e); + } + } + return bundleActivators; + } + /** * @return * @throws Exception */ private List getSystemBundleActivators() throws Exception { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); - List result = new ArrayList(); + List result = new ArrayList(); - List bundleActivators = getAdditionalBundleActivators(); - for (String bundleActivator : bundleActivators) { - try { - Object instance = cl.loadClass(bundleActivator).newInstance(); - if (!m_quiet) { - System.out.println("Adding additional bundle activator: " + bundleActivator); - } - result.add(instance); - } catch (Exception e) { - System.err.println("Failed to add bundle activator: " + bundleActivator + "!\nPossible reason: " + e); - } - } + List bundleActivators = getAdditionalBundleActivators(); + for (String bundleActivator : bundleActivators) { + try { + Object instance = cl.loadClass(bundleActivator).newInstance(); + if (!m_quiet) { + System.out.println("Adding additional bundle activator: " + bundleActivator); + } + result.add(instance); + } + catch (Exception e) { + System.err.println("Failed to add bundle activator: " + bundleActivator + "!\nPossible reason: " + e); + } + } - return result; + return result; } private void showHelp(List arguments) { System.out.println("Apache ACE Launcher\n" - + "Usage:\n" - + " java -jar ace-launcher.jar [identification=] [discovery=] [options...]"); + + "Usage:\n" + + " java -jar ace-launcher.jar [identification=] [discovery=] [options...]"); System.out.println("All known options are:"); for (Argument argument : arguments) { @@ -333,7 +341,7 @@ public class Main { } System.out.println("Example:\n" - + " java -jar ace-launcher.jar identification=MyTarget discovery=http://provisioning.company.com:8080 " - + "fwOption=org.osgi.framework.system.packages.extra=sun.misc,com.sun.management"); + + " java -jar ace-launcher.jar identification=MyTarget discovery=http://provisioning.company.com:8080 " + + "fwOption=org.osgi.framework.system.packages.extra=sun.misc,com.sun.management"); } } Modified: ace/trunk/org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java?rev=1478717&r1=1478716&r2=1478717&view=diff ============================================================================== --- ace/trunk/org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java (original) +++ ace/trunk/org.apache.ace.managementagent/src/org/apache/ace/managementagent/Activator.java Fri May 3 10:35:38 2013 @@ -1,10 +1,27 @@ +/* + * 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.ace.managementagent; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Dictionary; -import java.util.HashMap; import java.util.Hashtable; import java.util.Properties; @@ -35,7 +52,7 @@ public class Activator extends Dependenc new org.apache.felix.deploymentadmin.Activator(), new org.apache.felix.eventadmin.impl.Activator() }; - + private volatile ConfigurationAdmin m_config; /** @@ -85,7 +102,7 @@ public class Activator extends Dependenc .setService(ConfigurationAdmin.class) .setRequired(true))); } - + /** * Called by the dependency manager when the configuration admin service becomes available. */ @@ -111,7 +128,7 @@ public class Activator extends Dependenc // a=name, b=id, c=url String[] definitions = agents.split(";"); StringBuffer instances = new StringBuffer(); - + for (String definition : definitions) { String[] args = definition.split(","); if (args.length != 3) { @@ -121,9 +138,9 @@ public class Activator extends Dependenc String ma = args[0]; String id = args[1]; String url = args[2]; - + boolean isFileUrl = "file".equals((new URL(url)).getProtocol()); - + configureFactory("org.apache.ace.identification.property.factory", "ma", ma, "targetID", id); configureFactory("org.apache.ace.discovery.property.factory", "ma", ma, "serverURL", url); // if discovery points to the local filesystem, it's no use trying to sync the audit log @@ -136,8 +153,8 @@ public class Activator extends Dependenc configure("org.apache.ace.scheduler", "ma=" + ma + ";name=auditlog", syncInterval); instances.append( " Instance : " + ma + "\n" + - " Target ID : " + id + "\n" + - " Server : " + url + "\n"); + " Target ID : " + id + "\n" + + " Server : " + url + "\n"); } if (!m_quiet) { @@ -151,7 +168,7 @@ public class Activator extends Dependenc String server = System.getProperty("discovery", "http://localhost:8080"); String targetId = System.getProperty("identification", "defaultTargetID"); boolean isFileUrl = "file".equals((new URL(server)).getProtocol()); - + configure("org.apache.ace.discovery.property", "serverURL", server); configure("org.apache.ace.identification.property", "targetID", targetId); if (!isFileUrl) { @@ -209,7 +226,7 @@ public class Activator extends Dependenc conf.update(properties); } } - + private void configureAuth(String factoryPid, String value) throws IOException { try { File file = new File(value); @@ -231,14 +248,14 @@ public class Activator extends Dependenc System.err.println("Invalid authentication properties for " + value + " (" + e.getMessage() + ")"); } } - + private Properties loadProperties(String factoryPID, File f) throws IOException { return loadProperties(factoryPID, f.toURI().toURL()); } - + private Properties loadProperties(String factoryPID, URL url) throws IOException { Configuration conf = m_config.createFactoryConfiguration(factoryPID, null); - + Properties props = new Properties(); props.load(url.openStream()); conf.update((Dictionary) ((Hashtable) props)); Modified: ace/trunk/run-target/target.bndrun URL: http://svn.apache.org/viewvc/ace/trunk/run-target/target.bndrun?rev=1478717&r1=1478716&r2=1478717&view=diff ============================================================================== --- ace/trunk/run-target/target.bndrun (original) +++ ace/trunk/run-target/target.bndrun Fri May 3 10:35:38 2013 @@ -4,7 +4,7 @@ org.apache.felix.gogo.runtime,\ org.apache.felix.gogo.shell,\ org.apache.ace.managementagent;version=latest --runvm: -Dlog=true -Didentification=target-1 -Ddiscovery=http://localhost:8080 +-runvm: -Dlog=true -Didentification=target-1 -Ddiscovery=http://localhost:8080 -Dquiet=true -Dsyncinterval=10000 -runproperties: \ org.apache.felix.log.storeDebug=true,\ org.apache.felix.eventadmin.Timeout=0,\