ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1370188 - in /ace/sandbox/marrs/org.apache.ace.launcher: .settings/org.eclipse.jdt.core.prefs src/org/apache/ace/launcher/Main.java
Date Tue, 07 Aug 2012 11:30:20 GMT
Author: jawi
Date: Tue Aug  7 11:30:20 2012
New Revision: 1370188

URL: http://svn.apache.org/viewvc?rev=1370188&view=rev
Log:
Some code cleanups & simplifications.

Modified:
    ace/sandbox/marrs/org.apache.ace.launcher/.settings/org.eclipse.jdt.core.prefs
    ace/sandbox/marrs/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java

Modified: ace/sandbox/marrs/org.apache.ace.launcher/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.launcher/.settings/org.eclipse.jdt.core.prefs?rev=1370188&r1=1370187&r2=1370188&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.launcher/.settings/org.eclipse.jdt.core.prefs (original)
+++ ace/sandbox/marrs/org.apache.ace.launcher/.settings/org.eclipse.jdt.core.prefs Tue Aug
 7 11:30:20 2012
@@ -1,4 +1,9 @@
 eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
 org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
 org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
@@ -8,10 +13,11 @@ org.eclipse.jdt.core.compiler.problem.de
 org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
 org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
 org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
 org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
 org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
 org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
-org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
 org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
 org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
@@ -21,7 +27,9 @@ org.eclipse.jdt.core.compiler.problem.in
 org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
 org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
 org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
 org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
 org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
@@ -30,12 +38,17 @@ org.eclipse.jdt.core.compiler.problem.mi
 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
 org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
 org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
 org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
 org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
 org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
 org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
 org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
-org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
 org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
 org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
@@ -48,7 +61,8 @@ org.eclipse.jdt.core.compiler.problem.su
 org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
 org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
 org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
-org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
 org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
 org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
 org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore

Modified: ace/sandbox/marrs/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java
URL: http://svn.apache.org/viewvc/ace/sandbox/marrs/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java?rev=1370188&r1=1370187&r2=1370188&view=diff
==============================================================================
--- ace/sandbox/marrs/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java (original)
+++ ace/sandbox/marrs/org.apache.ace.launcher/src/org/apache/ace/launcher/Main.java Tue Aug
 7 11:30:20 2012
@@ -19,17 +19,22 @@
 
 package org.apache.ace.launcher;
 
