diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index dcb51bbdc4..eb7c5f2157 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -73,9 +73,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.project.builder.PomInterpolatorTag; -import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; +import org.apache.maven.project.builder.legacy.PomTransformer; import org.apache.maven.project.path.PathTranslator; import org.apache.maven.realm.MavenRealmManager; import org.apache.maven.realm.RealmManagementException; diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java index fcb83417ae..d5465398e9 100644 --- a/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java +++ b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java @@ -31,7 +31,7 @@ import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.builder.legacy.PomClassicDomainModel; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.model.ModelProperty; import org.codehaus.plexus.util.WriterFactory; @@ -171,16 +171,6 @@ public class PomTestWrapper return ( pomFile != null ) ? pomFile.getParentFile() : null; } - public String getValueOfProjectUri( String projectUri, boolean withResolvedValue ) - throws IOException - { - if ( projectUri.contains( "#collection" ) || projectUri.contains( "#set" ) ) - { - throw new IllegalArgumentException( "projectUri: contains a collection or set" ); - } - return asMap( withResolvedValue ).get( projectUri ); - } - public void setValueOnModel( String expression, Object value ) { context.setValue( expression, value ); diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java index a4a4634b90..54d42778bf 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java @@ -30,9 +30,9 @@ import org.apache.maven.mercury.builder.api.DependencyProcessor; import org.apache.maven.mercury.builder.api.DependencyProcessorException; import org.apache.maven.mercury.builder.api.MetadataReader; import org.apache.maven.mercury.builder.api.MetadataReaderException; -import org.apache.maven.project.builder.PomInterpolatorTag; -import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; +import org.apache.maven.project.builder.legacy.PomTransformer; import org.apache.maven.shared.model.DomainModel; import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.ModelContainer; diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor2.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor2.java index 610a54527b..124831bcf9 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor2.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor2.java @@ -10,7 +10,7 @@ import org.apache.maven.mercury.builder.api.DependencyProcessor; import org.apache.maven.mercury.builder.api.DependencyProcessorException; import org.apache.maven.mercury.builder.api.MetadataReader; import org.apache.maven.mercury.builder.api.MetadataReaderException; -import org.apache.maven.project.processor.ProcessorContext; +import org.apache.maven.project.builder.ProcessorContext; import org.apache.maven.shared.model.DomainModel; import org.apache.maven.shared.model.InterpolatorProperty; import org.codehaus.plexus.component.annotations.Component; @@ -62,7 +62,7 @@ public class MavenDependencyProcessor2 { throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage(), e ); } - +/* try { MavenDomainModel model = new MavenDomainModel(ProcessorContext.build(domainModels, interpolatorProperties)); @@ -72,5 +72,7 @@ public class MavenDependencyProcessor2 { throw new MetadataReaderException( "Unable to transform model", e ); } + */ + return null; } } diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java index ebec9897e3..3f20fce02d 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java @@ -28,11 +28,11 @@ import java.util.Collection; import java.util.List; import org.apache.maven.mercury.artifact.ArtifactMetadata; -import org.apache.maven.project.builder.PomClassicDomainModel; -import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; import org.apache.maven.project.builder.factories.ExclusionModelContainerFactory; +import org.apache.maven.project.builder.legacy.PomClassicDomainModel; +import org.apache.maven.project.builder.legacy.PomTransformer; import org.apache.maven.project.builder.profile.ProfileContext; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.InterpolatorProperty; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/DataSourceRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/DataSourceRule.java similarity index 82% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/DataSourceRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/DataSourceRule.java index 16c9c3f7f1..e48d3ca316 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/DataSourceRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/DataSourceRule.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; import org.apache.maven.shared.model.ModelDataSource; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/JoinRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/JoinRule.java similarity index 84% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/JoinRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/JoinRule.java index 3ccdc41541..2369263637 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/JoinRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/JoinRule.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModel.java new file mode 100644 index 0000000000..5d79265418 --- /dev/null +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModel.java @@ -0,0 +1,441 @@ +package org.apache.maven.project.builder.legacy; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.ModelMarshaller; +import org.apache.maven.shared.model.InputStreamDomainModel; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.ArrayList; +import java.util.Set; +import java.util.HashSet; + +/** + * Provides a wrapper for the maven model. + */ +public class PomClassicDomainModel implements InputStreamDomainModel +{ + + /** + * Bytes containing the underlying model + */ + private byte[] inputBytes; + + /** + * History of joins and deletes of model properties + */ + private String eventHistory; + + private String id; + + private File file; + + private File parentFile; + + private File projectDirectory; + + private List modelProperties; + + private int lineageCount; + + private boolean isMostSpecialized = false; + + private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath; + + private Model model; + + public Model getModel() throws IOException + { + if(model == null) + { + InputStream is; + try { + is = getInputStream(); + } catch (Exception e1) { + throw new IOException("inputStream not set"); + } + + MavenXpp3Reader reader = new MavenXpp3Reader(); + try + { + model = reader.read( is, false ) ; + } + catch ( XmlPullParserException e ) + { + throw new IOException( e.getMessage() ); + } + } + return model; + } + + public PomClassicDomainModel( List modelProperties ) + { + this.modelProperties = modelProperties; + try + { + String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); + inputBytes = xml.getBytes( "UTF-8" ); + } + catch ( IOException e ) + { + throw new IllegalStateException( "Unmarshalling of model properties failed", e ); + } + initializeProperties( modelProperties ); + } + + public PomClassicDomainModel( List modelProperties, boolean isMostSpecialized ) + { + this( modelProperties ); + this.isMostSpecialized = isMostSpecialized; + } + + + /** + * Constructor + * + * @param inputStream input stream of the maven model + * @throws IOException if there is a problem constructing the model + */ + public PomClassicDomainModel( InputStream inputStream ) + throws IOException + { + if ( inputStream == null ) + { + throw new IllegalArgumentException( "inputStream: null" ); + } + this.inputBytes = IOUtil.toByteArray( inputStream ); + modelProperties = getModelProperties(); + initializeProperties( modelProperties ); + } + + public PomClassicDomainModel( InputStream inputStream, boolean isMostSpecialized ) + throws IOException + { + this( inputStream ); + this.isMostSpecialized = isMostSpecialized; + } + + private void initializeProperties(List modelProperties) + { + String groupId = null, artifactId = null, version = null; + for(ModelProperty mp : modelProperties) + { + if(mp.getUri().equals(ProjectUri.groupId)) + { + groupId = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.artifactId)) + { + artifactId = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.version)) + { + version = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.Parent.artifactId)) + { + parentArtifactId = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.Parent.groupId)) + { + parentGroupId = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.Parent.version)) + { + parentVersion = mp.getResolvedValue(); + } + else if(mp.getUri().equals(ProjectUri.Parent.relativePath)) + { + parentRelativePath = mp.getResolvedValue(); + } + + if(groupId != null && artifactId != null && version != null && parentGroupId != null && + parentArtifactId != null && parentVersion != null & parentRelativePath != null) + { + break; + } + } + if( groupId == null && parentGroupId != null) + { + groupId = parentGroupId; + } + if( artifactId == null && parentArtifactId != null) + { + artifactId = parentArtifactId; + } + if( version == null && parentVersion != null ) + { + version = parentVersion; + } + + if(parentGroupId != null && parentArtifactId != null && parentVersion != null) + { + parentId = parentGroupId + ":" + parentArtifactId + ":" + parentVersion; + } + + if(parentRelativePath == null) + { + parentRelativePath = ".." + File.separator + "pom.xml"; + } + + id = groupId + ":" + artifactId + ":" + version; + } + + public PomClassicDomainModel( File file ) + throws IOException + { + this( new FileInputStream( file ) ); + this.file = file; + } + + public PomClassicDomainModel(Model model2) { + this.model = model2; + } + + public PomClassicDomainModel(Model model2, boolean b) { + this.model = model2; + this.isMostSpecialized = b; + } + + public File getParentFile() + { + return parentFile; + } + + public void setParentFile( File parentFile ) + { + this.parentFile = parentFile; + } + + public String getParentGroupId() { + return parentGroupId; + } + + public String getParentArtifactId() { + return parentArtifactId; + } + + public String getParentVersion() { + return parentVersion; + } + + /** + * This should only be set for projects that are in the build. Setting for poms in the repo may cause unstable behavior. + * + * @param projectDirectory + */ + public void setProjectDirectory(File projectDirectory) + { + this.projectDirectory = projectDirectory; + } + + public File getProjectDirectory() + { + return projectDirectory; + } + + public boolean isPomInBuild() + { + return projectDirectory != null; + } + + public String getParentId() throws IOException + { + return parentId; + } + + public String getRelativePathOfParent() + { + return parentRelativePath; + } + + public String getId() throws IOException + { + return id; + } + + + public boolean matchesParentOf( PomClassicDomainModel domainModel ) throws IOException + { + if ( domainModel == null ) + { + throw new IllegalArgumentException( "domainModel: null" ); + } + + return getId().equals(domainModel.getParentId()); + } + + /** + * Returns XML model as string + * + * @return XML model as string + */ + public String asString() + { + try + { + return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) ); + } + catch ( IOException ioe ) + { + // should not occur: everything is in-memory + return ""; + } + } + + /** + * @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream() + */ + public InputStream getInputStream() + { + byte[] copy = new byte[inputBytes.length]; + System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length ); + //System.out.println(new String(copy)); + return new ByteArrayInputStream( copy ); + } + + /** + * @return file of pom. May be null. + */ + public File getFile() + { + return file; + } + + public List getModelProperties() throws IOException + { + if(modelProperties == null) + { + Set s = new HashSet(); + //TODO: Should add all collections from ProjectUri + s.addAll(PomTransformer.URIS); + s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri); + s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri); + s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI); + s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri); + s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration); + s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration); + //TODO: More profile info + s.add(ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.Dependency.Exclusions.xUri); + s.add(ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri); + s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.xUri); + s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.Execution.Goals.xURI); + s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.xUri); + s.add(ProjectUri.Profiles.Profile.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration); + s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.Execution.configuration); + s.add(ProjectUri.Profiles.Profile.properties); + s.add(ProjectUri.Profiles.Profile.modules); + s.add(ProjectUri.Profiles.Profile.Dependencies.xUri); + s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration); + + modelProperties = ModelMarshaller.marshallXmlToModelProperties( + getInputStream(), ProjectUri.baseUri, s ); + } + return new ArrayList(modelProperties); + } + + /** + * @see org.apache.maven.shared.model.DomainModel#getEventHistory() + */ + public String getEventHistory() + { + return eventHistory; + } + + /** + * @see org.apache.maven.shared.model.DomainModel#setEventHistory(String) + */ + public void setEventHistory( String eventHistory ) + { + if ( eventHistory == null ) + { + throw new IllegalArgumentException( "eventHistory: null" ); + } + this.eventHistory = eventHistory; + } + + public int getLineageCount() + { + return lineageCount; + } + + public void setLineageCount( int lineageCount ) + { + this.lineageCount = lineageCount; + } + + public PomClassicDomainModel createCopy() + { + List props = new ArrayList(); + for(ModelProperty mp : modelProperties) + { + props.add(mp.createCopyOfOriginal()); + } + + return new PomClassicDomainModel(props); + } + + /** + * Returns true if this.asString.equals(o.asString()), otherwise false. + * + * @param o domain model + * @return true if this.asString.equals(o.asString()), otherwise false. + */ + public boolean equals( Object o ) + { + try { + return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() ); + } catch (IOException e) { + return false; + } + } + + public boolean isMostSpecialized() + { + return isMostSpecialized; + } + + public void setMostSpecialized( boolean isMostSpecialized ) + { + this.isMostSpecialized = isMostSpecialized; + } + + @Override + public String toString() + { + return String.valueOf( id ); + } + +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModelFactory.java similarity index 90% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModelFactory.java index e293584423..581ac2bcf9 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomClassicDomainModelFactory.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; import org.apache.maven.shared.model.DomainModelFactory; import org.apache.maven.shared.model.DomainModel; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomTransformer.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomTransformer.java index df059c9f0c..1826c4e5bd 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/PomTransformer.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -25,11 +25,14 @@ import java.util.*; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; +import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.rules.*; import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory; import org.apache.maven.project.builder.factories.AlwaysJoinModelContainerFactory; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; import org.apache.maven.project.builder.factories.IdModelContainerFactory; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; /** * Provides methods for transforming model properties into a domain model for the pom classic format and vice versa. diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRemovalRule.java similarity index 87% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRemovalRule.java index d735a81da5..4d00f4731c 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRemovalRule.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRule.java similarity index 85% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRule.java index cd69b17340..7c70a3c7e0 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/legacy/TransformerRule.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.legacy; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ActiveProfileMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ActiveProfileMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ActiveProfileMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ActiveProfileMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ByDefaultMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ByDefaultMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ByDefaultMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ByDefaultMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/FileMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/FileMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/FileMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/FileMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/JdkMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/OperatingSystemMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/OperatingSystemMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/OperatingSystemMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/OperatingSystemMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ProfileContext.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ProfileContext.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ProfileContext.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ProfileContext.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ProfileUri.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ProfileUri.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/ProfileUri.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/ProfileUri.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/PropertyMatcher.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/profile/PropertyMatcher.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/profile/PropertyMatcher.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/profile/PropertyMatcher.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java similarity index 96% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java index c89db8e7de..cf74367899 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java @@ -5,8 +5,8 @@ import org.apache.maven.shared.model.ModelDataSource; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.impl.DefaultModelDataSource; -import org.apache.maven.project.builder.TransformerRule; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.legacy.TransformerRule; import org.apache.maven.project.builder.ProjectUri; import java.util.List; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java similarity index 93% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java index 352dc5f237..6dd718ef25 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java @@ -3,7 +3,7 @@ package org.apache.maven.project.builder.rules; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.project.builder.TransformerRemovalRule; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import java.util.List; import java.util.ArrayList; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java index 46177b2aa9..eb513d70c7 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java @@ -1,8 +1,8 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.DataSourceRule; import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.legacy.DataSourceRule; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DependencyRule.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java similarity index 94% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java index bc1ce0bf72..cffc0fb80f 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/DuplicateFiltersTransformerRule.java @@ -1,7 +1,7 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java similarity index 100% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java similarity index 85% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java index 222c2a27f7..5358ee6960 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java @@ -1,10 +1,11 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRule; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.TransformerRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; -import static org.apache.maven.project.builder.PomTransformer.getPropertyFor; + +import static org.apache.maven.project.builder.legacy.PomTransformer.getPropertyFor; import java.util.List; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java similarity index 88% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java index 25031320d3..71cb0cf6d9 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java @@ -2,9 +2,9 @@ package org.apache.maven.project.builder.rules; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; -import org.apache.maven.project.builder.TransformerRule; -import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.PomTransformer; +import org.apache.maven.project.builder.legacy.TransformerRule; import java.util.List; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java similarity index 89% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java index 03a23c8738..758a3d9353 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java @@ -1,8 +1,8 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.project.builder.PomTransformer; +import org.apache.maven.project.builder.legacy.PomTransformer; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java similarity index 93% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java index 07897528e1..8f5e13e0e0 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NameNotInheritedTransformerRule.java @@ -1,7 +1,7 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java index 63ae156ec7..d6612960b7 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginExecutionTransformerRule.java @@ -1,9 +1,9 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.ModelDataSource; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java similarity index 94% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java index 210e30a705..905c076f6e 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/NotInheritedPluginTransformerRule.java @@ -1,8 +1,8 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.project.builder.PomTransformer; +import org.apache.maven.project.builder.legacy.PomTransformer; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.ModelDataSource; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java similarity index 95% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java index 948b5e9de5..3be3616ef0 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java @@ -1,9 +1,9 @@ package org.apache.maven.project.builder.rules; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.project.builder.PomTransformer; -import org.apache.maven.project.builder.JoinRule; import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.legacy.JoinRule; +import org.apache.maven.project.builder.legacy.PomTransformer; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java similarity index 93% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java index 0a2a9873e3..01a09758c9 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/PackagingNotInheritedTransformerRule.java @@ -1,7 +1,7 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java similarity index 93% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java rename to maven-mercury/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java index 36f9add5f2..a18c1e7b3b 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java +++ b/maven-mercury/src/main/java/org/apache/maven/project/builder/rules/RelativePathNotInheritedTransformerRule.java @@ -1,7 +1,7 @@ package org.apache.maven.project.builder.rules; -import org.apache.maven.project.builder.TransformerRemovalRule; import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.legacy.TransformerRemovalRule; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.DataSourceException; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/BaseProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/BaseProcessor.java index 17431f268d..b4fbd13ad4 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/BaseProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/BuildProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/BuildProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/BuildProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/BuildProcessor.java index 95cfd0e008..fc255ce038 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/BuildProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/BuildProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/CiManagementProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/CiManagementProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/CiManagementProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/CiManagementProcessor.java index 2830439423..78a37f2e73 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/CiManagementProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/CiManagementProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ContributorsProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ContributorsProcessor.java index d354893f0a..2a9fe4505b 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ContributorsProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependenciesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependenciesProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/DependenciesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/DependenciesProcessor.java index a05ef931a5..433c95f9ff 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependenciesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependenciesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyManagementProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyManagementProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyManagementProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyManagementProcessor.java index 4b8aebc38c..a3cce1afba 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyManagementProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyManagementProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyProcessor.java index 47313a8b48..37326999f6 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DependencyProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DependencyProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DevelopersProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/DevelopersProcessor.java index b84c8abfbd..cecfb9e836 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DevelopersProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DistributionManagementProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/DistributionManagementProcessor.java index 0ceab00a7e..c302194917 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/DistributionManagementProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IssueManagementProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/IssueManagementProcessor.java index 2b905406d4..a10c47f0a6 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IssueManagementProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/LicensesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/LicensesProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/LicensesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/LicensesProcessor.java index 5ecc502d7c..fdefdcf5ed 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/LicensesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/LicensesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/MailingListProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/MailingListProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/MailingListProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/MailingListProcessor.java index 3a360505fa..91538f92f9 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/MailingListProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/MailingListProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelListener.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelListener.java similarity index 95% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelListener.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelListener.java index 3b55ebc143..d65b67b9fc 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelListener.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelListener.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelProcessor.java index 3f5ce1ff81..3df88feb7a 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModelProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModuleProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModuleProcessor.java similarity index 96% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ModuleProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ModuleProcessor.java index faa26922d1..4bcea21031 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModuleProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ModuleProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/OrganizationProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/OrganizationProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/OrganizationProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/OrganizationProcessor.java index e0f4ec86aa..e8e42838ae 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/OrganizationProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/OrganizationProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ParentProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ParentProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ParentProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ParentProcessor.java index 9e7cb2c5c2..f6e87cb8db 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ParentProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ParentProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginProcessor.java index d2a12550d2..7282be9a48 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsManagementProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsManagementProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsManagementProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsManagementProcessor.java index 3a7df792bd..3aacc361c7 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsManagementProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsManagementProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsProcessor.java index f31170dcdb..621c383061 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PluginsProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginsProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java index aa77d5c81e..131cd08d71 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java @@ -1,47 +1,38 @@ package org.apache.maven.project.builder; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.ModelMarshaller; -import org.apache.maven.shared.model.InputStreamDomainModel; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.List; +import java.io.Writer; import java.util.ArrayList; -import java.util.Set; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; -/** - * Provides a wrapper for the maven model. - */ -public class PomClassicDomainModel implements InputStreamDomainModel +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.project.builder.interpolator.DomainModel; +import org.apache.maven.project.builder.interpolator.ModelProperty; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +public class PomClassicDomainModel implements DomainModel { /** @@ -49,11 +40,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel */ private byte[] inputBytes; - /** - * History of joins and deletes of model properties - */ - private String eventHistory; - private String id; private File file; @@ -74,74 +60,8 @@ public class PomClassicDomainModel implements InputStreamDomainModel public Model getModel() throws IOException { - if(model == null) - { - InputStream is; - try { - is = getInputStream(); - } catch (Exception e1) { - throw new IOException("inputStream not set"); - } - - MavenXpp3Reader reader = new MavenXpp3Reader(); - try - { - model = reader.read( is, false ) ; - } - catch ( XmlPullParserException e ) - { - throw new IOException( e.getMessage() ); - } - } return model; } - - public PomClassicDomainModel( List modelProperties ) - { - this.modelProperties = modelProperties; - try - { - String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); - inputBytes = xml.getBytes( "UTF-8" ); - } - catch ( IOException e ) - { - throw new IllegalStateException( "Unmarshalling of model properties failed", e ); - } - initializeProperties( modelProperties ); - } - - public PomClassicDomainModel( List modelProperties, boolean isMostSpecialized ) - { - this( modelProperties ); - this.isMostSpecialized = isMostSpecialized; - } - - - /** - * Constructor - * - * @param inputStream input stream of the maven model - * @throws IOException if there is a problem constructing the model - */ - public PomClassicDomainModel( InputStream inputStream ) - throws IOException - { - if ( inputStream == null ) - { - throw new IllegalArgumentException( "inputStream: null" ); - } - this.inputBytes = IOUtil.toByteArray( inputStream ); - modelProperties = getModelProperties(); - initializeProperties( modelProperties ); - } - - public PomClassicDomainModel( InputStream inputStream, boolean isMostSpecialized ) - throws IOException - { - this( inputStream ); - this.isMostSpecialized = isMostSpecialized; - } private void initializeProperties(List modelProperties) { @@ -212,17 +132,54 @@ public class PomClassicDomainModel implements InputStreamDomainModel public PomClassicDomainModel( File file ) throws IOException { - this( new FileInputStream( file ) ); + this( new FileInputStream( file ) ); this.file = file; } + + public PomClassicDomainModel( InputStream is ) + throws IOException + { + this.inputBytes = IOUtil.toByteArray( is); + + MavenXpp3Reader reader = new MavenXpp3Reader(); + try + { + model = reader.read( new ByteArrayInputStream( inputBytes ), false ) ; + } + catch ( XmlPullParserException e ) + { + throw new IOException( e.getMessage() ); + } + + modelProperties = getModelProperties(); + initializeProperties( modelProperties ); - public PomClassicDomainModel(Model model2) { - this.model = model2; + } + + public PomClassicDomainModel(Model model) throws IOException { + this (model, false); } - public PomClassicDomainModel(Model model2, boolean b) { - this.model = model2; + public PomClassicDomainModel(Model model, boolean b) throws IOException { + this.model = model; this.isMostSpecialized = b; + + 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(); + } + } + inputBytes = baos.toByteArray(); } public File getParentFile() @@ -318,7 +275,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel { byte[] copy = new byte[inputBytes.length]; System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length ); - //System.out.println(new String(copy)); return new ByteArrayInputStream( copy ); } @@ -336,7 +292,7 @@ public class PomClassicDomainModel implements InputStreamDomainModel { Set s = new HashSet(); //TODO: Should add all collections from ProjectUri - s.addAll(PomTransformer.URIS); + s.addAll(URIS); s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri); s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri); s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri); @@ -359,32 +315,11 @@ public class PomClassicDomainModel implements InputStreamDomainModel s.add(ProjectUri.Profiles.Profile.Dependencies.xUri); s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration); - modelProperties = ModelMarshaller.marshallXmlToModelProperties( - getInputStream(), ProjectUri.baseUri, s ); + modelProperties = marshallXmlToModelProperties(getInputStream(), ProjectUri.baseUri, s ); } return new ArrayList(modelProperties); } - /** - * @see org.apache.maven.shared.model.DomainModel#getEventHistory() - */ - public String getEventHistory() - { - return eventHistory; - } - - /** - * @see org.apache.maven.shared.model.DomainModel#setEventHistory(String) - */ - public void setEventHistory( String eventHistory ) - { - if ( eventHistory == null ) - { - throw new IllegalArgumentException( "eventHistory: null" ); - } - this.eventHistory = eventHistory; - } - public int getLineageCount() { return lineageCount; @@ -395,17 +330,6 @@ public class PomClassicDomainModel implements InputStreamDomainModel this.lineageCount = lineageCount; } - public PomClassicDomainModel createCopy() - { - List props = new ArrayList(); - for(ModelProperty mp : modelProperties) - { - props.add(mp.createCopyOfOriginal()); - } - - return new PomClassicDomainModel(props); - } - /** * Returns true if this.asString.equals(o.asString()), otherwise false. * @@ -436,5 +360,223 @@ public class PomClassicDomainModel implements InputStreamDomainModel { return String.valueOf( id ); } + + private static final Set URIS = Collections.unmodifiableSet(new HashSet( Arrays.asList( ProjectUri.Build.Extensions.xUri, + ProjectUri.Build.PluginManagement.Plugins.xUri, + ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration, + ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, + ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, + ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, + ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri, + ProjectUri.Build.Plugins.xUri, + ProjectUri.properties, + ProjectUri.Build.Plugins.Plugin.configuration, + ProjectUri.Reporting.Plugins.xUri, + ProjectUri.Reporting.Plugins.Plugin.configuration, + ProjectUri.Build.Plugins.Plugin.Dependencies.xUri, + ProjectUri.Build.Resources.xUri, + ProjectUri.Build.Resources.Resource.includes, + ProjectUri.Build.Resources.Resource.excludes, + ProjectUri.Build.TestResources.xUri, + ProjectUri.Build.Filters.xUri, + ProjectUri.CiManagement.Notifiers.xUri, + ProjectUri.Contributors.xUri, + ProjectUri.Dependencies.xUri, + ProjectUri.DependencyManagement.Dependencies.xUri, + ProjectUri.Developers.xUri, + ProjectUri.Developers.Developer.roles, + ProjectUri.Licenses.xUri, + ProjectUri.MailingLists.xUri, + ProjectUri.Modules.xUri, + ProjectUri.PluginRepositories.xUri, + ProjectUri.Profiles.xUri, + ProjectUri.Profiles.Profile.Build.Plugins.xUri, + ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri, + ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Executions.xUri, + ProjectUri.Profiles.Profile.Build.Resources.xUri, + ProjectUri.Profiles.Profile.Build.TestResources.xUri, + ProjectUri.Profiles.Profile.Dependencies.xUri, + ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri, + ProjectUri.Profiles.Profile.PluginRepositories.xUri, + ProjectUri.Profiles.Profile.Reporting.Plugins.xUri, + ProjectUri.Profiles.Profile.Repositories.xUri, + ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.xUri, + ProjectUri.Profiles.Profile.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri, + ProjectUri.Reporting.Plugins.xUri, + ProjectUri.Repositories.xUri) )); + + /** + * Returns list of model properties transformed from the specified input stream. + * + * @param inputStream input stream containing the xml document. May not be null. + * @param baseUri the base uri of every model property. May not be null or empty. + * @param collections set of uris that are to be treated as a collection (multiple entries). May be null. + * @return list of model properties transformed from the specified input stream. + * @throws IOException if there was a problem doing the transform + */ + public static List marshallXmlToModelProperties( InputStream inputStream, String baseUri, + Set collections ) + throws IOException { + if (inputStream == null) { + throw new IllegalArgumentException("inputStream: null"); + } + if (baseUri == null || baseUri.trim().length() == 0) { + throw new IllegalArgumentException("baseUri: null"); + } + + if (collections == null) { + collections = Collections.emptySet(); + } + + List modelProperties = new ArrayList(); + XMLInputFactory xmlInputFactory = new com.ctc.wstx.stax.WstxInputFactory(); + xmlInputFactory.setProperty( + XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); + xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, + Boolean.FALSE); + + Uri uri = new Uri(baseUri); + String tagName = baseUri; + StringBuilder tagValue = new StringBuilder(256); + + int depth = 0; + int depthOfTagValue = depth; + XMLStreamReader xmlStreamReader = null; + try { + xmlStreamReader = xmlInputFactory + .createXMLStreamReader(inputStream); + + Map attributes = new HashMap(); + for (;; xmlStreamReader.next()) { + int type = xmlStreamReader.getEventType(); + switch (type) { + + case XMLStreamConstants.CDATA: + case XMLStreamConstants.CHARACTERS: { + if (depth == depthOfTagValue) { + tagValue.append(xmlStreamReader.getTextCharacters(), + xmlStreamReader.getTextStart(), xmlStreamReader + .getTextLength()); + } + break; + } + + case XMLStreamConstants.START_ELEMENT: { + if (!tagName.equals(baseUri)) { + String value = null; + if (depth < depthOfTagValue) { + value = tagValue.toString().trim(); + } + modelProperties.add(new ModelProperty(tagName, value)); + if (!attributes.isEmpty()) { + for (Map.Entry e : attributes + .entrySet()) { + modelProperties.add(new ModelProperty(e + .getKey(), e.getValue())); + } + attributes.clear(); + } + } + + depth++; + tagName = uri.getUriFor(xmlStreamReader.getName() + .getLocalPart(), depth); + if (collections.contains(tagName + "#collection")) { + tagName = tagName + "#collection"; + uri.addTag(xmlStreamReader.getName().getLocalPart() + + "#collection"); + } else if (collections.contains(tagName + "#set")) { + tagName = tagName + "#set"; + uri.addTag(xmlStreamReader.getName().getLocalPart() + + "#set"); + } else { + uri.addTag(xmlStreamReader.getName().getLocalPart()); + } + tagValue.setLength(0); + depthOfTagValue = depth; + } + case XMLStreamConstants.ATTRIBUTE: { + for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) { + + attributes.put(tagName + + "#property/" + + xmlStreamReader.getAttributeName(i) + .getLocalPart(), xmlStreamReader + .getAttributeValue(i)); + } + break; + } + case XMLStreamConstants.END_ELEMENT: { + depth--; + break; + } + case XMLStreamConstants.END_DOCUMENT: { + modelProperties.add(new ModelProperty(tagName, tagValue + .toString().trim())); + if (!attributes.isEmpty()) { + for (Map.Entry e : attributes + .entrySet()) { + modelProperties.add(new ModelProperty(e.getKey(), e + .getValue())); + } + attributes.clear(); + } + return modelProperties; + } + } + } + } catch (XMLStreamException e) { + throw new IOException(":" + e.toString()); + } finally { + if (xmlStreamReader != null) { + try { + xmlStreamReader.close(); + } catch (XMLStreamException e) { + e.printStackTrace(); + } + } + try { + inputStream.close(); + } catch (IOException e) { + + } + } + } + /** + * Class for storing information about URIs. + */ + private static class Uri + { + + List uris; + + Uri( String baseUri ) + { + uris = new LinkedList(); + uris.add( baseUri ); + } + + String getUriFor( String tag, int depth ) + { + setUrisToDepth( depth ); + StringBuffer sb = new StringBuffer(); + for ( String tagName : uris ) + { + sb.append( tagName ).append( "/" ); + } + sb.append( tag ); + return sb.toString(); + } + + void addTag( String tag ) + { + uris.add( tag ); + } + + void setUrisToDepth( int depth ) + { + uris = new LinkedList( uris.subList( 0, depth ) ); + } + } } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PrerequisitesProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/PrerequisitesProcessor.java index 7c08281b39..eebeccdf64 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PrerequisitesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/Processor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/Processor.java similarity index 96% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/Processor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/Processor.java index 6ddc398213..bf938bdc77 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/Processor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/Processor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; import java.util.List; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProcessorContext.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProcessorContext.java similarity index 58% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ProcessorContext.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ProcessorContext.java index 2bf8e5b437..5080fb378d 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProcessorContext.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProcessorContext.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -47,13 +48,12 @@ import org.apache.maven.model.Resource; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.builder.PomClassicDomainModel; -import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.DomainModel; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.ModelProperty; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; import org.apache.maven.shared.model.ModelEventListener; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.ModelTransformerContext; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -136,7 +136,7 @@ public class ProcessorContext //TODO: Merge Dependency Management target.setDependencyManagement( depMng ); - PomClassicDomainModel targetModel = convertToDomainModel( target, domainModel.isMostSpecialized()); + PomClassicDomainModel targetModel = new PomClassicDomainModel( target, domainModel.isMostSpecialized()); targetModel.setParentFile(domainModel.getParentFile()); targetModel.setProjectDirectory(domainModel.getProjectDirectory()); return targetModel; @@ -179,18 +179,9 @@ public class ProcessorContext } } - else { - InputStream is = ( (PomClassicDomainModel) domainModel ).getInputStream(); - MavenXpp3Reader reader = new MavenXpp3Reader(); - try - { - models.add( reader.read( is ) ); - } - catch ( XmlPullParserException e ) - { - e.printStackTrace(); - throw new IOException( e.getMessage() ); - } + else + { + throw new IOException( "model: null" ); } } @@ -225,7 +216,7 @@ public class ProcessorContext new ContributorsProcessor(), new DevelopersProcessor(), new ProfilesProcessor() ); Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ), processors ); - PomClassicDomainModel domainModel = new PomClassicDomainModel( convertToDomainModel( target, child.isMostSpecialized() ).getModelProperties(), child.isMostSpecialized() ); + PomClassicDomainModel domainModel = new PomClassicDomainModel( target, child.isMostSpecialized() ); domainModel.setProjectDirectory(child.getProjectDirectory()); domainModel.setParentFile(child.getParentFile()); return domainModel; @@ -298,32 +289,6 @@ public class ProcessorContext } - private static PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized ) - throws IOException - { - if ( model == null ) - { - throw new IllegalArgumentException( "model: null" ); - } - - 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(); - } - } - return new PomClassicDomainModel( new ByteArrayInputStream( baos.toByteArray() ), isMostSpecialized ); - } - private static final Map aliases = new HashMap(); private static void addProjectAlias( String element, boolean leaf ) @@ -355,156 +320,6 @@ public class ProcessorContext addProjectAlias( "ciManagement", false ); } - public static void interpolateModelProperties( List modelProperties, - List interpolatorProperties, PomClassicDomainModel dm ) - throws IOException - { - - if(dm == null) - { - throw new IllegalArgumentException("dm: null"); - } - if ( !containsProjectVersion( interpolatorProperties ) ) - { - aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" ); - } - - if("jar".equals( dm.getModel().getPackaging() ) ) - { - modelProperties.add( new ModelProperty(ProjectUri.packaging, "jar") ); - } - - List firstPassModelProperties = new ArrayList(); - List secondPassModelProperties = new ArrayList(); - - ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null ); - for ( ModelProperty mp : modelProperties ) - { - if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) ) - { - if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals( - ProjectUri.Build.finalName ) ) ) - { - firstPassModelProperties.add( mp ); - } - else - { - secondPassModelProperties.add( mp ); - } - } - } - - 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 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() ) ); - } - - for ( ModelProperty mp : modelProperties ) - { - if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null ) - { - String uri = mp.getUri(); - standardInterpolatorProperties.add( new InterpolatorProperty( - "${" - + uri.substring( - uri.lastIndexOf( "/" ) + 1, - uri.length() ) + "}", - mp.getValue(), - PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - } - } - - // FIRST PASS - Withhold using build directories as interpolator properties - List ips1 = new ArrayList( interpolatorProperties ); - ips1.addAll( standardInterpolatorProperties ); - ips1.addAll( ModelTransformerContext.createInterpolatorProperties( - firstPassModelProperties, - ProjectUri.baseUri, - aliases, - PomInterpolatorTag.PROJECT_PROPERTIES.name(), - false, false ) ); - Collections.sort( ips1, new Comparator() - { - public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) - { - if ( o.getTag() == null || o1.getTag() == null ) - { - return 0; - } - return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); - } - } ); - - ModelTransformerContext.interpolateModelProperties( modelProperties, ips1 ); - - // SECOND PASS - Set absolute paths on build directories - - if ( dm.isPomInBuild() ) - { - 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() ); - } - } - - // THIRD PASS - Use build directories as interpolator properties - List ips2 = new ArrayList( interpolatorProperties ); - ips2.addAll( standardInterpolatorProperties ); - ips2.addAll( ModelTransformerContext.createInterpolatorProperties( - secondPassModelProperties, - ProjectUri.baseUri, - aliases, - PomInterpolatorTag.PROJECT_PROPERTIES.name(), - false, false ) ); - ips2.addAll( interpolatorProperties ); - Collections.sort( ips2, new Comparator() - { - public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) - { - if ( o.getTag() == null || o1.getTag() == null ) - { - return 0; - } - - return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); - } - } ); - - ModelTransformerContext.interpolateModelProperties( modelProperties, ips2 ); - } - private static boolean containsProjectVersion( List interpolatorProperties ) { InterpolatorProperty versionInterpolatorProperty = @@ -636,4 +451,408 @@ public class ProcessorContext return p; } + + public static 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 = dm.getModelProperties(); + + if ("jar".equals(dm.getModel().getPackaging())) { + modelProperties.add(new ModelProperty(ProjectUri.packaging, "jar")); + } + + List firstPassModelProperties = new ArrayList(); + List secondPassModelProperties = new ArrayList(); + + ModelProperty buildProperty = new ModelProperty(ProjectUri.Build.xUri, + null); + + for ( ModelProperty mp : modelProperties ) + { + if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) ) + { + if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals( + ProjectUri.Build.finalName ) ) ) + { + firstPassModelProperties.add( mp ); + } + else + { + secondPassModelProperties.add( mp ); + } + } + } + + /* + if ( !buildProperty.isParentOf(mp) && mp.getValue() != null && !mp.getUri().contains("#property") + && !mp.getUri().contains("#collection")) { + if ((!mp.getUri().equals( + ProjectUri.Reporting.outputDirectory) || mp + .getUri().equals(ProjectUri.Build.finalName))) { + firstPassModelProperties.add(mp); + } else { + secondPassModelProperties.add(mp); + } + } + */ + + 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 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())); + } + + for (ModelProperty mp : modelProperties) { + if (mp.getUri().startsWith(ProjectUri.properties) + && mp.getValue() != null) { + String uri = mp.getUri(); + standardInterpolatorProperties.add(new InterpolatorProperty( + "${" + + uri.substring(uri.lastIndexOf("/") + 1, uri + .length()) + "}", mp.getValue(), + PomInterpolatorTag.PROJECT_PROPERTIES.name())); + } + } + + // FIRST PASS - Withhold using build directories as interpolator + // properties + List ips1 = new ArrayList( + interpolatorProperties); + ips1.addAll(standardInterpolatorProperties); + ips1.addAll(createInterpolatorProperties( + firstPassModelProperties, ProjectUri.baseUri, aliases, + PomInterpolatorTag.PROJECT_PROPERTIES.name())); + Collections.sort(ips1, new Comparator() { + public int compare(InterpolatorProperty o, InterpolatorProperty o1) { + if (o.getTag() == null || o1.getTag() == null) { + return 0; + } + return PomInterpolatorTag.valueOf(o.getTag()).compareTo( + PomInterpolatorTag.valueOf(o1.getTag())); + } + }); + + interpolateModelProperties(modelProperties, ips1); + + // SECOND PASS - Set absolute paths on build directories + if (dm.isPomInBuild()) { + 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()); + } + } + + // THIRD PASS - Use build directories as interpolator properties + List ips2 = new ArrayList( + interpolatorProperties); + ips2.addAll(standardInterpolatorProperties); + ips2.addAll(createInterpolatorProperties( + secondPassModelProperties, ProjectUri.baseUri, aliases, + PomInterpolatorTag.PROJECT_PROPERTIES.name())); + ips2.addAll(interpolatorProperties); + Collections.sort(ips2, new Comparator() { + public int compare(InterpolatorProperty o, InterpolatorProperty o1) { + if (o.getTag() == null || o1.getTag() == null) { + return 0; + } + + return PomInterpolatorTag.valueOf(o.getTag()).compareTo( + PomInterpolatorTag.valueOf(o1.getTag())); + } + }); + + interpolateModelProperties(modelProperties, ips2); + + + + if ( dm.getProjectDirectory() != null ) + { + modelProperties = ProcessorContext.alignPaths( modelProperties, dm.getProjectDirectory() ); + } + try + { + String xml = unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); + return new PomClassicDomainModel( new ByteArrayInputStream ( xml.getBytes( "UTF-8" ))); + } + 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)) + { + + } + } + } + */ + } + + public static void interpolateModelProperties(List modelProperties, + List interpolatorProperties ) + { + if (modelProperties == null) { + throw new IllegalArgumentException("modelProperties: null"); + } + + if (interpolatorProperties == null) { + throw new IllegalArgumentException("interpolatorProperties: null"); + } + + List unresolvedProperties = new ArrayList(); + for (ModelProperty mp : modelProperties) { + if (!mp.isResolved()) { + unresolvedProperties.add(mp); + } + } + + LinkedHashSet ips = new LinkedHashSet(); + ips.addAll(interpolatorProperties); + boolean continueInterpolation = true; + while (continueInterpolation) { + continueInterpolation = false; + for (InterpolatorProperty ip : ips) { + for (ModelProperty mp : unresolvedProperties) { + if (mp.resolveWith(ip) && !continueInterpolation) { + continueInterpolation = true; + } + } + } + } + } + + private static List createInterpolatorProperties(List modelProperties, + String baseUriForModel, + Map aliases, + String interpolatorTag) + { + if (modelProperties == null) { + throw new IllegalArgumentException("modelProperties: null"); + } + + if (baseUriForModel == null) { + throw new IllegalArgumentException("baseUriForModel: null"); + } + + List interpolatorProperties = new ArrayList(); + + for (ModelProperty mp : modelProperties) { + InterpolatorProperty ip = mp + .asInterpolatorProperty(baseUriForModel); + if (ip != null) { + ip.setTag(interpolatorTag); + interpolatorProperties.add(ip); + for (Map.Entry a : aliases.entrySet()) { + interpolatorProperties.add(new InterpolatorProperty(ip + .getKey().replaceAll(a.getKey(), a.getValue()), ip + .getValue().replaceAll(a.getKey(), a.getValue()), + interpolatorTag)); + } + } + } + + List ips = new ArrayList(); + for (InterpolatorProperty ip : interpolatorProperties) { + if (!ips.contains(ip)) { + ips.add(ip); + } + } + return ips; + } + + /** + * Returns XML string unmarshalled from the specified list of model properties + * + * @param modelProperties the model properties to unmarshal. May not be null or empty + * @param baseUri the base uri of every model property. May not be null or empty. + * @return XML string unmarshalled from the specified list of model properties + * @throws IOException if there was a problem with unmarshalling + */ + public static String unmarshalModelPropertiesToXml( List modelProperties, String baseUri ) + throws IOException + { + if ( modelProperties == null || modelProperties.isEmpty() ) + { + throw new IllegalArgumentException( "modelProperties: null or empty" ); + } + + if ( baseUri == null || baseUri.trim().length() == 0 ) + { + throw new IllegalArgumentException( "baseUri: null or empty" ); + } + + final int basePosition = baseUri.length(); + + StringBuffer sb = new StringBuffer(); + List lastUriTags = new ArrayList(); + for ( ModelProperty mp : modelProperties ) + { + String uri = mp.getUri(); + if ( uri.contains( "#property" ) ) + { + 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 ); + } + + List tagNames = getTagNamesFromUri( basePosition, uri ); + + for ( int i = lastUriTags.size() - 1; i >= 0 && i >= tagNames.size() - 1; i-- ) + { + sb.append( toEndTag( lastUriTags.get( i ) ) ); + } + + String tag = tagNames.get( tagNames.size() - 1 ); + + List attributes = new ArrayList(); + for(int peekIndex = modelProperties.indexOf( mp ) + 1; peekIndex < modelProperties.size(); peekIndex++) + { + if ( peekIndex <= modelProperties.size() - 1 ) + { + ModelProperty peekProperty = modelProperties.get( peekIndex ); + if ( peekProperty.getUri().contains( "#property" ) ) + { + attributes.add(peekProperty); + } + else + { + break; + } + } + else + { + break; + } + } + + sb.append( toStartTag( tag, attributes ) ); + + if ( mp.getResolvedValue() != null ) + { + sb.append( mp.getResolvedValue() ); + } + + lastUriTags = tagNames; + } + + for ( int i = lastUriTags.size() - 1; i >= 1; i-- ) + { + sb.append( toEndTag( lastUriTags.get( i ) ) ); + } + + return sb.toString(); + } + + /** + * Returns list of tag names parsed from the specified uri. All #collection parts of the tag are removed from the + * tag names. + * + * @param basePosition the base position in the specified URI to start the parse + * @param uri the uri to parse for tag names + * @return list of tag names parsed from the specified uri + */ + private static List getTagNamesFromUri( int basePosition, String uri ) + { + return Arrays.asList( uri.substring( basePosition ).replaceAll( "#collection", "" ) + .replaceAll("#set", "").split( "/" ) ); + } + + /** + * Returns the XML formatted start tag for the specified value and the specified attribute. + * + * @param value the value to use for the start tag + * @param attributes the attribute to use in constructing of start tag + * @return the XML formatted start tag for the specified value and the specified attribute + */ + private static String toStartTag( String value, List attributes ) + { + StringBuffer sb = new StringBuffer(); //TODO: Support more than one attribute + sb.append( "\r\n<" ).append( value ); + if ( attributes != null ) + { + for(ModelProperty attribute : attributes) + { + sb.append( " " ).append( + attribute.getUri().substring( attribute.getUri().indexOf( "#property/" ) + 10 ) ).append( "=\"" ) + .append( attribute.getResolvedValue() ).append( "\" " ); + } + } + sb.append( ">" ); + return sb.toString(); + } + + /** + * Returns XML formatted end tag for the specified value. + * + * @param value the value to use for the end tag + * @return xml formatted end tag for the specified value + */ + private static String toEndTag( String value ) + { + if ( value.trim().length() == 0 ) + { + return ""; + } + StringBuffer sb = new StringBuffer(); + sb.append( "" ); + return sb.toString(); + } + } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilePropertiesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilePropertiesProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilePropertiesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilePropertiesProcessor.java index e542ecdb9c..b7283bf1ba 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilePropertiesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilePropertiesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; import java.util.Properties; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesModuleProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesModuleProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesModuleProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesModuleProcessor.java index d4b6e3417e..9498a48f14 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesModuleProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesModuleProcessor.java @@ -1,4 +1,4 @@ - package org.apache.maven.project.processor; + package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesProcessor.java index 9c9205a410..c647506b29 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ProfilesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProfilesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PropertiesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PropertiesProcessor.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/PropertiesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/PropertiesProcessor.java index e91aa37bc0..7614691170 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/PropertiesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PropertiesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ReportingProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ReportingProcessor.java similarity index 99% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ReportingProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ReportingProcessor.java index 617adbed90..c1e0bf0801 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ReportingProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ReportingProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/RepositoriesProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/RepositoriesProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/RepositoriesProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/RepositoriesProcessor.java index 176a43eb0f..1d8fbb4f2e 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/RepositoriesProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/RepositoriesProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ScmProcessor.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/ScmProcessor.java index ab65aa6661..2fad6eb64d 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ScmProcessor.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.processor; +package org.apache.maven.project.builder; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/DomainModel.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/DomainModel.java new file mode 100644 index 0000000000..cb3ddb4c8e --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/DomainModel.java @@ -0,0 +1,13 @@ +package org.apache.maven.project.builder.interpolator; + +import java.io.IOException; +import java.util.List; + +public interface DomainModel { + + List getModelProperties() throws IOException; + + boolean isMostSpecialized(); + + void setMostSpecialized(boolean isMostSpecialized); +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/InterpolatorProperty.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/InterpolatorProperty.java new file mode 100644 index 0000000000..3bbe425af8 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/InterpolatorProperty.java @@ -0,0 +1,175 @@ +package org.apache.maven.project.builder.interpolator; + +import java.util.*; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Provides interpolator property information. + */ +public final class InterpolatorProperty +{ + /** + * The key (or name) of the property + */ + private final String key; + + /** + * The value of the property + */ + private final String value; + + /** + * Metadata tag (general use) + */ + private String tag; + + + /** + * Constructor + * + * @param key the key (or name) of the property. May not be null + * @param value the value of the property. May not be null. + */ + public InterpolatorProperty( String key, String value ) + { + this(key, value, null); + } + + public InterpolatorProperty( String key, String value, String tag ) + { + if ( key == null ) + { + throw new IllegalArgumentException( "key: null" ); + } + + if ( value == null ) + { + throw new IllegalArgumentException( "value: null" ); + } + this.key = key; + this.value = value; + this.tag = tag; + + } + + /** + * Returns key (or name) of property. + * + * @return key (or name) of property + */ + public String getKey() + { + return key; + } + + /** + * Returns value of property. + * + * @return value of property + */ + public String getValue() + { + return value; + } + + public String getTag() + { + return tag; + } + + public void setTag(String tag) + { + this.tag = tag; + } + public static List toInterpolatorProperties( Map properties, String tag ) + { + if( properties == null ) + { + throw new IllegalArgumentException( "properties: null" ); + } + + List interpolatorProperties = new ArrayList(); + for ( Map.Entry e : properties.entrySet() ) + { + interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", e.getValue(), tag) ); + } + return interpolatorProperties; + } + + /** + * Returns true if key values match, otherwise returns false. + * + * @param o interpolator property to compare + * @return true if key values match, otherwise returns false + */ + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + InterpolatorProperty that = (InterpolatorProperty) o; + + if ( !key.equals( that.key ) ) + { + return false; + } + + return true; + } + + /** + * Returns hash code of interpolator property key. + * + * @return hash code of interpolator property key + */ + public int hashCode() + { + return key.hashCode(); + } + + public String toString() + { + return "Key = " + key + ", Value = " + value + ", Hash = " + + this.hashCode(); + } + + public static List toInterpolatorProperties( Properties properties, String tag ) + { + if( properties == null ) + { + throw new IllegalArgumentException( "properties: null" ); + } + + List interpolatorProperties = new ArrayList(); + for ( Map.Entry e : properties.entrySet() ) + { + interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) ); + } + return interpolatorProperties; + } +} + diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelInterpolator.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelInterpolator.java new file mode 100644 index 0000000000..304ee57d39 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelInterpolator.java @@ -0,0 +1,343 @@ +package org.apache.maven.project.builder.interpolator; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; + +import org.apache.maven.model.Model; +import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.builder.ProjectUri; + +public class ModelInterpolator { + + private HashMap values; + + public ModelInterpolator() + { + values = new HashMap(); + } + + public static void interpolate(PomClassicDomainModel domainModel, List interpolatorProperties ) throws IOException + { + List m = new ArrayList(); + + Model model = domainModel.getModel(); + + m.add(new ModelProperty(ProjectUri.groupId, model.getGroupId())); + m.add(new ModelProperty(ProjectUri.artifactId, model.getArtifactId())); + + interpolateModelProperties(m, interpolatorProperties, domainModel); + //Set model properties on model + + + + //InterpolatorProperty ip = new InterpolatorProperty(); + //ModelProperty mp; + /* + values.put("groupId", model.getGroupId()); + values.put("artifactId", model.getArtifactId()); + values.put("version", model.getVersion()); + values.put("packaging", model.getPackaging()); + values.put("name", model.getName()); + values.put("description", model.getDescription()); + + //Collect uninterpolated values + HashMap hm = new HashMap(); + for(Map.Entry entry : hm.entrySet()) + { + + } + */ + } + + /* + * addProjectAlias( "modelVersion", true ); + addProjectAlias( "groupId", true ); + addProjectAlias( "artifactId", true ); + addProjectAlias( "version", true ); + addProjectAlias( "packaging", true ); + addProjectAlias( "name", true ); + addProjectAlias( "description", true ); + addProjectAlias( "inceptionYear", true ); + addProjectAlias( "url", true ); + addProjectAlias( "parent", false ); + addProjectAlias( "prerequisites", false ); + addProjectAlias( "organization", false ); + addProjectAlias( "build", false ); + addProjectAlias( "reporting", false ); + addProjectAlias( "scm", false ); + addProjectAlias( "distributionManagement", false ); + addProjectAlias( "issueManagement", false ); + addProjectAlias( "ciManagement", false ); + */ + + private static final Map aliases = new HashMap(); + + private static void addProjectAlias( String element, boolean leaf ) + { + String suffix = leaf ? "\\}" : "\\."; + aliases.put( "\\$\\{project\\." + element + suffix, "\\$\\{" + element + suffix ); + } + + static + { + aliases.put( "\\$\\{project\\.", "\\$\\{pom\\." ); + addProjectAlias( "modelVersion", true ); + addProjectAlias( "groupId", true ); + addProjectAlias( "artifactId", true ); + addProjectAlias( "version", true ); + addProjectAlias( "packaging", true ); + addProjectAlias( "name", true ); + addProjectAlias( "description", true ); + addProjectAlias( "inceptionYear", true ); + addProjectAlias( "url", true ); + addProjectAlias( "parent", false ); + addProjectAlias( "prerequisites", false ); + addProjectAlias( "organization", false ); + addProjectAlias( "build", false ); + addProjectAlias( "reporting", false ); + addProjectAlias( "scm", false ); + addProjectAlias( "distributionManagement", false ); + addProjectAlias( "issueManagement", false ); + addProjectAlias( "ciManagement", false ); + } + + private static void interpolateModelProperties( List mps, + List interpolatorProperties, + PomClassicDomainModel dm ) + throws IOException + { + + if(dm == null) + { + throw new IllegalArgumentException("dm: null"); + } + if ( !containsProjectVersion( interpolatorProperties ) ) + { + aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" ); + } + + if("jar".equals( dm.getModel().getPackaging() ) ) + { + mps.add( new ModelProperty(ProjectUri.packaging, "jar") ); + } + + List firstPassModelProperties = new ArrayList(); + List secondPassModelProperties = new ArrayList(); + + ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null ); + for ( ModelProperty mp : mps ) + { + if ( mp.getValue() != null ) + { + //!buildProperty.isParentOf( mp ) && + if ( ( !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals( + ProjectUri.Build.finalName ) ) ) + { + firstPassModelProperties.add( mp ); + } + else + { + secondPassModelProperties.add( mp ); + } + } + } + + 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 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() ) ); + } + + for ( ModelProperty mp : mps ) + { + if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null ) + { + String uri = mp.getUri(); + standardInterpolatorProperties.add( new InterpolatorProperty( + "${" + + uri.substring( + uri.lastIndexOf( "/" ) + 1, + uri.length() ) + "}", + mp.getValue(), + PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + } + } + + // FIRST PASS - Withhold using build directories as interpolator properties + List ips1 = new ArrayList( interpolatorProperties ); + ips1.addAll( standardInterpolatorProperties ); + ips1.addAll(createInterpolatorProperties(firstPassModelProperties, + ProjectUri.baseUri, aliases, + PomInterpolatorTag.PROJECT_PROPERTIES.name())); + Collections.sort( ips1, new Comparator() + { + public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) + { + if ( o.getTag() == null || o1.getTag() == null ) + { + return 0; + } + return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); + } + } ); + + interpolateModelProperties( mps, ips1 ); + + // SECOND PASS - Set absolute paths on build directories + + if ( dm.isPomInBuild() ) + { + 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() ); + } + } + + // THIRD PASS - Use build directories as interpolator properties + List ips2 = new ArrayList( interpolatorProperties ); + ips2.addAll( standardInterpolatorProperties ); + ips2.addAll(createInterpolatorProperties(secondPassModelProperties, + ProjectUri.baseUri, aliases, + PomInterpolatorTag.PROJECT_PROPERTIES.name())); + ips2.addAll( interpolatorProperties ); + Collections.sort( ips2, new Comparator() + { + public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) + { + if ( o.getTag() == null || o1.getTag() == null ) + { + return 0; + } + + return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); + } + } ); + + interpolateModelProperties( mps, ips2 ); + } + + private static void interpolateModelProperties( + List modelProperties, + List interpolatorProperties) { + if (modelProperties == null) { + throw new IllegalArgumentException("modelProperties: null"); + } + + if (interpolatorProperties == null) { + throw new IllegalArgumentException("interpolatorProperties: null"); + } + + List unresolvedProperties = new ArrayList(); + for (ModelProperty mp : modelProperties) { + if (!mp.isResolved()) { + unresolvedProperties.add(mp); + } + } + + LinkedHashSet ips = new LinkedHashSet(); + ips.addAll(interpolatorProperties); + boolean continueInterpolation = true; + while (continueInterpolation) { + continueInterpolation = false; + for (InterpolatorProperty ip : ips) { + for (ModelProperty mp : unresolvedProperties) { + if (mp.resolveWith(ip) && !continueInterpolation) { + continueInterpolation = true; + } + } + } + } + } + + public static List createInterpolatorProperties(List modelProperties, + String baseUriForModel, + Map aliases, + String interpolatorTag) +{ + if (modelProperties == null) { + throw new IllegalArgumentException("modelProperties: null"); + } + + if (baseUriForModel == null) { + throw new IllegalArgumentException("baseUriForModel: null"); + } + + List interpolatorProperties = new ArrayList(); + + for (ModelProperty mp : modelProperties) { + InterpolatorProperty ip = mp + .asInterpolatorProperty(baseUriForModel); + if (ip != null) { + ip.setTag(interpolatorTag); + interpolatorProperties.add(ip); + for (Map.Entry a : aliases.entrySet()) { + interpolatorProperties.add(new InterpolatorProperty(ip + .getKey().replaceAll(a.getKey(), a.getValue()), ip + .getValue().replaceAll(a.getKey(), a.getValue()), + interpolatorTag)); + } + } + } + + List ips = new ArrayList(); + for (InterpolatorProperty ip : interpolatorProperties) { + if (!ips.contains(ip)) { + ips.add(ip); + } + } + return ips; + } + + private static boolean containsProjectVersion( List interpolatorProperties ) + { + InterpolatorProperty versionInterpolatorProperty = + new ModelProperty( ProjectUri.version, "" ).asInterpolatorProperty( ProjectUri.baseUri ); + for ( InterpolatorProperty ip : interpolatorProperties ) + { + if ( ip.equals( versionInterpolatorProperty ) ) + { + return true; + } + } + return false; + } + +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelProperty.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelProperty.java new file mode 100644 index 0000000000..7a9a4ca8af --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/ModelProperty.java @@ -0,0 +1,254 @@ +package org.apache.maven.project.builder.interpolator; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Maps a URI to a string value, which may be null. This class is immutable. + */ +public final class ModelProperty +{ + + /** + * A pattern used for finding pom, project and env properties + */ + private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" ); + + /** + * URI of the resource + */ + private final String uri; + + /** + * Value associated with the uri + */ + private final String value; + + /** + * The count of '/' within this model property's uri, which is the depth of its XML nodes. + */ + private final int depth; + + /** + * Value of this model property after interpolation + */ + private String resolvedValue; + + /** + * List of unresolved expressions within this model property's value + */ + private final List unresolvedExpressions; + + /** + * Constructor + * + * @param uri URI of the resource. May not be null + * @param value Value associated with specified uri. Value may be null if uri does not map to primitive type. + */ + public ModelProperty( String uri, String value ) + { + if ( uri == null ) + { + throw new IllegalArgumentException( "uri" ); + } + this.uri = uri; + this.value = value; + resolvedValue = value; + + unresolvedExpressions = new ArrayList(); + if ( value != null ) + { + Matcher matcher = EXPRESSION_PATTERN.matcher( value ); + while ( matcher.find() ) + { + unresolvedExpressions.add( matcher.group( 0 ) ); + } + } + + String uriWithoutProperty; + int index = uri.lastIndexOf( "/" ); + if(index > -1) { + uriWithoutProperty = uri.substring( 0, uri.lastIndexOf( "/" ) ); + if(uriWithoutProperty.endsWith("#property") || uriWithoutProperty.endsWith("combine.children") ) + { + uriWithoutProperty = uriWithoutProperty.substring( 0, uriWithoutProperty.lastIndexOf( "/" ) ); + } + } + else + { + uriWithoutProperty = uri; + } + + depth = uriWithoutProperty.split( "/" ).length; + } + + /** + * Returns URI key + * + * @return URI key + */ + public String getUri() + { + return uri; + } + + /** + * Returns value for the URI key. Value may be null. + * + * @return value for the URI key. Value may be null + */ + public String getValue() + { + return value; + } + + /** + * Value of this model property after interpolation. CDATA section will be added if needed. + * + * @return value of this model property after interpolation + */ + public String getResolvedValue() + { + if( !uri.contains("#property") && resolvedValue != null && !resolvedValue.startsWith (""; + } + return resolvedValue; + } + + /** + * Returns true if model property is completely interpolated, otherwise returns false. + * + * @return true if model property is completely interpolated, otherwise returns false + */ + public boolean isResolved() + { + return unresolvedExpressions.isEmpty(); + } + + /** + * Returns copy of the uninterpolated model property + * + * @return copy of the uninterpolated model property + */ + public ModelProperty createCopyOfOriginal() + { + return new ModelProperty( uri, value ); + } + + /** + * Returns the count of '/' within this model property's uri, which is the depth of its XML nodes. + * + * @return the count of '/' within this model property's uri, which is the depth of its XML nodes + */ + public int getDepth() + { + return depth; + } + + /** + * Returns true if this model property is a direct parent of the specified model property, otherwise returns false. + * + * @param modelProperty the model property + * @return true if this model property is a direct parent of the specified model property, otherwise returns false + */ + public boolean isParentOf( ModelProperty modelProperty ) + { + if ( Math.abs( depth - modelProperty.getDepth() ) > 1 ) + { + return false; + } + if ( uri.equals( modelProperty.getUri() ) || uri.startsWith( modelProperty.getUri() ) ) + { + return false; + } + return ( modelProperty.getUri().startsWith( uri ) ); + } + + /** + * Returns this model property as an interpolator property, allowing the interpolation of model elements within + * other model elements. + * + * @param baseUri the base uri of the model property + * @return this model property as an interpolator property, allowing the interpolation of model elements within + * other model elements + */ + public InterpolatorProperty asInterpolatorProperty( String baseUri ) + { + if ( uri.contains( "#collection" ) || uri.contains("#set") || value == null ) + { + return null; + } + String key = "${" + uri.replace( baseUri + "/", "" ).replace( "/", "." ) + "}"; + return new InterpolatorProperty( key, value ); + } + + /** + * Resolves any unresolved model property expressions using the specified interpolator property + * + * @param property the interpolator property used to resolve + */ + public boolean resolveWith( InterpolatorProperty property ) + { + if ( property == null ) + { + throw new IllegalArgumentException( "property: null" ); + } + if ( isResolved() ) + { + return false; + } + boolean resolved = false; + for ( String expression : unresolvedExpressions ) + { + if ( property.getKey().equals( expression ) ) + { + resolved = true; + resolvedValue = resolvedValue.replace( property.getKey(), property.getValue() ); + unresolvedExpressions.clear(); + Matcher matcher = EXPRESSION_PATTERN.matcher( resolvedValue ); + while ( matcher.find() ) + { + unresolvedExpressions.add( matcher.group( 0 ) ); + } + break; + } + } + return resolved; + } + + public String toCode() { + String val = (value != null) ? "\"" + value + "\"" : null; + return "mpz.add(new ModelProperty(\"" + uri + "\", " + val +"));"; + } + + public String toString() + { + return "Uri = " + uri + ", Value = " + value + ", Resolved Value = " + resolvedValue + ", Hash = " + + this.hashCode(); + } +} + + diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/PomInterpolatorTag.java similarity index 66% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/PomInterpolatorTag.java index 5f7693550e..747011f0c6 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomInterpolatorTag.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/interpolator/PomInterpolatorTag.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.interpolator; public enum PomInterpolatorTag diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java deleted file mode 100644 index 077d3df6d2..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.apache.maven.project.builder; - -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.InputStreamDomainModel; - -import java.util.List; -import java.io.IOException; -import java.io.File; -import java.io.InputStream; - -public class DefaultDomainModel extends PomClassicDomainModel { - - private List modelProperties; - - public DefaultDomainModel(List modelProperties, boolean isMostSpecialized) { - super( modelProperties, isMostSpecialized); - this.modelProperties = modelProperties; - } - - public List getModelProperties() throws IOException { - return modelProperties; - } - - public String getEventHistory() { - return ""; - } - - public void setEventHistory(String s) { - - } - - public boolean isPomInBuild() { - return false; - } - - public File getProjectDirectory() { - return null; - } - - public InputStream getInputStream() { - return null; - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java deleted file mode 100644 index da3814e2d9..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.maven.project.builder; - -import org.apache.maven.shared.model.DomainModelFactory; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.ModelProperty; - -import java.util.List; -import java.io.IOException; - -public class DefaultDomainModelFactory implements DomainModelFactory { - public DomainModel createDomainModel(List modelProperties) throws IOException { - return new DefaultDomainModel(modelProperties, false); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java deleted file mode 100644 index 8583c03d3a..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.maven.project.builder; - -import org.apache.maven.shared.model.*; -import org.apache.maven.shared.model.impl.DefaultModelDataSource; - -import java.util.List; -import java.util.ArrayList; -import java.util.Arrays; -import java.io.IOException; - -import static org.junit.Assert.*; - -public class EnforcerPomTest -{ - @org.junit.Test - public void dependencyManagementWithScopeAndClassifier() throws IOException - { - List mp = new ArrayList(); - mp.add(new ModelProperty(ProjectUri.xUri, null)); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.xUri, null)); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.xUri, null)); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null)); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.scope, "test")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.classifier, "tests")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null)); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid")); - mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1")); - - List mp2 = new ArrayList(); - mp2.add(new ModelProperty(ProjectUri.xUri, null)); - mp2.add(new ModelProperty(ProjectUri.Dependencies.xUri, null)); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null)); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid")); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid")); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null)); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid")); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid")); - mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.classifier, "tests")); - - DomainModel childModel = new DefaultDomainModel(mp2, true); - DomainModel parentModel = new DefaultDomainModel(mp, false); - - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); - - ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory()); - DomainModel domainModel = ctx.transform( Arrays.asList(childModel, parentModel), transformer, transformer ); - - DefaultModelDataSource source = new DefaultModelDataSource( domainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES); - - List containers = source.queryFor(ProjectUri.Dependencies.Dependency.xUri); - assertTrue(containers.size() == 2 ); - - ModelContainer mc0 = containers.get(0); - assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc0)); - assertFalse(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc0)); - - ModelContainer mc1 = containers.get(1); - assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", mc1)); - assertTrue(contains(ProjectUri.Dependencies.Dependency.classifier, "tests", mc1)); - } - - private boolean contains(String name, String value, ModelContainer modelContainer) { - for(ModelProperty mp : modelContainer.getProperties()) { - if(mp.getUri().equals(name) && mp.getValue() != null && mp.getValue().equals(value)) { - return true; - } - } - return false; - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java deleted file mode 100644 index ebefb8b46d..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.apache.maven.project.builder; - -import static org.junit.Assert.*; -import org.apache.maven.shared.model.*; -import org.apache.maven.shared.model.impl.DefaultModelDataSource; -import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory; - -import java.util.List; -import java.util.ArrayList; -import java.util.Arrays; -import java.io.IOException; - -public class PluginSpecTest { - - @org.junit.Test - public void goalsInherited() throws IOException { - - List mp0 = new ArrayList(); - mp0.add(new ModelProperty(ProjectUri.xUri, null)); - mp0.add(new ModelProperty(ProjectUri.Build.xUri, null)); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null)); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null)); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null)); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello")); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin")); - mp0.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1")); - - List mp = new ArrayList(); - mp.add(new ModelProperty(ProjectUri.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.groupId, "org.codehaus.modello")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.artifactId, "modello-maven-plugin")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.version, "v1")); - - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "site-docs")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.phase, "phase")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xdoc")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xsd")); - - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.id, "standard")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.xURI, null)); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-reader")); - mp.add(new ModelProperty(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal, "xpp3-writer")); - - DomainModel parentModel = new DefaultDomainModel(mp, false); - - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); - - ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory()); - DomainModel domainModel = ctx.transform( Arrays.asList(parentModel, new DefaultDomainModel(mp0, true)), transformer, transformer ); - - - List factories = new ArrayList(PomTransformer.MODEL_CONTAINER_FACTORIES); - factories.add(new PluginExecutionIdModelContainerFactory()); - DefaultModelDataSource source = new DefaultModelDataSource(domainModel.getModelProperties(), factories); - - List containers = source.queryFor(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.xUri); - assertTrue(2 == containers.size()); - - int numberOfGoals = 0; - for(ModelProperty x : containers.get(0).getProperties()) - { - if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal)) - { - numberOfGoals++; - } - } - assertTrue(numberOfGoals == 2); - - numberOfGoals = 0; - for(ModelProperty x : containers.get(1).getProperties()) - { - if(x.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.Execution.Goals.goal)) - { - numberOfGoals++; - } - } - assertTrue(numberOfGoals == 2); - - // System.out.println(ModelMarshaller.unmarshalModelPropertiesToXml(domainModel.getModelProperties(), ProjectUri.baseUri)); - - - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java deleted file mode 100644 index d3311eb380..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.project.builder.profile; - -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelContainerAction; -import org.apache.maven.shared.model.ModelProperty; - -import java.util.ArrayList; -import java.util.List; - - -public class DefaultModelContainer implements ModelContainer -{ - - List modelProperties; - - public DefaultModelContainer(List properties) { - this.modelProperties = properties; - } - - public List getProperties() { - return new ArrayList(modelProperties); - } - - public ModelContainerAction containerAction(ModelContainer modelContainer) { - return null; - } - - public ModelContainer createNewInstance(List modelProperties) { - return null; - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java deleted file mode 100644 index a64f436957..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.apache.maven.project.builder.profile; - -import org.apache.maven.project.builder.profile.FileMatcher; -import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelProperty; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class FileMatcherTest { - - private static String basedir = System.getProperty("basedir"); - - @org.junit.Test(expected=IllegalArgumentException.class) - public void modelContainerIsNull() { - FileMatcher matcher = new FileMatcher(); - matcher.isMatch(null, new ArrayList()); - } - - @org.junit.Test - public void fileExistActivationAndExists() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.exists , - new File(basedir, "src/test/resources/test.txt").getAbsolutePath())); - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - FileMatcher matcher = new FileMatcher(); - assertTrue(matcher.isMatch(modelContainer, new ArrayList())); - } - - @org.junit.Test - public void fileExistActivationButDoesNotExist() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.exists , - new File(basedir, "src/test/resources/bogus.txt").getAbsolutePath())); - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - FileMatcher matcher = new FileMatcher(); - assertFalse(matcher.isMatch(modelContainer, new ArrayList())); - } - - @org.junit.Test - public void fileMissingActivationButExists() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.missing , - new File(basedir, "src/test/resources/test.txt").getAbsolutePath())); - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - FileMatcher matcher = new FileMatcher(); - assertFalse(matcher.isMatch(modelContainer, new ArrayList())); - } - - @org.junit.Test - public void fileMissingActivationAndDoesNotExist() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.File.missing , - new File(basedir, "src/test/resources/bogus.txt").getAbsolutePath())); - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - FileMatcher matcher = new FileMatcher(); - assertTrue(matcher.isMatch(modelContainer, new ArrayList())); - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java deleted file mode 100644 index 610aa99f51..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java +++ /dev/null @@ -1,228 +0,0 @@ -package org.apache.maven.project.builder.profile; - -import org.apache.maven.project.builder.profile.JdkMatcher; -import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelProperty; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -public class JdkMatcherTest { - - @org.junit.Test(expected=IllegalArgumentException.class) - public void modelContainerIsNull() { - JdkMatcher matcher = new JdkMatcher(); - matcher.isMatch(null, new ArrayList()); - } - - @org.junit.Test - public void jdkVersionMatches() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionPrefixMatches() - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.jdk, "1.5" ) ); - - ModelContainer modelContainer = new DefaultModelContainer( modelProperties ); - - List props = new ArrayList(); - props.add( new InterpolatorProperty( "${java.specification.version}", "1.5.2" ) ); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue( matcher.isMatch( modelContainer, props ) ); - } - - @org.junit.Test - public void jdkVersionDoesNotMatchWithNotSymbol() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(!matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionDoesMatchWithNotSymbol() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "!1.5")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.6")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - - @org.junit.Test - public void jdkVersionNotMatches() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.4")); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_ClosedEdge() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "[1.5,")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenEdge() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.5,")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenEdge2() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.4,")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenEdgeWithPadding() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "(1.5.0,")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenRightEdge() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ", 1.6)")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenRightEdge2() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ",1.5)")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionRange_OpenRightEdgeWithWhiteSpace() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , ", 1.5)")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${java.specification.version}" , "1.5")); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void jdkVersionNotFound() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.jdk , "1.5")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - JdkMatcher matcher = new JdkMatcher(); - assertFalse(matcher.isMatch(modelContainer, new ArrayList())); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java deleted file mode 100644 index 01cf5dc762..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.apache.maven.project.builder.profile; - -import org.apache.maven.project.builder.profile.ProfileContext; -import org.apache.maven.project.builder.PomTransformer; -import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.shared.model.DataSourceException; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.impl.DefaultModelDataSource; -import org.junit.Test; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class ProfileContextTest { - - @Test - public void getActiveProfiles() throws DataSourceException { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo")); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bar")); - - DefaultModelDataSource dataSource = new DefaultModelDataSource(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); - - List interpolatorProperties = new ArrayList(); - interpolatorProperties.add(new InterpolatorProperty( "${foo}", "bar")); - - ProfileContext ctx = new ProfileContext(dataSource, null, null, interpolatorProperties); - - Collection profiles = ctx.getActiveProfiles(); - - assertTrue(profiles.size() == 1); - - } - - @Test - public void getActiveProfilesById() throws DataSourceException { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.id , "test")); - - DefaultModelDataSource dataSource = new DefaultModelDataSource(modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); - - List interpolatorProperties = new ArrayList(); - - ProfileContext ctx = new ProfileContext(dataSource, Arrays.asList("test"), null, interpolatorProperties); - - Collection profiles = ctx.getActiveProfiles(); - - assertTrue(profiles.size() == 1); - - } - - @Test - public void getActiveByDefaultProfilesOnlyActivatedIfNoOtherPomProfilesAreActive() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( ProjectUri.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "default" ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.activeByDefault, "true" ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "explicit" ) ); - - DefaultModelDataSource dataSource = - new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); - - List interpolatorProperties = new ArrayList(); - - ProfileContext ctx = new ProfileContext( dataSource, Arrays.asList( "explicit" ), null, interpolatorProperties ); - - Collection profiles = ctx.getActiveProfiles(); - - assertEquals( 1, profiles.size() ); - assertProperty( profiles.iterator().next().getProperties(), ProjectUri.Profiles.Profile.id, "explicit" ); - } - - @Test - public void getDeactivateProfiles() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( ProjectUri.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.id, "default" ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.xUri, null ) ); - modelProperties.add( new ModelProperty( ProjectUri.Profiles.Profile.Activation.activeByDefault, "true" ) ); - - DefaultModelDataSource dataSource = - new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); - - List interpolatorProperties = new ArrayList(); - - ProfileContext ctx = new ProfileContext( dataSource, null, Arrays.asList( "default" ), interpolatorProperties ); - - Collection profiles = ctx.getActiveProfiles(); - - assertEquals( 0, profiles.size() ); - } - - private void assertProperty( Collection properties, String uri, String value ) - { - for ( ModelProperty property : properties ) - { - if ( uri.equals( property.getUri() ) && value.equals( property.getValue() ) ) - { - return; - } - } - fail( "missing model property " + uri + " = " + value ); - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java deleted file mode 100644 index 1ee0590753..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apache.maven.project.builder.profile; - -import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelProperty; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - - -public class PropertyMatcherTest { - - @org.junit.Test - public void propertyMatches() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo")); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bar")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${foo}" , "bar")); - - PropertyMatcher matcher = new PropertyMatcher(); - assertTrue(matcher.isMatch(modelContainer, props)); - } - - @org.junit.Test - public void propertyDoesNotMatch() { - List modelProperties = new ArrayList(); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.xUri, null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null)); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo")); - modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bars")); - - ModelContainer modelContainer = new DefaultModelContainer(modelProperties); - - List props = new ArrayList(); - props.add(new InterpolatorProperty("${foo}" , "bar")); - - PropertyMatcher matcher = new PropertyMatcher(); - assertFalse(matcher.isMatch(modelContainer, props)); - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java deleted file mode 100644 index 69aeacb0b2..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/rules/ExecutionRuleTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.maven.project.builder.rules; - -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.project.builder.ProjectUri; - -import java.io.IOException; -import java.util.List; -import java.util.Arrays; - -public class ExecutionRuleTest { - - @org.junit.Test - public void execute() throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri, null), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-a"), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "parent-b"), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, null), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-b"), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "merged"), - new ModelProperty(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal, "child-a")); - - List mps = new ExecutionRule().execute(modelProperties); - for(ModelProperty mp : mps) { - //System.out.println(mp); - } - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/BuildProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/BuildProcessorTest.java deleted file mode 100644 index 6a07e83cb6..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/BuildProcessorTest.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; - -import org.apache.maven.model.Build; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.model.Resource; - -import junit.framework.TestCase; - -public class BuildProcessorTest extends TestCase -{ - - public void testPluginManagementInheritance() - { - Model parent = new Model(); - - PluginManagement pm = new PluginManagement(); - Plugin p = new Plugin(); - p.setArtifactId( "aid" ); - pm.addPlugin( p ); - Build b = new Build(); - b.setPluginManagement( pm ); - parent.setBuild( b ); - - Model child = new Model(); - Model target = new Model(); - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, true); - - assertNotNull(target.getBuild()); - assertNotNull(target.getBuild().getPluginManagement()); - assertEquals(1, target.getBuild().getPluginManagement().getPlugins().size()); - } - - public void testChild_FinalName() - { - Model child = new Model(); - child.setBuild( new Build() ); - child.getBuild().setFinalName( "name" ); - Model target = new Model(); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( null, child, target, false ); - - assertEquals("name", target.getBuild().getFinalName()); - - child.getBuild().setFinalName( "name2" ); - assertEquals("name", target.getBuild().getFinalName()); - } - - public void testParent_FinalName() - { - Model child = new Model(); - Model parent = new Model(); - parent.setBuild( new Build() ); - parent.getBuild().setFinalName( "name" ); - Model target = new Model(); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, false ); - - assertEquals("name", target.getBuild().getFinalName()); - - //Immutable - parent.getBuild().setFinalName( "name2" ); - assertEquals("name", target.getBuild().getFinalName()); - - } - - public void testParent_Filters() - { - Model child = new Model(); - - Model parent = new Model(); - parent.setBuild( new Build() ); - - parent.getBuild().getFilters().add( "filter1" ); - Model target = new Model(); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, false ); - - assertEquals(1, target.getBuild().getFilters().size()); - assertEquals("filter1", target.getBuild().getFilters().get( 0 )); - - } - - public void testChild_Filters() - { - Model child = new Model(); - child.setBuild( new Build() ); - child.getBuild().getFilters().add( "filter1" ); - Model target = new Model(); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( null, child, target, false ); - - assertEquals(1, target.getBuild().getFilters().size()); - assertEquals("filter1", target.getBuild().getFilters().get( 0 )); - - } - public void testJoin_Filters() - { - Model child = new Model(); - child.setBuild( new Build() ); - child.getBuild().getFilters().add( "filter1" ); - Model target = new Model(); - - Model parent = new Model(); - parent.setBuild( new Build() ); - - parent.getBuild().getFilters().add( "filter2" ); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, false ); - - assertEquals(2, target.getBuild().getFilters().size()); - - //ORDER - assertEquals("filter1", target.getBuild().getFilters().get( 0 )); - assertEquals("filter2", target.getBuild().getFilters().get( 1 )); - } - - public void testJoin_DuplicateFilters() - { - Model child = new Model(); - child.setBuild( new Build() ); - child.getBuild().getFilters().add( "filter" ); - Model target = new Model(); - - Model parent = new Model(); - parent.setBuild( new Build() ); - - parent.getBuild().getFilters().add( "filter" ); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, false ); - - assertEquals(1, target.getBuild().getFilters().size()); - - assertEquals("filter", target.getBuild().getFilters().get( 0 )); - } - - public void testDoNotInheritParentIfChildExists_Resources() - { - Resource r = new Resource(); - r.setDirectory( "dir" ); - - Resource r1 = new Resource(); - r1.setDirectory( "dir1" ); - - Model child = new Model(); - child.setBuild( new Build() ); - child.getBuild().getResources().add( r ); - - Model target = new Model(); - - Model parent = new Model(); - parent.setBuild( new Build() ); - - parent.getBuild().getResources().add( r1 ); - - BuildProcessor proc = new BuildProcessor(new ArrayList()); - proc.process( parent, child, target, false ); - - assertEquals(1, target.getBuild().getResources().size()); - assertEquals("dir", target.getBuild().getResources().get( 0 ).getDirectory()); - - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/CiManagementProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/CiManagementProcessorTest.java deleted file mode 100644 index edfc0b2c8f..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/CiManagementProcessorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.Properties; - -import junit.framework.TestCase; - -import org.apache.maven.model.CiManagement; -import org.apache.maven.model.Model; -import org.apache.maven.model.Notifier; - -public class CiManagementProcessorTest - extends TestCase -{ - public void testChildCopy() - { - CiManagement mng = new CiManagement(); - mng.setSystem( "system" ); - mng.setUrl( "uri" ); - - Notifier notifier = new Notifier(); - notifier.setAddress( "address" ); - notifier.setType( "type" ); - Properties prop = new Properties(); - prop.put( "key", "value" ); - notifier.setConfiguration( prop ); - mng.addNotifier( notifier ); - - Model child = new Model(); - child.setCiManagement( mng ); - - Model target = new Model(); - - CiManagementProcessor proc = new CiManagementProcessor(); - proc.process( null, child, target, false ); - - assertEquals( "system", target.getCiManagement().getSystem() ); - assertEquals( "uri", target.getCiManagement().getUrl() ); - assertEquals( 1, target.getCiManagement().getNotifiers().size() ); - assertEquals( "address", target.getCiManagement().getNotifiers().get( 0 ).getAddress() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependenciesProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependenciesProcessorTest.java deleted file mode 100644 index e004e558b1..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependenciesProcessorTest.java +++ /dev/null @@ -1,168 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; - -import junit.framework.TestCase; - -public class DependenciesProcessorTest - extends TestCase -{ - public void testCopyChild() - { - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid" ); - - List child = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( null, child, target, false ); - - assertEquals( 1, target.size() ); - assertEquals( "aid", target.get( 0 ).getArtifactId() ); - } - - public void testParentCopy() - { - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid" ); - - List child = new ArrayList(); - - List parent = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 1, target.size() ); - assertEquals( "aid", target.get( 0 ).getArtifactId() ); - } -/**FIX - public void testDependencyOrder() - { - Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "aid1" ); - List child = Arrays.asList( dependency1 ); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid" ); - List parent = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 2, target.size() ); - assertEquals( "aid1", target.get( 0 ).getArtifactId() ); - assertEquals( "aid", target.get( 1 ).getArtifactId() ); - } -*/ - public void testJoin_NullVersion() - { - Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "aid-c" ); - dependency1.setGroupId( "gid-c" ); - - List child = Arrays.asList( dependency1 ); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid-c" ); - dependency.setGroupId( "gid-c" ); - dependency.setSystemPath( "sp" ); - - List parent= Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 1, target.size() ); - assertEquals( "sp", target.get( 0 ).getSystemPath() ); - } - - public void testJoin_DefaultType() - { - Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "aid-c" ); - dependency1.setGroupId( "gid-c" ); - dependency1.setVersion( "1.0" ); - dependency1.setType( "jar" ); - List child = Arrays.asList( dependency1 ); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid-c" ); - dependency.setGroupId( "gid-c" ); - dependency.setVersion( "1.0" ); - dependency.setSystemPath( "sp" ); - - List parent = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 1, target.size() ); - assertEquals( "sp", target.get( 0 ).getSystemPath() ); - } - - public void testJoin_DifferentClassifiers() - { - Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "aid-c" ); - dependency1.setGroupId( "gid-c" ); - dependency1.setVersion( "1.0" ); - dependency1.setClassifier( "c1" ); - - List child = Arrays.asList( dependency1 ); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid-c" ); - dependency.setGroupId( "gid-c" ); - dependency.setVersion( "1.0" ); - dependency1.setClassifier( "c2" ); - - List parent = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 2, target.size() ); - } - - public void testJoin_DifferentVersions() - { - Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "aid-c" ); - dependency1.setGroupId( "gid-c" ); - dependency1.setVersion( "1.1" ); - - List child = Arrays.asList( dependency1 ); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid-c" ); - dependency.setGroupId( "gid-c" ); - dependency.setVersion( "1.0" ); - - List parent = Arrays.asList( dependency ); - - List target = new ArrayList(); - - DependenciesProcessor processor = new DependenciesProcessor(); - processor.process( parent, child, target, false ); - - assertEquals( 1, target.size() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependencyProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependencyProcessorTest.java deleted file mode 100644 index db166b9238..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/DependencyProcessorTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Exclusion; - -import junit.framework.TestCase; - -public class DependencyProcessorTest - extends TestCase -{ - public void testCopyChild() - { - DependencyProcessor processor = new DependencyProcessor(); - List dependencies = new ArrayList(); - Dependency child = new Dependency(); - child.setArtifactId( "aid" ); - - processor.process( null, child, dependencies, false ); - assertEquals( 1, dependencies.size() ); - - // Immutable - child.setArtifactId( "aid2" ); - assertEquals( "aid", dependencies.get( 0 ).getArtifactId() ); - } - - public void testCopyParent() - { - DependencyProcessor processor = new DependencyProcessor(); - List dependencies = new ArrayList(); - Dependency parent = new Dependency(); - parent.setArtifactId( "aid" ); - - processor.process( parent, null, dependencies, false ); - assertEquals( 1, dependencies.size() ); - - // Immutable - parent.setArtifactId( "aid2" ); - assertEquals( "aid", dependencies.get( 0 ).getArtifactId() ); - } -/**FIX - public void testJoinChildOverridesParent() - { - DependencyProcessor processor = new DependencyProcessor(); - List dependencies = new ArrayList(); - Dependency child = new Dependency(); - child.setArtifactId( "aid" ); - - Dependency parent = new Dependency(); - parent.setArtifactId( "aid2" ); - - processor.process( parent, child, dependencies, false ); - assertEquals( 1, dependencies.size() ); - - assertEquals( "aid", dependencies.get( 0 ).getArtifactId() ); - - // Immutable - child.setArtifactId( "aid3" ); - assertEquals( "aid", dependencies.get( 0 ).getArtifactId() ); - } -*/ - public void testJoinElements() - { - DependencyProcessor processor = new DependencyProcessor(); - List dependencies = new ArrayList(); - Dependency child = new Dependency(); - child.setArtifactId( "aid" ); - - Dependency parent = new Dependency(); - parent.setGroupId( "gid" ); - - processor.process( parent, child, dependencies, false ); - assertEquals( 1, dependencies.size() ); - - assertEquals( "aid", dependencies.get( 0 ).getArtifactId() ); - assertEquals( "gid", dependencies.get( 0 ).getGroupId() ); - - } -/* - public void testExclusionJoin() - { - DependencyProcessor processor = new DependencyProcessor(); - List dependencies = new ArrayList(); - - Exclusion e = new Exclusion(); - e.setArtifactId( "aid" ); - e.setGroupId( "gid" ); - - Dependency child = new Dependency(); - child.addExclusion( e ); - - Exclusion e1 = new Exclusion(); - e1.setArtifactId( "aid1" ); - e1.setGroupId( "gid1" ); - Dependency parent = new Dependency(); - parent.addExclusion( e1 ); - - processor.process( parent, child, dependencies, false ); - assertEquals( 2, dependencies.get( 0 ).getExclusions().size() ); - assertEquals( "aid", dependencies.get( 0 ).getExclusions().get( 0 ).getArtifactId() ); - assertEquals( "aid1", dependencies.get( 0 ).getExclusions().get( 1 ).getArtifactId() ); - } - */ -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java deleted file mode 100644 index eabfa5ee87..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.apache.maven.project.processor; - -import org.apache.maven.model.IssueManagement; -import org.apache.maven.model.Model; - -import junit.framework.TestCase; - -public class IssueManagementProcessorTest - extends TestCase -{ - public void testChildCopy() - { - IssueManagement mng = new IssueManagement(); - mng.setSystem( "system" ); - mng.setUrl( "http://url" ); - - Model child = new Model(); - child.setIssueManagement( mng ); - - Model target = new Model(); - - IssueManagementProcessor proc = new IssueManagementProcessor(); - proc.process( null, child, target, false ); - - assertEquals( "system", target.getIssueManagement().getSystem() ); - assertEquals( "http://url", target.getIssueManagement().getUrl() ); - } - - /** - * If child does not have issue management node, then use parent. - */ - public void testParentCopy() - { - IssueManagement mng = new IssueManagement(); - mng.setSystem( "system" ); - mng.setUrl( "http://url" ); - - Model child = new Model(); - - Model parent = new Model(); - ; - parent.setIssueManagement( mng ); - - Model target = new Model(); - - IssueManagementProcessor proc = new IssueManagementProcessor(); - proc.process( parent, child, target, false ); - - assertEquals( "system", target.getIssueManagement().getSystem() ); - assertEquals( "http://url", target.getIssueManagement().getUrl() ); - } - - public void testChildCopy_DontInheritParent() - { - IssueManagement mng = new IssueManagement(); - mng.setSystem( "system" ); - mng.setUrl( "http://url" ); - - Model child = new Model(); - child.setIssueManagement( mng ); - - IssueManagement mng1 = new IssueManagement(); - Model parent = new Model(); - ; - mng1.setSystem( "system-1" ); - mng1.setUrl( "http://url-1" ); - parent.setIssueManagement( mng1 ); - - Model target = new Model(); - - IssueManagementProcessor proc = new IssueManagementProcessor(); - proc.process( parent, child, target, false ); - - assertEquals( "system", target.getIssueManagement().getSystem() ); - assertEquals( "http://url", target.getIssueManagement().getUrl() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/MailingListProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/MailingListProcessorTest.java deleted file mode 100644 index bef5e6abff..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/MailingListProcessorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.project.processor; - -import org.apache.maven.model.MailingList; -import org.apache.maven.model.Model; - -import junit.framework.TestCase; - -public class MailingListProcessorTest - extends TestCase -{ - public void testChildCopy() - { - Model child = new Model(); - - MailingList list = new MailingList(); - list.setArchive( "archive" ); - list.setPost( "post" ); - - child.getMailingLists().add( list ); - - Model target = new Model(); - - MailingListProcessor proc = new MailingListProcessor(); - proc.process( null, child, target, false ); - - assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() ); - - list.setArchive( "aaa" ); - assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() ); - } - - public void testParentCopy() - { - Model child = new Model(); - - Model parent = new Model(); - - MailingList list = new MailingList(); - list.setArchive( "archive" ); - list.setPost( "post" ); - - parent.getMailingLists().add( list ); - - Model target = new Model(); - - MailingListProcessor proc = new MailingListProcessor(); - proc.process( parent, child, target, false ); - - assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() ); - - list.setArchive( "aaa" ); - assertEquals( "archive", target.getMailingLists().get( 0 ).getArchive() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModelProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModelProcessorTest.java deleted file mode 100644 index bd92b6f07b..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModelProcessorTest.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.model.Model; -import org.apache.maven.model.Parent; - -public class ModelProcessorTest - extends TestCase -{ - public void testModelProcessorVersion() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setVersion( "1.0" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "1.0", targetModel.getVersion() ); - } - - public void testModelProcessorVersionFromParent() - { - Model targetModel = new Model(); - Model childModel = new Model(); - - Parent parent = new Parent(); - parent.setVersion( "1.0" ); - childModel.setParent( parent ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "1.0", targetModel.getVersion() ); - } - - public void testModelProcessorGroupId() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setGroupId( "gid" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "gid", targetModel.getGroupId() ); - } - - public void testModelProcessorGroupIdFromParent() - { - Model targetModel = new Model(); - Model childModel = new Model(); - - Parent parent = new Parent(); - parent.setGroupId( "gid" ); - childModel.setParent( parent ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "gid", targetModel.getGroupId() ); - } - - public void testModelVersion() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setModelVersion( "4.0" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "4.0", targetModel.getModelVersion() ); - } - - public void testPackaging() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setPackaging( "pom" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "pom", targetModel.getPackaging() ); - } - - public void testNameSpecialized() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setName( "name" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, true ); - assertEquals( "name", targetModel.getName() ); - } - - public void testNameNotSpecialized() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setName( "name" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertNull( targetModel.getName() ); - } - - public void testDescriptionSpecialized() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setDescription( "description" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, true ); - assertEquals( "description", targetModel.getDescription() ); - } - - public void testInceptionYearFromChild() - { - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setInceptionYear( "2000" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, childModel, targetModel, false ); - assertEquals( "2000", targetModel.getInceptionYear() ); - - childModel.setInceptionYear( "2001" ); - assertEquals( "2000", targetModel.getInceptionYear() ); - } - - public void testInceptionYearFromParent() - { - Model targetModel = new Model(); - - Model childModel = new Model(); - - Model parentModel = new Model(); - parentModel.setInceptionYear( "2000" ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( parentModel, childModel, targetModel, false ); - assertEquals( "2000", targetModel.getInceptionYear() ); - - parentModel.setInceptionYear( "2001" ); - assertEquals( "2000", targetModel.getInceptionYear() ); - } - - public void testDependencyManagementChildCopy() - { - Model target= new Model(); - - Model child = new Model(); - - Dependency dependency = new Dependency(); - dependency.setArtifactId( "aid" ); - - DependencyManagement mng = new DependencyManagement(); - mng.addDependency( dependency ); - - child.setDependencyManagement( mng ); - - ModelProcessor mp = new ModelProcessor( new ArrayList() ); - mp.process( null, child, target, false ); - - assertNotNull(target.getDependencyManagement()); - - assertEquals(1, target.getDependencyManagement().getDependencies().size()); - assertEquals("aid", target.getDependencyManagement().getDependencies().get( 0 ).getArtifactId()); - - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModuleTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModuleTest.java deleted file mode 100644 index 919bfc65fb..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ModuleTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.Arrays; - -import org.apache.maven.model.Model; - -import junit.framework.TestCase; - -public class ModuleTest - extends TestCase -{ - - public void testIsMostSpecialized() - { - ModuleProcessor proc = new ModuleProcessor(); - - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setModules( Arrays.asList( "m1", "m2" ) ); - - proc.process( null, childModel, targetModel, true ); - - assertEquals( 2, targetModel.getModules().size() ); - assertEquals( "m1", targetModel.getModules().get( 0 ) ); - assertEquals( "m2", targetModel.getModules().get( 1 ) ); - } - - public void testIsNotMostSpecialized() - { - ModuleProcessor proc = new ModuleProcessor(); - - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setModules( Arrays.asList( "m1", "m2" ) ); - - proc.process( null, childModel, targetModel, false ); - - assertEquals( 0, targetModel.getModules().size() ); - } - - public void testImmutable() - { - ModuleProcessor proc = new ModuleProcessor(); - - Model targetModel = new Model(); - Model childModel = new Model(); - childModel.setModules( Arrays.asList( "m1", "m2" ) ); - - proc.process( null, childModel, targetModel, true ); - - childModel.getModules().set( 0, "m0" ); - - assertEquals( "m1", targetModel.getModules().get( 0 ) ); - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/OrganizationProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/OrganizationProcessorTest.java deleted file mode 100644 index 348074ceaf..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/OrganizationProcessorTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.maven.project.processor; - -import org.apache.maven.model.Model; -import org.apache.maven.model.Organization; - -import junit.framework.TestCase; - -public class OrganizationProcessorTest - extends TestCase -{ - public void testChildCopy() - { - Model child = new Model(); - Organization org = new Organization(); - org.setName( "name" ); - org.setUrl( "url" ); - - child.setOrganization( org ); - - Model target = new Model(); - - OrganizationProcessor proc = new OrganizationProcessor(); - proc.process( null, child, target, false ); - - assertNotNull( target.getOrganization() ); - assertEquals( "name", target.getOrganization().getName() ); - assertEquals( "url", target.getOrganization().getUrl() ); - - org.setName( "new" ); - assertEquals( "name", target.getOrganization().getName() ); - } - - public void testParentCopy() - { - Model child = new Model(); - Organization org = new Organization(); - org.setName( "name" ); - org.setUrl( "url" ); - - Model parent = new Model(); - parent.setOrganization( org ); - - Model target = new Model(); - - OrganizationProcessor proc = new OrganizationProcessor(); - proc.process( parent, child, target, false ); - - assertNotNull( target.getOrganization() ); - assertEquals( "name", target.getOrganization().getName() ); - assertEquals( "url", target.getOrganization().getUrl() ); - - org.setName( "new" ); - assertEquals( "name", target.getOrganization().getName() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ParentProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/ParentProcessorTest.java deleted file mode 100644 index f4c5a93f7d..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ParentProcessorTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apache.maven.project.processor; - -import org.apache.maven.model.Model; -import org.apache.maven.model.Parent; - -import junit.framework.TestCase; - -public class ParentProcessorTest - extends TestCase -{ - public void testVersion() - { - Model targetModel = new Model(); - Model childModel = new Model(); - Parent parent = new Parent(); - parent.setVersion( "1.0" ); - childModel.setParent( parent ); - - ParentProcessor mp = new ParentProcessor(); - mp.process( null, childModel, targetModel, false ); - assertEquals( "1.0", targetModel.getParent().getVersion() ); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginProcessorTest.java deleted file mode 100644 index f6c966e8a8..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginProcessorTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginExecution; - -import junit.framework.TestCase; - -public class PluginProcessorTest - extends TestCase -{ - public void testPluginExecutionCopyOfGoals() - { - Plugin plugin = new Plugin(); - plugin.setArtifactId( "aid" ); - plugin.setGroupId( "gid" ); - plugin.setVersion( "1.0" ); - - PluginExecution ex = new PluginExecution(); - ex.setId( "id" ); - ex.setInherited( "true" ); - ex.setGoals( Arrays.asList("a", "b") ); - plugin.addExecution( ex ); - - Plugin plugin1 = new Plugin(); - plugin1.setArtifactId( "aid" ); - plugin1.setGroupId( "gid" ); - plugin1.setVersion( "1.0" ); - - PluginExecution ex1 = new PluginExecution(); - ex1.setId( "id" ); - ex1.setInherited( "true" ); - ex1.setGoals( Arrays.asList("b", "c") ); - plugin1.addExecution( ex1 ); - - List plugins = new ArrayList(); - - PluginProcessor proc = new PluginProcessor(); - proc.process( plugin1, plugin, plugins, false ); - - assertEquals(1, plugins.size()); - assertEquals(1, plugins.get( 0 ).getExecutions().size()); - assertEquals(3, plugins.get( 0 ).getExecutions().get( 0 ).getGoals().size()); - } - - public void testPluginJoin_GroupId() - { - Plugin plugin = new Plugin(); - plugin.setArtifactId( "aid" ); - plugin.setGroupId( "gid" ); - plugin.setVersion( "1.0" ); - - Plugin plugin1 = new Plugin(); - plugin1.setArtifactId( "aid" ); - plugin1.setGroupId( "gid" ); - plugin1.setVersion( "1.0" ); - - - List plugins = new ArrayList(); - - PluginProcessor proc = new PluginProcessor(); - proc.process( plugin1, plugin, plugins, false ); - - assertEquals(1, plugins.size()); - assertEquals("gid", plugins.get( 0 ).getGroupId()); - } - - public void testPluginExecutionJoin_Phase() - { - Plugin plugin = new Plugin(); - plugin.setArtifactId( "aid" ); - plugin.setGroupId( "gid" ); - plugin.setVersion( "1.0" ); - - PluginExecution ex = new PluginExecution(); - ex.setId( "id" ); - ex.setPhase( "p" ); - ex.setGoals( Arrays.asList("a", "b") ); - plugin.addExecution( ex ); - - Plugin plugin1 = new Plugin(); - plugin1.setArtifactId( "aid" ); - plugin1.setGroupId( "gid" ); - plugin1.setVersion( "1.0" ); - - PluginExecution ex1 = new PluginExecution(); - ex1.setId( "id" ); - ex1.setPhase( "p1" ); - ex1.setGoals( Arrays.asList("b", "c") ); - plugin1.addExecution( ex1 ); - - List plugins = new ArrayList(); - - PluginProcessor proc = new PluginProcessor(); - proc.process( plugin1, plugin, plugins, false ); - - assertEquals(1, plugins.size()); - assertEquals(1, plugins.get( 0 ).getExecutions().size()); - assertEquals("p", plugins.get( 0 ).getExecutions().get( 0 ).getPhase()); - } - - - public void testPluginDependencyChildCopy_DependencyGroupId() - { - Dependency dependency = new Dependency(); - dependency.setGroupId( "gid" ); - - List target = new ArrayList(); - Plugin child = new Plugin(); - child.addDependency( dependency ); - - PluginProcessor proc = new PluginProcessor(); - proc.process( null, child, target, false ); - - assertEquals(1, target.size()); - assertEquals(1, target.get( 0 ).getDependencies().size()); - assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId()); - } - /* - public void testPluginDependencyJoin() - { - Dependency dependency = new Dependency(); - dependency.setGroupId( "gid" ); - - List target = new ArrayList(); - - Plugin child = new Plugin(); - child.setArtifactId( "aid" ); - child.setGroupId( "gid" ); - child.setVersion( "1.0" ); - child.addDependency( dependency ); - - Plugin parent = new Plugin(); - parent.setGroupId( "gid" ); - parent.setArtifactId( "aid" ); - parent.setVersion( "1.0" ); - - Dependency dependency1 = new Dependency(); - dependency1.setGroupId( "gid1" ); - parent.addDependency( dependency1 ); - - PluginProcessor proc = new PluginProcessor(); - proc.process( parent, child, target, false ); - - assertEquals(1, target.size()); - assertEquals(2, target.get( 0 ).getDependencies().size()); - assertEquals("gid", target.get( 0 ).getDependencies().get( 0 ).getGroupId()); - assertEquals("gid1", target.get( 0 ).getDependencies().get( 1 ).getGroupId()); - } - */ - /* - public void testMergeOfPluginConfiguration() - { - - List target = new ArrayList(); - - Xpp3Dom dom = new Xpp3Dom("a"); - Xpp3Dom dom2 = new Xpp3Dom("b"); - dom2.setValue( "test3" ); - dom.addChild( dom2 ); - - Plugin child = new Plugin(); - child.setArtifactId( "aid" ); - child.setGroupId( "gid" ); - child.setVersion( "1.0" ); - child.setConfiguration( dom ); - - Plugin parent = new Plugin(); - parent.setGroupId( "gid" ); - parent.setArtifactId( "aid" ); - parent.setVersion( "1.0" ); - - Xpp3Dom dom3 = new Xpp3Dom("a"); - Xpp3Dom dom4 = new Xpp3Dom("b"); - dom4.setValue( "test2" ); - dom.addChild( dom4 ); - - parent.setConfiguration( dom3 ); - - PluginProcessor proc = new PluginProcessor(); - proc.process( parent, child, target, false ); - - assertNotNull(target.get( 0 ).getConfiguration() ); - assertEquals( 2, ((Xpp3Dom) target.get( 0 ).getConfiguration()).getChildren( "b" ).length ); - } - */ -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginsManagementProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginsManagementProcessorTest.java deleted file mode 100644 index 3ff34d53cc..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PluginsManagementProcessorTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Plugin; - -import junit.framework.TestCase; - -public class PluginsManagementProcessorTest extends TestCase -{ - public void testChildCopy_Dependencies() - { - PluginsManagementProcessor proc = new PluginsManagementProcessor(); - - Plugin p = new Plugin(); - p.setArtifactId( "aid" ); - p.setGroupId( "gid"); - p.setVersion( "1.0" ); - Dependency d = new Dependency(); - d.setArtifactId( "d-aid" ); - d.setGroupId( "gid" ); - - p.setDependencies( new ArrayList(Arrays.asList(d) )); - - Plugin p1 = new Plugin(); - p1.setArtifactId( "aid" ); - p1.setGroupId( "gid"); - p1.setVersion( "1.0" ); - p1.setInherited( "true" ); - - Dependency d1 = new Dependency(); - d1.setArtifactId( "d1-aid" ); - d1.setGroupId( "gid" ); - - p1.setDependencies( Arrays.asList( d1 ) ); - - List plugins = new ArrayList(); - plugins.add(p); - proc.process( null, Arrays.asList(p1), plugins , false); - - assertEquals(1, plugins.size()); - assertEquals(2, plugins.get( 0 ).getDependencies().size()); - assertEquals("true", plugins.get( 0 ).getInherited()); - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java deleted file mode 100644 index cf54824fb5..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.project.processor; - -import org.apache.maven.model.Model; -import org.apache.maven.model.Prerequisites; - -import junit.framework.TestCase; - -public class PrerequisitesProcessorTest - extends TestCase -{ - - public void testMaven() - { - Prerequisites prerequisites = new Prerequisites(); - prerequisites.setMaven( "2.1" ); - - Model child = new Model(); - child.setPrerequisites( prerequisites ); - - Model target = new Model(); - - PrerequisitesProcessor proc = new PrerequisitesProcessor(); - proc.process( null, child, target, true ); - - assertEquals( "2.1", target.getPrerequisites().getMaven() ); - - // Immutable - prerequisites.setMaven( "2.2" ); - assertEquals( "2.1", target.getPrerequisites().getMaven() ); - - } - - public void testMavenParent() - { - Prerequisites prerequisites = new Prerequisites(); - prerequisites.setMaven( "2.1" ); - - Model parent = new Model(); - parent.setPrerequisites( prerequisites ); - - Model target = new Model(); - - PrerequisitesProcessor proc = new PrerequisitesProcessor(); - proc.process( parent, new Model(), target, false ); - - assertEquals( null, target.getPrerequisites() ); - - } - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ProcessorContextTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/ProcessorContextTest.java deleted file mode 100644 index 919b66fba4..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/ProcessorContextTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.maven.project.processor; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -import org.apache.maven.model.Build; -import org.apache.maven.model.Model; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; -import org.apache.maven.model.Profile; -import org.apache.maven.project.builder.PomClassicDomainModel; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.InterpolatorProperty; -import junit.framework.TestCase; - -public class ProcessorContextTest extends TestCase -{ - - public void testProfileModules() throws IOException - { - Model model = new Model(); - Profile profile = new Profile(); - profile.setModules( Arrays.asList( "m1", "m2" ) ); - - PomClassicDomainModel m = ProcessorContext.mergeProfilesIntoModel( Arrays.asList( profile ), new PomClassicDomainModel(model) ); - - assertEquals(2, m.getModel().getModules().size()); - } - - public void testPackagingInheritance() throws IOException - { - Model parent = new Model(); - parent.setPackaging( "jar" ); - Model child = new Model(); - child.setPackaging( "pom" ); - - DomainModel pdmParent = new PomClassicDomainModel(parent); - - DomainModel pdmChild = new PomClassicDomainModel(child, true); - ProcessorContext.build( Arrays.asList( pdmChild, pdmParent ), new ArrayList() ); - - assertEquals("pom", child.getPackaging()); - } - /* - public void testProfilePluginManagement() throws IOException - { - Model model = new Model(); - - Profile profile = new Profile(); - PluginManagement pm = new PluginManagement(); - Plugin p = new Plugin(); - p.setArtifactId( "aid" ); - pm.addPlugin( p ); - BuildBase b = new BuildBase(); - b.setPluginManagement( pm ); - profile.setBuild( b); - - - PomClassicDomainModel m = ProcessorContext.mergeProfilesIntoModel( Arrays.asList( profile ), model, false ); - - assertEquals(1, m.getModel().getBuild().getPluginManagement().getPlugins().size()); - } - */ - public void testInheritancePluginManagement() throws IOException - { - Model model = new Model(); - model.setBuild( createPluginManagement("aid") ); - DomainModel pdm = new PomClassicDomainModel(model); - - DomainModel child = new PomClassicDomainModel(new Model(), true); - - PomClassicDomainModel m = - ProcessorContext.build( Arrays.asList( child, pdm ), new ArrayList() ); - - assertEquals(1, m.getModel().getBuild().getPluginManagement().getPlugins().size()); - } - - - private static Build createPluginManagement(String id) - { - - PluginManagement pm = new PluginManagement(); - Plugin p = new Plugin(); - p.setArtifactId( id ); - pm.addPlugin( p ); - Build b = new Build(); - b.setPluginManagement( pm ); - return b; - } - /* - public void testInheritancePluginManagement2() throws IOException - { - Model model = new Model(); - model.setBuild( createPluginManagement("aid") ); - - DomainModel pdm = new PomClassicDomainModel(model); - - Model model2 = new Model(); - model2.setBuild( createPluginManagement("aid2") ); - - DomainModel pdm2 = new PomClassicDomainModel(model); - - DomainModel child = new PomClassicDomainModel(new Model(), true); - - PomClassicDomainModel m = ProcessorContext.build( Arrays.asList(child, pdm, pdm2)) ; - - assertEquals(2, m.getModel().getBuild().getPluginManagement().getPlugins().size()); - } - */ - -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PropertiesProcessorTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/processor/PropertiesProcessorTest.java deleted file mode 100644 index 1dff784639..0000000000 --- a/maven-project-builder/src/test/java/org/apache/maven/project/processor/PropertiesProcessorTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.apache.maven.project.processor; - -import java.util.Properties; - -import junit.framework.TestCase; - -import org.apache.maven.model.Model; - -public class PropertiesProcessorTest - extends TestCase -{ - public void testParentChildMerge() - { - Model targetModel = new Model(); - Model childModel = new Model(); - Model parentModel = new Model(); - - Properties childProperties = new Properties(); - childProperties.put( "k1", "v1" ); - childModel.setProperties( childProperties ); - - Properties parentProperties = new Properties(); - parentProperties.put( "k2", "v2" ); - parentModel.setProperties( parentProperties ); - - PropertiesProcessor proc = new PropertiesProcessor(); - proc.process( parentModel, childModel, targetModel, false ); - - assertEquals( 2, targetModel.getProperties().size() ); - - // Test order of child first - /* - * ArrayList list = Collections.list( targetModel.getProperties().elements() ); - * targetModel.getProperties().list( System.out ); assertEquals("v1", list.get( 0 )); assertEquals("v2", - * list.get( 1 )); - */ - } - - public void testChildCopy() - { - Model targetModel = new Model(); - Model childModel = new Model(); - - Properties childProperties = new Properties(); - childProperties.put( "k1", "v1" ); - childModel.setProperties( childProperties ); - - PropertiesProcessor proc = new PropertiesProcessor(); - proc.process( null, childModel, targetModel, false ); - - assertEquals( 1, targetModel.getProperties().size() ); - } - - public void testParentCopy() - { - Model targetModel = new Model(); - Model childModel = new Model(); - Model parentModel = new Model(); - - Properties parentProperties = new Properties(); - parentProperties.put( "k2", "v2" ); - parentModel.setProperties( parentProperties ); - - PropertiesProcessor proc = new PropertiesProcessor(); - proc.process( parentModel, childModel, targetModel, false ); - - assertEquals( 1, targetModel.getProperties().size() ); - } -} diff --git a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java index 8b9bc6b383..51cdb7c545 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java @@ -30,9 +30,9 @@ import org.apache.maven.profiles.matchers.FileMatcher; import org.apache.maven.profiles.matchers.JdkMatcher; import org.apache.maven.profiles.matchers.ProfileMatcher; import org.apache.maven.profiles.matchers.PropertyMatcher; -import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.project.ProjectBuilderConfiguration; -import org.apache.maven.project.builder.PomInterpolatorTag; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.MutablePlexusContainer; diff --git a/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java b/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java index 05eb403d09..1aa88d0bd9 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/ProfileManagerInfo.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; public class ProfileManagerInfo { diff --git a/maven-project/src/main/java/org/apache/maven/profiles/matchers/DefaultMatcher.java b/maven-project/src/main/java/org/apache/maven/profiles/matchers/DefaultMatcher.java index 51d35c92c5..047c81b59c 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/matchers/DefaultMatcher.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/matchers/DefaultMatcher.java @@ -22,7 +22,7 @@ package org.apache.maven.profiles.matchers; import java.util.List; import org.apache.maven.model.Profile; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; public class DefaultMatcher implements ProfileMatcher { diff --git a/maven-project/src/main/java/org/apache/maven/profiles/matchers/FileMatcher.java b/maven-project/src/main/java/org/apache/maven/profiles/matchers/FileMatcher.java index dcf925c004..10eaa7f28a 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/matchers/FileMatcher.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/matchers/FileMatcher.java @@ -5,7 +5,7 @@ import java.util.List; import org.apache.maven.model.ActivationFile; import org.apache.maven.model.Profile; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; public class FileMatcher implements ProfileMatcher { diff --git a/maven-project/src/main/java/org/apache/maven/profiles/matchers/JdkMatcher.java b/maven-project/src/main/java/org/apache/maven/profiles/matchers/JdkMatcher.java index 9858aa219b..c02f758c4b 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/matchers/JdkMatcher.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/matchers/JdkMatcher.java @@ -5,7 +5,7 @@ import java.util.Arrays; import java.util.List; import org.apache.maven.model.Profile; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; public class JdkMatcher implements ProfileMatcher diff --git a/maven-project/src/main/java/org/apache/maven/profiles/matchers/ProfileMatcher.java b/maven-project/src/main/java/org/apache/maven/profiles/matchers/ProfileMatcher.java index d35ec722d2..d6f4ac9e0f 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/matchers/ProfileMatcher.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/matchers/ProfileMatcher.java @@ -21,7 +21,7 @@ package org.apache.maven.profiles.matchers; import java.util.List; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; import org.apache.maven.model.Profile; public interface ProfileMatcher diff --git a/maven-project/src/main/java/org/apache/maven/profiles/matchers/PropertyMatcher.java b/maven-project/src/main/java/org/apache/maven/profiles/matchers/PropertyMatcher.java index bda305dca5..a24702ce85 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/matchers/PropertyMatcher.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/matchers/PropertyMatcher.java @@ -22,7 +22,7 @@ package org.apache.maven.profiles.matchers; import java.util.List; import org.apache.maven.model.Profile; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; public class PropertyMatcher implements ProfileMatcher { diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index eab60ceac6..fb196497f2 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -41,23 +41,22 @@ import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.ProfileActivationException; import org.apache.maven.profiles.ProfileManagerInfo; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.builder.PomClassicDomainModel; -import org.apache.maven.project.builder.PomInterpolatorTag; -import org.apache.maven.project.processor.ProcessorContext; +import org.apache.maven.project.builder.ProcessorContext; +import org.apache.maven.project.builder.interpolator.DomainModel; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.ModelProperty; +import org.apache.maven.project.builder.interpolator.PomInterpolatorTag; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.VersionNotFoundException; -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.ModelEventListener; -import org.apache.maven.shared.model.ModelProperty; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -65,7 +64,6 @@ import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.WriterFactory; /** * @version $Id$ @@ -388,11 +386,13 @@ public class DefaultMavenProjectBuilder { interpolatorProperties.add( new InterpolatorProperty( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( config.getBuildStartTime() ), PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - } + } + try { - List mps = domainModel.getModelProperties(); - ProcessorContext.interpolateModelProperties( mps, interpolatorProperties, domainModel ); + //List mps = domainModel.getModelProperties(); + model = ProcessorContext.interpolateDomainModel( domainModel, interpolatorProperties ).getModel(); + /* if ( domainModel.getProjectDirectory() != null ) { mps = ProcessorContext.alignPaths( mps, domainModel.getProjectDirectory() ); @@ -400,14 +400,17 @@ public class DefaultMavenProjectBuilder File f = domainModel.getParentFile(); domainModel = new PomClassicDomainModel( mps, false ); domainModel.setParentFile(f); + model = domainModel.getModel(); + */ } catch ( IOException e ) { throw new ProjectBuildingException(projectId, "", projectDescriptor, e); - } + } + MavenProject project; @@ -481,7 +484,7 @@ public class DefaultMavenProjectBuilder domainModels.addAll( mavenParents ); } - domainModels.add( convertToDomainModel( getSuperModel(), false ) ); + domainModels.add( new PomClassicDomainModel( getSuperModel(), false ) ); List profileModels = new ArrayList(); //Process Profiles for(DomainModel domain : domainModels) @@ -567,31 +570,6 @@ public class DefaultMavenProjectBuilder } } - private static PomClassicDomainModel convertToDomainModel( Model model, boolean isMostSpecialized ) - throws IOException - { - if ( model == null ) - { - throw new IllegalArgumentException( "model: null" ); - } - 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(); - } - } - return new PomClassicDomainModel( new ByteArrayInputStream( baos.toByteArray() ), isMostSpecialized ); - } - /** * Returns true if the relative path of the specified parent references a pom, otherwise returns * false. diff --git a/maven-project/src/test/java/org/apache/maven/profiles/matchers/JdkMatcherTest.java b/maven-project/src/test/java/org/apache/maven/profiles/matchers/JdkMatcherTest.java index 28a99c704f..67e31cde50 100644 --- a/maven-project/src/test/java/org/apache/maven/profiles/matchers/JdkMatcherTest.java +++ b/maven-project/src/test/java/org/apache/maven/profiles/matchers/JdkMatcherTest.java @@ -4,7 +4,7 @@ import java.util.Collections; import org.apache.maven.model.Activation; import org.apache.maven.model.Profile; -import org.apache.maven.shared.model.InterpolatorProperty; +import org.apache.maven.project.builder.interpolator.InterpolatorProperty; import junit.framework.TestCase; diff --git a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java index fcb83417ae..058641906e 100644 --- a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java +++ b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java @@ -32,8 +32,8 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.builder.interpolator.ModelProperty; import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.model.ModelProperty; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -68,11 +68,7 @@ public class PomTestWrapper } this.domainModel = domainModel; this.pomFile = pomFile; - try { - context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream())); - } catch (XmlPullParserException e) { - throw new IOException(e.getMessage()); - } + context = JXPathContext.newContext( domainModel.getModel()); } public PomTestWrapper( File pomFile, MavenProject mavenProject ) @@ -107,11 +103,7 @@ public class PomTestWrapper } this.domainModel = new PomClassicDomainModel( file ); - try { - context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream())); - } catch (XmlPullParserException e) { - throw new IOException(e.getMessage()); - } + context = JXPathContext.newContext( domainModel.getModel() ); } public MavenProject getMavenProject() @@ -120,67 +112,26 @@ public class PomTestWrapper } public PomClassicDomainModel getDomainModel() - { + throws IOException { if ( domainModel == null && mavenProject != null ) { - try - { - domainModel = convertToDomainModel( mavenProject.getModel() ); + domainModel = new PomClassicDomainModel( mavenProject.getModel() ); int lineageCount = 1; for ( MavenProject parent = mavenProject.getParent(); parent != null; parent = parent.getParent() ) { lineageCount++; } domainModel.setLineageCount( lineageCount ); - } - catch ( IOException e ) - { - - } } return this.domainModel; } - private PomClassicDomainModel convertToDomainModel(Model model) throws IOException - { - if ( model == null ) - { - throw new IllegalArgumentException( "model: null" ); - } - 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(); - } - } - return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray())); - } - public File getBasedir() { return ( pomFile != null ) ? pomFile.getParentFile() : null; } - public String getValueOfProjectUri( String projectUri, boolean withResolvedValue ) - throws IOException - { - if ( projectUri.contains( "#collection" ) || projectUri.contains( "#set" ) ) - { - throw new IllegalArgumentException( "projectUri: contains a collection or set" ); - } - return asMap( withResolvedValue ).get( projectUri ); - } - public void setValueOnModel( String expression, Object value ) { context.setValue( expression, value ); @@ -227,106 +178,4 @@ public class PomTestWrapper return context.getValue( expression ) != null && context.getValue( expression ).equals( value ); } - public Map asMap( boolean withResolvedValues ) - throws IOException - { - Map map = new HashMap(); - for ( ModelProperty mp : domainModel.getModelProperties() ) - { - if ( withResolvedValues ) - { - map.put( mp.getUri(), mp.getResolvedValue() ); - } - else - { - map.put( mp.getUri(), mp.getValue() ); - } - - } - return map; - } - - public boolean containsModelProperty( ModelProperty modelProperty ) - throws IOException - { - return domainModel.getModelProperties().contains( modelProperty ); - } - - public boolean containsAllModelPropertiesOf( List modelProperties ) - throws IOException - { - for ( ModelProperty mp : modelProperties ) - { - if ( !containsModelProperty( mp ) ) - { - return false; - } - } - return true; - } - - public boolean matchModelProperties( List hasProperties, List doesNotHaveProperties ) - throws IOException - { - return containsAllModelPropertiesOf( hasProperties ) && containNoModelPropertiesOf( doesNotHaveProperties ); - } - - public boolean matchUris( List hasAllUris, List doesNotHaveUris ) - throws IOException - { - return hasAllUris( hasAllUris ) && hasNoUris( doesNotHaveUris ); - } - - public boolean containNoModelPropertiesOf( List modelProperties ) - throws IOException - { - for ( ModelProperty mp : modelProperties ) - { - if ( containsModelProperty( mp ) ) - { - return false; - } - } - return true; - } - - public boolean hasUri( String uri ) - throws IOException - { - for ( ModelProperty mp : domainModel.getModelProperties() ) - { - if ( mp.getValue().equals( uri ) ) - { - return true; - } - } - return false; - } - - public boolean hasAllUris( List uris ) - throws IOException - { - for ( String s : uris ) - { - if ( !hasUri( s ) ) - { - return false; - } - } - return true; - } - - public boolean hasNoUris( List uris ) - throws IOException - { - for ( String s : uris ) - { - if ( hasUri( s ) ) - { - return false; - } - } - return true; - } - }