dion 2003/08/18 21:29:25 Modified: src/java/org/apache/maven/project Branch.java Project.java Dependency.java Repository.java License.java Build.java BaseObject.java Resource.java Added: src/java/org/apache/maven/project ArtifactType.java Log: Switch stable branch back to HEAD Revision Changes Path 1.4 +0 -0 maven/src/java/org/apache/maven/project/Branch.java Index: Branch.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Branch.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 1.88 +274 -395 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.87 retrieving revision 1.88 diff -u -r1.87 -r1.88 --- Project.java 4 Aug 2003 06:27:56 -0000 1.87 +++ Project.java 19 Aug 2003 04:29:25 -0000 1.88 @@ -56,18 +56,33 @@ * ==================================================================== */ -import org.apache.maven.ArtifactListBuilder; -import org.apache.maven.Maven; import org.apache.maven.MavenConstants; -import org.apache.maven.jelly.MavenJellyContext; +import org.apache.maven.MavenUtils; +import org.apache.maven.DependencyClasspathBuilder; +import org.apache.maven.ArtifactListBuilder; +import org.apache.maven.AntProjectBuilder; +import org.apache.maven.plugin.PluginManager; import org.apache.maven.repository.Artifact; -import org.apache.maven.verifier.ChecksumVerificationException; -import org.apache.maven.verifier.DependencyVerifier; import org.apache.maven.verifier.RepoConfigException; import org.apache.maven.verifier.UnsatisfiedDependencyException; -import org.apache.plexus.util.StringUtils; +import org.apache.maven.verifier.DependencyVerifier; +import org.apache.maven.verifier.ChecksumVerificationException; +import org.apache.maven.jelly.MavenJellyContext; +import org.apache.maven.jelly.JellyUtils; +import org.apache.tools.ant.types.Path; +import org.apache.commons.grant.GrantProject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.dom4j.Document; +import org.dom4j.io.SAXReader; + +import com.werken.forehead.Forehead; +import com.werken.forehead.ForeheadClassLoader; import java.io.File; +import java.io.InputStreamReader; +import java.io.InputStream; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -75,6 +90,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.StringTokenizer; /** * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> @@ -205,6 +221,9 @@ */ private List reports; + /** This project's Jelly context. */ + private MavenJellyContext context; + /** * A list of the plugin context for the plugins that have been loaded for this project. * This allows inter plugin communication. Needs some fleshing out. @@ -216,40 +235,9 @@ /** ArtifactId. */ private String artifactId; - - /** - * Properties that consist of the contents of the standard Maven properties files - * and System properties. - */ - private Map projectProperties; - - private Project parent; - - /** The maven session this project is running in. */ - private Maven maven; - /** the maven.xml file for this project */ - private File mavenXml; - - public Project getParent() - { - return parent; - } - - public void setParent( Project parent ) - { - this.parent = parent; - } - - public Maven getMaven() - { - return maven; - } - - public void setMaven( Maven maven ) - { - this.maven = maven; - } + /** log for debug and output */ + private static final Log log = LogFactory.getLog(Project.class); /** * Default constructor. @@ -265,6 +253,7 @@ branches = new ArrayList(); dependencyPaths = new HashMap(); dependencyMap = new HashMap(); + goalNames = new ArrayList(); reports = new ArrayList(); packageGroups = new ArrayList(); } @@ -382,6 +371,26 @@ } /** + * Set the context attribute. + * + * @param context + */ + public void setContext( MavenJellyContext context ) + { + this.context = context; + } + + /** + * Get the context attribute. + * + * @return The + */ + public MavenJellyContext getContext() + { + return context; + } + + /** * Set the attribute. * * @param artifactList @@ -448,7 +457,7 @@ */ public boolean hasParent() { - return getParent() != null; + return isValid( getExtend() ); } /** @@ -472,26 +481,6 @@ } /** - * @return the maven.xml file - */ - public File getMavenXml() - { - if (mavenXml == null) - { - mavenXml = new File( getFile().getParentFile(), MavenConstants.BUILD_FILE_NAME ); - } - return mavenXml; - } - - /** - * @return true if the maven.xml file for the project exists - */ - public boolean hasMavenXml() - { - return getMavenXml().exists(); - } - - /** * Set the gump repository descriptor. * * @param gumpRepositoryId Gump repository id. @@ -1141,6 +1130,36 @@ } /** + * Add a branch to this project. + * + * @param branch Branch for this project. + */ + public void addBranch( Branch branch ) + { + branches.add( branch ); + } + + /** + * Set the branches for this project. + * + * @param branches List of branches for this project. + */ + public void setBranches( List branches ) + { + this.branches = branches; + } + + /** + * Return the branches for this project. + * + * @return List of branches. + */ + public List getBranches() + { + return branches; + } + + /** * Return a distribution for this project. * * @param versionId the id of the version to return @@ -1217,8 +1236,25 @@ packageGroups.add( packageGroup ); } + /** + * Create a dom4j document from the POM. Used for dvsl processing right now. + * Hopefully we can make this more general so that people + * can use the POM in XSLT transformations. This is not + * working for some reason, I believe due to encoding problems. + * This might be working now but I will test it later. + * + * @return Document Dom4j document. + * @throws Exception If an error occurs while creating the dom4j document. + */ + public Document createDocument() + throws Exception + { + SAXReader reader = new SAXReader(); + return reader.read( new InputStreamReader( MavenUtils.getProjectInputStream( this ) ) ); + } + // ---------------------------------------------------------------------- - // Properties that have been created + // // ---------------------------------------------------------------------- /** Flag to indicate the project has been verified. */ @@ -1230,6 +1266,11 @@ /** Dependency classpath used for compilation. */ private String dependencyClasspath; + /** Goal names the project has been asked to satisfy. */ + private List goalNames; + + private GrantProject grantProject; + /** * Initialize the project. This consists of the following stages. * @@ -1242,6 +1283,8 @@ * * 4) Create the dependency verifier. * + * 5) Initialize the driver for this project. + * * @throws Exception If an error occurs during project initialization. */ public void initialize() @@ -1252,15 +1295,76 @@ return; } + setAntProject( AntProjectBuilder.build( this ) ); + getContext().setAntProject( getAntProject() ); buildArtifactList(); - getDependencyClasspath(); + buildDependencyClasspath(); setDependencyVerifier( new DependencyVerifier( this ) ); - getDependencyVerifier().setIgnoreErrors( false ); - + getDependencyVerifier().setIgnoreErrors(false); + initializeDriver(); + if ( build != null ) + { + build.resolveDirectories( file.getParentFile() ); + } initialized = true; } /** + * Set the grantProject attribute. + * + * @param grantProject + */ + public void setAntProject( GrantProject grantProject ) + { + this.grantProject = grantProject; + } + + /** + * Get the grantProject attribute. + * + * @return The + */ + public GrantProject getAntProject() + { + return grantProject; + } + + /** + * Return an InputStream found in the classpath. Used + * specifically to find resources stored in the maven.jar + * + * @param name Name of the resource to find. + * @return InputStream Found the found resource. + * @throws Exception If an error occurs while trying to retreive the + * named resource. + */ + private InputStream getResourceAsStream( String name ) + throws Exception + { + return Project.class.getClassLoader().getResourceAsStream( name ); + } + + /** + * Initialise the jelly script that drives the build + * + * @throws Exception when any error occurs + */ + private void initializeDriver() + throws Exception + { + // this is working correctly and the driver can be initialized + // for a project then we can go way and initialize other projects + // come back in the reactor and the values set are still correct. + + InputStream driverInputStream = getResourceAsStream( "driver.jelly" ); + + JellyUtils.runScript( driverInputStream, + null, + getContext(), + getContext().getXMLOutput() ); + } + + /** * Verify the dependencies for this project. * * @throws RepoConfigException If an error occurs checking the local settings. @@ -1317,41 +1421,10 @@ */ 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. @@ -1359,23 +1432,10 @@ public void buildDependencyClasspath() throws Exception { - StringBuffer classpath = new StringBuffer(); - - for ( Iterator i = getArtifacts().iterator(); i.hasNext(); ) - { - Artifact artifact = (Artifact) i.next(); - Dependency d = artifact.getDependency(); - - // Only add jar dependencies to the classpath - if ( d.getType().equals( "jar" ) == false ) - { - continue; - } - - classpath.append( artifact.getPath() ).append( PS ); - } - - setDependencyClasspath( classpath.toString() ); + setDependencyClasspath( DependencyClasspathBuilder.build( this ) ); + Path p = new Path( getContext().getAntProject() ); + p.setPath( getDependencyClasspath() ); + getContext().getAntProject().addReference( MavenConstants.DEPENDENCY_CLASSPATH, p ); } /** @@ -1386,73 +1446,65 @@ artifactList = ArtifactListBuilder.build( this ); } - // ---------------------------------------------------------------------- - // Test and compile sourceroots. - // ---------------------------------------------------------------------- - - private static String PS = System.getProperty( "path.separator" ); - - private String compileSourceRoots = ""; - - private String testCompileSourceRoots = ""; - - public void addCompileSourceRoot( String path ) + /** + * Get the goal names that must be satisfied. + * + * @return The goal names to be satisfied. + */ + public List getGoalNames() { - compileSourceRoots += PS + path; + return goalNames; } /** - * Get sourceroots. + * Set the goal names to be satisfied. * - * @return location of Maven local home installation. + * @param goals Goals to be satisfied. */ - public String getCompileSourceRoots() + public void setGoalNames( List goals ) { - return compileSourceRoots; + getGoalNames().addAll( goals ); } - public List getCompileSourceRootsList() + /** + * Set goals as a CSV list. + * + * @param goalsCsv List of goals in CSV form. + */ + public void setGoalNames( String goalsCsv ) { - String[] s = StringUtils.split( getCompileSourceRoots(), PS ); - - List list = new ArrayList(); - - for ( int i = 0; i < s.length; i++ ) + if ( goalNames != null ) { - list.add( s[i] ); - } + StringTokenizer tokens = new StringTokenizer( goalsCsv, "," ); - return list; + while ( tokens.hasMoreTokens() ) + { + goalNames.add( tokens.nextToken().trim() ); + } + } } - - public void addTestCompileSourceRoot( String path ) + + /** + * Remove all project goals. + */ + public void removeGoalNames() { - testCompileSourceRoots += PS + path; + if ( goalNames != null ) + { + goalNames.clear(); + } } - /** - * Get sourceroots. + * Load a Jelly script for this project. * - * @return location of Maven local home installation. + * @param jellyScript Jelly script to run for this project's use. + * @throws Exception If an error occurs while running Jelly script. */ - public String getTestCompileSourceRoots() - { - return testCompileSourceRoots; - } - - public List getTestCompileSourceRootsList() + public void loadJellyScript( File jellyScript ) + throws Exception { - String[] s = StringUtils.split( getTestCompileSourceRoots(), PS ); - - List list = new ArrayList(); - - for ( int i = 0; i < s.length; i++ ) - { - list.add( s[i] ); - } - - return list; + getContext().getMavenSession().loadJellyScript( jellyScript, this ); } // ---------------------------------------------------------------------- @@ -1519,249 +1571,76 @@ return id; } - // ---------------------------------------------------------------------- - // Convenience properties accessors - // ---------------------------------------------------------------------- - - public String getProjectProperty( String key ) - { - String p; - - p = (String) getProjectProperties().get( key ); - - if ( p != null ) - { - return p; - } - - // These are properties in the XML document that look like this: - // - // <properties> - // <key>value</key> - // </properties> - // - p = (String) getProperties().get( key ); - - if ( p != null ) - { - return p; - } - - if ( hasParent() ) - { - return getParent().getProjectProperty( key ); - } - - return p; - } - /** - * Convert a <code>String</code> property to a - * <code>Boolean</code> based on its contents. It would be nice - * if Jelly would deal with this automatically. - * - * @param key The property key to lookup and convert. - * - * @return The boolean value of the property if convertiable, - * otherwise <code>Boolean.FALSE</code>. + * Process the dependencies of the project, adding dependencies to the + * appropriate classloader etc + * + * @throws MalformedURLException */ - public boolean getBoolean( String key ) + public void processDependencies() throws MalformedURLException, Exception { - String value = getProjectProperty( key ); - - if ( "true".equalsIgnoreCase( value ) - || "on".equalsIgnoreCase( value ) - || "1".equals( value ) ) + if (getArtifacts() == null) { - return true; + log.debug("No dependencies to process for project " + getName()); + return; } - - return false; - } - - public Map getProjectProperties() - { - return projectProperties; - } - - public void setProjectProperties( Map projectProperties ) - { - this.projectProperties = projectProperties; - } - - public void setProjectProperty( String key, Object value ) - { - getProjectProperties().put( key, value ); - } - - /** - * Add a remote repository to the list of remote repositories. - * - * @param mavenRemoteRepo Remote repository to add. - */ - public void addMavenRemoteRepo( String mavenRemoteRepo ) - { - ( (List) getProjectProperties().get( MavenConstants.REPO_REMOTE ) ).add( mavenRemoteRepo ); - } - - /** - * Set the mavenRepoRemote attribute. - * - * @param mavenRepoRemote List of remove repositories. - */ - public void setMavenRepoRemotes( List mavenRepoRemote ) - { - setProjectProperty( MavenConstants.REPO_REMOTE, mavenRepoRemote ); - } - - /** - * Get the mavenRepoRemote attribute. - * - * @return The list of remote repositories. - */ - public List getMavenRepoRemote() - { - // We might have CSV list of remote repositories. - return convertCsvStringToList( getProjectProperty( MavenConstants.REPO_REMOTE ) ); - } - - /** - * Convert a CSV list of values into a List - * - * @param csvString CVS list of values. - * @return The List of value. - */ - private List convertCsvStringToList( String csvString ) - { - ArrayList list = new ArrayList(); - String[] s = StringUtils.split( csvString, "," ); - - for ( int i = 0; i < s.length; i++ ) + + // This may definitely break plugins. + ClassLoader projectClassLoader = getContext().getClassLoader(); + + if ( projectClassLoader instanceof ForeheadClassLoader ) { - list.add( s[i] ); - } - - return list; - } - - /** - * Set the location of the local maven repository. - * - * @param mavenRepoLocal The local repository. - */ - public void setMavenRepoLocal( String mavenRepoLocal ) - { - setProjectProperty( MavenConstants.REPO_LOCAL, mavenRepoLocal ); - } - - /** - * Get the location of the local maven repository. - * - * @return The local repository. - */ - public String getMavenRepoLocal() - { - return getProjectProperty( MavenConstants.REPO_LOCAL ); - } - - - /** - * Set flag indicating if the remote repository is enabled for use. - * - * @param remoteRepositoryEnabled Remote repository usage flag. - */ - public void setRemoteRepositoryEnabled( Boolean remoteRepositoryEnabled ) - { - setProjectProperty( MavenConstants.REPO_REMOTE_ENABLED, remoteRepositoryEnabled ); - } - - /** - * Set flag indicating if the remote repository is enabled for use. - * - * @return Remote repository usage flag. - */ - public boolean getRemoteRepositoryEnabled() - { - return getBoolean( MavenConstants.REPO_REMOTE_ENABLED ); - } - - /** - * Set the flag indicating the use of the JAR overriding facility. - * - * @param mavenJarOverride MavenSession jar override flag. - */ - public void setMavenJarOverride( Boolean mavenJarOverride ) - { - setProjectProperty( MavenConstants.JAR_OVERRIDE, mavenJarOverride ); - } - - /** - * Get the flag indicating the use of the JAR overriding facility. - * - * @return MavenSession jar override flag. - */ - public boolean getMavenJarOverride() - { - return getBoolean( MavenConstants.JAR_OVERRIDE ); - } - - /** - * Get the maven jar override value for a particular dependency. - * - * @param id Id of the project to override. - * @return MavenSession jar override value for a particular dependency. - */ - public String getMavenJarOverride( String id ) - { - return getProjectProperty( MavenConstants.JAR_OVERRIDE_PROPERTY + id ); - } - - /** - * Get MavenSession home. - * - * @return MavenSession home. - */ - public String getMavenHome() - { - return getProjectProperty( MavenConstants.MAVEN_HOME ); - } - - /** - * Get local maven home. - * - * @return location of Maven local home installation. - */ - public String getMavenHomeLocal() - { - return getProjectProperty( MavenConstants.MAVEN_HOME_LOCAL ); - } - - /** - * Get unpacked plugins location. - * - * @return unpacked plugins location. - */ - public String getUnpackedPluginsDir() - { - return getProjectProperty( MavenConstants.MAVEN_UNPACKED_PLUGINS_DIR ); - } + // add the dependencies to the classpath + for ( Iterator i = getArtifacts().iterator(); i.hasNext(); ) + { + ForeheadClassLoader loader = (ForeheadClassLoader)projectClassLoader; + Artifact artifact = (Artifact) i.next(); + Dependency dependency = artifact.getDependency(); + if (dependency.isPlugin()) + { + // dependencies should already be downloaded + // get the plugin manager to install it + PluginManager pluginManager = getContext().getMavenSession().getPluginManager(); + pluginManager.installPlugin(this, artifact.getFile()); + } - /** - * @return the list of branches for a project - */ - public List getBranches() - { + // get correct classloader + String classLoader = artifact.getDependency().getProperty( "classloader" ); + if (classLoader != null) + { + loader = Forehead.getInstance().getClassLoader( classLoader ); + if (loader == null) + { + log.info("classloader '" + classLoader + + "' not found. Adding dependencies to the project classloader instead"); + loader = (ForeheadClassLoader)projectClassLoader; + } + } + + // add to classloader + if (artifact.exists()) + { + if (dependency.isAddedToClasspath()) + { + loader.addURL( artifact.getFile().toURL() ); + } + else + { + log.debug("Non classpath dependency: '" + artifact.getFile() + "'" + + " not added to classpath " + loader); + } + } + else + { + log.info("Artifact '" + artifact.getFile() + "' not found to add to classpath"); + } + } + } - return branches; - } - - /** - * Add a branch to the project - * @param b a Branch - */ - public void addBranch(Branch b) - { - branches.add(b); + // FIXME: Don't know why we're doing this? + // Explicity set the classloader used to find resources. As we just + // poked all the dependencies into the classloader. + getContext().setClassLoader( projectClassLoader ); } } 1.37 +47 -10 maven/src/java/org/apache/maven/project/Dependency.java Index: Dependency.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Dependency.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- Dependency.java 28 Jul 2003 05:00:03 -0000 1.36 +++ Dependency.java 19 Aug 2003 04:29:25 -0000 1.37 @@ -80,7 +80,7 @@ private String groupId; /** The dependency type */ - private String type; + private ArtifactType type; /** Flag to indicate the artifact is poorly named. */ //private boolean isPoorlyNamed = false; @@ -223,7 +223,7 @@ return jar; } - return getArtifactId() + "-" + getVersion() + "." + getType(); + return getArtifactId() + "-" + getVersion() + "." + getExtension(); } /** @@ -298,15 +298,33 @@ /** - * Set the type of the dependency. - * - * @return dependency type such as "jar" or "war" + * @return dependency type such as "jar", "war", etc. */ public String getType() { - return type; - } - + String result = null; + + if (this.type != null) + { + result = this.type.getType(); + } + return result; + } + + /** + * @return dependency extension such as "jar", "war", etc. + */ + public String getExtension() + { + String result = null; + + if (this.type != null) + { + result = this.type.getExtension(); + } + return result; + } + /** * Sets the dependency type such as "jar" or "war" * @@ -314,7 +332,7 @@ */ public void setType( String type ) { - this.type = type; + this.type = ArtifactType.findType(type); } /** @@ -327,5 +345,24 @@ return "Dep[ id:" + getId() + " pid:" + getId() + " ver:" + getVersion() + " ar:" + getArtifact() + " jar:" + getJar() + " ]"; + } + + /** + * Usually only jars and ejbs are added to the classpath + * + * @return true if the given dependency belongs on the classpath + */ + public boolean isAddedToClasspath() + { + String artifactType = type.getType(); + return artifactType.equals("jar") || artifactType.equalsIgnoreCase("ejb"); + } + + /** + * @return true if the dependency is a maven plugin + */ + public boolean isPlugin() + { + return type.getType().equals("plugin"); } } 1.15 +1 -1 maven/src/java/org/apache/maven/project/Repository.java Index: Repository.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Repository.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 1.4 +1 -1 maven/src/java/org/apache/maven/project/License.java Index: License.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/License.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 1.23 +51 -1 maven/src/java/org/apache/maven/project/Build.java Index: Build.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Build.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- Build.java 27 Jul 2003 23:33:59 -0000 1.22 +++ Build.java 19 Aug 2003 04:29:25 -0000 1.23 @@ -56,8 +56,13 @@ * ==================================================================== */ +import org.apache.maven.MavenUtils; + import java.util.ArrayList; import java.util.List; +import java.util.Iterator; +import java.io.File; +import java.io.IOException; /** * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> @@ -297,5 +302,50 @@ { return "[ sourceDirectory = " + getSourceDirectory() + ", unitTestSourceDirectory = " + getUnitTestSourceDirectory() + " ]"; + } + + /** + * Resolve relative directories against a base directory. + * @param basedir the base directory + * @todo *sourceDirectory + * @throws IOException file resolution error + */ + public void resolveDirectories( File basedir ) throws IOException + { + for ( Iterator i = resources.iterator(); i.hasNext(); ) + { + Resource r = ( Resource ) i.next(); + r.resolveDirectory( basedir ); + } + + if ( unitTest != null ) + { + for ( Iterator i = unitTest.getResources().iterator(); i.hasNext(); ) + { + Resource r = ( Resource ) i.next(); + r.resolveDirectory( basedir ); + } + } + + if ( sourceDirectory != null && sourceDirectory.length() > 0 ) + { + sourceDirectory = MavenUtils.makeAbsolutePath( basedir, sourceDirectory ); + } + + if ( aspectSourceDirectory != null && aspectSourceDirectory.length() > 0 ) + { + aspectSourceDirectory = MavenUtils.makeAbsolutePath( basedir, aspectSourceDirectory ); + } + + if ( unitTestSourceDirectory != null && unitTestSourceDirectory.length() > 0 ) + { + unitTestSourceDirectory = MavenUtils.makeAbsolutePath( basedir, unitTestSourceDirectory ); + } + + if ( integrationUnitTestSourceDirectory != null && integrationUnitTestSourceDirectory.length() > 0 ) + { + integrationUnitTestSourceDirectory = + MavenUtils.makeAbsolutePath( basedir, integrationUnitTestSourceDirectory ); + } } } 1.26 +83 -15 maven/src/java/org/apache/maven/project/BaseObject.java Index: BaseObject.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/BaseObject.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- BaseObject.java 28 Jul 2003 04:56:43 -0000 1.25 +++ BaseObject.java 19 Aug 2003 04:29:25 -0000 1.26 @@ -56,7 +56,12 @@ * ==================================================================== */ +import org.apache.commons.lang.StringUtils; + +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -88,6 +93,11 @@ private Map properties; /** + * properties that are in the format name:value + */ + private List combinedProperties = new ArrayList(); + + /** * Sets the name attribute * * @param name the new name value @@ -133,44 +143,102 @@ } /** + * Add a meta property to this object. * - * @param key - * @param value + * @param combinedProperty The property that is fed in by + * the MetaPropertiesRule is in the form name:value + * so that we can fake out betwixt. Not beautiful + * but it works and when we find a better solution + * nothing will change for users. */ - public void addProperty( String key, Object value ) + public void addProperty( String combinedProperty ) { - getProperties().put( key, value ); + combinedProperties.add( combinedProperty ); } - public String getProperty( String key ) + /** + * Get a meta property. The first time one is retrieved we + * create a property Map from the name:value entries in the + * list we have used to store the meta properties during + * mapping through betwixt. + * + * @param propertyName the name of the property to retrieve + * @return the property value + */ + public String getProperty( String propertyName ) { - return (String) getProperties().get( key ); + if ( properties == null ) + { + resolveProperties(); + } + + return (String) properties.get( propertyName ); } /** + * Set meta properties. They are stored in a [EMAIL PROTECTED] List} of + * name:value entries. * - * @param properties + * @param combinedProperties a list of name:value strings */ - public void setProperties( Map properties ) + public void setProperties( List combinedProperties ) { - this.properties = properties; + this.combinedProperties = combinedProperties; } /** + * Get meta properties. * - * @return + * @return a [EMAIL PROTECTED] List} of name:value entries */ - public Map getProperties() + public List getProperties() + { + return combinedProperties; + } + + /** + * Get the resolved properties after the name:value + * processing has been done. + * + * @return a map from the [EMAIL PROTECTED] #getProperties() meta properties} turning + * the name:value strings into a key and value for the map + */ + public Map resolvedProperties() { if ( properties == null ) { - properties = new HashMap(); + resolveProperties(); } return properties; } /** + * Resolve the name:value list into a real Map. + */ + private void resolveProperties() + { + properties = new HashMap(); + + for ( Iterator i = combinedProperties.iterator(); i.hasNext(); ) + { + String combinedProperty = (String) i.next(); + String[] s = StringUtils.split( combinedProperty, ":" ); + + if ( s.length == 3 ) + { + // Property is specific and has a value. + properties.put( s[1], s[2] ); + } + else + { + // Property is specific but has no value. + properties.put( s[1], "" ); + } + } + } + + /** * Return a string suitable for display/debugging * * @return the name attribute as a default @@ -237,8 +305,8 @@ */ protected boolean isValid( String value ) { - if ( value != null - && value.trim().equals( "" ) == false ) + if ( value != null + && value.trim().equals("") == false ) { return true; } 1.11 +17 -1 maven/src/java/org/apache/maven/project/Resource.java Index: Resource.java =================================================================== RCS file: /home/cvs/maven/src/java/org/apache/maven/project/Resource.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Resource.java 27 Jul 2003 23:33:59 -0000 1.10 +++ Resource.java 19 Aug 2003 04:29:25 -0000 1.11 @@ -56,8 +56,12 @@ * ==================================================================== */ +import org.apache.maven.MavenUtils; + import java.util.ArrayList; import java.util.List; +import java.io.File; +import java.io.IOException; /** * Represents a set of files in a single directory. @@ -170,7 +174,7 @@ } /** - * @param filtering specifies whether filtering is active or not + * @param isFiltering specifies whether filtering is active or not */ public void setFiltering( boolean isFiltering ) { @@ -184,4 +188,16 @@ { return this.isFiltering; } + + /** + * Resolve directory against a base directory if it is not already absolute. + * @todo proper project marshaller should construct as such + * @param basedir the base directory for relative paths + * @throws IOException if canonical path fails + */ + public void resolveDirectory( File basedir ) throws IOException + { + dir = MavenUtils.makeAbsolutePath( basedir, dir ); + } + } 1.3 +11 -2 maven/src/java/org/apache/maven/project/ArtifactType.java
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]