geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r391393 - in /geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin: GeneratorMojo.java LaunchOSGIMojo.java XSDImporterMojo.java
Date Tue, 04 Apr 2006 19:54:20 GMT
Author: sppatel
Date: Tue Apr  4 12:54:19 2006
New Revision: 391393

URL: http://svn.apache.org/viewcvs?rev=391393&view=rev
Log:
preservere osgi instance between executions

Modified:
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/GeneratorMojo.java
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/LaunchOSGIMojo.java
    geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/XSDImporterMojo.java

Modified: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/GeneratorMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/GeneratorMojo.java?rev=391393&r1=391392&r2=391393&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/GeneratorMojo.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/GeneratorMojo.java
Tue Apr  4 12:54:19 2006
@@ -26,6 +26,8 @@
 public class GeneratorMojo extends LaunchOSGIMojo {
 
 	public static final String APPLICATION_ID = "org.eclipse.emf.codegen.ecore.Generator";
+	
+	public static final String GOAL_NAME = "generate";
 
 	/**
 	 * @parameter
@@ -62,6 +64,10 @@
 	 */
 	protected String getApplicationID() {
 		return APPLICATION_ID;
+	}
+	
+	protected String getGoalName() {
+		return GOAL_NAME;
 	}
 
 	/*

Modified: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/LaunchOSGIMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/LaunchOSGIMojo.java?rev=391393&r1=391392&r2=391393&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/LaunchOSGIMojo.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/LaunchOSGIMojo.java
Tue Apr  4 12:54:19 2006
@@ -23,9 +23,13 @@
 import java.net.URLClassLoader;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -40,8 +44,13 @@
 	public static final String PROP_INSTANCE_AREA = "osgi.instance.area";
 	public static final String PROP_APPLICATION_ID = "eclipse.application";
 	public static final String PROP_USE_SYS_PROPS = "osgi.framework.useSystemProperties";
+	public static final String PROP_NOSHUTDOWN = "osgi.noShutdown";
 	public static final String STARTER = "org.eclipse.core.runtime.adaptor.EclipseStarter";
 
+	public static final String TOTAL_EXECUTIONS = "plugin.total.executions";
+	public static final String CURRENT_EXECUTION = "plugin.current.execution";
+	public static final String PLUGIN_ARTIFACT_ID = "maven-emf-plugin";
+
 	/**
 	 * @parameter expression="${settings.localRepository}/eclipse/eclipse"
 	 */
@@ -76,6 +85,9 @@
 
 		validate();
 
+		boolean keepFrameworkAlive = keepFrameworkAlive();
+		System.out.println("keepFrameworkAlive = " + keepFrameworkAlive);
+
 		String[] args = getArguments();
 		if (args == null)
 			args = new String[] {};
@@ -93,29 +105,48 @@
 			initalPropertyMap.put(PROP_FRAMEWORK, osgi.toExternalForm());
 			initalPropertyMap.put(PROP_INSTANCE_AREA, workspace.toURL().toExternalForm());
 			initalPropertyMap.put(PROP_APPLICATION_ID, getApplicationID());
+			initalPropertyMap.put(PROP_NOSHUTDOWN, Boolean.toString(keepFrameworkAlive));
 
 			URL[] osgiURLArray = { new URL((String) initalPropertyMap.get(PROP_FRAMEWORK)) };
-			URLClassLoader frameworkClassLoader = new URLClassLoader(osgiURLArray);
-			Class clazz = frameworkClassLoader.loadClass(STARTER);
+			
+			Class clazz = null;
+			if(getPluginContext().containsKey(STARTER)) {
+				clazz = (Class) getPluginContext().get(STARTER);
+			} else  {
+				URLClassLoader frameworkClassLoader = new URLClassLoader(osgiURLArray);
+				clazz = frameworkClassLoader.loadClass(STARTER);
+				getPluginContext().put(STARTER, clazz);
+			}
 
 			Method setInitialProperties = clazz.getMethod("setInitialProperties", new Class[] { Map.class
});
 			setInitialProperties.invoke(null, new Object[] { initalPropertyMap });
 
-			Method runMethod = clazz.getMethod("run", new Class[] {
-					String[].class, Runnable.class });
-			runMethod.invoke(null, new Object[] { args, null });
+			if (!keepFrameworkAlive || getCurrentExecution() == 1) {
+				Method runMethod = clazz.getMethod("run", new Class[] {
+						String[].class, Runnable.class });
+				runMethod.invoke(null, new Object[] { args, null });			
+			} else {				
+				Method runMethod = clazz.getMethod("run", new Class[] { Object.class });
+				runMethod.invoke(null, new Object[] { args });
+			}
 		} catch (Exception e) {
+			e.printStackTrace();
 			throw new MojoFailureException(e.getMessage());
 		}
 		
