You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by "Henning P. Schmiedehausen" <hp...@intermeta.de> on 2002/12/27 20:01:38 UTC

[PATCH] Make installation read only

This is a patch to force maven to consider an installation "read
only". This is necessary to avoid maven trying to rewrite the cache
files in the maven.home directory at every run.

The caches must have been created before using the "readonly"
property!  If you don't run maven as a user which is allowed to write
the maven.home directory (in a shared installation usually root),
maven will _NOT WORK_!

After you ran it once, users can use maven.mode.readonly = true in
their build.properties, which actually speeds up the maven startup
time.

diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Fri Dec 27 17:44:49 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Fri Dec 27 17:45:05 2002
@@ -87,6 +87,9 @@
     /** Online tag. */
     public static final String ONLINE = "maven.mode.online";
 
+    /** Readonly tag. */
+    public static final String READONLY = "maven.mode.readonly";
+
     /** Jar Override tag. */
     public static final String JAR_OVERRIDE = "maven.jar.override";
 
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Fri Dec 27 17:44:49 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Fri Dec 27 17:50:01 2002
@@ -461,6 +461,39 @@
     }
 
     /**
+     * Set the readonly flag.
+     *
+     * @param readonly The readonly flag.
+     */
+    public void setReadonly( Boolean readonly )
+    {
+        setVariable( MavenConstants.READONLY, readonly );
+    }
+
+    /**
+     * Get the readonly flag.
+     *
+     * @return The readonly flag.
+     */
+    public Boolean getReadonly()
+    {
+        Object readonly = getVariable( MavenConstants.READONLY );
+
+        if ( readonly == null )
+        {
+            return Boolean.FALSE;
+        }
+        else if (readonly instanceof Boolean)
+        {
+            return (Boolean) readonly;
+        }
+        else
+        {
+            return new Boolean ( readonly.toString() );
+        }
+    }
+
+    /**
      * Set the maven project.
      *
      * @param project The maven project.
@@ -822,6 +855,7 @@
         child.setDebugOn( getDebugOn() );
         child.setEmacsModeOn( getEmacsModeOn() );
         child.setOnline( getOnline() );
+        child.setReadonly( getReadonly() );
         child.setDescriptorDirectory( childBasedir );
 
         return child;
Only in jakarta-turbine-maven/src/java/org/apache/maven/jelly: MavenJellyContext.java~
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java	Wed Dec 18 18:13:38 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java	Fri Dec 27 17:45:05 2002
@@ -171,6 +171,10 @@
 
         loadCache();
 
+        boolean readOnly = getContext().getReadonly().booleanValue();
+
+        if ( ! readOnly )
+        {
         File pluginsDir = getPluginsDir();
 
         File[] files = pluginsDir.listFiles();
@@ -241,6 +245,7 @@
 
         saveCache();
     }
+    }
 
     /**
      *  Load on-disk cache information, if possible.


	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

Re: [PATCH] Make installation read only

Posted by Jason van Zyl <ja...@zenplex.com>.
I'll take a look at the patches after I'm finished my check which I hope
to start tomorrow and will probably take me all day to get in. After
that I will examine, modify and merge any acceptable patches. What I
currently have here doesn't much resembled internally what's in HEAD.

-- 
jvz.

Jason van Zyl
jason@zenplex.com
http://tambora.zenplex.org

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.
  
  -- Jacques Ellul, The Technological Society


Re: [PATCH] Make installation read only

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Henning P. Schmiedehausen" <hp...@intermeta.de> writes:

>This is a patch to force maven to consider an installation "read
>only". This is necessary to avoid maven trying to rewrite the cache
>files in the maven.home directory at every run.

>The caches must have been created before using the "readonly"
>property!  If you don't run maven as a user which is allowed to write
>the maven.home directory (in a shared installation usually root),
>maven will _NOT WORK_!

>After you ran it once, users can use maven.mode.readonly = true in
>their build.properties, which actually speeds up the maven startup
>time.

I was a little too trigger happy here. The first patch stopped the
plugin.properties from being loaded which was bad for most
plugins. :-)

This patch passes all my tests.

diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Sat Dec 28 01:24:00 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/MavenConstants.java	Sat Dec 28 01:25:17 2002
@@ -87,6 +87,9 @@
     /** Online tag. */
     public static final String ONLINE = "maven.mode.online";
 
+    /** Readonly tag. */
+    public static final String READONLY = "maven.mode.readonly";
+
     /** Jar Override tag. */
     public static final String JAR_OVERRIDE = "maven.jar.override";
 
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Sat Dec 28 01:24:00 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/jelly/MavenJellyContext.java	Sat Dec 28 01:25:17 2002
@@ -461,6 +461,39 @@
     }
 
     /**
+     * Set the readonly flag.
+     *
+     * @param readonly The readonly flag.
+     */
+    public void setReadonly( Boolean readonly )
+    {
+        setVariable( MavenConstants.READONLY, readonly );
+    }
+
+    /**
+     * Get the readonly flag.
+     *
+     * @return The readonly flag.
+     */
+    public Boolean getReadonly()
+    {
+        Object readonly = getVariable( MavenConstants.READONLY );
+
+        if ( readonly == null )
+        {
+            return Boolean.FALSE;
+        }
+        else if (readonly instanceof Boolean)
+        {
+            return (Boolean) readonly;
+        }
+        else
+        {
+            return new Boolean ( readonly.toString() );
+        }
+    }
+
+    /**
      * Set the maven project.
      *
      * @param project The maven project.
@@ -822,6 +855,7 @@
         child.setDebugOn( getDebugOn() );
         child.setEmacsModeOn( getEmacsModeOn() );
         child.setOnline( getOnline() );
+        child.setReadonly( getReadonly() );
         child.setDescriptorDirectory( childBasedir );
 
         return child;
diff -urb test/jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java
--- test/jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java	Wed Dec 18 18:13:38 2002
+++ jakarta-turbine-maven/src/java/org/apache/maven/plugin/PluginManager.java	Sat Dec 28 01:32:41 2002
@@ -171,10 +171,14 @@
 
         loadCache();
 
-        File pluginsDir = getPluginsDir();
+        boolean readOnly = getContext().getReadonly().booleanValue();
 
-        File[] files = pluginsDir.listFiles();
+        File pluginsDir = getPluginsDir();
 
+        File[] files = null; 
+        if ( ! readOnly )
+        {
+            files = pluginsDir.listFiles();
         // First we expand any JARs that contain plugins.
         for ( int i = 0; i < files.length; ++i )
         {
@@ -205,13 +209,14 @@
                 }
             }
         }
+        }
 
         // We need to get the directory listing again so that we
         // can process plugins that were just unpacked by the
         // above process.
         files = pluginsDir.listFiles();
 
-        // Process each of the directorties.
+        // Process each of the directories.
         for ( int i = 0; i < files.length; ++i )
         {
             if ( files[i].isDirectory() )
@@ -223,8 +228,8 @@
                 loadPluginProperties( directory );
 
                 // If we haven't cached (or previous cache data has become invalid)
-                // the plugin, then do so now.
-                if ( !isCached( directory ) )
+                // the plugin, then do so now if we're not running read only
+                if ( !readOnly && !isCached( directory ) )
                 {
                     try
                     {
@@ -239,8 +244,11 @@
             }
         }
 
+        if ( ! readOnly )
+        {
         saveCache();
     }
+    }
 
     /**
      *  Load on-disk cache information, if possible.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20