brett 2004/03/25 16:20:41 Modified: src/java/org/apache/maven/plugin Tag: MAVEN-1_0-BRANCH PluginCacheManager.java Log: use a lock file to avoid multiple maven instances scrogging each other's plugin cache Revision Changes Path No revision No revision 1.16.4.9 +66 -17 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.8 retrieving revision 1.16.4.9 diff -u -r1.16.4.8 -r1.16.4.9 --- PluginCacheManager.java 25 Mar 2004 05:33:11 -0000 1.16.4.8 +++ PluginCacheManager.java 26 Mar 2004 00:20:41 -0000 1.16.4.9 @@ -46,6 +46,9 @@ /** Maven session log */ private static final Log sessionLog = LogFactory.getLog(MavenSession.class); + /** Plug-in cache lock. */ + public static final String LOCK_CACHE = "lock.cache"; + /** Plug-in cache valid. */ public static final String VALID_CACHE = "valid.cache"; @@ -122,22 +125,65 @@ { } - void saveCache(File directory) throws IOException + void checkLockFile( File lockFile ) throws IOException { - directory.mkdirs(); - if ( log.isDebugEnabled() ) + for ( int i = 1; i <= 10; i++ ) { - log.debug( "Saving caches to " + directory.getAbsolutePath() ); + if ( lockFile.exists() ) + { + log.info( "Lock file " + lockFile + " exists, waiting... " + i + " of 10" ); + try + { + Thread.sleep( 1000 ); + } + catch ( InterruptedException e ) + { + // do nothing + } + } + else + { + break; + } } + if ( lockFile.exists() ) + { + log.warn( "Lock file still exists: ignoring" ); + lockFile.delete(); + } + } + + void saveCache( File directory ) throws IOException + { + directory.mkdirs(); + + File lockFile = new File( directory, LOCK_CACHE ); + checkLockFile( lockFile ); + + log.debug( "Locking " + lockFile ); + lockFile.createNewFile(); - File f = new File( directory, VALID_CACHE ); - f.delete(); - storeProperties(pluginCache, new File( directory, PLUGINS_CACHE ), "plugins cache"); - storeProperties(goalCache, new File( directory, GOALS_CACHE ), "goals cache"); - 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"); - f.createNewFile(); + try + { + if ( log.isDebugEnabled() ) + { + log.debug( "Saving caches to " + directory.getAbsolutePath() ); + } + + File f = new File( directory, VALID_CACHE ); + f.delete(); + storeProperties( pluginCache, new File( directory, PLUGINS_CACHE ), "plugins cache" ); + storeProperties( goalCache, new File( directory, GOALS_CACHE ), "goals cache" ); + 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" ); + f.createNewFile(); + } + finally + { + log.debug( "Unlocking " + lockFile ); + lockFile.delete(); + } } /** @@ -160,18 +206,18 @@ * @return a loaded properties file from disk or a new one if there are any problems * @param name the name of the file within the unpacked plugins dir to load */ - private Properties loadProperties(File file) + private Properties loadProperties( File file ) { Properties properties = new Properties(); if ( file.exists() ) { try { - FileInputStream stream = new FileInputStream(file); - properties.load(stream); + FileInputStream stream = new FileInputStream( file ); + properties.load( stream ); stream.close(); } - catch (IOException e) + catch ( IOException e ) { log.debug("IOException reading cache", e); } @@ -186,8 +232,11 @@ /** * Load on-disk cache information, if possible. */ - void loadCache( File directory ) + void loadCache( File directory ) throws IOException { + File lockFile = new File( directory, LOCK_CACHE ); + checkLockFile( lockFile ); + File f = new File( directory, VALID_CACHE ); if ( !f.exists() ) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]