From baf09a414887fbd3ee73c58827f1128a57531d29 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Wed, 29 Apr 2009 17:00:17 +0000 Subject: [PATCH] Cleanup of interpolator, removing references to PomClassicDomainModel, these aren't needed anymore. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769827 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/DefaultMavenProjectBuilder.java | 3 +- .../interpolator/DefaultInterpolator.java | 132 ++++---- .../model/interpolator/Interpolator.java | 5 +- .../interpolator/PomInterpolatorTag.java | 4 - .../projects/enforcer/enforcer-api/pom.xml | 90 ------ .../projects/enforcer/enforcer-rules/pom.xml | 120 -------- .../enforcer/maven-enforcer-plugin/pom.xml | 166 ----------- .../src/test/projects/enforcer/pom.xml | 281 ------------------ .../src/test/resources/test.txt | 1 - 9 files changed, 70 insertions(+), 732 deletions(-) delete mode 100644 maven-model-builder/src/test/projects/enforcer/enforcer-api/pom.xml delete mode 100644 maven-model-builder/src/test/projects/enforcer/enforcer-rules/pom.xml delete mode 100644 maven-model-builder/src/test/projects/enforcer/maven-enforcer-plugin/pom.xml delete mode 100644 maven-model-builder/src/test/projects/enforcer/pom.xml delete mode 100644 maven-model-builder/src/test/resources/test.txt diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index b70133b866..b7c51636b7 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -417,7 +417,7 @@ public class DefaultMavenProjectBuilder } try { - model = interpolator.interpolateDomainModel( domainModel, props ).getModel(); + model = interpolator.interpolateModel( model, props, domainModel.getProjectDirectory() ); } catch ( IOException e ) { @@ -465,7 +465,6 @@ public class DefaultMavenProjectBuilder List interpolatorProperties = new ArrayList(); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( projectBuilderConfiguration.getExecutionProperties(), PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) ); - interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( projectBuilderConfiguration.getUserProperties(), PomInterpolatorTag.USER_PROPERTIES.name() ) ); ProfileManagerInfo profileInfo = new ProfileManagerInfo(interpolatorProperties, activeProfileIds, inactiveProfileIds); PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java index ab6432ea9b..64838e64ad 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/DefaultInterpolator.java @@ -1,9 +1,11 @@ package org.apache.maven.model.interpolator; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -29,39 +31,41 @@ import org.apache.maven.model.PomClassicDomainModel; import org.apache.maven.model.ProjectUri; import org.apache.maven.model.Reporting; import org.apache.maven.model.Resource; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.WriterFactory; @Component(role = Interpolator.class) public class DefaultInterpolator implements Interpolator { - public PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, Properties properties ) + public Model interpolateModel( Model model, Properties properties, File projectDirectory ) throws IOException { - List props = new ArrayList(); + if ( model == null ) + { + throw new IllegalArgumentException( "model: null" ); + } + + if(properties == null) + { + return model; + } + + List interpolatorProperties = new ArrayList(); for ( Entry e : properties.entrySet() ) { - props.add( new InterpolatorProperty( (String) e.getKey(), (String) e.getValue(), PomInterpolatorTag.EXECUTION_PROPERTIES.toString() ) ); + interpolatorProperties.add( new InterpolatorProperty( (String) e.getKey(), (String) e.getValue(), PomInterpolatorTag.EXECUTION_PROPERTIES.toString() ) ); } - return interpolateDomainModel( dm, props ); - } - public PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List interpolatorProperties ) - throws IOException - { - - if ( dm == null ) - { - throw new IllegalArgumentException( "dm: null" ); - } if ( !containsProjectVersion( interpolatorProperties ) ) { aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" ); } //TODO: Insert customized logic for parsing - List modelProperties = getModelProperties( dm.getInputStream() ); + List modelProperties = getModelProperties( model ); - if ( "jar".equals( dm.getModel().getPackaging() ) ) + if ( "jar".equals( model.getPackaging() ) ) { modelProperties.add( new ModelProperty( ProjectUri.packaging, "jar" ) ); } @@ -88,17 +92,14 @@ public class DefaultInterpolator List standardInterpolatorProperties = new ArrayList(); - if ( dm.isPomInBuild() ) - { - String basedir = dm.getProjectDirectory().getAbsolutePath(); - standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + String basedir = projectDirectory.getAbsolutePath(); + standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - String baseuri = dm.getProjectDirectory().toURI().toString(); - standardInterpolatorProperties.add( new InterpolatorProperty( "${project.baseUri}", baseuri, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.baseUri}", baseuri, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - } + String baseuri = projectDirectory.toURI().toString(); + standardInterpolatorProperties.add( new InterpolatorProperty( "${project.baseUri}", baseuri, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.baseUri}", baseuri, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); for ( ModelProperty mp : modelProperties ) { @@ -129,28 +130,24 @@ public class DefaultInterpolator interpolateModelProperties( modelProperties, ips1 ); - // SECOND PASS - Set absolute paths on build directories - if ( dm.isPomInBuild() ) + Map buildDirectories = new HashMap(); + for ( ModelProperty mp : secondPassModelProperties ) { - String basedir = dm.getProjectDirectory().getAbsolutePath(); - Map buildDirectories = new HashMap(); - for ( ModelProperty mp : secondPassModelProperties ) - { - if ( mp.getUri().startsWith( ProjectUri.Build.xUri ) || mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) ) - { - File file = new File( mp.getResolvedValue() ); - if ( !file.isAbsolute() && !mp.getResolvedValue().startsWith( "${project.build." ) && !mp.getResolvedValue().equals( "${project.basedir}" ) ) - { - buildDirectories.put( mp, new ModelProperty( mp.getUri(), new File( basedir, file.getPath() ).getAbsolutePath() ) ); - } - } - } - for ( Map.Entry e : buildDirectories.entrySet() ) - { - secondPassModelProperties.remove( e.getKey() ); - secondPassModelProperties.add( e.getValue() ); - } + if ( mp.getUri().startsWith( ProjectUri.Build.xUri ) || mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) ) + { + File file = new File( mp.getResolvedValue() ); + if ( !file.isAbsolute() && !mp.getResolvedValue().startsWith( "${project.build." ) && !mp.getResolvedValue().equals( "${project.basedir}" ) ) + { + buildDirectories.put( mp, new ModelProperty( mp.getUri(), new File( basedir, file.getPath() ).getAbsolutePath() ) ); + } + } } + for ( Map.Entry e : buildDirectories.entrySet() ) + { + secondPassModelProperties.remove( e.getKey() ); + secondPassModelProperties.add( e.getValue() ); + } + // THIRD PASS - Use build directories as interpolator properties List ips2 = new ArrayList( interpolatorProperties ); @@ -175,30 +172,17 @@ public class DefaultInterpolator try { String xml = unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); - PomClassicDomainModel domainModel = new PomClassicDomainModel( new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ) ); - if ( dm.getProjectDirectory() != null ) + Model m = new PomClassicDomainModel( new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ) ).getModel(); + if ( projectDirectory != null ) { - alignPaths( domainModel.getModel(), dm.getProjectDirectory() ); + alignPaths( m, projectDirectory ); } - return domainModel; + return m; } catch ( IOException e ) { throw new IllegalStateException( "Unmarshalling of model properties failed", e ); } - - /* - for(ModelProperty mp : modelProperties) - { - if((mp.getValue() != null) && !mp.getValue().equals(mp.getResolvedValue())) - { - if(mp.getUri().equals(ProjectUri.version)) - { - - } - } - } - */ } /** @@ -350,9 +334,27 @@ public class DefaultInterpolator return ips; } - private static List getModelProperties( InputStream is ) + + private static List getModelProperties( Model model ) throws IOException { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Writer out = null; + MavenXpp3Writer writer = new MavenXpp3Writer(); + try + { + out = WriterFactory.newXmlWriter( baos ); + writer.write( out, model ); + } + finally + { + if ( out != null ) + { + out.close(); + } + } + Set s = new HashSet(); //TODO: Should add all collections from ProjectUri s.addAll( URIS ); @@ -378,7 +380,7 @@ public class DefaultInterpolator s.add( ProjectUri.Profiles.Profile.Dependencies.xUri ); s.add( ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration ); - return new ArrayList( marshallXmlToModelProperties( is, ProjectUri.baseUri, s ) ); + return new ArrayList( marshallXmlToModelProperties( new ByteArrayInputStream(baos.toByteArray()), ProjectUri.baseUri, s ) ); } /** @@ -414,8 +416,6 @@ public class DefaultInterpolator continue; } - //String val = (mp.getResolvedValue() != null) ? "\"" + mp.getResolvedValue() + "\"" : null; - // System.out.println("new ModelProperty(\"" + mp.getUri() +"\" , " + val +"),"); if ( !uri.startsWith( baseUri ) ) { throw new IllegalArgumentException( "Passed in model property that does not match baseUri: Property URI = " + uri + ", Base URI = " + baseUri ); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java index 7e9aa9dde0..21a4a0a557 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/Interpolator.java @@ -1,12 +1,13 @@ package org.apache.maven.model.interpolator; +import java.io.File; import java.io.IOException; import java.util.Properties; -import org.apache.maven.model.PomClassicDomainModel; +import org.apache.maven.model.Model; public interface Interpolator { - PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, Properties interpolatorProperties ) + Model interpolateModel( Model model, Properties properties, File projectDirectory ) throws IOException; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/PomInterpolatorTag.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/PomInterpolatorTag.java index 18c1057e8f..57b0c8f2bc 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/PomInterpolatorTag.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolator/PomInterpolatorTag.java @@ -1,11 +1,7 @@ package org.apache.maven.model.interpolator; - public enum PomInterpolatorTag { - - USER_PROPERTIES, - PROJECT_PROPERTIES, EXECUTION_PROPERTIES diff --git a/maven-model-builder/src/test/projects/enforcer/enforcer-api/pom.xml b/maven-model-builder/src/test/projects/enforcer/enforcer-api/pom.xml deleted file mode 100644 index f417b67577..0000000000 --- a/maven-model-builder/src/test/projects/enforcer/enforcer-api/pom.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.enforcer - enforcer - 2-SNAPSHOT - - enforcer-api - jar - 1.0-alpha-5-SNAPSHOT - Enforcer API - - This component provides the generic interfaces needed to implement custom rules for the maven-enforcer-plugin. - - - - - maven-compiler-plugin - - 1.4 - 1.4 - - - - org.codehaus.plexus - plexus-maven-plugin - - - - descriptor - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.2-beta-2 - - - custom-rule - pre-site - - single - - - custom-rule - target/site - - src/main/assembly/custom-rule-sample.xml - - false - - - - - - - - - org.apache.maven - maven-plugin-api - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-9 - - - diff --git a/maven-model-builder/src/test/projects/enforcer/enforcer-rules/pom.xml b/maven-model-builder/src/test/projects/enforcer/enforcer-rules/pom.xml deleted file mode 100644 index ec36d01e2d..0000000000 --- a/maven-model-builder/src/test/projects/enforcer/enforcer-rules/pom.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.enforcer - enforcer - 2-SNAPSHOT - - enforcer-rules - jar - 1.0-alpha-5-SNAPSHOT - Enforcer Rules - This component contains the standard Enforcer Rules - - - - org.codehaus.plexus - plexus-maven-plugin - - - - descriptor - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - - - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-plugin-api - - - org.apache.maven - maven-project - - - org.apache.maven - maven-core - - - org.codehaus.plexus - plexus-utils - - - org.apache.maven.shared - maven-plugin-testing-harness - test - - - commons-lang - commons-lang - - - org.apache.maven.enforcer - enforcer-api - - - org.beanshell - bsh - 2.0b4 - - - junit - junit - - - diff --git a/maven-model-builder/src/test/projects/enforcer/maven-enforcer-plugin/pom.xml b/maven-model-builder/src/test/projects/enforcer/maven-enforcer-plugin/pom.xml deleted file mode 100644 index 1a069dc5a5..0000000000 --- a/maven-model-builder/src/test/projects/enforcer/maven-enforcer-plugin/pom.xml +++ /dev/null @@ -1,166 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.enforcer - enforcer - 2-SNAPSHOT - - org.apache.maven.plugins - maven-enforcer-plugin - maven-plugin - Maven Enforcer Plugin - The Loving Iron Fist of Maven - 1.0-alpha-5-SNAPSHOT - http://maven.apache.org/plugins/maven-enforcer-plugin/ - - JIRA - http://jira.codehaus.org/browse/MENFORCER - - - - 2.0.6 - - - - brianf - Brian Fox - brianf@apache.org - - Lead Developer - - 5 - - - - - Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - apache.website - ${site.deploy.url}/plugins/maven-enforcer-plugin - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - clean - - clean - - - - - - maven-site-plugin - - - scp://people.apache.org/www/maven.apache.org/plugins/${project.artifactId}-${project.version} - - - - - org.apache.maven.plugins - maven-plugin-plugin - - - generated-helpmojo - - helpmojo - - - - - - - - - ${basedir}/src/main/resources - - - - - - org.apache.maven - maven-artifact - - - org.apache.maven - maven-plugin-api - - - org.apache.maven - maven-project - - - org.apache.maven - maven-core - - - org.codehaus.plexus - plexus-utils - - - commons-lang - commons-lang - - - org.apache.maven.enforcer - enforcer-api - - - org.apache.maven.enforcer - enforcer-rules - - - org.apache.maven.enforcer - enforcer-rules - tests - - - org.apache.maven.shared - maven-plugin-testing-harness - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${maven.plugin.plugin.version} - - - - diff --git a/maven-model-builder/src/test/projects/enforcer/pom.xml b/maven-model-builder/src/test/projects/enforcer/pom.xml deleted file mode 100644 index 199a8bd63e..0000000000 --- a/maven-model-builder/src/test/projects/enforcer/pom.xml +++ /dev/null @@ -1,281 +0,0 @@ - - - - 4.0.0 - - maven-parent - org.apache.maven - 9 - ../pom/maven/pom.xml - - org.apache.maven.enforcer - enforcer - pom - Enforcer - 2-SNAPSHOT - Enforcer is a build rule execution framework. - http://maven.apache.org/enforcer - - 2.0.6 - - - jira - http://jira.codehaus.org/browse/MENFORCER - - 2007 - - - Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - brianf - Brian Fox - brianf@apache.org - - Lead Developer - - 5 - - - - - Maven User List - users-subscribe@maven.apache.org - users-unsubscribe@maven.apache.org - users@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-users - - http://www.mail-archive.com/users@maven.apache.org/ - http://www.nabble.com/Maven---Users-f178.html - http://maven.users.markmail.org/ - - - - Maven Developer List - dev-subscribe@maven.apache.org - dev-unsubscribe@maven.apache.org - dev@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-dev - - http://www.mail-archive.com/dev@maven.apache.org/ - http://www.nabble.com/Maven-Developers-f179.html - http://maven.dev.markmail.org/ - - - - Maven Issues List - issues-subscribe@maven.apache.org - issues-unsubscribe@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-issues/ - - http://www.mail-archive.com/issues@maven.apache.org - http://www.nabble.com/Maven---Issues-f15573.html - http://maven.issues.markmail.org/ - - - - Maven Commits List - commits-subscribe@maven.apache.org - commits-unsubscribe@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-dev - - http://www.mail-archive.com/commits@maven.apache.org - http://www.nabble.com/Maven---Commits-f15575.html - http://maven.commits.markmail.org/ - - - - - Maven Announcements List - announce@maven.apache.org - announce-subscribe@maven.apache.org - announce-unsubscribe@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-announce/ - - http://www.mail-archive.com/announce@maven.apache.org - http://www.nabble.com/Maven-Announcements-f15617.html - http://maven.announce.markmail.org/ - - - - Maven Notifications List - notifications-subscribe@maven.apache.org - notifications-unsubscribe@maven.apache.org - http://mail-archives.apache.org/mod_mbox/maven-notifications/ - - http://www.mail-archive.com/notifications@maven.apache.org - http://www.nabble.com/Maven---Notifications-f15574.html - http://maven.notifications.markmail.org/ - - - - - scm:svn:http://svn.apache.org/repos/asf/maven/enforcer/trunk/ - scm:svn:https://svn.apache.org/repos/asf/maven/enforcer/trunk/ - http://svn.apache.org/viewcvs.cgi/maven/enforcer/trunk - - - 1.0-alpha-4-SNAPSHOT - 1.0-alpha-4-SNAPSHOT - 2.0.9 - 2.4.3 - scp://people.apache.org/www/maven.apache.org - - - - - - ${basedir}/src/main/resources - - - - - - maven-compiler-plugin - - 1.4 - 1.4 - - - - maven-plugin-plugin - ${maven.plugin.plugin.version} - - - maven-release-plugin - - https://svn.apache.org/repos/asf/maven/enforcer/tags - - - - - - - - apache.website - ${site.deploy.url}/enforcer/ - - - - - - org.apache.maven.enforcer - enforcer-api - 1.0-alpha-5-SNAPSHOT - - - org.apache.maven.enforcer - enforcer-rules - 1.0-alpha-5-SNAPSHOT - - - org.apache.maven.enforcer - enforcer-rules - 1.0-alpha-5-SNAPSHOT - tests - test - - - org.apache.maven - maven-artifact - ${maven.version} - - - org.apache.maven - maven-plugin-api - ${maven.version} - - - org.apache.maven - maven-project - ${maven.version} - - - org.apache.maven - maven-core - ${maven.version} - - - org.codehaus.plexus - plexus-utils - 1.5.1 - - - junit - junit - 3.8.2 - test - - - commons-lang - commons-lang - 2.3 - - - org.apache.maven.shared - maven-plugin-testing-harness - test - 1.1 - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - 2.2 - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.5 - - - - org.apache.maven.plugin-tools - maven-plugin-tools-javadoc - 2.4.3 - - - org.codehaus.plexus - plexus-javadoc - 1.0 - - - - - - - - enforcer-api - enforcer-rules - maven-enforcer-plugin - - diff --git a/maven-model-builder/src/test/resources/test.txt b/maven-model-builder/src/test/resources/test.txt deleted file mode 100644 index 30d74d2584..0000000000 --- a/maven-model-builder/src/test/resources/test.txt +++ /dev/null @@ -1 +0,0 @@ -test \ No newline at end of file