You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2004/02/02 23:48:27 UTC
cvs commit: maven/src/java/org/apache/maven/plugin GoalToJellyScriptHousingMapper.java JellyPlugin.java PluginCacheManager.java PluginManager.java
brett 2004/02/02 14:48:27
Modified: src/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH
GoalToJellyScriptHousingMapper.java
JellyPlugin.java PluginCacheManager.java
PluginManager.java
Log:
cleanup and bugfix
Revision Changes Path
No revision
No revision
1.3.4.6 +5 -0 maven/src/java/org/apache/maven/plugin/Attic/GoalToJellyScriptHousingMapper.java
Index: GoalToJellyScriptHousingMapper.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/Attic/GoalToJellyScriptHousingMapper.java,v
retrieving revision 1.3.4.5
retrieving revision 1.3.4.6
diff -u -r1.3.4.5 -r1.3.4.6
--- GoalToJellyScriptHousingMapper.java 29 Jan 2004 01:04:15 -0000 1.3.4.5
+++ GoalToJellyScriptHousingMapper.java 2 Feb 2004 22:48:26 -0000 1.3.4.6
@@ -669,5 +669,10 @@
{
resolvedPlugins.addAll( projectHousings );
}
+
+ void clearResolvedPlugins()
+ {
+ resolvedPlugins.clear();
+ }
}
1.3.4.5 +3 -103 maven/src/java/org/apache/maven/plugin/Attic/JellyPlugin.java
Index: JellyPlugin.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/Attic/JellyPlugin.java,v
retrieving revision 1.3.4.4
retrieving revision 1.3.4.5
diff -u -r1.3.4.4 -r1.3.4.5
--- JellyPlugin.java 26 Jan 2004 23:32:27 -0000 1.3.4.4
+++ JellyPlugin.java 2 Feb 2004 22:48:27 -0000 1.3.4.5
@@ -60,7 +60,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.maven.MavenException;
import org.apache.maven.project.Project;
-import org.apache.maven.util.Expand;
import java.io.File;
import java.io.IOException;
@@ -78,19 +77,6 @@
/** Logger. */
private static final Log log = LogFactory.getLog( JellyPlugin.class );
- /**
- * The plugin ID. This will be the artifact ID + version (not a usual ID.
- *
- * @todo rename? [RC2]
- */
- private final String id;
-
- /** the jar file the plugin was extracted from. @todo [RC2] - needed? */
- private File jarFile;
-
- /** the directory to unpack the plugin into. @todo [RC2] - needed? */
- private File unpackDirectory;
-
/** the directory the plugin is installed into. @todo [RC2] - needed? */
private File directory;
@@ -107,69 +93,11 @@
* Constructor.
*
* @param pluginFile the JAR file to read the plugin from.
- */
- JellyPlugin( File pluginFile )
- {
- String directory = pluginFile.getName();
- int index = directory.indexOf( ".jar" );
- if ( index >= 0 )
- {
- this.id = directory.substring( 0, index );
- this.jarFile = pluginFile;
- }
- else
- {
- this.id = directory;
- }
- }
-
- /**
- * Get the plugin identifier.
- *
- * @return the plugin identifier
- */
- String getId()
- {
- return id;
- }
-
- /**
- * Unpack the plugin.
- *
* @param unpackDirectory the directory to unpack the plugin to
- * @throws MavenException if there was a problem unpacking
- * @todo [RC2] refactor with new parameter
*/
- void unpack( File unpackDirectory ) throws MavenException
+ JellyPlugin( File directory )
{
- if ( jarFile == null )
- {
- return;
- }
-
- File unzipDir = new File( unpackDirectory, id );
-
- // if there's no directory, or the jar is newer, expand the jar
- if ( !unzipDir.exists() || ( jarFile.lastModified() > unzipDir.lastModified() ) )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Unpacking '" + id + "' plugin to directory --> " + unzipDir.getAbsolutePath() );
- }
- /** TODO [RC2] - reinstate for cache: cacheManager.invalidateCache(id); */
-
- try
- {
- Expand unzipper = new Expand();
- unzipper.setSrc( jarFile );
- unzipper.setDest( unzipDir );
- unzipper.execute();
- }
- catch ( IOException e )
- {
- throw new MavenException( "Unable to extract plugin: " + jarFile, e );
- }
- }
+ this.directory = directory;
}
/**
@@ -177,22 +105,10 @@
*/
public File getDirectory()
{
- if ( directory == null && unpackDirectory != null )
- {
- directory = new File( unpackDirectory, id );
- }
return directory;
}
/**
- * @param aDirectory 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()
@@ -238,21 +154,5 @@
public void setProject( Project project )
{
this.project = project;
- }
-
- /**
- * @param file the jar file containing the plugin
- */
- public void setJarFile( File file )
- {
- jarFile = file;
- }
-
- /**
- * @param file the directory to unpack the plugin into
- */
- public void setUnpackDirectory( File file )
- {
- unpackDirectory = file;
}
}
1.16.4.3 +10 -10 maven/src/java/org/apache/maven/plugin/PluginCacheManager.java
Index: PluginCacheManager.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/PluginCacheManager.java,v
retrieving revision 1.16.4.2
retrieving revision 1.16.4.3
diff -u -r1.16.4.2 -r1.16.4.3
--- PluginCacheManager.java 26 Jan 2004 23:36:09 -0000 1.16.4.2
+++ PluginCacheManager.java 2 Feb 2004 22:48:27 -0000 1.16.4.3
@@ -85,11 +85,9 @@
final class PluginCacheManager
{
/** Log. */
- private static final Log log =
- LogFactory.getLog( PluginCacheManager.class );
+ private static final Log log = LogFactory.getLog( PluginCacheManager.class );
/** Maven session log */
- private static final Log sessionLog =
- LogFactory.getLog(MavenSession.class);
+ private static final Log sessionLog = LogFactory.getLog(MavenSession.class);
/** Plug-in cache */
public static final String PLUGINS_CACHE = "plugins.cache";
@@ -124,15 +122,15 @@
/**
* Dyanamic tag libraries that are created within plugin.jelly scripts using
* the jelly:define tags. So we might have something like the following:
- *
- * <define:taglib uri="aptdoc">
- * <define:jellybean
+ * <pre>
+ * <define:taglib uri="aptdoc">
+ * <define:jellybean
* name="convert"
* className="org.apache.maven.aptdoc.AptToXdocConverter"
* method="doExecute"
- * />
- * </define:taglib>
- *
+ * />
+ * </define:taglib>
+ * </pre>
* What will end up in the dynamic-taglibs.cache file is something like
* the following:
*
@@ -238,6 +236,7 @@
// ----------------------------------------------------------------------
/**
+ * Replace with goal mapper.
*/
Set parsePluginScript( File pluginScript )
{
@@ -519,3 +518,4 @@
}
}
+
1.70.4.13 +164 -138 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.70.4.12
retrieving revision 1.70.4.13
diff -u -r1.70.4.12 -r1.70.4.13
--- PluginManager.java 29 Jan 2004 01:04:15 -0000 1.70.4.12
+++ PluginManager.java 2 Feb 2004 22:48:27 -0000 1.70.4.13
@@ -75,6 +75,7 @@
import org.apache.maven.project.Dependency;
import org.apache.maven.project.Project;
import org.apache.maven.repository.Artifact;
+import org.apache.maven.util.Expand;
import java.io.File;
import java.io.FileInputStream;
@@ -155,17 +156,17 @@
/** This contains a map of plugins, keyed by id. */
private final Map plugins = new HashMap();
+ /** This contains a map of plugins, keyed by artifact id. */
+ private final Map artifactIdToPluginMap = new HashMap();
+
/** This contains a map of housings, keyed by id. */
private final Map housings = new HashMap();
/** Maven session reference. */
private MavenSession mavenSession;
- /** Plugin cache manager. @todo reinstate */
- // private final PluginCacheManager cacheManager = new PluginCacheManager();
-
- /** Cache manager for user jelly scripts. @todo reinstate */
- // private final PluginCacheManager transientCacheManager = new PluginCacheManager();
+ /** Plugin cache manager. */
+ private final PluginCacheManager cacheManager = new PluginCacheManager();
/** Goal to Plugins mapper. */
private final GoalToJellyScriptHousingMapper mapper = new GoalToJellyScriptHousingMapper();
@@ -202,9 +203,13 @@
*
* @throws MavenException when the plugin jars can't be expanded
*/
- private void expandPluginJars() throws MavenException
+ private void expandPluginJars( File directory ) throws MavenException
{
- File[] files = pluginsDir.listFiles();
+ File[] files = directory.listFiles();
+ if ( files == null )
+ {
+ return;
+ }
// First we expand any JARs that contain plugins to the unpack directory.
// This will be a different directory than the plugin jars
@@ -212,61 +217,36 @@
// than MAVEN_HOME / maven.home.
for ( int i = 0; i < files.length; ++i )
{
- processPluginFile( files[i] );
+ unpackPlugin( files[i] );
}
}
- private JellyPlugin processPluginFile( File pluginFile ) throws MavenException
+ /**
+ * Load unpacked plugins.
+ *
+ * @throws MavenException when the plugin jars can't be expanded
+ */
+ private void loadUnpackedPlugins( File directory ) throws Exception
{
- // TODO [RC2] - refactor whole method
- // TODO [RC2] - need to make sure nothing gets loaded twice!
- // Only unpack the JAR if it hasn't been already, or is newer
- // than the plugin directory
- if ( pluginFile.getName().endsWith( ".jar" ) )
+ File[] files = directory.listFiles();
+ if ( files == null )
{
- // TODO: what if it isn't a Jelly plugin?
- JellyPlugin plugin = new JellyPlugin( pluginFile );
- plugin.unpack( unpackedPluginsDir );
- // TODO [RC2] - cleanup. Needed here so project != null
- try
- {
- loadPlugin( plugin );
- }
- catch ( Exception e )
- {
- throw new MavenException( "error", e );
- }
- // TODO [RC2]: fix id stuff
- plugins.put( plugin.getProject().getArtifactId(), plugin );
- return plugin;
+ return;
}
- else if ( pluginFile.isDirectory() )
+
+ // First we expand any JARs that contain plugins to the unpack directory.
+ // This will be a different directory than the plugin jars
+ // MAVEN_HOME_LOCAL / maven.home.local was set to a different directory
+ // than MAVEN_HOME / maven.home.
+ for ( int i = 0; i < files.length; ++i )
{
- // TODO: what if it isn't a Jelly plugin?
- JellyPlugin plugin = new JellyPlugin( pluginFile );
- // TODO [RC2] - very nasty now. Maybe pass unpackDirectory to constructor
- plugin.setUnpackDirectory( pluginFile.getParentFile() );
- if ( !plugin.getDescriptor().exists() )
- {
- // check it really is a plugin
- return null;
- }
- // TODO [RC2] - cleanup. Needed here so project != null
- try
- {
- loadPlugin( plugin, pluginFile.getParentFile() );
- }
- catch ( Exception e )
+ File pluginDir = files[i];
+
+ // TODO [RC2]: put descriptor / loading logic into JellyPlugin
+ if ( pluginDir.isDirectory() && new File( pluginDir, "project.xml" ).exists() )
{
- throw new MavenException( "error", e );
+ loadPlugin( pluginDir );
}
- // TODO [RC2]: fix id stuff
- plugins.put( plugin.getProject().getArtifactId(), plugin );
- return plugin;
- }
- else
- {
- return null;
}
}
@@ -299,44 +279,44 @@
// TODO [RC2] bring back cache
// cacheManager.loadCache();
- expandPluginJars();
-
- // TODO [RC2] bring back cache
- // cachePlugins();
+ expandPluginJars( pluginsDir );
+ expandPluginJars( unpackedPluginsDir );
+ loadUnpackedPlugins( pluginsDir );
+ loadUnpackedPlugins( unpackedPluginsDir );
initialized = true;
log.debug( "Finished initializing Plugins!" );
}
- private void loadPlugin( JellyPlugin plugin )
+ private void loadPlugin( File pluginDir ) throws Exception
{
- try
+ String name = pluginDir.getName();
+ if ( !plugins.containsKey( name ) )
{
- loadPlugin( plugin, getUnpackedPluginsDir() );
- }
- catch ( Exception e )
- {
- log.info( "Error loading plugin from directory '" + plugin.getDirectory() + "'", e );
- }
- }
+ log.debug( "Loading plugin '" + name + "'" );
- private void loadPlugin( JellyPlugin plugin, File unpackedDir ) throws Exception
- {
- plugin.setUnpackDirectory( unpackedDir );
- log.debug( "Loading plugin '" + plugin.getId() + "'" );
+ JellyPlugin plugin = new JellyPlugin( pluginDir );
+ Project project = MavenUtils.getProject( plugin.getDescriptor(), mavenSession.getRootContext(), false );
- Project project = MavenUtils.getProject( plugin.getDescriptor(), mavenSession.getRootContext(), false );
- // TODO: move this?
- project.verifyDependencies();
- plugin.setProject( project );
+ // TODO: move this?
+ project.verifyDependencies();
+ plugin.setProject( project );
- if ( plugin.hasScript() )
- {
- JellyScriptHousing housing = createJellyScriptHousing( plugin );
+ if ( plugin.hasScript() )
+ {
+ JellyScriptHousing housing = createJellyScriptHousing( plugin );
- // Store the plugin housing for future use.
- mapper.parse( new FileInputStream( plugin.getScriptFile() ), housing );
+ // Store the plugin housing for future use.
+ mapper.parse( new FileInputStream( plugin.getScriptFile() ), housing );
+ }
+ plugins.put( name, plugin );
+ artifactIdToPluginMap.put( project.getArtifactId(), plugin );
+ // TODO [RC2]: cache
+ }
+ else
+ {
+ log.debug( "Skipping already loaded plugin '" + name + "'" );
}
}
@@ -365,19 +345,13 @@
* @todo [RC2] refactor into housing
* @deprecated get rid of this - it duplicates functionality in the housing
*/
- private JellyScriptHousing createJellyScriptHousing( Project project, File unpackedPluginDirectory,
- InputStream jelly ) throws Exception
+ private JellyScriptHousing createJellyScriptHousing( Project project, InputStream jelly ) throws Exception
{
JellyScriptHousing jellyScriptHousing = new JellyScriptHousing();
+ // TODO [RC2]: this is processing the loaded project, and hence all project dependencies - move it?
ForeheadClassLoader classLoader = new ForeheadClassLoader( mavenRootClassLoader, project.getId() );
- if ( unpackedPluginDirectory != null )
- {
- // We will add the plugin classes to the plugin class loader.
- classLoader.addURL( unpackedPluginDirectory.toURL() );
- }
-
// We will add the JARs that have been instructed to be place in the class loader
// for use in the plugin in the plugin class loader.
processDependencies( project, classLoader );
@@ -401,19 +375,14 @@
* @return
* @todo [RC2] into the housing?
*/
- private JellyScriptHousing createJellyScriptHousing( Project project, File classesDirectory, File jelly )
+ private JellyScriptHousing createJellyScriptHousing( Project project, File jelly )
throws Exception
{
JellyScriptHousing jellyScriptHousing = new JellyScriptHousing();
+ // TOOD [RC2]: isn't this all redundant processing?
ForeheadClassLoader classLoader = new ForeheadClassLoader( mavenRootClassLoader, project.getId() );
- if ( classesDirectory != null )
- {
- // We will add the plugin classes to the plugin class loader.
- classLoader.addURL( classesDirectory.toURL() );
- }
-
// We will add the JARs that have been instructed to be place in the class loader
// for use in the plugin in the plugin class loader.
processDependencies( project, classLoader );
@@ -556,7 +525,7 @@
// driver.jelly
InputStream driver = getClass().getResourceAsStream( "/driver.jelly" );
- JellyScriptHousing driverHousing = createJellyScriptHousing( project, null, driver );
+ JellyScriptHousing driverHousing = createJellyScriptHousing( project, driver );
// TODO [RC2] stop reading all scripts 2 times
driver.close();
driver = getClass().getResourceAsStream( "/driver.jelly" );
@@ -571,7 +540,7 @@
{
File mavenXml = p.getMavenXml();
- JellyScriptHousing jellyScriptHousing = createJellyScriptHousing( p, null, mavenXml );
+ JellyScriptHousing jellyScriptHousing = createJellyScriptHousing( p, mavenXml );
// TODO [RC2] stop reading all scripts 2 times
transientMapper.parse( new FileInputStream( mavenXml ), jellyScriptHousing );
projectHousings.add( jellyScriptHousing );
@@ -594,47 +563,47 @@
goals = Collections.EMPTY_LIST;
}
+ // TODO [RC2]: any reason not to do this at the start?
transientMapper.merge( mapper );
- transientMapper.addResolvedPlugins( projectHousings );
Thread.currentThread().setContextClassLoader( null );
+ WerkzProject werkzProject = new WerkzProject();
+ baseContext.setWerkzProject( werkzProject );
+
+ Set pluginSet = new HashSet();
+ // poor mans stack - only pop when you finish the same frame that the plugin was lazily init in
+ Set oldDelayedPops = new HashSet( delayedPops );
+ delayedPops.clear();
+
try
{
+ for ( Iterator j = projectHousings.iterator(); j.hasNext(); )
+ {
+ JellyScriptHousing housing = ( JellyScriptHousing ) j.next();
+ housing.run( this, baseContext );
+ }
+ transientMapper.addResolvedPlugins( projectHousings );
+
// Plugin Jelly scripts
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
String goalName = ( String ) i.next();
+
+ pluginSet.addAll( prepAttainGoal( goalName, baseContext, transientMapper ));
+ }
- // The werkz project must be redefined to avoid preGoals
- // accumulating
- WerkzProject werkzProject = new WerkzProject();
- baseContext.setWerkzProject( werkzProject );
-
- for ( Iterator j = projectHousings.iterator(); j.hasNext(); )
- {
- JellyScriptHousing housing = ( JellyScriptHousing ) j.next();
- housing.run( this, baseContext );
- }
-
- Set pluginSet = prepAttainGoal( goalName, baseContext, transientMapper );
-
- Set oldDelayedPops = new HashSet( delayedPops );
- delayedPops.clear();
-
- try
- {
- werkzProject.attainGoal( goalName, session );
- }
- finally
- {
- cleanupAttainGoal( pluginSet );
- delayedPops = oldDelayedPops;
- }
+ // Plugin Jelly scripts
+ for ( Iterator i = goals.iterator(); i.hasNext(); )
+ {
+ String goalName = ( String ) i.next();
+ werkzProject.attainGoal( goalName, session );
}
}
finally
{
+ cleanupAttainGoal( pluginSet );
+ delayedPops = oldDelayedPops;
project.popContext();
}
}
@@ -662,9 +631,9 @@
* @throws Exception TODO poor form
*/
public Set prepAttainGoal( String goalName, MavenJellyContext baseContext,
- GoalToJellyScriptHousingMapper transientMapper ) throws Exception
+ GoalToJellyScriptHousingMapper goalMapper ) throws Exception
{
- Set pluginSet = transientMapper.resolveJellyScriptHousings( goalName );
+ Set pluginSet = goalMapper.resolveJellyScriptHousings( goalName );
for ( Iterator j = pluginSet.iterator(); j.hasNext(); )
{
@@ -809,6 +778,13 @@
}
}
+ public void installPlugin( File file, Project parentProject ) throws Exception
+ {
+ // By default, don't copy to the unpacked plugins directory - only use this dependency for this project
+ installPlugin( file, parentProject, false );
+ // TODO: we should unload the plugin after the project is done in this case - we really need to define the lifecycle of plugins
+ }
+
/**
* Load and install a plugin.
*
@@ -817,19 +793,26 @@
* @todo remove any old one, but don't save updated cache
* @todo more refactoring
*/
- public void installPlugin( File file, Project parentProject ) throws Exception
+ public void installPlugin( File file, Project parentProject, boolean installToUnpackedPluginDirectory ) throws Exception
{
- // copy the file to the unpacked plugins dir
- FileUtils.copyFileToDirectory( file, getUnpackedPluginsDir() );
- String pluginName = file.getCanonicalFile().getName();
- pluginName = pluginName.substring( 0, pluginName.indexOf( ".jar" ) );
- if ( !plugins.containsKey( pluginName ) )
- {
- // expand it
- JellyPlugin plugin = processPluginFile( file );
- // already done - loadPlugin( plugin );
- // TODO [RC2] cache
- // cachePlugin( pluginName );
+ if ( installToUnpackedPluginDirectory )
+ {
+ FileUtils.copyFileToDirectory( file, getUnpackedPluginsDir() );
+ }
+
+ // TODO - would be nice to be able to use this instead so it doesn't get unpacked every time?
+ // String pluginName = file.getCanonicalFile().getName();
+ // pluginName = pluginName.substring( 0, pluginName.indexOf( ".jar" ) );
+
+ // expand it
+ File unpackedPluginDir = unpackPlugin( file );
+ if ( unpackedPluginDir != null )
+ {
+ loadPlugin( unpackedPluginDir );
+ }
+ else
+ {
+ throw new MavenException( "Not a valid plugin file: " + file );
}
}
@@ -846,7 +829,7 @@
{
return housing.getProject().getContext();
}
- JellyPlugin plugin = ( JellyPlugin ) plugins.get( id );
+ JellyPlugin plugin = ( JellyPlugin ) artifactIdToPluginMap.get( id );
if ( plugin != null )
{
return plugin.getProject().getContext();
@@ -890,5 +873,48 @@
{
delayedPops.addAll( set );
}
+
+ /**
+ * Unpack the plugin.
+ *
+ * @throws MavenException if there was a problem unpacking
+ */
+ File unpackPlugin( File jarFile ) throws MavenException
+ {
+ String directory = jarFile.getName();
+ int index = directory.indexOf( ".jar" );
+ if ( index < 0 )
+ {
+ return null;
+ }
+
+ String id = directory.substring( 0, index );
+
+ File unzipDir = new File( unpackedPluginsDir, id );
+
+ // if there's no directory, or the jar is newer, expand the jar
+ if ( !unzipDir.exists() || ( jarFile.lastModified() > unzipDir.lastModified() ) )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Unpacking '" + id + "' plugin to directory --> " + unzipDir.getAbsolutePath() );
+ }
+ /** TODO [RC2] - reinstate for cache: cacheManager.invalidateCache(id); */
+
+ try
+ {
+ Expand unzipper = new Expand();
+ unzipper.setSrc( jarFile );
+ unzipper.setDest( unzipDir );
+ unzipper.execute();
+ }
+ catch ( IOException e )
+ {
+ throw new MavenException( "Unable to extract plugin: " + jarFile, e );
+ }
+ }
+ return unzipDir;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org