+import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.ace.managementagent.Activator;
+import org.apache.felix.framework.util.FelixConstants;
 import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
 
 /**
@@ -37,150 +42,180 @@ import org.osgi.framework.launch.Framewo
  */
 public class Main {
 
-    private final boolean m_quiet = Boolean.parseBoolean(System.getProperty("quiet", "false"));
-    private final List m_additionalBundleActivators = new ArrayList();
-
-    private Argument m_identification = new KeyValueArgument() {
-        public void handle(String key, String value) {
-            if ("identification".equals(key)) {
-                System.setProperty("identification", value);
-            }
-        }
-
-        public String getDescription() {
-            return "identification: sets the target ID to use";
-        }
-    };
-
-    private Argument m_discovery = new KeyValueArgument() {
-        public void handle(String key, String value) {
-            if ("discovery".equals(key)) {
-                System.setProperty("discovery", value);
-            }
-        }
+	private static class AdditionalBundlesOption extends KeyValueArgument {
+        private final List<String> m_additionalBundleActivators;
+        
+		public AdditionalBundlesOption() {
+			super("bundle");
+			
+			m_additionalBundleActivators = new ArrayList<String>();
+		}
+		
+		/**
+		 * @return the additionalBundleActivators
+		 */
+		public List<String> getAdditionalBundleActivators() {
+			return new ArrayList<String>(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");
+		}
+		
         public String getDescription() {
-            return "discovery: sets the ACE server to connect to";
+            return "fwOption: sets framework options for the OSGi framework to be created.
This argument may be repeated";
         }
-    };
 
-    private Argument m_agents = new KeyValueArgument() {
-        public void handle(String key, String value) {
-            if ("agents".equals(key)) {
-                System.setProperty("agents", value);
-            }
+        public Properties getProperties() {
+            return m_properties;
         }
 
-        public String getDescription() {
-            return "agents: configures multiple management agents: agent-id,identification,discovery[;agent-id,identification,discovery]*";
-        }
-    };
-    
-    private Argument m_auth = new KeyValueArgument() {
         @Override
-        protected void handle(String key, String value) {
-            if ("auth".equals(key)) {
-                System.setProperty("auth", value);
+        protected void doHandle(String value) {
+            Pattern pattern = Pattern.compile("([^=]*)=(.*)");
+            Matcher m = pattern.matcher(value);
+            if (!m.matches()) {
+                throw new IllegalArgumentException(value + " is not a valid framework option.");
             }
+            m_properties.put(m.group(1), m.group(2));
         }
-        
-        public String getDescription() {
-            return "auth: point to the properties file containing the authentication credentials
for a certain subsystem: <dir/file/url>";
-        }
-    };
+    }
 
-    private Argument m_help = new Argument() {
+    private static abstract class KeyValueArgument implements Argument {
+    	protected final String m_key;
+    	
+		public KeyValueArgument(String key) {
+			m_key = key;
+		}
+    	
         public void handle(String argument) {
-            if ("help".equals(argument)) {
-                showHelp();
-                System.exit(0);
+            Pattern pattern = Pattern.compile(m_key + "=(.*)");
+            Matcher m = pattern.matcher(argument);
+            if (m.matches()) {
+                doHandle(m.group(1));
             }
         }
 
-        public String getDescription() {
-            return "help: prints this help message";
-        }
-    };
+        protected abstract void doHandle(String value);
+    }
 
-    private Argument m_additionalBundles = new KeyValueArgument() {
-        public void handle(String key, String value) {
-            if ("bundle".equals(key)) {
-                try {
-                    Class clazz = Class.forName(value);
-                    if (!m_quiet) {
-                        System.out.println("Adding additional bundle activator: " + clazz.getName());
-                    }
-                    m_additionalBundleActivators.add(clazz.newInstance());
-                }
-                catch (Exception e) {
-                    System.err.println("Bundle (" + value + ") not added! Details: " + e.getMessage());
-                }
-            }
-        }
+    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);
+		}
+    }
 
-        public String getDescription() {
-            return "bundle: adds an additional bundle to be started with this management
agent: bundle=my.fully.qualified.BundleActivator";
-        }
-    };
-    
-    private FrameworkOption m_fwOptionHandler = new FrameworkOption();
-    
-    private final List<Argument> m_arguments = Arrays.asList(
-        m_auth,
-        m_additionalBundles,
-        m_identification,
-        m_discovery,
-        m_agents,
-        m_fwOptionHandler,
-        m_help);
+    private static final boolean m_quiet = Boolean.parseBoolean(System.getProperty("quiet",
"false"));
 
+	/**
+     * MAIN ENTRY POINT
+     * 
+     * @param args the command line arguments, never <code>null</code>.
+     * @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 <code>null</code>.
+     */
     public Main(String[] args) {
+    	m_additionalBundleHandler = new AdditionalBundlesOption();
+    	m_fwOptionHandler = new FrameworkOption();
+    	
+        final List<Argument> arguments = new ArrayList<Argument>();
+
+    	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: <dir/file/url>");
+        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);
+        	}
+        };
+    	Argument help = new Argument() {
+            public String getDescription() {
+                return "help: prints this help message";
+            }
+
+            public void handle(String argument) {
+                if ("help".equals(argument)) {
+                    showHelp(arguments);
+                    System.exit(0);
+                }
+            }
+        };
+
+        arguments.addAll(Arrays.asList(agents, auth, discovery, identification, m_additionalBundleHandler,
m_fwOptionHandler, help));
+        
         for (String arg : args) {
-            for (Argument argument : m_arguments) {
+            for (Argument argument : arguments) {
                 argument.handle(arg);
             }
         }
     }
-
+    
     public void run() throws Exception {
-        FrameworkFactory factory = (FrameworkFactory) Class.forName("org.apache.felix.framework.FrameworkFactory").newInstance();
-
-        List activators = new ArrayList();
-        activators.add(new Activator());
-        activators.addAll(m_additionalBundleActivators);
-        
-        String[] extraSystemPackageArray = {
-            "org.osgi.service.deploymentadmin;version=\"1.0\"",
-            "org.osgi.service.deploymentadmin.spi;version=\"1.0\"",
-            "org.osgi.service.cm;version=\"1.3\"",
-            "org.osgi.service.event;version=\"1.2\"",
-            "org.osgi.service.log;version=\"1.3\"",
-            "org.osgi.service.metatype;version=\"1.1\"",
-            "org.apache.felix.dm;version=\"3.0\"",
-            "org.apache.felix.dm.tracker;version=\"3.0\"",
-            "org.apache.ace.log;version=\"0.8.1.SNAPSHOT\"",
-            "org.apache.ace.deployment.service;version=\"0.8.1.SNAPSHOT\""
-        };
+        Map frameworkProperties = createFrameworkProperties();
+        FrameworkFactory factory = createFrameworkFactory();
         
-        String extraSystemPackages = createExtraSystemPackages(extraSystemPackageArray);
+        Framework framework = factory.newFramework(frameworkProperties);
 
-        Map frameworkProperties = new HashMap();
-        frameworkProperties.put("felix.systembundle.activators", activators);
-        frameworkProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, extraSystemPackages);
-        frameworkProperties.putAll(m_fwOptionHandler.getProperties());
+		framework.start();
 
-        factory.newFramework(frameworkProperties).start();
+		try {
+		    framework.waitForStop(0);
+		} finally {
+		    System.exit(0);
+		}
     }
