dion 2003/08/03 18:11:14 Modified: src/java/org/apache/maven/plugin JellyPlugin.java PluginManager.java src/java/org/apache/maven/verifier DependencyVerifier.java src/java/org/apache/maven Maven.java ArtifactListBuilder.java src/java/org/apache/maven/project Project.java Log: More reworking to include JellyPlugin Revision Changes Path 1.2 +61 -5 maven/src/java/org/apache/maven/plugin/JellyPlugin.java Index: JellyPlugin.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/plugin/JellyPlugin.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JellyPlugin.java 1 Aug 2003 07:39:24 -0000 1.1 +++ JellyPlugin.java 4 Aug 2003 01:11:13 -0000 1.2 @@ -30,8 +30,7 @@ * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * - * 5. Products derived from this software may not be called "Apache", - * "Apache Maven", nor may "Apache" appear in their name, without + * 5. Products derived from this software may not be called "Apache", * "Apache Maven", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -61,9 +60,11 @@ import java.net.MalformedURLException; import org.apache.commons.jelly.Script; +import org.apache.maven.MavenException; import org.apache.maven.jelly.JellyUtils; import org.apache.maven.jelly.MavenJellyContext; import org.apache.maven.project.Project; +import org.apache.maven.util.Expand; import org.apache.maven.verifier.ChecksumVerificationException; import org.apache.maven.verifier.RepoConfigException; import org.apache.maven.verifier.UnsatisfiedDependencyException; @@ -81,7 +82,13 @@ /** the id of the plugin */ private String id; + + /** the jar file the plugin was extracted from */ + private File jarFile; + /** the directory to unpack the plugin into */ + private File unpackDirectory; + /** the directory the plugin is installed into */ private File directory; @@ -134,6 +141,10 @@ */ public File getDirectory() { + if (directory == null && unpackDirectory != null) + { + directory = new File(unpackDirectory, id); + } return directory; } @@ -159,7 +170,7 @@ public File getScriptFile() { if (scriptFile == null) { - scriptFile = new File( directory, "plugin.jelly"); + scriptFile = new File( getDirectory(), "plugin.jelly"); } return scriptFile; } @@ -170,7 +181,7 @@ public File getDescriptor() { if (descriptor == null) { - descriptor = new File( directory, "project.xml"); + descriptor = new File( getDirectory(), "project.xml"); } return descriptor; } @@ -182,7 +193,7 @@ { if (processedMarker == null) { - processedMarker = new File(directory, ".processed"); + processedMarker = new File(getDirectory(), ".processed"); } return processedMarker; } @@ -272,5 +283,50 @@ compiledScript = JellyUtils.compileScript( getScriptFile(), context ); } return compiledScript; + } + /** + * @param file the jar file containing the plugin + */ + public void setJarFile(File file) + { + jarFile = file; + } + + /** + * @param file the directory to unpack the plugin into + */ + public void setUnpackDirectory(File file) + { + unpackDirectory = file; + } + + /** + */ + public void unpack() throws MavenException + { + File unzipDir = getDirectory(); + + // if there's no directory, or the jar is newer, expand the jar + if ( !unzipDir.exists() + || jarFile.lastModified() > unzipDir.lastModified() ) + { + File processed = getProcessedMarker(); + if ( processed.exists() ) + { + processed.delete(); + } + + try + { + Expand unzipper = new Expand(); + unzipper.setSrc( jarFile ); + unzipper.setDest( unzipDir ); + unzipper.execute(); + } + catch ( IOException e ) + { + throw new MavenException( "Unable to extract plugin: " + jarFile, e ); + } + } } } 1.59 +139 -138 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.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- PluginManager.java 1 Aug 2003 07:39:24 -0000 1.58 +++ PluginManager.java 4 Aug 2003 01:11:13 -0000 1.59 @@ -82,7 +82,6 @@ import org.apache.maven.project.Project; import org.apache.maven.repository.Artifact; import org.apache.maven.util.Expand; -import org.apache.plexus.util.FileUtils; import org.apache.tools.ant.types.Path; import java.io.File; @@ -120,8 +119,6 @@ { /** Logger */ private static final Log log = LogFactory.getLog( PluginManager.class ); - /** Plug-in main script name. */ - public static final String PLUGIN_SCRIPT_NAME = "plugin.jelly"; /** */ public static final String PLUGIN_MANAGER = "maven.pluginManager"; /** */ @@ -153,6 +150,9 @@ /** map of loaded plugins by id */ private Map loadedPlugins; + + /** map of plugins by id */ + private Map plugins; /** rootClassLoader classloader. */ private ForeheadClassLoader rootClassLoader; @@ -178,6 +178,7 @@ jellyScriptHousings = new HashMap(); loadedPlugins = new HashMap(); + plugins = new HashMap(); mapper = new GoalToJellyScriptHousingMapper(); @@ -203,95 +204,63 @@ } /** - * @todo Why is this method public? - * @return - */ - public GoalToJellyScriptHousingMapper getMapper() - { - return mapper; - } - - // ---------------------------------------------------------------------- - // P U B L I C A P I - // ---------------------------------------------------------------------- - - /** - * Initialize all plugins. - * - * @throws Exception If an error occurs while initializing any plugin. - * @todo why is this method public/ + * Expand the plugin jars if needed + * @throws MavenException */ - public void initialize() - throws Exception + private void expandPlugins() throws MavenException { - if ( initialized ) - { - return; - } - - setPluginsDir( new File( getMaven().getProperty( MavenConstants.MAVEN_HOME ), "plugins" ) ); - setUnpackedPluginsDir( new File( maven.getProperty( MavenConstants.MAVEN_UNPACKED_PLUGINS_DIR ) ) ); - 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 if // MAVEN_HOME_LOCAL / maven.home.local was set to a different directory // than MAVEN_HOME / maven.home. + Expand unzipper = new Expand(); for ( int i = 0; i < files.length; ++i ) { - // Only unpack the JAR if it hasn't been already, or is newer - // than the plugin directory - if ( files[i].getName().endsWith( ".jar" ) ) - { - String directory = files[i].getName(); - directory = directory.substring( 0, directory.indexOf( ".jar" ) ); - File unzipDir = new File( getUnpackedPluginsDir(), directory ); - - // if there's no directory, or the jar is newer, expand the jar - if ( unzipDir.exists() == false - || files[i].lastModified() > unzipDir.lastModified() ) - { - File processed = getPluginProcessedMarker( unzipDir.getName() ); - if ( processed.exists() ) - { - processed.delete(); - } - - try - { - Expand unzipper = new Expand(); - unzipper.setSrc( files[i] ); - unzipper.setDest( unzipDir ); - unzipper.execute(); - } - catch ( IOException e ) - { - throw new MavenException( "Unable to extract plugin: " + files[i], e ); - } - } - } + processPluginFile(unzipper, files[i]); } + } - // 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(); + /** + * Load all plugins in the unpacked plugins dir + * @throws Exception + */ + private void loadPlugins() throws Exception + { + File[] files = getUnpackedPluginsDir().listFiles(); // Process each of the directorties. - for ( int i = 0; i < files.length; ++i ) { if ( files[i].isDirectory() ) { - String directory = files[i].getName(); - loadPlugin( directory ); + String pluginId = files[i].getName(); + if ( !isLoaded( pluginId ) ) + { + loadPlugin( pluginId ); + } } } + } - initialized = true; - - log.info( "Finished initializing Plugins!" ); + private void processPluginFile(Expand unzipper, File pluginFile) + throws MavenException + { + // Only unpack the JAR if it hasn't been already, or is newer + // than the plugin directory + if ( pluginFile.getName().endsWith( ".jar" ) ) + { + // this is where JellyPlugins should be determined and created + JellyPlugin plugin = new JellyPlugin(); + plugin.setJarFile( pluginFile ); + String directory = pluginFile.getName(); + directory = directory.substring( 0, directory.indexOf( ".jar" ) ); + plugin.setId( directory ); + plugin.setUnpackDirectory( getUnpackedPluginsDir() ); + plugin.unpack(); + plugins.put(plugin.getId(), plugin); + } } /** @@ -305,42 +274,78 @@ throws Exception { System.err.println( "Loading plugin '" + name + "'" ); - if ( isLoaded( name ) ) + JellyPlugin plugin = (JellyPlugin)plugins.get(name); + if (plugin == null) { - return; + plugin = new JellyPlugin(); + plugin.setId(name); } - JellyPlugin plugin = new JellyPlugin(); - plugin.setId(name); - // FIXME Plugin should construct this... - plugin.setDirectory( getUnpackedPluginDir( plugin.getId() ) ); - Project pluginProject = getMaven().getProject( plugin.getDescriptor() , false ); + + plugin.setUnpackDirectory( getUnpackedPluginsDir() ); plugin.setParentClassLoader( mavenRootClassLoader ); + Project pluginProject = getMaven().getProject( plugin.getDescriptor() , false ); plugin.setProject( pluginProject ); - plugin.processDependencies(); - if ( !plugin.hasScript() ) + if ( plugin.hasScript() ) { - return; + JellyScriptHousing jellyScriptHousing = null; + try + { + // Create the PluginHousing + jellyScriptHousing = createJellyScriptHousing( plugin ); + } + catch ( Exception e ) + { + System.err.println( "Error loading plugin '" + name + "'" ); + throw e; + } + + // Store the plugin housing for future use. + jellyScriptHousings.put( name, jellyScriptHousing ); + mapper.parse( new FileReader( plugin.getScriptFile() ), jellyScriptHousing ); } + loadedPlugins.put(plugin.getId(), plugin); - JellyScriptHousing jellyScriptHousing = null; - try - { - // Create the PluginHousing - jellyScriptHousing = createJellyScriptHousing( plugin ); - } - catch ( Exception e ) + } + + /** + * @todo Why is this method public? + * @return + */ + public GoalToJellyScriptHousingMapper getMapper() + { + return mapper; + } + + // ---------------------------------------------------------------------- + // P U B L I C A P I + // ---------------------------------------------------------------------- + + /** + * Initialize all plugins. + * + * @throws Exception If an error occurs while initializing any plugin. + * @todo why is this method public? + */ + public void initialize() + throws Exception + { + if ( initialized ) { - System.err.println( "Error loading plugin '" + name + "'" ); - throw e; + return; } - // Store the plugin housing for future use. - jellyScriptHousings.put( name, jellyScriptHousing ); - loadedPlugins.put(plugin.getId(), plugin); + setPluginsDir( new File( getMaven().getProperty( MavenConstants.MAVEN_HOME ), "plugins" ) ); + setUnpackedPluginsDir( new File( maven.getProperty( MavenConstants.MAVEN_UNPACKED_PLUGINS_DIR ) ) ); + + expandPlugins(); + + loadPlugins(); + + initialized = true; - mapper.parse( new FileReader( plugin.getScriptFile() ), jellyScriptHousing ); + log.info( "Finished initializing Plugins!" ); } /** @@ -353,37 +358,21 @@ public void attainGoals( Project project, List goals ) throws GoalException, Exception { - File sourceDirectory = new File( project.getBuild().getSourceDirectory() ); - if ( sourceDirectory.exists() ) - { - project.setProjectProperty( "sourcesPresent", "true" ); - project.addCompileSourceRoot( project.getBuild().getSourceDirectory() ); - } - - File unitTestSourceDirectory = new File( project.getBuild().getUnitTestSourceDirectory() ); - if ( unitTestSourceDirectory.exists() ) - { - project.setProjectProperty( "unitTestSourcesPresent", "true" ); - project.addTestCompileSourceRoot( project.getBuild().getUnitTestSourceDirectory() ); - } - MavenJellyContext baseContext = createBaseContext( project ); // Before attempting to attain the goals verify the project // if desired. + // FIXME: From attainGoals angle, how does it know the project needs to + // to be verified, or that the project object has project.verifyDependencies(); // Set up the ant project. - build( project, baseContext ); - Path p = new Path( baseContext.getAntProject() ); + GrantProject antProject = buildAntProject( project, baseContext ); + Path p = new Path( antProject ); p.setPath( project.getDependencyClasspath() ); - baseContext.getAntProject().addReference( MavenConstants.DEPENDENCY_CLASSPATH, p ); + antProject.addReference( MavenConstants.DEPENDENCY_CLASSPATH, p ); - // Create the Jelly session - Session session = new JellySession( getJellyOutputSink() ); - session.setAttribute( XML_OUTPUT, getJellyOutputSink() ); - session.setAttribute( PLUGIN_MANAGER, this ); - session.setAttribute( BASE_CONTEXT, baseContext ); + Session session = getJellySession(baseContext); // add the global session to the pluginContext so that it can be used by tags baseContext.setVariable( GLOBAL_SESSION_KEY, session ); @@ -402,7 +391,7 @@ // // We run the Jelly scripts in the following order: // - // 1) driver.jelly + // 1) driver.jelly - doesn't exist anymore // 2) project's maven.xml // 3) parent's maven.xml (if it exists) // 4) plugin.jelly @@ -416,11 +405,11 @@ // ------------------------------------------------------------------------------------------------------------- // driver.jelly - InputStream driver = PluginManager.class.getClassLoader().getResourceAsStream( "driver.jelly" ); - JellyScriptHousing driverHousing = createJellyScriptHousing( project, null, driver ); - driverHousing.setSource( "driver.jelly" ); + //InputStream driver = PluginManager.class.getClassLoader().getResourceAsStream( "driver.jelly" ); + //JellyScriptHousing driverHousing = createJellyScriptHousing( project, null, driver ); + //driverHousing.setSource( "driver.jelly" ); //mapper.parse( new InputStreamReader( driver ), driverHousing ); - runJellyScriptHousing( driverHousing, baseContext ); + //runJellyScriptHousing( driverHousing, baseContext ); // Project's Jelly script if ( project.getFile() != null ) @@ -492,6 +481,23 @@ } } + /** + * Get the Werkz Session + * FIXME: Describe what it's for? + * @param baseContext the maven context the session should use + * @return A Werkz Session + * @throws Exception FIXME For anything + */ + private Session getJellySession(MavenJellyContext baseContext) throws Exception + { + // Create the Jelly session + Session session = new JellySession( getJellyOutputSink() ); + session.setAttribute( XML_OUTPUT, getJellyOutputSink() ); + session.setAttribute( PLUGIN_MANAGER, this ); + session.setAttribute( BASE_CONTEXT, baseContext ); + return session; + } + private void runJellyScriptHousing( JellyScriptHousing jellyScriptHousing, MavenJellyContext context ) throws Exception { @@ -578,7 +584,7 @@ return baseContext; } - + /** XML output goes to System.out*/ private XMLOutput output; private XMLOutput getJellyOutputSink() @@ -596,7 +602,15 @@ return output; } - public GrantProject build( Project project, MavenJellyContext context ) + /** + * FIXME: Not sure why building an Ant project is the plugin manager's responisbility + * + * @param project a maven project + * @param context a maven context + * @return an Ant project + * @throws Exception When any error occurs. FIXME this is bad. + */ + public GrantProject buildAntProject( Project project, MavenJellyContext context ) throws Exception { // Create the build listener. @@ -844,19 +858,6 @@ File getUnpackedPluginDir( String pluginName ) { return new File( getUnpackedPluginsDir(), pluginName ); - } - - /** - * Retrieve the plugin's entry-point jelly script. - * - * @param pluginName The name of the plugin. - * - * @return The entry-point script for the plugin, or <code>null</code> if - * no such plugin. - */ - File getPluginScript( String pluginName ) - { - return new File( getUnpackedPluginDir( pluginName ), PLUGIN_SCRIPT_NAME ); } /** 1.28 +2 -2 maven/src/java/org/apache/maven/verifier/DependencyVerifier.java Index: DependencyVerifier.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/verifier/DependencyVerifier.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- DependencyVerifier.java 28 Jul 2003 05:11:29 -0000 1.27 +++ DependencyVerifier.java 4 Aug 2003 01:11:13 -0000 1.28 @@ -185,7 +185,7 @@ { failedDependencies.add( artifact ); } - else if ( online == false && artifact.isSnapshot() ) + else if ( !online && artifact.isSnapshot() ) { System.out.println( getMessage( "offline.snapshot.warning", artifact.getName() ) ); } 1.16 +34 -2 maven/src/java/org/apache/maven/Maven.java Index: Maven.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/Maven.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- Maven.java 29 Jul 2003 00:12:52 -0000 1.15 +++ Maven.java 4 Aug 2003 01:11:13 -0000 1.16 @@ -249,10 +249,40 @@ project.getName() ) ); } } + Project mavenProject = mavenUtils.getProject(project, this); + setPomProperties( mavenProject ); + getPluginManager().attainGoals( mavenProject, goalNames ); + } + + /** + * Set any properties necessary based on the pom for convenience + */ + private void setPomProperties(Project project) + { + File sourceDirectory = new File( project.getBuild().getSourceDirectory() ); + if ( sourceDirectory.exists() ) + { + project.setProjectProperty( "sourcesPresent", "true" ); + project.addCompileSourceRoot( project.getBuild().getSourceDirectory() ); + } + + File unitTestSourceDirectory = new File( project.getBuild().getUnitTestSourceDirectory() ); + if ( unitTestSourceDirectory.exists() ) + { + project.setProjectProperty( "unitTestSourcesPresent", "true" ); + project.addTestCompileSourceRoot( project.getBuild().getUnitTestSourceDirectory() ); + } - getPluginManager().attainGoals( mavenUtils.getProject( project, this ), goalNames ); } + + /** + * + * @param project + * @param goalNamesList + * @throws GoalException + * @throws Exception + */ public void attainGoals( File project, String goalNamesList ) throws GoalException, Exception { @@ -262,6 +292,7 @@ public void attainGoals( Project project, String goalNamesList ) throws GoalException, Exception { + setPomProperties( project ); getPluginManager().attainGoals( project, list( goalNamesList ) ); } @@ -283,6 +314,7 @@ public void attainGoals( Project project, List goalNames ) throws GoalException, Exception { + setPomProperties( project ); getPluginManager().attainGoals( project, goalNames ); } 1.13 +1 -2 maven/src/java/org/apache/maven/ArtifactListBuilder.java Index: ArtifactListBuilder.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/ArtifactListBuilder.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ArtifactListBuilder.java 29 Jul 2003 00:09:08 -0000 1.12 +++ ArtifactListBuilder.java 4 Aug 2003 01:11:13 -0000 1.13 @@ -120,7 +120,6 @@ { artifact.setPath( project.getMavenRepoLocal() + artifact.generatePath() ); } - projectArtifacts.add( artifact ); } 1.86 +33 -3 maven/src/java/org/apache/maven/project/Project.java Index: Project.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Project.java,v retrieving revision 1.85 retrieving revision 1.86 diff -u -r1.85 -r1.86 --- Project.java 29 Jul 2003 00:08:32 -0000 1.85 +++ Project.java 4 Aug 2003 01:11:13 -0000 1.86 @@ -1230,7 +1230,7 @@ } buildArtifactList(); - buildDependencyClasspath(); + getDependencyClasspath(); setDependencyVerifier( new DependencyVerifier( this ) ); getDependencyVerifier().setIgnoreErrors( false ); @@ -1294,10 +1294,41 @@ */ public String getDependencyClasspath() { + if (dependencyClasspath == null) + { + StringBuffer classpath = new StringBuffer(); + + for ( Iterator i = getArtifacts().iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + Dependency d = artifact.getDependency(); + + // Only add appropriate dependencies to the classpath + if ( isClasspathDependency(d) ) + { + classpath.append( artifact.getPath() ).append( PS ); + } + setDependencyPath( d.getId(), artifact.getPath() ); + } + + dependencyClasspath = classpath.toString(); + + } return dependencyClasspath; } /** + * Currently this is just jars. + * + * @param d + * @return true if the given dependency belongs on the classpath + */ + private boolean isClasspathDependency(Dependency d) + { + return d.getType().equals( "jar" ); + } + + /** * Build the dependency classpath. * * @throws Exception If an error occurs while building the dependency classpath. @@ -1319,7 +1350,6 @@ } classpath.append( artifact.getPath() ).append( PS ); - setDependencyPath( d.getId(), artifact.getPath() ); } setDependencyClasspath( classpath.toString() );
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]