dion        2003/08/17 16:47:44

  Modified:    src/java/org/apache/maven/plugin Tag: MAVEN_RC1_STABLE
                        PluginManager.java
  Log:
  Refactor out some large methods from initialize
  Move setting of cacheManager unpackedPlugins dir to set method
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.45.2.6  +65 -45    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.45.2.5
  retrieving revision 1.45.2.6
  diff -u -r1.45.2.5 -r1.45.2.6
  --- PluginManager.java        14 Aug 2003 07:01:32 -0000      1.45.2.5
  +++ PluginManager.java        17 Aug 2003 23:47:43 -0000      1.45.2.6
  @@ -202,7 +202,7 @@
       /**
        *  Retrieve a goal description by the goal name.
        *
  -     *  @param name THe goal name.
  +     *  @param name The goal name.
        *
        *  @return The description or <code>null</code> if no
        *          description has been set.
  @@ -245,7 +245,6 @@
           }
           setPluginsDir( new File( mavenSession.getRootContext().getMavenHome(), 
"plugins" ) );
           setUnpackedPluginsDir( new File( 
mavenSession.getRootContext().getUnpackedPluginsDir() ) );
  -        cacheManager.setUnpackedPluginsDir( getUnpackedPluginsDir() );
           if( log.isDebugEnabled() )
           {
               log.debug( "Set plugin source directory to "
  @@ -255,13 +254,74 @@
           }
           cacheManager.loadCache();
   
  -        File[] files = getPluginsDir().listFiles();
           if( log.isDebugEnabled() )
           {
               log.debug( "Unpacking plugins from directory --> "
                   + getPluginsDir().getAbsolutePath() );
           }
   
  +        expandPluginJars();
  +
  +        cachePlugins();
  +
  +        initialized = true;
  +
  +        log.debug( "Finished initializing Plugins!" );
  +    }
  +
  +    /**
  +     * For any plugin that is not already cached according to the cache manager
  +     * we cache it.
  +     * @throws Exception FIXME. When anything goes wrong
  +     */
  +    private void cachePlugins() throws Exception
  +    {
  +        // We need to get the directory listing again so that we
  +        // can process plugins that were just unpacked by the
  +        // above process. This time we're looking at the unpacked plugins.
  +        File[] files = getUnpackedPluginsDir().listFiles();
  +        
  +        if (log.isDebugEnabled())
  +        {
  +            log.debug( "Processing unpacked plugins in "
  +                + getUnpackedPluginsDir().getAbsolutePath() );
  +        }
  +        
  +        // Process each of the directorties.
  +        for ( int i = 0; i < files.length; ++i )
  +        {
  +            if ( files[i].isDirectory() )
  +            {
  +                String directory = files[i].getName();
  +        
  +                // If we haven't cached (or previous cache data has become invalid)
  +                // the plugin, then do so now.
  +                if ( isCached( directory ) == false )
  +                {
  +                    try
  +                    {
  +                        cachePlugin( files[i].getName() );
  +                    }
  +                    catch ( Exception e )
  +                    {
  +                        log.error( getMessage( "plugin.loading.error", 
files[i].getName() ) );
  +                        e.printStackTrace();
  +                    }
  +                }
  +            }
  +        }
  +        
  +        saveCache();
  +    }
  +
  +    /**
  +     * Expand the plugin jars if needed
  +     * @throws MavenException
  +     */
  +    private void expandPluginJars() throws MavenException
  +    {
  +        File[] files = getPluginsDir().listFiles();
  +
           // 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
  @@ -308,47 +368,6 @@
                   }
               }
           }
  -
  -        // We need to get the directory listing again so that we
  -        // can process plugins that were just unpacked by the
  -        // above process. This time we're looking at the unpacked plugins.
  -        files = getUnpackedPluginsDir().listFiles();
  -
  -        if( log.isDebugEnabled() )
  -        {
  -            log.debug( "Processing unpacked plugins in "
  -                + getUnpackedPluginsDir().getAbsolutePath() );
  -        }
  -
  -        // Process each of the directorties.
  -        for ( int i = 0; i < files.length; ++i )
  -        {
  -            if ( files[i].isDirectory() )
  -            {
  -                String directory = files[i].getName();
  -
  -                // If we haven't cached (or previous cache data has become invalid)
  -                // the plugin, then do so now.
  -                if ( isCached( directory ) == false )
  -                {
  -                    try
  -                    {
  -                        cachePlugin( files[i].getName() );
  -                    }
  -                    catch ( Exception e )
  -                    {
  -                        log.error( getMessage( "plugin.loading.error", 
files[i].getName() ) );
  -                        e.printStackTrace();
  -                    }
  -                }
  -            }
  -        }
  -
  -        saveCache();
  -
  -        initialized = true;
  -
  -        log.debug( "Finished initializing Plugins!" );
       }
   
   
  @@ -987,6 +1006,7 @@
       void setUnpackedPluginsDir( File unpackedPluginsDir )
       {
           this.unpackedPluginsDir = unpackedPluginsDir;
  +        cacheManager.setUnpackedPluginsDir( unpackedPluginsDir );
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to