dion 2003/08/22 01:01:24
Modified: src/java/org/apache/maven/plugin PluginCacheManager.java
Log:
- Fix license
- Fix file in use issues when storing/loading properties files
- Various checkstyle issues
Revision Changes Path
1.15 +53 -67 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- PluginCacheManager.java 19 Aug 2003 04:28:50 -0000 1.14
+++ PluginCacheManager.java 22 Aug 2003 08:01:24 -0000 1.15
@@ -52,10 +52,13 @@
* 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.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileOutputStream;
@@ -86,7 +89,7 @@
private static final Log log =
LogFactory.getLog( PluginCacheManager.class );
/** Maven session log */
- private static final Log sessionLog =
+ private static final Log sessionLog =
LogFactory.getLog(MavenSession.class);
/** Plug-in cache */
@@ -95,6 +98,7 @@
/** Goal cache */
public static final String GOALS_CACHE = "goals.cache";
+ /** call backs cache */
public static final String CALLBACKS_CACHE = "callbacks.cache";
/** Taglibs cache */
@@ -199,7 +203,7 @@
/**
*
- * @param goalCache
+ * @param goalCache the goal cache
*/
public void setGoalCache( Properties goalCache )
{
@@ -208,7 +212,7 @@
/**
*
- * @return
+ * @return the cache of goals
*/
public Properties getGoalCache()
{
@@ -375,85 +379,67 @@
public void saveCache()
throws Exception
{
- if( log.isDebugEnabled() )
+ if ( log.isDebugEnabled() )
{
log.debug( "Saving caches to " +
getUnpackedPluginsDir().getAbsolutePath() );
}
- getPluginCache().store(
- new FileOutputStream( new File( getUnpackedPluginsDir(), PLUGINS_CACHE
) ), "plugins cache" );
-
- getGoalCache().store(
- new FileOutputStream( new File( getUnpackedPluginsDir(), GOALS_CACHE )
), "goals cache" );
-
- getCallbackCache().store(
- new FileOutputStream( new File( getUnpackedPluginsDir(),
CALLBACKS_CACHE ) ), "callbacks cache" );
- getDynaTagLibCache().store(
- new FileOutputStream( new File( getUnpackedPluginsDir(),
DYNAMIC_TAGLIBS_CACHE ) ), "taglibs cache" );
-
- getPluginDynaTagDepsCache().store(
- new FileOutputStream( new File( getUnpackedPluginsDir(),
PLUGIN_DYNATAG_DEPS_CACHE ) ), "plugin deps cache" );
+ storeProperties(getPluginCache(), PLUGINS_CACHE, "plugins cache");
+ storeProperties(getGoalCache(), GOALS_CACHE, "goals cache");
+ storeProperties(getCallbackCache(), CALLBACKS_CACHE, "callbacks cache");
+ storeProperties(getDynaTagLibCache(), DYNAMIC_TAGLIBS_CACHE, "taglibs
cache");
+ storeProperties(getPluginDynaTagDepsCache(), PLUGIN_DYNATAG_DEPS_CACHE,
+ "plugin deps cache");
}
/**
- * Load on-disk cache information, if possible.
+ * Write the given properties to the given file in the unpacked dir
+ * @param properties the properties object to store
+ * @param name the file name within the unpacked plugins directory to store the
properties
+ * @param header the header for the written properties
+ * @throws FileNotFoundException when the unpacked plugin directory can't be
found
+ * @throws IOException if there is a problem storing properties
*/
- void loadCache()
+ private void storeProperties(Properties properties, String name, String header)
+ throws FileNotFoundException, IOException
{
- pluginCache = new Properties();
-
- try
- {
- pluginCache.load( new FileInputStream( new File(
getUnpackedPluginsDir(), PLUGINS_CACHE ) ) );
- }
- catch ( IOException e )
- {
- // ignore, new cache.
- }
-
- goalCache = new Properties();
-
- try
- {
- goalCache.load( new FileInputStream( new File( getUnpackedPluginsDir(),
GOALS_CACHE ) ) );
- }
- catch ( IOException e )
- {
- // ignore, new cache.
- }
-
- callbackCache = new Properties();
-
- try
- {
- callbackCache.load( new FileInputStream( new File(
getUnpackedPluginsDir(), CALLBACKS_CACHE ) ) );
- }
- catch ( IOException e )
- {
- // ignore, new cache;
- }
-
- dynaTagLibCache = new Properties();
-
+ File file = new File(getUnpackedPluginsDir(), name);
+ FileOutputStream stream = new FileOutputStream(file);
+ properties.store(stream, header);
+ stream.close();
+ }
+
+ /**
+ * @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(String name)
+ {
+ Properties properties = new Properties();
+ File file = new File(getUnpackedPluginsDir(), name);
try
{
- dynaTagLibCache.load( new FileInputStream( new File(
getUnpackedPluginsDir(), DYNAMIC_TAGLIBS_CACHE ) ) );
+ FileInputStream stream = new FileInputStream(file);
+ properties.load(stream);
+ stream.close();
}
- catch ( IOException e )
+ catch (IOException e)
{
- // ignore, new cache;
+ log.debug("IOException reading cache, possibly not there", e);
}
+ return properties;
+ }
- pluginDynaTagDepsCache = new Properties();
-
- try
- {
- pluginDynaTagDepsCache.load( new FileInputStream( new File(
getUnpackedPluginsDir(), PLUGIN_DYNATAG_DEPS_CACHE ) ) );
- }
- catch ( IOException e )
- {
- // ignore, new cache;
- }
+ /**
+ * Load on-disk cache information, if possible.
+ */
+ void loadCache()
+ {
+ pluginCache = loadProperties(PLUGINS_CACHE );
+ goalCache = loadProperties(GOALS_CACHE);
+ callbackCache = loadProperties(CALLBACKS_CACHE);
+ dynaTagLibCache = loadProperties(DYNAMIC_TAGLIBS_CACHE);
+ pluginDynaTagDepsCache = loadProperties(PLUGIN_DYNATAG_DEPS_CACHE);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]