-
+    
     /**
      * @param extraSystemPackages
      * @return
      */
-    private String createExtraSystemPackages(String[] extraSystemPackages) {
+    private String getExtraSystemPackages(String[] extraSystemPackages) {
         String isolateMA = System.getProperty("isolateMA", "managementagent");
 
         StringBuilder sb = new StringBuilder();
@@ -196,58 +231,109 @@ public class Main {
         return sb.toString();
     }
 
-    private void showHelp() {
-        System.out.println("Apache ACE Launcher\n"
-                + "Usage:\n"
-                + "  java -jar ace-launcher.jar [identification=<id>] [discovery=<ace-server>]
[options...]");
+    /**
+     * @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);
+		}
+    }
 
-        System.out.println("All known options are,");
-        for (Argument argument : m_arguments) {
-            System.out.println("  " + argument.getDescription());
-        }
+    /**
+	 * @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\"",
+            "org.osgi.service.event;version=\"1.2\"",
+            "org.osgi.service.log;version=\"1.3\"",
+            "org.osgi.service.metatype;version=\"1.1\"",
+            "org.apache.felix.dm;version=\"3.0\"",
+            "org.apache.felix.dm.tracker;version=\"3.0\"",
+            "org.apache.ace.log;version=\"0.8\"",
+            "org.apache.ace.deployment.service;version=\"0.8\""
+        };
 
-        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");
-    }
+        Map frameworkProperties = new HashMap();
+        frameworkProperties.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, getSystemBundleActivators());
+        frameworkProperties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, getExtraSystemPackages(extraSystemPackageArray));
+        frameworkProperties.putAll(m_fwOptionHandler.getProperties());
 
-    private interface Argument {
-        void handle(String argument);
-        String getDescription();
-    }
+		return frameworkProperties;
+	}
+    
+    /**
+	 * @return
+	 * @throws IOException
+	 */
+	private List<String> getAdditionalBundleActivators() throws IOException {
+		List<String> 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<URL> 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<Object> getSystemBundleActivators() throws Exception {
+    	ClassLoader cl = Thread.currentThread().getContextClassLoader();
 
-    private static abstract class KeyValueArgument implements Argument {
-        public void handle(String argument) {
-            Pattern pattern = Pattern.compile("(\\w*)=(.*)");
-            Matcher m = pattern.matcher(argument);
-            if (m.matches()) {
-                handle(m.group(1), m.group(2));
-            }
-        }
+    	List<Object> result = new ArrayList<Object>();
 
-        protected abstract void handle(String key, String value);
+    	List<String> 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;
     }
 
-    private static class FrameworkOption extends KeyValueArgument {
-        private Properties m_properties = new Properties();
-        @Override
-        protected void handle(String key, String value) {
-            if (key.equals("fwOption")) {
-                Pattern pattern = Pattern.compile("([^=]*)=(.*)");
-                Matcher m = pattern.matcher(value);
-                if (!m.matches()) {
-                    throw new IllegalArgumentException(value + " is not a valid framework
option.");
-                }
-                m_properties.put(m.group(1), m.group(2));
-            }
-        }
+    private void showHelp(List<Argument> arguments) {
+        System.out.println("Apache ACE Launcher\n"
+                + "Usage:\n"
+                + "  java -jar ace-launcher.jar [identification=<id>] [discovery=<ace-server>]
[options...]");
 
-        public String getDescription() {
-            return "fwOption: sets framework options for the OSGi framework to be created.
This argument may be repeated";
+        System.out.println("All known options are:");
+        for (Argument argument : arguments) {
+            System.out.println("  " + argument.getDescription());
         }
 
-        public Properties getProperties() {
-            return m_properties;
-        }
+        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");
     }
 }



Mime
View raw message