dion 2003/08/01 00:39:24
Modified: src/java/org/apache/maven/plugin PluginManager.java
Added: src/java/org/apache/maven/plugin JellyPlugin.java
Log:
Start to move plugin related processing into its own class.
This leaves JellyScriptHousing as a very similar class, but with
a little refactoring, we should be able to work out a good
strategy here.
The code now reads close to what happens in real life.
Revision Changes Path
1.58 +57 -27 maven/src/java/org/apache/maven/plugin/PluginManager.java
Index: PluginManager.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/PluginManager.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- PluginManager.java 30 Jul 2003 03:34:24 -0000 1.57
+++ PluginManager.java 1 Aug 2003 07:39:24 -0000 1.58
@@ -150,6 +150,9 @@
private Maven maven;
private Map jellyScriptHousings;
+
+ /** map of loaded plugins by id */
+ private Map loadedPlugins;
/** rootClassLoader classloader. */
private ForeheadClassLoader rootClassLoader;
@@ -174,6 +177,7 @@
this.maven = mavenSession;
jellyScriptHousings = new HashMap();
+ loadedPlugins = new HashMap();
mapper = new GoalToJellyScriptHousingMapper();
@@ -305,33 +309,26 @@
{
return;
}
+ JellyPlugin plugin = new JellyPlugin();
+ plugin.setId(name);
+ // FIXME Plugin should construct this...
+ plugin.setDirectory( getUnpackedPluginDir( plugin.getId() ) );
+ Project pluginProject = getMaven().getProject( plugin.getDescriptor() ,
false );
+ plugin.setParentClassLoader( mavenRootClassLoader );
+ plugin.setProject( pluginProject );
- File jellyScript = getPluginScript( name );
+ plugin.processDependencies();
- if ( jellyScript.exists() == false )
+ if ( !plugin.hasScript() )
{
return;
}
- File unpackedPluginDir = getUnpackedPluginDir( name );
-
- Project pluginProject = getMaven().getProject( new File( unpackedPluginDir,
"project.xml" ), false );
-
- if ( !isPluginProcessed( name ) )
- {
- // We need all the dependencies present for the plugin to work so we
have to ensure
- // that they are all present and accounted for.
- pluginProject.verifyDependencies();
-
- // Mark the plugin as processed now that we have verified the
dependencies.
- FileUtils.fileWrite( getPluginProcessedMarker( name ).getPath(),
"plugin has been processed." );
- }
-
JellyScriptHousing jellyScriptHousing = null;
try
{
// Create the PluginHousing
- jellyScriptHousing = createJellyScriptHousing( pluginProject,
unpackedPluginDir, jellyScript );
+ jellyScriptHousing = createJellyScriptHousing( plugin );
}
catch ( Exception e )
{
@@ -341,8 +338,9 @@
// Store the plugin housing for future use.
jellyScriptHousings.put( name, jellyScriptHousing );
+ loadedPlugins.put(plugin.getId(), plugin);
- mapper.parse( new FileReader( jellyScript ), jellyScriptHousing );
+ mapper.parse( new FileReader( plugin.getScriptFile() ), jellyScriptHousing
);
}
/**
@@ -644,6 +642,27 @@
return jellyScriptHousing;
}
+ /**
+ * @param plugin the plugin to create a housing for
+ * @return a housing
+ * @throws MalformedURLException
+ * @throws Exception
+ */
+ private JellyScriptHousing createJellyScriptHousing(JellyPlugin plugin)
+ throws MalformedURLException, Exception
+ {
+ JellyScriptHousing jellyScriptHousing = new JellyScriptHousing();
+ jellyScriptHousing.setId( plugin.getId() );
+
+ // Now before we even _compile_ the jelly script you must set the
classloader because
+ // the whole process needs to be able to resolve the tags. I thought a
StaticTag was
+ // supposed to be created and the search deferred but this is _not_ the
case.
+ jellyScriptHousing.setClassLoader( plugin.getClassLoader() );
+ jellyScriptHousing.setProject( plugin.getProject() );
+ jellyScriptHousing.setScript(
plugin.getCompiledScriptFor(compileScriptContext) );
+
+ return jellyScriptHousing;
+ }
private JellyScriptHousing createJellyScriptHousing( Project project, File
unpackedPluginDirectory, InputStream jelly )
throws Exception
@@ -705,12 +724,19 @@
{
System.out.println( "urls[" + i + "] = " + urls[i] );
}
+
+ ClassLoader parent = classLoader.getParent();
+ if (parent != null && parent instanceof ForeheadClassLoader)
+ {
+ System.out.println("Displaying Parent classloader: ");
+ displayClassLoaderContents(project,
(ForeheadClassLoader)classLoader.getParent());
+ }
}
/**
* process the dependencies for this project
*/
- private void processDependencies( Project project, ForeheadClassLoader
classLoader )
+ public static void processDependencies( Project project, ForeheadClassLoader
classLoader )
throws MalformedURLException
{
if ( project.getArtifacts() == null )
@@ -722,20 +748,24 @@
{
Artifact artifact = (Artifact) i.next();
Dependency dependency = artifact.getDependency();
- String classloader = dependency.getProperty( "classloader" );
+ String classloaderProperty = dependency.getProperty( "classloader" );
// Only add compile type dependencies to classloader
+ // what about ejbs etc
if ( dependency.getType().equals( "jar" ) )
{
// We have the jar and the classloader to push it into so
// lets do it!
if ( artifact.exists() )
{
- if ( classloader != null && classloader.equals( "root" ) )
+ if ( classloaderProperty != null )
{
- //System.out.println( "classloader = " + classloader );
- //System.out.println( "artifact.getFile() = " +
artifact.getFile() );
- rootClassLoader.addURL( artifact.getFile().toURL() );
+ ForeheadClassLoader otherClassLoader =
+
Forehead.getInstance().getClassLoader(classloaderProperty);
+ if (otherClassLoader != null)
+ {
+ otherClassLoader.addURL( artifact.getFile().toURL() );
+ }
}
else
{
@@ -799,9 +829,9 @@
* @return <code>true</code> if the plugin has been loaded,
* otherwise <code>false</code>.
*/
- boolean isLoaded( String name )
+ boolean isLoaded( String id )
{
- return jellyScriptHousings.get( name ) != null;
+ return loadedPlugins.get( id ) != null;
}
/**
1.1 maven/src/java/org/apache/maven/plugin/JellyPlugin.java
Index: JellyPlugin.java
===================================================================
package org.apache.maven.plugin;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.commons.jelly.Script;
import org.apache.maven.jelly.JellyUtils;
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Project;
import org.apache.maven.verifier.ChecksumVerificationException;
import org.apache.maven.verifier.RepoConfigException;
import org.apache.maven.verifier.UnsatisfiedDependencyException;
import org.apache.plexus.util.FileUtils;
import com.werken.forehead.ForeheadClassLoader;
/**
* A runtime view of a plugin written in Jelly.
*
* @author dion
*/
public class JellyPlugin
{
/** the id of the plugin */
private String id;
/** the directory the plugin is installed into */
private File directory;
/** the project.xml file for the plugin */
private File descriptor;
/** the script for this plugin */
private File scriptFile;
/** the processed marker */
private File processedMarker;
/** Maven project for the plugin */
private Project project;
/** classloader for the plugin */
private ForeheadClassLoader classLoader;
/** classloader for the plugin */
private ClassLoader parentClassLoader;
/** compiled script */
private Script compiledScript;
/**
* Create a Jelly Plugin
*/
public JellyPlugin()
{
}
/**
* @return the id of the plugin
*/
public String getId()
{
return id;
}
/**
* @param aString the new id of the plugin
*/
public void setId(String aString)
{
id = aString;
}
/**
* @return the install directory of the plugin
*/
public File getDirectory()
{
return directory;
}
/**
* @param string the install directory of the plugin
*/
public void setDirectory(File aDirectory)
{
directory = aDirectory;
}
/**
* @return true if a plugin.jelly exists in the directory
*/
public boolean hasScript()
{
return getScriptFile().exists();
}
/**
* @return the jelly script
*/
public File getScriptFile()
{
if (scriptFile == null) {
scriptFile = new File( directory, "plugin.jelly");
}
return scriptFile;
}
/**
* @return the project descriptor for this plugin
*/
public File getDescriptor()
{
if (descriptor == null) {
descriptor = new File( directory, "project.xml");
}
return descriptor;
}
/**
* @return the processed marker
*/
private File getProcessedMarker()
{
if (processedMarker == null)
{
processedMarker = new File(directory, ".processed");
}
return processedMarker;
}
/**
* @return true if this plugin has been processed
*/
public boolean isProcessed()
{
return getProcessedMarker().exists();
}
/**
* Process the plugin
*/
public void processDependencies()
throws ChecksumVerificationException, RepoConfigException,
UnsatisfiedDependencyException,
IOException, Exception
{
if (!isProcessed())
{
// We need all the dependencies present for the plugin to work so we
have to ensure
// that they are all present and accounted for.
getProject().verifyDependencies();
// Mark the plugin as processed now that we have verified the
dependencies.
FileUtils.fileWrite( getProcessedMarker().getCanonicalPath(), "plugin
has been processed." );
}
}
/**
* @return the maven project for this plugin
*/
public Project getProject()
{
return project;
}
/**
* @param project a maven project
*/
public void setProject(Project project)
{
this.project = project;
}
/**
* @return the classloader for this plugin
*/
public ForeheadClassLoader getClassLoader()
throws MalformedURLException, ChecksumVerificationException, IOException,
RepoConfigException, UnsatisfiedDependencyException, Exception
{
if (classLoader == null)
{
classLoader = new ForeheadClassLoader(getParentClassLoader(), getId());
classLoader.addURL(getDirectory().toURL());
// add other artifacts here, make sure they've been downloaded first!
processDependencies();
PluginManager.processDependencies( project, classLoader);
}
return classLoader;
}
/**
* @return the parent classloader
*/
public ClassLoader getParentClassLoader()
{
return parentClassLoader;
}
/**
* @param loader
*/
public void setParentClassLoader(ClassLoader loader)
{
parentClassLoader = loader;
}
public Script getCompiledScriptFor(MavenJellyContext context)
throws MalformedURLException, Exception
{
if (hasScript())
{
context.setClassLoader(getClassLoader());
compiledScript = JellyUtils.compileScript( getScriptFile(), context );
}
return compiledScript;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]