+		if(getCurrentExecution() == getTotalExecutions()) {
+			getPluginContext().remove(CURRENT_EXECUTION);
+		} else {
+			getPluginContext().put(CURRENT_EXECUTION, new Integer(getCurrentExecution() + 1));
+		}
 	}
-	
-
 
 	protected abstract String getApplicationID();
 
 	protected abstract String[] getArguments();
 
+	protected abstract String getGoalName();
+
 	protected URL findOSGI() {
 		File bundleDir = new File(eclipseHome.getAbsoluteFile()
 				+ File.separator + "plugins");
@@ -146,5 +177,39 @@
 
 	protected void validate() throws MojoFailureException {
 
+	}
+
+	private boolean keepFrameworkAlive() {
+		return getCurrentExecution() <= getTotalExecutions();
+	}
+
+	private int getCurrentExecution() {
+		int currentExecution = 1;
+		if (getPluginContext().containsKey(CURRENT_EXECUTION)) {
+			currentExecution = ((Integer) getPluginContext().get(CURRENT_EXECUTION)).intValue();
+		}
+		return currentExecution;
+	}
+
+	private int getTotalExecutions() {
+		if (!getPluginContext().containsKey(TOTAL_EXECUTIONS)) {
+			System.out.println("totalExecutions not set");
+			int totalExecutions = 0;
+			List plugins = mavenProject.getBuild().getPlugins();
+			Iterator i = plugins.iterator();
+			while (i.hasNext()) {
+				Plugin plugin = (Plugin) i.next();
+				if (PLUGIN_ARTIFACT_ID.equals(plugin.getArtifactId())) {
+					Iterator j = plugin.getExecutions().iterator();
+					while (j.hasNext()) {
+						PluginExecution execution = (PluginExecution) j.next();
+						if (execution.getGoals().contains(getGoalName()))
+							totalExecutions++;
+					}
+				}
+			}
+			getPluginContext().put(TOTAL_EXECUTIONS, new Integer(totalExecutions));
+		}
+		return ((Integer) getPluginContext().get(TOTAL_EXECUTIONS)).intValue();
 	}
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/XSDImporterMojo.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/XSDImporterMojo.java?rev=391393&r1=391392&r2=391393&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/XSDImporterMojo.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/maven-plugins/maven-emf-plugin/src/main/java/org/apache/emf/plugin/XSDImporterMojo.java
Tue Apr  4 12:54:19 2006
@@ -28,6 +28,8 @@
 public class XSDImporterMojo extends LaunchOSGIMojo {
 
 	public static final String APPLICATION_ID = "org.eclipse.xsd.ecore.importer.XSD2GenModel";
+	
+	public static final String GOAL_NAME = "xsd2genmodel";
 
 	/**
 	 * @parameter
@@ -95,6 +97,10 @@
 	 */
 	protected String getApplicationID() {
 		return APPLICATION_ID;
+	}
+	
+	protected String getGoalName() {
+		return GOAL_NAME;
 	}
 
 	protected StringBuffer processParameters() {



Mime
View raw message