servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r428858 - in /incubator/servicemix/trunk/tooling: jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java pom.xml servicemix-embedded-simple/
Date Fri, 04 Aug 2006 19:52:57 GMT
Author: gnodet
Date: Fri Aug  4 12:52:56 2006
New Revision: 428858

URL: http://svn.apache.org/viewvc?rev=428858&view=rev
Log:
Fix jbi:embeddedServicemix so that it uses the project classpath + the plugin classpath to
load servicemix

Modified:
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java
    incubator/servicemix/trunk/tooling/pom.xml
    incubator/servicemix/trunk/tooling/servicemix-embedded-simple/   (props changed)

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java?rev=428858&r1=428857&r2=428858&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java
(original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/ServiceMixEmbeddedMojo.java
Fri Aug  4 12:52:56 2006
@@ -17,7 +17,14 @@
 package org.apache.servicemix.maven.plugin.jbi;
 
 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.servicemix.jbi.container.SpringJBIContainer;
@@ -74,13 +81,53 @@
 	}
 
 	private void startServiceMix() throws MojoExecutionException {
+        ClassLoader old = Thread.currentThread().getContextClassLoader();
 		try {
+            Thread.currentThread().setContextClassLoader(getClassLoader());
 			context = new FileSystemXmlApplicationContext(servicemixConfig
 					.getAbsolutePath());
 			container = (SpringJBIContainer) context.getBean("jbi");
 		} catch (Exception e) {
 			throw new MojoExecutionException(
 					"Unable to start the ServiceMix container", e);
-		}
+		} finally {
+		    Thread.currentThread().setContextClassLoader(old);      
+        }
 	}
+
+    /**
+     * Set up a classloader for the execution of the
+     * main class.
+     *
+     * @return
+     * @throws MojoExecutionException
+     */
+    private URLClassLoader getClassLoader() throws MojoExecutionException {
+        try {
+            Set urls = new HashSet();
+
+            URL mainClasses = new File(project.getBuild().getOutputDirectory()).toURL();
+            getLog().debug("Adding to classpath : " + mainClasses);
+            urls.add(mainClasses);
+
+            URL testClasses = new File(project.getBuild().getTestOutputDirectory()).toURL();
+            getLog().debug("Adding to classpath : " + testClasses);
+            urls.add(testClasses);
+
+            Set dependencies = project.getArtifacts();
+            Iterator iter = dependencies.iterator();
+            while (iter.hasNext()) {
+                Artifact classPathElement = (Artifact) iter.next();
+                getLog().debug("Adding artifact: " + classPathElement.getArtifactId() + "
to classpath");
+                urls.add(classPathElement.getFile().toURL());
+            }
+            URLClassLoader appClassloader = new URLClassLoader(
+                            (URL[]) urls.toArray(new URL[urls.size()]),
+                            this.getClass().getClassLoader());
+            return appClassloader;
+        } catch (MalformedURLException e) {
+            throw new MojoExecutionException("Error during setting up classpath", e);
+        }
+    }
+
 }

Modified: incubator/servicemix/trunk/tooling/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/pom.xml?rev=428858&r1=428857&r2=428858&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/pom.xml (original)
+++ incubator/servicemix/trunk/tooling/pom.xml Fri Aug  4 12:52:56 2006
@@ -49,6 +49,7 @@
     <module>servicemix-jsr181-wsdl-first-service-unit</module>
     <module>servicemix-lwcontainer-service-unit</module>
     <module>servicemix-eip-service-unit</module>
+    <module>servicemix-embedded-simple</module>
     <module>jbi-maven-plugin</module>
   </modules>
 </project>

Propchange: incubator/servicemix/trunk/tooling/servicemix-embedded-simple/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Aug  4 12:52:56 2006
@@ -0,0 +1 @@
+target



Mime
View raw message