brett 2004/03/31 17:52:21
Modified: src/java/org/apache/maven Tag: MAVEN-1_0-BRANCH
MavenConstants.java
src/java/org/apache/maven/jelly Tag: MAVEN-1_0-BRANCH
MavenJellyContext.java
src/test/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH
PluginCacheManagerTest.java
src/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH
JellyScriptHousing.java PluginCacheManager.java
PluginManager.java PluginScriptParser.java
Log:
plugin cache enhancements and robustness.
No more need to rm -rf ~/.maven/plugins to fix a bad cache!
Revision Changes Path
No revision
No revision
1.30.4.5 +4 -1 maven/src/java/org/apache/maven/MavenConstants.java
Index: MavenConstants.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/MavenConstants.java,v
retrieving revision 1.30.4.4
retrieving revision 1.30.4.5
diff -u -r1.30.4.4 -r1.30.4.5
--- MavenConstants.java 1 Mar 2004 22:36:36 -0000 1.30.4.4
+++ MavenConstants.java 1 Apr 2004 01:52:19 -0000 1.30.4.5
@@ -92,6 +92,9 @@
/** MavenSession home local context tag **/
public static final String MAVEN_HOME_LOCAL = "maven.home.local";
+ /** MavenSession plugins context tag **/
+ public static final String MAVEN_PLUGINS_DIR = "maven.plugin.dir";
+
/** MavenSession unpacked plugins context tag **/
public static final String MAVEN_UNPACKED_PLUGINS_DIR =
"maven.plugin.unpacked.dir";
No revision
No revision
1.35.4.4 +11 -1 maven/src/java/org/apache/maven/jelly/MavenJellyContext.java
Index: MavenJellyContext.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/jelly/MavenJellyContext.java,v
retrieving revision 1.35.4.3
retrieving revision 1.35.4.4
diff -u -r1.35.4.3 -r1.35.4.4
--- MavenJellyContext.java 1 Mar 2004 22:36:36 -0000 1.35.4.3
+++ MavenJellyContext.java 1 Apr 2004 01:52:20 -0000 1.35.4.4
@@ -638,6 +638,16 @@
}
/**
+ * Get plugins location.
+ *
+ * @return plugins location.
+ */
+ public String getPluginsDir()
+ {
+ return (String) getVariable( MavenConstants.MAVEN_PLUGINS_DIR );
+ }
+
+ /**
* Get unpacked plugins location.
*
* @return unpacked plugins location.
No revision
No revision
1.5.4.4 +2 -1
maven/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java
Index: PluginCacheManagerTest.java
===================================================================
RCS file:
/home/cvs/maven/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java,v
retrieving revision 1.5.4.3
retrieving revision 1.5.4.4
diff -u -r1.5.4.3 -r1.5.4.4
--- PluginCacheManagerTest.java 2 Mar 2004 05:38:54 -0000 1.5.4.3
+++ PluginCacheManagerTest.java 1 Apr 2004 01:52:20 -0000 1.5.4.4
@@ -26,6 +26,7 @@
import javax.xml.parsers.ParserConfigurationException;
+import org.apache.maven.MavenException;
import org.xml.sax.SAXException;
/**
@@ -52,7 +53,7 @@
/**
* Test the plugin cache builder.
*/
- public void testPluginGraphBuilder() throws FileNotFoundException, IOException,
ParserConfigurationException, SAXException
+ public void testPluginGraphBuilder() throws FileNotFoundException, IOException,
MavenException
{
PluginCacheManager pgb = new PluginCacheManager();
JellyScriptHousing housing = new JellyScriptHousing( new File(
PLUGIN_SCRIPT ).getParentFile(), null );
No revision
No revision
1.3.4.11 +43 -10 maven/src/java/org/apache/maven/plugin/JellyScriptHousing.java
Index: JellyScriptHousing.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/JellyScriptHousing.java,v
retrieving revision 1.3.4.10
retrieving revision 1.3.4.11
diff -u -r1.3.4.10 -r1.3.4.11
--- JellyScriptHousing.java 28 Mar 2004 19:14:34 -0000 1.3.4.10
+++ JellyScriptHousing.java 1 Apr 2004 01:52:20 -0000 1.3.4.11
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
@@ -30,6 +31,7 @@
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.jelly.Script;
+import org.apache.maven.MavenException;
import org.apache.maven.MavenUtils;
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Project;
@@ -96,7 +98,7 @@
*
* @return
*/
- public Project getProject() throws Exception
+ Project initProject() throws MavenException
{
if ( project == null )
{
@@ -107,6 +109,15 @@
/**
*
+ * @return
+ */
+ Project getProject()
+ {
+ return project;
+ }
+
+ /**
+ *
* @param project
*/
public void setProject( Project project )
@@ -143,18 +154,40 @@
return name;
}
- void parse( PluginDefinitionHandler handler, InputStream inStream ) throws
IOException, ParserConfigurationException, SAXException
+ void parse( PluginDefinitionHandler handler, InputStream inStream ) throws
MavenException
{
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware( true );
- SAXParser parser = factory.newSAXParser();
- InputSource is = new InputSource( inStream );
- parser.parse( is, new PluginScriptParser( handler, this ) );
+ try
+ {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware( true );
+ SAXParser parser = factory.newSAXParser();
+ InputSource is = new InputSource( inStream );
+ parser.parse( is, new PluginScriptParser( handler, this ) );
+ }
+ catch ( ParserConfigurationException e )
+ {
+ throw new MavenException( "Error parsing plugin script", e );
+ }
+ catch ( SAXException e )
+ {
+ throw new MavenException( "Error parsing plugin script", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MavenException( "Error reading plugin script", e );
+ }
}
- void parse( PluginDefinitionHandler handler ) throws IOException,
ParserConfigurationException, SAXException
+ void parse( PluginDefinitionHandler handler ) throws MavenException
{
- parse( handler, new FileInputStream( source ) );
+ try
+ {
+ parse( handler, new FileInputStream( source ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new MavenException( "Error reading plugin script", e );
+ }
}
/**
1.16.4.13 +188 -80 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.12
retrieving revision 1.16.4.13
diff -u -r1.16.4.12 -r1.16.4.13
--- PluginCacheManager.java 28 Mar 2004 21:27:27 -0000 1.16.4.12
+++ PluginCacheManager.java 1 Apr 2004 01:52:20 -0000 1.16.4.13
@@ -22,6 +22,8 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -65,6 +67,9 @@
/** Plugin -> dynatag dependencies. */
public static final String PLUGIN_DYNATAG_DEPS_CACHE =
"plugin-dynatag-deps.cache";
+ /** Dirty flag. */
+ private boolean dirty = true;
+
/**
* The goals caches contains a mapping of goal names to a description for the
* goal and any prerequisite goals.
@@ -151,6 +156,11 @@
void saveCache( File directory ) throws IOException
{
+ if ( !dirty )
+ {
+ return;
+ }
+
directory.mkdirs();
File lockFile = new File( directory, LOCK_CACHE );
@@ -174,6 +184,7 @@
storeProperties( dynaTagLibCache, new File( directory,
DYNAMIC_TAGLIBS_CACHE ), "taglibs cache" );
storeProperties( pluginDynaTagDepsCache, new File( directory,
PLUGIN_DYNATAG_DEPS_CACHE ), "plugin deps cache" );
f.createNewFile();
+ dirty = false;
}
finally
{
@@ -192,8 +203,8 @@
private void storeProperties(Properties properties, File file, String header)
throws FileNotFoundException, IOException
{
- FileOutputStream stream = new FileOutputStream(file);
- properties.store(stream, header);
+ FileOutputStream stream = new FileOutputStream( file );
+ properties.store( stream, header );
stream.close();
}
@@ -214,7 +225,7 @@
}
catch ( IOException e )
{
- log.debug("IOException reading cache", e);
+ log.debug( "IOException reading cache", e );
}
}
else
@@ -238,11 +249,13 @@
log.info( "Plugin cache will be regenerated" );
return;
}
+ log.debug( "Loading plugin cache" );
pluginCache = loadProperties( new File( directory, PLUGINS_CACHE ) );
goalCache = loadProperties( new File( directory, GOALS_CACHE ) );
callbackCache = loadProperties( new File( directory, CALLBACKS_CACHE ) );
dynaTagLibCache = loadProperties( new File( directory,
DYNAMIC_TAGLIBS_CACHE ) );
pluginDynaTagDepsCache = loadProperties( new File( directory,
PLUGIN_DYNATAG_DEPS_CACHE ) );
+ dirty = false;
}
/**
@@ -276,12 +289,13 @@
}
}
- public void addPluginDynaTagDep(JellyScriptHousing housing, String uri)
+ public void addPluginDynaTagDep( JellyScriptHousing housing, String uri )
{
appendCsvProperty( pluginDynaTagDepsCache, housing.getName(), uri );
+ dirty = true;
}
-
- public void removePluginDynaTagDep(JellyScriptHousing housing, String uri)
+
+ public void removePluginDynaTagDep( JellyScriptHousing housing, String uri )
{
String prop = (String) pluginDynaTagDepsCache.get( housing.getName() );
int tl = uri.length();
@@ -292,39 +306,42 @@
}
else
{
- int i = prop.indexOf(uri + ",");
- if (i == 0)
+ int i = prop.indexOf( uri + "," );
+ if ( i == 0 )
{
// First
- prop = prop.substring(tl + 1);
+ prop = prop.substring( tl + 1 );
}
- else if (i > 0)
+ else if ( i > 0 )
{
// Middle
- prop = prop.substring(0, i) + prop.substring(i + tl + 1);
+ prop = prop.substring( 0, i ) + prop.substring( i + tl + 1 );
}
else
{
// The last entry
- prop = prop.substring(0, prop.length() - tl - 1);
+ prop = prop.substring( 0, prop.length() - tl - 1 );
}
- if (log.isDebugEnabled())
+ if ( log.isDebugEnabled() )
{
- log.debug("Caching Taglib Dependency --> " + prop);
+ log.debug( "Caching Taglib Dependency --> " + prop );
}
pluginDynaTagDepsCache.put( housing.getName(), prop );
}
+ dirty = true;
}
public void addPostGoal( String name, JellyScriptHousing housing )
{
appendCsvProperty( callbackCache, name + ".post", housing.getName() );
+ dirty = true;
}
public void addPreGoal( String name, JellyScriptHousing housing )
{
appendCsvProperty( callbackCache, name + ".pre", housing.getName() );
+ dirty = true;
}
public void addGoal( String name, String prereqs, String description,
JellyScriptHousing housing )
@@ -338,146 +355,237 @@
goalCache.setProperty( name, goalProperty );
pluginCache.setProperty( name, housing.getName() );
+ dirty = true;
}
public void addDynaTagLib( String tagLibUri, JellyScriptHousing housing )
{
dynaTagLibCache.setProperty( tagLibUri, housing.getName() );
+ dirty = true;
}
/**
* Invalidate cache information for a single plugin.
*
* @param pluginName The name of the plugin to invalid cache entries.
- */
- void invalidateCache( String pluginName )
+ *
+ private void invalidateCache( String pluginName )
{
+ log.debug( "Invalidating plugin " + pluginName );
+ for ( Iterator i = dynaTagLibCache.keySet().iterator(); i.hasNext();)
+ {
+ String uri = ( String ) i.next();
+
+ if ( dynaTagLibCache.getProperty( uri ).equals( pluginName ) )
+ {
+ sessionLog.debug( "removing dynataglib cache entry for uri " + uri
);
+ i.remove();
+ }
+ }
for ( Iterator i = goalCache.keySet().iterator(); i.hasNext();)
{
- String eachGoal = (String) i.next();
-
+ String eachGoal = ( String ) i.next();
+
if ( pluginCache.getProperty( eachGoal ).equals( pluginName ) )
{
+ // TODO: this could be bad if the other one was already loaded
+ sessionLog.debug( "removing goal, plugin and callback cache entry
for goal " + eachGoal );
+ i.remove();
+ pluginCache.remove( eachGoal );
+ callbackCache.remove( eachGoal + ".pre" );
+ callbackCache.remove( eachGoal + ".post" );
+ }
+ }
+ for ( Iterator i = callbackCache.keySet().iterator(); i.hasNext();)
+ {
+ String callbackName = ( String ) i.next();
+ String goalName =
+ callbackName.endsWith( ".pre" )
+ ? callbackName.substring( 0, callbackName.length() - 4 )
+ : callbackName.substring( 0, callbackName.length() - 5 );
+
+ if ( pluginCache.getProperty( goalName ).equals( pluginName ) )
+ {
+ // TODO: this could be bad if the other one was already loaded
+ sessionLog.debug( "removing goal, plugin and callback cache entry
for goal " + eachGoal );
i.remove();
pluginCache.remove( eachGoal );
callbackCache.remove( eachGoal + ".pre" );
callbackCache.remove( eachGoal + ".post" );
}
}
+ if ( pluginDynaTagDepsCache.containsKey( pluginName ) )
+ {
+ sessionLog.debug( "removing dynatag dependency cache entry" );
+ pluginDynaTagDepsCache.remove( pluginName );
+ }
+
+ dirty = true;
+ }
+*/
+ private JellyScriptHousing loadHousing( String pluginName, PluginManager
manager, Map pluginDirs, String desc )
+ throws IOException
+ {
+ File dir = ( File ) pluginDirs.get( pluginName );
+ if ( dir == null )
+ {
+ sessionLog.warn( "plugin " + pluginName + " is cached (" + desc + ")
but no longer present" );
+ return null;
+ }
+
+ JellyScriptHousing housing = manager.loadPluginHousing( pluginName, dir );
+ if ( housing == null )
+ {
+ sessionLog.error( "plugin " + pluginName + " is cached (" + desc + ")
but no longer valid" );
+ return null;
+ }
+ return housing;
+ }
+
+ private void clearCache()
+ {
+ pluginCache.clear();
+ callbackCache.clear();
+ goalCache.clear();
+ dynaTagLibCache.clear();
+ pluginDynaTagDepsCache.clear();
}
/**
* @param mapper
* @param housing
*/
- void mapPlugins(GoalToJellyScriptHousingMapper mapper, PluginManager manager)
throws Exception
+ boolean mapPlugins( GoalToJellyScriptHousingMapper mapper, PluginManager
manager, Map pluginDirs )
+ throws IOException
{
- Map pluginHousings = manager.getPluginHousings();
-
- for ( Iterator i = pluginDynaTagDepsCache.keySet().iterator(); i.hasNext();)
+ // Must invalidate bad ones first to keep iterators and cache consistent
+ for ( Iterator i = pluginDynaTagDepsCache.keySet().iterator(); i.hasNext();
)
{
- String pluginName = (String) i.next();
- JellyScriptHousing housing = (JellyScriptHousing) pluginHousings.get(
pluginName );
+ String pluginName = ( String ) i.next();
+ JellyScriptHousing housing = loadHousing( pluginName, manager,
pluginDirs, "dynatag dep" );
if ( housing == null )
{
- housing = manager.loadPlugin( pluginName );
- if ( housing == null )
- {
- sessionLog.warn("plugin " + pluginName + " is cached as a
dynatag dep, but no longer present.");
- continue;
- }
- }
- String csv = pluginDynaTagDepsCache.getProperty( pluginName );
- StringTokenizer tok = new StringTokenizer( csv, "," );
- while ( tok.hasMoreTokens() )
- {
- String uri = tok.nextToken();
- mapper.addPluginDynaTagDep( housing, uri );
+ clearCache();
+ return false;
}
}
-
- for ( Iterator i = pluginCache.keySet().iterator(); i.hasNext();)
+ for ( Iterator i = pluginCache.keySet().iterator(); i.hasNext(); )
{
String goalName = ( String ) i.next();
String pluginName = pluginCache.getProperty( goalName );
- JellyScriptHousing housing = (JellyScriptHousing) pluginHousings.get(
pluginName );
+ JellyScriptHousing housing = loadHousing( pluginName, manager,
pluginDirs, "goal" );
if ( housing == null )
{
- housing = manager.loadPlugin( pluginName );
- if ( housing == null )
- {
- sessionLog.warn("plugin " + pluginName + " is cached, but no
longer present.");
- continue;
- }
- }
- String goal = goalCache.getProperty(goalName);
- int index = goal.indexOf(">");
- String description = null;
- if (index > 0)
- {
- description = goal.substring(0, index);
+ clearCache();
+ return false;
}
- String prereqs = goal.substring( index + 1 );
-
- mapper.addGoal(goalName, prereqs, description, housing);
}
- for ( Iterator i = callbackCache.keySet().iterator(); i.hasNext();)
+ Map preGoals = new HashMap();
+ Map postGoals = new HashMap();
+ for ( Iterator i = callbackCache.keySet().iterator(); i.hasNext(); )
{
String callbackName = ( String ) i.next();
- boolean isPreGoal = callbackName.endsWith(".pre");
+ boolean isPreGoal = callbackName.endsWith( ".pre" );
String goalName =
isPreGoal
- ? callbackName.substring(0, callbackName.length() - 4)
- : callbackName.substring(0, callbackName.length() - 5);
+ ? callbackName.substring( 0, callbackName.length() - 4 )
+ : callbackName.substring( 0, callbackName.length() - 5 );
String pluginNames = callbackCache.getProperty( callbackName );
StringTokenizer tok = new StringTokenizer( pluginNames, "," );
while ( tok.hasMoreTokens() )
{
String pluginName = tok.nextToken();
- JellyScriptHousing housing = (JellyScriptHousing)
pluginHousings.get( pluginName );
- if ( housing == null )
+ JellyScriptHousing housing = loadHousing( pluginName, manager,
pluginDirs, "callbacks" );
+ if ( housing != null )
{
- housing = manager.loadPlugin( pluginName );
- if ( housing == null )
+ if ( isPreGoal )
{
- sessionLog.warn("plugin " + pluginName + " is cached for
callbacks, but no longer present.");
- continue;
+ preGoals.put( goalName, housing );
+ }
+ else
+ {
+ postGoals.put( goalName, housing );
}
- }
- if ( isPreGoal )
- {
- mapper.addPreGoal( goalName, housing );
}
else
{
- mapper.addPostGoal( goalName, housing );
+ clearCache();
+ return false;
}
}
}
- for ( Iterator i = dynaTagLibCache.keySet().iterator(); i.hasNext();)
+ for ( Iterator i = dynaTagLibCache.keySet().iterator(); i.hasNext(); )
{
String uri = ( String ) i.next();
String pluginName = dynaTagLibCache.getProperty( uri );
- JellyScriptHousing housing = (JellyScriptHousing) pluginHousings.get(
pluginName );
+ JellyScriptHousing housing = loadHousing( pluginName, manager,
pluginDirs, "dynataglib" );
if ( housing == null )
{
- housing = manager.loadPlugin( pluginName );
- if ( housing == null )
- {
- sessionLog.warn("plugin " + pluginName + " is cached for a
dynatag library, but no longer present.");
- continue;
- }
+ clearCache();
+ return false;
+ }
+ }
+
+ // Now map the clean set of plugins
+ for ( Iterator i = preGoals.keySet().iterator(); i.hasNext(); )
+ {
+ String goalName = ( String ) i.next();
+ JellyScriptHousing housing = ( JellyScriptHousing ) preGoals.get(
goalName );
+ mapper.addPreGoal( goalName, housing );
+ }
+ for ( Iterator i = postGoals.keySet().iterator(); i.hasNext(); )
+ {
+ String goalName = ( String ) i.next();
+ JellyScriptHousing housing = ( JellyScriptHousing ) postGoals.get(
goalName );
+ mapper.addPostGoal( goalName, housing );
+ }
+
+ for ( Iterator i = pluginDynaTagDepsCache.keySet().iterator(); i.hasNext();
)
+ {
+ String pluginName = ( String ) i.next();
+ JellyScriptHousing housing = manager.loadPluginHousing( pluginName, (
File ) pluginDirs.get( pluginName ) );
+ String csv = pluginDynaTagDepsCache.getProperty( pluginName );
+ StringTokenizer tok = new StringTokenizer( csv, "," );
+ while ( tok.hasMoreTokens() )
+ {
+ String uri = tok.nextToken();
+ mapper.addPluginDynaTagDep( housing, uri );
+ }
+ }
+
+ for ( Iterator i = pluginCache.keySet().iterator(); i.hasNext(); )
+ {
+ String goalName = ( String ) i.next();
+ String pluginName = pluginCache.getProperty( goalName );
+ JellyScriptHousing housing = manager.loadPluginHousing( pluginName, (
File ) pluginDirs.get( pluginName ) );
+ String goal = goalCache.getProperty( goalName );
+ int index = goal.indexOf( ">" );
+ String description = null;
+ if ( index > 0 )
+ {
+ description = goal.substring( 0, index );
}
+ String prereqs = goal.substring( index + 1 );
+
+ mapper.addGoal( goalName, prereqs, description, housing );
+ }
+
+ for ( Iterator i = dynaTagLibCache.keySet().iterator(); i.hasNext(); )
+ {
+ String uri = ( String ) i.next();
+ String pluginName = dynaTagLibCache.getProperty( uri );
+ JellyScriptHousing housing = manager.loadPluginHousing( pluginName, (
File ) pluginDirs.get( pluginName ) );
mapper.addDynaTagLib( uri, housing );
}
+ return true;
}
/* (non-Javadoc)
* @see
org.apache.maven.plugin.PluginDefintionHandler#setDefaultGoalName(java.lang.String)
*/
- public void setDefaultGoalName(String defaultGoalName)
+ public void setDefaultGoalName( String defaultGoalName )
{
// this method intentionally left blank
}
1.70.4.32 +171 -127 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.31
retrieving revision 1.70.4.32
diff -u -r1.70.4.31 -r1.70.4.32
--- PluginManager.java 28 Mar 2004 21:27:27 -0000 1.70.4.31
+++ PluginManager.java 1 Apr 2004 01:52:21 -0000 1.70.4.32
@@ -128,7 +128,7 @@
private final GoalToJellyScriptHousingMapper mapper = new
GoalToJellyScriptHousingMapper();
/** Current plugins mapper (transient - includes maven.xml, etc). **/
- private GoalToJellyScriptHousingMapper transientMapper = null;
+ private GoalToJellyScriptHousingMapper transientMapper = mapper;
/** Plugins to be popped afterwards. */
private Set delayedPops = new HashSet();
@@ -145,64 +145,61 @@
}
/**
- * Expand the plugin jars if needed
- *
- * @throws MavenException when the plugin jars can't be expanded
+ * Get the list of plugin files.
*/
- private void expandPluginJars( File directory ) throws MavenException
+ private Map getPluginFiles( File directory, boolean acceptDirectories ) throws
MavenException
{
File[] files = directory.listFiles();
if ( files == null )
{
- return;
+ return Collections.EMPTY_MAP;
}
- // 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 )
+ Map pluginFiles = new HashMap();
+ for ( int i = 0; i < files.length; i++ )
{
- unpackPlugin( files[i] );
+ String plugin = files[i].getName();
+ if ( files[i].isDirectory() && acceptDirectories )
+ {
+ pluginFiles.put( plugin, files[i] );
+ }
+ else
+ {
+ int index = plugin.indexOf( ".jar" );
+ if ( index >= 0 )
+ {
+ String name = plugin.substring( 0, index );
+ pluginFiles.put( name, files[i] );
+ }
+ }
}
+ return pluginFiles;
}
/**
- * Load unpacked plugins.
- * @param directory The unpacked plugins directory
- * @throws Exception when the plugin jars can't be expanded
+ * Load plugins.
+ *
+ * @throws MavenException when the plugin jars can't be expanded
*/
- private void loadUnpackedPlugins( File directory ) throws Exception
+ private void loadUncachedPlugins( Map pluginFiles ) throws IOException,
MavenException
{
- File[] files = directory.listFiles();
- if ( files == null )
+ log.debug( "Now loading uncached plugins" );
+
+ for ( Iterator i = pluginFiles.keySet().iterator(); i.hasNext(); )
{
- return;
- }
+ String name = ( String ) i.next();
+ File pluginDir = ( File ) pluginFiles.get( name );
- // 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.
- boolean loadedNewPlugins = false;
- for ( int i = 0; i < files.length; ++i )
- {
- File pluginDir = files[i];
-
- if ( pluginDir.isDirectory() && new File( pluginDir, "project.xml"
).exists()
- && !isLoaded( pluginDir.getName() ) )
- {
- loadedNewPlugins = true;
- JellyScriptHousing housing = loadPlugin( pluginDir );
- // TODO: optimise like installplugin
- housing.parse( cacheManager );
- housing.parse( mapper );
+ if ( !isLoaded( name ) )
+ {
+ JellyScriptHousing housing = createPluginHousing( pluginDir );
+ if ( housing != null )
+ {
+ housing.parse( cacheManager );
+ housing.parse( mapper );
+ }
}
}
- if ( loadedNewPlugins )
- {
- cacheManager.saveCache( unpackedPluginsDir );
- }
}
/**
@@ -210,14 +207,14 @@
*
* @throws Exception If an error occurs while initializing any plugin.
*/
- public void initialize() throws Exception
+ public void initialize() throws IOException, MavenException
{
if ( log.isDebugEnabled() )
{
log.debug( "Initializing Plugins!" );
}
- setPluginsDir( new File( mavenSession.getRootContext().getMavenHome(),
"plugins" ) );
+ setPluginsDir( new File( mavenSession.getRootContext().getPluginsDir() ) );
setUnpackedPluginsDir( new File(
mavenSession.getRootContext().getUnpackedPluginsDir() ) );
if ( log.isDebugEnabled() )
@@ -225,44 +222,75 @@
log.debug( "Set plugin source directory to " +
getPluginsDir().getAbsolutePath() );
log.debug( "Set unpacked plugin directory to " +
getUnpackedPluginsDir().getAbsolutePath() );
}
+
+ // plugin profile at this point is all of the JAR files in the plugins
directory and the unpacked plugins dir
+ // future ideas: have installation, user (outside of the cache), and
project (via deps) plugins
+ // allow further customisation via a profile descriptor.
+
+ Map pluginFiles = getPluginFiles( pluginsDir, true );
+ pluginFiles.putAll( getPluginFiles( unpackedPluginsDir, false ) );
+ Map pluginDirs = expandPluginFiles( pluginFiles );
+
cacheManager.loadCache( unpackedPluginsDir );
- cacheManager.mapPlugins( mapper, this );
- expandPluginJars( pluginsDir );
- expandPluginJars( unpackedPluginsDir );
- loadUnpackedPlugins( pluginsDir );
- loadUnpackedPlugins( unpackedPluginsDir );
+ log.debug( "Now mapping cached plugins" );
+ if ( !cacheManager.mapPlugins( mapper, this, pluginDirs ) )
+ {
+ log.info( "Cache invalidated due to out of date plugins" );
+ for ( Iterator i = pluginHousings.values().iterator(); i.hasNext(); )
+ {
+ JellyScriptHousing housing = ( JellyScriptHousing ) i.next();
+ housing.parse( cacheManager );
+ housing.parse( mapper );
+ }
+ }
+
+ loadUncachedPlugins( pluginDirs );
+
+ cacheManager.saveCache( unpackedPluginsDir );
log.debug( "Finished initializing Plugins!" );
}
- JellyScriptHousing loadPlugin( String pluginName ) throws Exception
+ private Map expandPluginFiles( Map pluginFiles ) throws MavenException
+ {
+ Map pluginDirs = new HashMap();
+ for ( Iterator i = pluginFiles.keySet().iterator(); i.hasNext(); )
+ {
+ String name = ( String ) i.next();
+ File jarFile = ( File ) pluginFiles.get( name );
+ File dir = jarFile.isDirectory() ? jarFile : unpackPlugin( name,
jarFile );
+ pluginDirs.put( name, dir );
+ }
+ return pluginDirs;
+ }
+
+ JellyScriptHousing loadPluginHousing( String name, File pluginDir ) throws
IOException
{
- return loadPlugin( new File( unpackedPluginsDir, pluginName ) );
+ JellyScriptHousing housing = ( JellyScriptHousing ) pluginHousings.get(
name );
+ return ( housing == null ? createPluginHousing( pluginDir ) : housing );
}
- // TODO: this can probably be refactored out now.
- private JellyScriptHousing loadPlugin( File pluginDir ) throws Exception
+ private JellyScriptHousing createPluginHousing( File pluginDir ) throws
IOException
{
- String pluginName = pluginDir.getName();
- if ( !isLoaded( pluginName ) )
+ if ( !pluginDir.isDirectory() || !new File( pluginDir, "project.xml"
).exists() )
{
- log.debug( "Loading plugin '" + pluginName + "'" );
+ log.debug( "Not a plugin directory: " + pluginDir );
+ return null;
+ }
- JellyScriptHousing jellyScriptHousing = new JellyScriptHousing(
pluginDir, mavenSession.getRootContext() );
+ String pluginName = pluginDir.getName();
- pluginHousings.put( pluginName, jellyScriptHousing );
+ log.debug( "Loading plugin '" + pluginName + "'" );
- return jellyScriptHousing;
- }
- else
- {
- log.debug( "Skipping already loaded plugin '" + pluginName + "'" );
- return (JellyScriptHousing) pluginHousings.get( pluginName );
- }
+ JellyScriptHousing jellyScriptHousing = new JellyScriptHousing( pluginDir,
mavenSession.getRootContext() );
+
+ pluginHousings.put( pluginName, jellyScriptHousing );
+
+ return jellyScriptHousing;
}
- private boolean isLoaded(String name)
+ private boolean isLoaded( String name )
{
return pluginHousings.containsKey( name );
}
@@ -275,6 +303,7 @@
* @throws Exception
* @todo [1.0] refactor into housing
* @deprecated get rid of this - it duplicates functionality in the housing
+ * @todo don't throw Exception
*/
private JellyScriptHousing createJellyScriptHousing( Project project,
InputStream jelly ) throws Exception
{
@@ -297,7 +326,6 @@
* @todo [1.0] into the housing?
*/
private JellyScriptHousing createJellyScriptHousing( Project project, File
jelly )
- throws Exception
{
JellyScriptHousing jellyScriptHousing = new JellyScriptHousing();
@@ -392,7 +420,8 @@
* @throws Exception
* If one of the specified
* goals refers to an non-existent goal.
- * @throws Exception If an exception occurs while running a goal. FIXME this is
bad
+ * @throws Exception If an exception occurs while running a goal.
+ * @todo stop throwing Exception
*/
public void attainGoals( Project project, List goals ) throws Exception
{
@@ -541,6 +570,9 @@
}
}
+ /**
+ * @todo don't throw Exception
+ */
public void cleanupAttainGoal( Set pluginSet ) throws Exception
{
delayedPops.addAll( pluginSet );
@@ -561,7 +593,8 @@
* @param goalName the goal
* @param baseContext the base context to attain in
* @return a set of plugins required to attain the goal
- * @throws Exception TODO poor form
+ * @throws Exception
+ * @todo don't throw Exception
*/
public Set prepAttainGoal( String goalName, MavenJellyContext baseContext,
GoalToJellyScriptHousingMapper goalMapper ) throws
Exception
@@ -571,16 +604,16 @@
for ( Iterator j = pluginSet.iterator(); j.hasNext();)
{
JellyScriptHousing housing = ( JellyScriptHousing ) j.next();
- artifactIdToHousingMap.put( housing.getProject().getArtifactId(),
housing );
+ Project project = initHousingProject( housing );
MavenUtils.integrateMapInContext( housing.getPluginProperties(),
baseContext );
// TODO necessary to create a new one every time?
MavenJellyContext pluginContext = new MavenJellyContext( baseContext );
- housing.getProject().pushContext( pluginContext );
+ project.pushContext( pluginContext );
pluginContext.setInherit( true );
pluginContext.setVariable( "context", pluginContext );
- pluginContext.setVariable( "plugin", housing.getProject() );
+ pluginContext.setVariable( "plugin", project );
pluginContext.setVariable( "plugin.dir", housing.getPluginDirectory() );
pluginContext.setVariable( "plugin.resources", new File(
housing.getPluginDirectory(), "plugin-resources" ) );
@@ -638,7 +671,9 @@
return mapper.getGoalNames();
}
- public void installPlugin( File file, Project parentProject ) throws Exception
+ /**
+ */
+ public void installPlugin( File file, Project parentProject ) throws
MavenException
{
// By default, don't copy to the unpacked plugins directory - only use this
dependency for this project
installPlugin( file, parentProject, false );
@@ -651,39 +686,54 @@
*
* @param file the file to install. Must be a plugin jar
* @param parentProject the project to load the installed plugin into
- * @todo remove any old one, but don't save updated cache
- * @todo more refactoring
+ * @todo remove any old one
*/
- public void installPlugin( File file, Project parentProject, boolean
installToUnpackedPluginDirectory ) throws Exception
+ public void installPlugin( File file, Project parentProject, boolean
installToUnpackedPluginDirectory )
+ throws MavenException
{
- if ( installToUnpackedPluginDirectory )
- {
- FileUtils.copyFileToDirectory( file, unpackedPluginsDir );
- }
-
- String pluginName = file.getCanonicalFile().getName();
- pluginName = pluginName.substring( 0, pluginName.indexOf( ".jar" ) );
-
- if ( !isLoaded( pluginName ) )
+ log.debug( "Using plugin dependency: " + file );
+ try
{
- // expand it
- File unpackedPluginDir = unpackPlugin( file );
- if ( unpackedPluginDir != null )
+ if ( installToUnpackedPluginDirectory )
{
- JellyScriptHousing housing = loadPlugin( unpackedPluginDir );
- housing.parse( cacheManager );
- housing.parse( mapper );
- if ( transientMapper != null )
+ FileUtils.copyFileToDirectory( file, unpackedPluginsDir );
+ }
+
+ String pluginName = file.getCanonicalFile().getName();
+ pluginName = pluginName.substring( 0, pluginName.indexOf( ".jar" ) );
+
+ if ( !isLoaded( pluginName ) )
+ {
+ // expand it
+ File unpackedPluginDir = unpackPlugin( pluginName, file );
+ if ( unpackedPluginDir != null )
{
+ JellyScriptHousing housing = createPluginHousing(
unpackedPluginDir );
+ if ( housing == null )
+ {
+ throw new MavenException( "Not a valid plugin file: " +
file );
+ }
+
+ // By default, not caching the plugin - its a per execution
installation
housing.parse( transientMapper );
+ // Should only be putting in the transientMapper - but it is
not consistent with isLoaded
+ housing.parse( mapper );
+ if ( installToUnpackedPluginDirectory )
+ {
+ housing.parse( cacheManager );
+ cacheManager.saveCache( unpackedPluginsDir );
+ }
+ }
+ else
+ {
+ throw new MavenException( "Not a valid JAR file: " + file );
}
- cacheManager.saveCache( unpackedPluginsDir );
- }
- else
- {
- throw new MavenException( "Not a valid plugin file: " + file );
}
}
+ catch ( IOException e )
+ {
+ throw new MavenException( "Error installing plugin", e );
+ }
}
/**
@@ -691,17 +741,30 @@
* @param id
* @return
* @throws UnknownPluginException
+ * @todo remove throws Exception
*/
- public MavenJellyContext getPluginContext( String id ) throws Exception
+ public MavenJellyContext getPluginContext( String id ) throws MavenException,
UnknownPluginException
{
JellyScriptHousing housing = ( JellyScriptHousing )
artifactIdToHousingMap.get( id );
if ( housing != null )
{
- return housing.getProject().getContext();
+ Project project = initHousingProject( housing );
+ return project.getContext();
}
throw new UnknownPluginException( id );
}
+ private Project initHousingProject( JellyScriptHousing housing ) throws
MavenException
+ {
+ Project project = housing.getProject();
+ if ( project == null )
+ {
+ project = housing.initProject();
+ artifactIdToHousingMap.put( project.getArtifactId(), housing );
+ }
+ return project;
+ }
+
public String getGoalDescription( String goalName )
{
return mapper.getGoalDescription( goalName );
@@ -717,17 +780,8 @@
*
* @throws MavenException if there was a problem unpacking
*/
- File unpackPlugin( File jarFile ) throws MavenException
+ File unpackPlugin( String pluginName, File jarFile ) throws MavenException
{
- String directory = jarFile.getName();
- int index = directory.indexOf( ".jar" );
- if ( index < 0 )
- {
- return null;
- }
-
- String pluginName = directory.substring( 0, index );
-
File unzipDir = new File( unpackedPluginsDir, pluginName );
// if there's no directory, or the jar is newer, expand the jar
@@ -735,9 +789,8 @@
{
if ( log.isDebugEnabled() )
{
- log.debug( "Unpacking '" + pluginName + "' plugin to directory -->
" + unzipDir.getAbsolutePath() );
+ log.debug( "Unpacking " + jarFile.getName() + " to directory --> "
+ unzipDir.getAbsolutePath() );
}
- cacheManager.invalidateCache(pluginName);
try
{
@@ -755,19 +808,10 @@
}
/**
+ * @todo get rid of throws Exception
* @return
*/
- Map getPluginHousings()
- {
- return pluginHousings;
- }
-
- /**
- *
- * @return
- */
- private Script loadScript(JellyScriptHousing jellyScriptHousing)
- throws Exception
+ private Script loadScript( JellyScriptHousing jellyScriptHousing ) throws
Exception
{
// TODO [1.0]: this currently duplicates createJellyScriptHousing for
others - it is the lazy version
@@ -778,8 +822,7 @@
// TODO: should differentiate between plugins and script housings better
jellyScriptHousing.getProject().verifyDependencies();
processDependencies( jellyScriptHousing.getProject() );
- ForeheadClassLoader pluginClassLoader = (ForeheadClassLoader)
jellyScriptHousing.getProject()
- .getContext().getClassLoader();
+ ForeheadClassLoader pluginClassLoader = ( ForeheadClassLoader )
jellyScriptHousing.getProject().getContext().getClassLoader();
pluginClassLoader.addURL(
jellyScriptHousing.getPluginDirectory().toURL() );
}
@@ -790,7 +833,7 @@
context.setRootURL( jellyScriptHousing.getSource().toURL() );
context.setCurrentURL( jellyScriptHousing.getSource().toURL() );
- Script script = JellyUtils.compileScript(jellyScriptHousing.getSource(),
context);
+ Script script = JellyUtils.compileScript( jellyScriptHousing.getSource(),
context );
context.setRootURL( oldRoot );
context.setCurrentURL( oldCurrent );
@@ -799,8 +842,9 @@
}
/**
- * @param context
- * @throws Exception
+ * @param context
+ * @throws Exception
+ * @todo get rid of throws Exception
*/
void runScript( JellyScriptHousing jellyScriptHousing, MavenJellyContext
context ) throws Exception
{
1.1.4.11 +3 -6 maven/src/java/org/apache/maven/plugin/PluginScriptParser.java
Index: PluginScriptParser.java
===================================================================
RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/PluginScriptParser.java,v
retrieving revision 1.1.4.10
retrieving revision 1.1.4.11
diff -u -r1.1.4.10 -r1.1.4.11
--- PluginScriptParser.java 28 Mar 2004 21:27:27 -0000 1.1.4.10
+++ PluginScriptParser.java 1 Apr 2004 01:52:21 -0000 1.1.4.11
@@ -20,6 +20,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.maven.MavenException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -118,11 +119,7 @@
{
jellyScriptHousing.parse( handler, new FileInputStream(
importUri ) );
}
- catch ( ParserConfigurationException e )
- {
- log.warn( "Error parsing content from uri " + importUri, e );
- }
- catch ( SAXException e )
+ catch ( MavenException e )
{
log.warn( "Error parsing content from uri " + importUri, e );
}
@@ -148,7 +145,7 @@
String prereqs = attributes.getValue( "prereqs" );
String description = attributes.getValue( "description" );
- handler.addGoal(name, prereqs, description, jellyScriptHousing);
+ handler.addGoal( name, prereqs, description, jellyScriptHousing );
}
else if ( rawName.equals( "preGoal" ) )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]