All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.fractal.adl.JuliaLauncherMojo Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
/**
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 USA

  Contributor(s):
  - Philippe Merle (set the class loader used to obtain the Fractal ADL Factory)
 */
package org.objectweb.fractal.adl;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import java.util.Map;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.LifeCycleController;
import org.objectweb.fractal.julia.Julia;
import org.objectweb.fractal.util.Fractal;

/**
 * Executes the fractaladl Launcher in the current VM with the enclosing project's
 * runtime dependencies as classpath + the mojo dependencies.
 * 
 * This plugin lets you specify:
 * 
    *
  • the ADL file containing the top level component definition
  • *
  • the name of the Runnable interface to run on the top level component
  • *
  • the factory to use to instantiate the component
  • *
  • the backend used by the factory
  • *
* * * Requires the enclosing project (runtime) dependencies * The compile phase must be / have been run before the MOJO * Associate the MOJO with the goal run * * @author Alessio Pace * * @execute phase="compile" * @requiresDependencyResolution runtime * @goal run */ public class JuliaLauncherMojo extends AbstractMojo { public final static String BASIC_FACTORY = "org.objectweb.fractal.adl.BasicFactory"; /** * The fully qualified name of the factory to use (the corresponding .fractal file must be in the classpath). * * @parameter expression="org.objectweb.fractal.adl.BasicFactory" */ private String factory; /** * The fully qualified name of the backend to use (the corresponding .fractal file must be in the classpath). * * @parameter expression="org.objectweb.fractal.adl.FractalBackend" */ private String backend; /** * The fully qualified name of the component definition to load (must be in the classpath). * * @parameter */ private String definition; /** * @parameter expression="r" */ private String runnableItf; /** * @parameter expression="true" */ private boolean daemon; /** * A comma separated value of Julia config files. * * @parameter */ private String juliaConfig; /** * The Maven project reference. * * @parameter expression="${project}" * @required */ private MavenProject project; /** * @parameter expression="${plugin.artifacts}" * @readonly */ //private List pluginDependencies; public void execute() throws MojoExecutionException { /* this is the julia-launcher-plugin, so... */ System.setProperty("fractal.provider", Julia.class.getCanonicalName()); // Will be removed in Julia version 2.1.6 //System.setProperty("julia.loader", DynamicLoader.class.getCanonicalName()); if(juliaConfig!=null && juliaConfig.length() > 0) System.setProperty("julia.config", juliaConfig); /* get the current MOJO ClassLoader */ ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader(); getLog().debug("MOJO initial classloader: " + initialClassLoader); /* get the new ClassLoader */ ClassLoader classLoader = getClassLoader(initialClassLoader); getLog().debug("MOJO new classloader: " + classLoader); /* * this is not technically needed because FractalADL tries to the ClassLoader * passed with the "classloader" key in the context Map, or falls back on * the XMLLoader's instance.class.getClassLoader() which is the same ClassLoader * of the initialClassLoader variable (and which is not enough to load * resources of the enclosing project) */ Thread.currentThread().setContextClassLoader(classLoader); try { new Launcher(classLoader, this.daemon).main(new String[]{factory, backend, definition, runnableItf}); } catch(Exception e){ e.printStackTrace(); throw new MojoExecutionException("Unable to launch Fractal application", e); } /* set again the initial MOJO ClassLoader */ Thread.currentThread().setContextClassLoader(initialClassLoader); } protected ClassLoader getClassLoader(final ClassLoader currentThreadClassLoader) { try { //String outputDirectory = project.getBuild().getOutputDirectory(); //URL targetClassesUrl = new File(outputDirectory).toURL(); /* contains the enclosing project dependencies and target/classes */ List classpaths = project.getRuntimeClasspathElements(); /* copy the List of classpaths into an array of URL*/ URL[] classpathsUrls = new URL[classpaths.size()]; for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy