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/04/02 05:42:25 UTC
cvs commit: maven/src/java/org/apache/maven/plugin JellyScriptHousing.java PluginCacheManager.java PluginManager.java
brett 2004/04/01 19:42:25
Modified: src/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH
JellyScriptHousing.java PluginCacheManager.java
PluginManager.java
Log:
artifact Id cache
Revision Changes Path
No revision
No revision
1.3.4.13 +2 -11 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.12
retrieving revision 1.3.4.13
diff -u -r1.3.4.12 -r1.3.4.13
--- JellyScriptHousing.java 1 Apr 2004 06:47:50 -0000 1.3.4.12
+++ JellyScriptHousing.java 2 Apr 2004 03:42:25 -0000 1.3.4.13
@@ -98,21 +98,12 @@
*
* @return
*/
- Project initProject() throws MavenException
+ public Project getProject() throws MavenException
{
if ( project == null )
{
project = MavenUtils.getProject( new File( pluginDirectory, "project.xml" ), parentContext, false );
}
- return project;
- }
-
- /**
- *
- * @return
- */
- public Project getProject()
- {
return project;
}
1.16.4.14 +59 -20 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.13
retrieving revision 1.16.4.14
diff -u -r1.16.4.13 -r1.16.4.14
--- PluginCacheManager.java 1 Apr 2004 01:52:20 -0000 1.16.4.13
+++ PluginCacheManager.java 2 Apr 2004 03:42:25 -0000 1.16.4.14
@@ -32,6 +32,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.apache.maven.MavenSession;
/**
@@ -52,6 +53,9 @@
/** Plug-in cache valid. */
public static final String VALID_CACHE = "valid.cache";
+ /** Artifact ID to Plug-in cache */
+ public static final String ARTIFACT_ID_CACHE = "artifactIdToPlugin.cache";
+
/** Plug-in cache */
public static final String PLUGINS_CACHE = "plugins.cache";
@@ -64,13 +68,19 @@
/** Taglibs cache */
public static final String DYNAMIC_TAGLIBS_CACHE = "dynatag.cache";
- /** Plugin -> dynatag dependencies. */
+ /** Plugin -> dynatag dependencies. */
public static final String PLUGIN_DYNATAG_DEPS_CACHE = "plugin-dynatag-deps.cache";
/** Dirty flag. */
private boolean dirty = true;
/**
+ * The artifact id cache contains plugin name to artifact ID mappings.
+ * @todo just for getPluginContext - should not be loading multiple versions, and hence using artifact ID instead of name everywhere...
+ */
+ private Properties artifactIdCache = new Properties();
+
+ /**
* The goals caches contains a mapping of goal names to a description for the
* goal and any prerequisite goals.
*/
@@ -183,6 +193,7 @@
storeProperties( callbackCache, new File( directory, CALLBACKS_CACHE ), "callbacks cache" );
storeProperties( dynaTagLibCache, new File( directory, DYNAMIC_TAGLIBS_CACHE ), "taglibs cache" );
storeProperties( pluginDynaTagDepsCache, new File( directory, PLUGIN_DYNATAG_DEPS_CACHE ), "plugin deps cache" );
+ storeProperties( artifactIdCache, new File( directory, ARTIFACT_ID_CACHE ), "artifact ID to plugin mapping" );
f.createNewFile();
dirty = false;
}
@@ -212,25 +223,21 @@
* @return a loaded properties file from disk or a new one if there are any problems
* @param file the file within the unpacked plugins dir to load
*/
- private Properties loadProperties( File file )
+ private Properties loadProperties( File file ) throws IOException
{
Properties properties = new Properties();
- if ( file.exists() )
+ FileInputStream stream = null;
+ try
+ {
+ stream = new FileInputStream( file );
+ properties.load( stream );
+ }
+ finally
{
- try
+ if ( stream != null )
{
- FileInputStream stream = new FileInputStream( file );
- properties.load( stream );
stream.close();
}
- catch ( IOException e )
- {
- log.debug( "IOException reading cache", e );
- }
- }
- else
- {
- log.debug( "Cache file does not exist, skipping: " + file );
}
return properties;
}
@@ -250,11 +257,21 @@
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 ) );
+ try
+ {
+ 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 ) );
+ artifactIdCache = loadProperties( new File( directory, ARTIFACT_ID_CACHE ) );
+ }
+ catch ( IOException e )
+ {
+ log.warn( "Clearing cache due to exception loading part of cache" );
+ log.debug( "Exception", e );
+ clearCache();
+ }
dirty = false;
}
@@ -300,7 +317,7 @@
String prop = (String) pluginDynaTagDepsCache.get( housing.getName() );
int tl = uri.length();
- if (prop.indexOf(",") < 0)
+ if ( prop.indexOf(",") < 0 )
{
pluginDynaTagDepsCache.remove( housing.getName() );
}
@@ -331,6 +348,10 @@
dirty = true;
}
+ void registerPlugin( String name, JellyScriptHousing housing ) throws MavenException
+ {
+ artifactIdCache.put( name, housing.getProject().getArtifactId() );
+ }
public void addPostGoal( String name, JellyScriptHousing housing )
{
@@ -449,6 +470,7 @@
goalCache.clear();
dynaTagLibCache.clear();
pluginDynaTagDepsCache.clear();
+ artifactIdCache.clear();
}
/**
@@ -480,6 +502,16 @@
return false;
}
}
+ for ( Iterator i = artifactIdCache.keySet().iterator(); i.hasNext(); )
+ {
+ String pluginName = ( String ) i.next();
+ JellyScriptHousing housing = loadHousing( pluginName, manager, pluginDirs, "artifactId" );
+ if ( housing == null )
+ {
+ clearCache();
+ return false;
+ }
+ }
Map preGoals = new HashMap();
Map postGoals = new HashMap();
@@ -578,6 +610,13 @@
String pluginName = dynaTagLibCache.getProperty( uri );
JellyScriptHousing housing = manager.loadPluginHousing( pluginName, ( File ) pluginDirs.get( pluginName ) );
mapper.addDynaTagLib( uri, housing );
+ }
+
+ for ( Iterator i = artifactIdCache.keySet().iterator(); i.hasNext(); )
+ {
+ String pluginName = ( String ) i.next();
+ JellyScriptHousing housing = manager.loadPluginHousing( pluginName, ( File ) pluginDirs.get( pluginName ) );
+ manager.mapArtifactIdToPluginHousing( artifactIdCache.getProperty( pluginName ), housing );
}
return true;
}
1.70.4.33 +25 -16 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.32
retrieving revision 1.70.4.33
diff -u -r1.70.4.32 -r1.70.4.33
--- PluginManager.java 1 Apr 2004 01:52:21 -0000 1.70.4.32
+++ PluginManager.java 2 Apr 2004 03:42:25 -0000 1.70.4.33
@@ -195,6 +195,7 @@
JellyScriptHousing housing = createPluginHousing( pluginDir );
if ( housing != null )
{
+ cacheManager.registerPlugin( name, housing );
housing.parse( cacheManager );
housing.parse( mapper );
}
@@ -237,9 +238,11 @@
if ( !cacheManager.mapPlugins( mapper, this, pluginDirs ) )
{
log.info( "Cache invalidated due to out of date plugins" );
+ // The following housings are considered loaded - so go through and cache them manually
for ( Iterator i = pluginHousings.values().iterator(); i.hasNext(); )
{
JellyScriptHousing housing = ( JellyScriptHousing ) i.next();
+ cacheManager.registerPlugin( housing.getName(), housing );
housing.parse( cacheManager );
housing.parse( mapper );
}
@@ -268,10 +271,26 @@
JellyScriptHousing loadPluginHousing( String name, File pluginDir ) throws IOException
{
JellyScriptHousing housing = ( JellyScriptHousing ) pluginHousings.get( name );
- return ( housing == null ? createPluginHousing( pluginDir ) : housing );
+ return ( housing == null ? createLazyPluginHousing( pluginDir ) : housing );
}
- private JellyScriptHousing createPluginHousing( File pluginDir ) throws IOException
+ private JellyScriptHousing createPluginHousing( File pluginDir ) throws MavenException, IOException
+ {
+ JellyScriptHousing housing = createLazyPluginHousing( pluginDir );
+ if ( housing != null )
+ {
+ String artifactId = housing.getProject().getArtifactId();
+ mapArtifactIdToPluginHousing( artifactId, housing );
+ }
+ return housing;
+ }
+
+ void mapArtifactIdToPluginHousing( String artifactId, JellyScriptHousing housing )
+ {
+ artifactIdToHousingMap.put( artifactId, housing );
+ }
+
+ private JellyScriptHousing createLazyPluginHousing( File pluginDir ) throws IOException
{
if ( !pluginDir.isDirectory() || !new File( pluginDir, "project.xml" ).exists() )
{
@@ -604,7 +623,7 @@
for ( Iterator j = pluginSet.iterator(); j.hasNext();)
{
JellyScriptHousing housing = ( JellyScriptHousing ) j.next();
- Project project = initHousingProject( housing );
+ Project project = housing.getProject();
MavenUtils.integrateMapInContext( housing.getPluginProperties(), baseContext );
@@ -720,6 +739,7 @@
housing.parse( mapper );
if ( installToUnpackedPluginDirectory )
{
+ cacheManager.registerPlugin( pluginName, housing );
housing.parse( cacheManager );
cacheManager.saveCache( unpackedPluginsDir );
}
@@ -748,21 +768,10 @@
JellyScriptHousing housing = ( JellyScriptHousing ) artifactIdToHousingMap.get( id );
if ( housing != null )
{
- Project project = initHousingProject( housing );
+ Project project = housing.getProject();
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 )
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org