o pull from trunky dunk dunk

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@767707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-04-22 23:04:06 +00:00
parent 822f348c93
commit 5d7758b358
251 changed files with 12744 additions and 6703 deletions

View File

@ -0,0 +1,36 @@
BOOTSTRAPPING BASICS
-----------------------
You'll need:
- Java 1.5
- Ant 1.6.5 or later
First, give Ant a location into which the completed Maven distro should be installed:
export M2_HOME=$HOME/apps/maven/apache-maven-3.0-SNAPSHOT
Then, run Ant:
ant -f build-mercury.xml
You can use additiona options on ant command line:
-Dmaven.repo.update.policy={never|always|daily}
-Dmaven.repo.system={mercury|legacy}
-Dmaven.home=$HOME/apps/maven/apache-maven-3.0-SNAPSHOT
if you'd like to debug the bootstrap from Eclipse, uncomment the debugging options in the build-mercury.xml around
line 310, then use the following commands:
For the first time - run the following, it will update the local repo
ant -f build-mercury.xml -Dmaven.repo.update.policy=always -Dmaven.repo.system=mercury
then you can run
ant -f build-mercury.xml -Dmaven.repo.update.policy=never -Dmaven.repo.system=mercury
not to bother with repo updates

View File

@ -8,7 +8,7 @@ You'll need:
First, give Ant a location into which the completed Maven distro should be installed:
export M2_HOME=$HOME/apps/maven/apache-maven-2.1-SNAPSHOT
export M2_HOME=$HOME/apps/maven/apache-maven-3.0-SNAPSHOT
Then, run Ant:

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -13,15 +14,20 @@
License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>apache-maven</artifactId>
<name>Maven Distribution</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -82,6 +88,7 @@
<version>${mercuryVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@ -97,6 +104,7 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>standard</id>

View File

@ -67,7 +67,13 @@ END SNIPPET: ant-bootstrap -->
<property name="maven.repo.central" value="http://repository.sonatype.org/content/groups/public"/>
<!--
<property name="maven.repo.central" value="http://repo1.maven.org/maven2"/>
<property name="maven.repo.update.policy" value="daily"/>
<property name="maven.repo.update.policy" value="always"/>
-->
<property name="maven.repo.update.policy" value="daily"/>
<property name="maven.repo.system" value="don.t"/>
<condition property="do.not.clean.local.repo">
<not>
<isset property="clean.local.repo"/>
@ -87,15 +93,61 @@ END SNIPPET: ant-bootstrap -->
<mkdir dir="${maven.repo.local}"/>
</target>
<target name="flip-default-repository" unless="do.not.flip.repository">
<replace dir="${basedir}/maven-repository/src/main/java">
<include name="**/LegacyRepositorySystem.java"/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "default" )'
value='@Component( role = RepositorySystem.class, hint = "${legacy-hint}" )'/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "legacy" )'
value='@Component( role = RepositorySystem.class, hint = "${legacy-hint}" )'/>
</replace>
<replace dir="${basedir}/maven-repository-mercury/src/main/java">
<include name="**/MercuryRepositorySystem.java"/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "mercury" )'
value='@Component( role = RepositorySystem.class, hint = "${mercury-hint}" )'/>
<replacefilter token='@Component( role = RepositorySystem.class, hint = "default" )'
value='@Component( role = RepositorySystem.class, hint = "${mercury-hint}" )'/>
</replace>
<echo>maven.repo.system is ${maven.repo.system}, flip: legacy-hint=${legacy-hint}, mercury-hint=${mercury-hint}</echo>
</target>
<target name="flip-default-repository-system" description="flips repository system impl">
<condition property="legacy-hint" value="default">
<equals arg1="${maven.repo.system}" arg2="legacy"/>
</condition>
<condition property="mercury-hint" value="mercury">
<equals arg1="${maven.repo.system}" arg2="legacy"/>
</condition>
<condition property="legacy-hint" value="legacy">
<equals arg1="${maven.repo.system}" arg2="mercury"/>
</condition>
<condition property="mercury-hint" value="default">
<equals arg1="${maven.repo.system}" arg2="mercury"/>
</condition>
<condition property="do.not.flip.repository" value="default">
<equals arg1="${maven.repo.system}" arg2="don.t"/>
</condition>
<antcall target="flip-default-repository"/>
</target>
<target name="pull" depends="init,clean-local-repo" unless="skip.pull">
<property name="verbose" value="false"/>
<!-- Pull the dependencies that Maven needs to build -->
<copy file="pom.xml" tofile="dependencies.xml"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--start--&gt;" value="&lt;!--"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--end--&gt;" value="--&gt;"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--bootstrap-start-comment--&gt;" value="&lt;!--"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--bootstrap-end-comment--&gt;" value="--&gt;"/>
<mercury:local-repository location="${maven.repo.local}"/>
<mercury:remote-repository id="central" location="${maven.repo.central}"/>
<mercury:remote-repository id="central" location="${maven.repo.central}" updatePolicy="${maven.repo.update.policy}"/>
<property name="tsFormat" value="HH:mm:ss"/>
<tstamp><format property="start.time" pattern="${tsFormat}"/></tstamp>
@ -121,10 +173,10 @@ END SNIPPET: ant-bootstrap -->
<property name="mc" refid="mercury.classpath"/>
<echo>mercury.classpath=${mc}</echo>
<echo>========================================================================</echo>
<!--
-->
<!--
<delete file="${basedir}/dependencies.xml"/>
-->
<tstamp><format property="modello.start.time" pattern="${tsFormat}"/></tstamp>
@ -209,14 +261,15 @@ END SNIPPET: ant-bootstrap -->
</macrodef>
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<modello file="maven-lifecycle/src/main/mdo/maven-lifecycle.mdo"/>
<modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-project/src/main/mdo/profiles.mdo"/>
<modello file="maven-model-builder/src/main/mdo/profiles.mdo"/>
<modello file="maven-core/src/main/mdo/settings.mdo"/>
<modello file="maven-toolchain/src/main/mdo/toolchains.xml"/>
<modello file="maven-compat/src/main/mdo/metadata.mdo"/>
</target>
<target name="compile-boot" depends="generate-sources" description="compiles the bootstrap sources">
<target name="compile-boot" depends="generate-sources,flip-default-repository-system" description="compiles the bootstrap sources">
<path id="sources">
<dirset dir=".">
@ -244,12 +297,22 @@ END SNIPPET: ant-bootstrap -->
<target name="maven-compile" depends="compile-boot,process-classes" description="compiles Maven using the bootstrap Maven, skipping automated tests">
<java fork="true" classname="org.apache.maven.cli.MavenCli" failonerror="true">
<classpath refid="maven.classpath"/>
<arg value="-e"/>
<arg value="-X"/>
<arg value="-B"/>
<arg value="clean"/>
<arg value="install"/>
<arg value="-Dmaven.repo.local=${maven.repo.local}"/>
<arg value="-Dsurefire.useFile=${surefire.useFile}"/>
<!--
<debug-the-bootstrap>
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xnoagent"/>
<jvmarg value="-Djava.compiler=NONE"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"/>
</debug-the-bootstrap>
-->
</java>
</target>

View File

@ -78,8 +78,8 @@ END SNIPPET: ant-bootstrap -->
<property name="verbose" value="false"/>
<!-- Pull the dependencies that Maven needs to build -->
<copy file="pom.xml" tofile="dependencies.xml"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--start--&gt;" value="&lt;!--"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--end--&gt;" value="--&gt;"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--bootstrap-start-comment--&gt;" value="&lt;!--"/>
<replace file="${basedir}/dependencies.xml" token="&lt;!--bootstrap-end-comment--&gt;" value="--&gt;"/>
<artifact:pom file="${basedir}/dependencies.xml" id="pom"/>
<artifact:dependencies pathId="pom.pathid" filesetId="pom.fileset" verbose="${verbose}" useScope="compile">
<localRepository path="${maven.repo.local}"/>
@ -165,7 +165,7 @@ END SNIPPET: ant-bootstrap -->
<modello file="maven-model/src/main/mdo/maven.mdo" version="4.0.0"/>
<modello file="maven-plugin-api/src/main/mdo/lifecycle.mdo"/>
<modello file="maven-project/src/main/mdo/profiles.mdo"/>
<modello file="maven-model-builder/src/main/mdo/profiles.mdo"/>
<modello file="maven-core/src/main/mdo/settings.mdo"/>
<modello file="maven-toolchain/src/main/mdo/toolchains.xml"/>
<modello file="maven-compat/src/main/mdo/metadata.mdo"/>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
@ -8,15 +9,20 @@
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-compat</artifactId>
<name>Maven Compat</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -46,6 +52,7 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -324,6 +324,11 @@ public void getArtifact( Artifact artifact, List<ArtifactRepository> remoteRepos
public void getArtifact( Artifact artifact, List<ArtifactRepository> remoteRepositories, TransferListener downloadMonitor, boolean force )
throws TransferFailedException, ResourceDoesNotExistException
{
if(remoteRepositories == null)
{
throw new IllegalArgumentException("remoteRepositories: null");
}
for ( ArtifactRepository repository : remoteRepositories )
{
try

View File

@ -88,4 +88,6 @@ void getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, Art
void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase );
void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts );
}

View File

@ -55,4 +55,9 @@ public boolean include( Artifact artifact )
}
return matched;
}
public List<String> getPatterns()
{
return patterns;
}
}

View File

@ -39,9 +39,13 @@ public class ScopeArtifactFilter
private final boolean providedScope;
private final boolean systemScope;
private final String scope;
public ScopeArtifactFilter( String scope )
{
this.scope = scope;
if ( Artifact.SCOPE_COMPILE.equals( scope ) )
{
systemScope = true;
@ -111,4 +115,9 @@ else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
return true;
}
}
public String getScope()
{
return scope;
}
}

View File

@ -26,6 +26,7 @@
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.codehaus.plexus.component.annotations.Component;
@ -77,6 +78,13 @@ public void alignToBaseDirectory( Model model, File basedir )
build.setTestOutputDirectory( alignToBaseDirectory( build.getTestOutputDirectory(), basedir ) );
}
Reporting reporting = model.getReporting();
if ( reporting != null )
{
reporting.setOutputDirectory( alignToBaseDirectory( reporting.getOutputDirectory(), basedir ) );
}
}
public String alignToBaseDirectory( String path, File basedir )
@ -204,6 +212,13 @@ public void unalignFromBaseDirectory( Model model, File basedir )
build.setTestOutputDirectory( unalignFromBaseDirectory( build.getTestOutputDirectory(), basedir ) );
}
Reporting reporting = model.getReporting();
if ( reporting != null )
{
reporting.setOutputDirectory( unalignFromBaseDirectory( reporting.getOutputDirectory(), basedir ) );
}
}
public String unalignFromBaseDirectory( String directory, File basedir )

View File

@ -11,14 +11,18 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-core</artifactId>
<name>Maven Core</name>
<dependencies>
<!-- Maven -->
<dependency>
@ -39,7 +43,7 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project-builder</artifactId>
<artifactId>maven-model-builder</artifactId>
</dependency>
<!--
<dependency>
@ -85,30 +89,16 @@
<artifactId>maven-mercury</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sonatype.spice</groupId>
<artifactId>model-builder</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-sec-dispatcher</artifactId>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -211,7 +211,7 @@ private List<MavenProject> collectProjects( List<File> files, MavenExecutionRequ
File basedir = file.getParentFile();
List<File> moduleFiles = new ArrayList<File>();
for ( String name : project.getModules() )
{
if ( StringUtils.isEmpty( StringUtils.trim( name ) ) )

View File

@ -67,6 +67,8 @@ public class DefaultMavenExecutionRequest
private File globalSettingsFile;
private File userToolchainsFile;
// ----------------------------------------------------------------------------
// Request
// ----------------------------------------------------------------------------
@ -130,6 +132,7 @@ public static MavenExecutionRequest copy( MavenExecutionRequest original )
copy.setProjectPresent( original.isProjectPresent() );
copy.setUserSettingsFile( original.getUserSettingsFile() );
copy.setGlobalSettingsFile( original.getGlobalSettingsFile() );
copy.setUserToolchainsFile( original.getUserToolchainsFile() );
copy.setBaseDirectory( new File( original.getBaseDirectory() ) );
copy.setGoals( original.getGoals() );
copy.setRecursive( original.isRecursive() );
@ -611,7 +614,7 @@ public MavenExecutionRequest setProjectPresent( boolean projectPresent )
return this;
}
// Settin10gs files
// Settings files
public File getUserSettingsFile()
{
@ -637,6 +640,18 @@ public MavenExecutionRequest setGlobalSettingsFile( File globalSettingsFile )
return this;
}
public File getUserToolchainsFile()
{
return userToolchainsFile;
}
public MavenExecutionRequest setUserToolchainsFile( File userToolchainsFile )
{
this.userToolchainsFile = userToolchainsFile;
return this;
}
public MavenExecutionRequest addRemoteRepository( ArtifactRepository repository )
{
if ( remoteRepositories == null )

View File

@ -212,5 +212,8 @@ public interface MavenExecutionRequest
MavenExecutionRequest setRemoteRepositories( List<ArtifactRepository> repositories );
List<ArtifactRepository> getRemoteRepositories();
File getUserToolchainsFile();
MavenExecutionRequest setUserToolchainsFile( File userToolchainsFile );
ProjectBuilderConfiguration getProjectBuildingConfiguration();
}

View File

@ -2,17 +2,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.DataSourceException;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerFactory;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.ProjectUri;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Configuration;
@ -43,81 +39,17 @@ public class BuildExtensionListener
@Requirement
PlexusPluginManager pluginManager;
private List<BuildExtension> buildExtensions = new ArrayList<BuildExtension>();
public void fire(List<? extends ModelContainer> modelContainers)
throws DataSourceException
{
if ( !inBuild )
{
return;
}
for ( ModelContainer mc : modelContainers )
{
if ( hasExtension( mc ) )
{
buildExtensions.add( new BuildExtension( mc.getProperties() ) );
}
}
private List<Extension> buildExtensions = new ArrayList<Extension>();
public void fire(Model model)
{
buildExtensions.addAll(new ArrayList<Extension>(model.getBuild().getExtensions()));
}
public List<String> getUris()
{
return Arrays.asList( ProjectUri.Build.Extensions.Extension.xUri );
}
public Collection<ModelContainerFactory> getModelContainerFactories()
{
return Arrays.asList( (ModelContainerFactory) new ArtifactModelContainerFactory() );
}
private static boolean hasExtension( ModelContainer container )
{
for ( ModelProperty mp : container.getProperties() )
{
if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.xUri ) )
{
return true;
}
}
return false;
}
private static class BuildExtension
{
private String groupId;
private String artifactId;
private String version;
public BuildExtension( String groupId, String artifactId, String version )
{
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}
BuildExtension( List<ModelProperty> modelProperties )
{
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.groupId ) )
{
groupId = mp.getValue();
}
else if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.artifactId ) )
{
artifactId = mp.getValue();
}
else if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.version ) )
{
version = mp.getValue();
}
}
}
}
/**
* Take the extension elements that were found during the POM construction process and now
@ -129,11 +61,16 @@ else if ( mp.getUri().equals( ProjectUri.Build.Extensions.Extension.version ) )
* @param session Maven session used as the execution context for the current Maven project.
*/
public void processModelContainers( MavenSession session )
{
for ( BuildExtension be : buildExtensions )
{
if(!inBuild)
{
return;
}
for ( Extension be : buildExtensions )
{
PluginResolutionRequest request = new PluginResolutionRequest()
.setPluginMetadata( new PluginMetadata( be.groupId, be.artifactId, be.version ) )
.setPluginMetadata( new PluginMetadata( be.getGroupId(), be.getArtifactId(), be.getVersion() ) )
.addLocalRepository( session.getRequest().getLocalRepositoryPath() )
.setRemoteRepositories( convertToMercuryRepositories( session.getRequest().getRemoteRepositories() ) );

View File

@ -1,7 +1,8 @@
package org.apache.maven.listeners;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.shared.model.ModelEventListener;
import org.apache.maven.model.ModelEventListener;
public interface MavenModelEventListener
extends ModelEventListener

View File

@ -292,28 +292,19 @@
*/
public synchronized Proxy getActiveProxy()
{
if(activeProxy == null)
if (activeProxy == null)
{
java.util.List proxies = getProxies();
java.util.List<Proxy> proxies = getProxies();
if ( proxies != null && !proxies.isEmpty() )
{
if ( proxies.size() > 1 )
for ( Proxy proxy : proxies )
{
for ( java.util.Iterator it = proxies.iterator(); it.hasNext(); )
if ( proxy.isActive() )
{
Proxy proxy = (Proxy) it.next();
if ( proxy.isActive() )
{
activeProxy = proxy;
break;
}
activeProxy = proxy;
break;
}
}
else
{
// If we only have one proxy, use it as the active one.
activeProxy = (Proxy) proxies.get( 0 );
}
}
}
@ -464,7 +455,7 @@
<name>active</name>
<version>1.0.0</version>
<required>false</required>
<defaultValue>false</defaultValue>
<defaultValue>true</defaultValue>
<description>
<![CDATA[
Whether this proxy configuration is the active one.

View File

@ -1,22 +1,17 @@
package org.apache.maven.listeners;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DuplicateProjectException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.model.Build;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerAction;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.wagon.Wagon;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.dag.CycleDetectedException;
@ -30,16 +25,19 @@ public void testBuildExtensionListener()
{
BuildExtensionListener listener = (BuildExtensionListener) lookup( MavenModelEventListener.class, "extensions" );
// Create the model properties and the model container to feed to the event firing
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
modelProperties.add( new ModelProperty( ProjectUri.Build.Extensions.Extension.xUri, null ) );
modelProperties.add( new ModelProperty( ProjectUri.Build.Extensions.Extension.groupId, "org.apache.maven.wagon" ) );
modelProperties.add( new ModelProperty( ProjectUri.Build.Extensions.Extension.artifactId, "wagon-webdav" ) );
modelProperties.add( new ModelProperty( ProjectUri.Build.Extensions.Extension.version, "1.0-beta-2" ) );
ModelContainer container = new TestModelContainer( modelProperties );
Extension extension = new Extension();
extension.setGroupId("org.apache.maven.wagon" );
extension.setArtifactId("wagon-webdav" );
extension.setVersion( "1.0-beta-2" );
Build build = new Build();
build.addExtension(extension);
Model model = new Model();
model.setBuild(build);
// Fire the event.
listener.fire( Arrays.asList( container ) );
listener.fire( model );
try
{
@ -55,7 +53,7 @@ public void testBuildExtensionListener()
listener.processModelContainers( newMavenSession() );
// Now we should be able to find the extension.
// lookup( Wagon.class, "dav" );
lookup( Wagon.class, "dav" );
}
private MavenSession newMavenSession()
@ -75,29 +73,4 @@ private MavenSession newMavenSession()
return session;
}
public class TestModelContainer
implements ModelContainer
{
List<ModelProperty> modelProperties;
public TestModelContainer( List<ModelProperty> properties )
{
this.modelProperties = properties;
}
public List<ModelProperty> getProperties()
{
return new ArrayList<ModelProperty>( modelProperties );
}
public ModelContainerAction containerAction( ModelContainer modelContainer )
{
return null;
}
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
{
return null;
}
}
}

View File

@ -0,0 +1,173 @@
package org.apache.maven.project.harness;
/*
* 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.io.*;
import java.util.Iterator;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathNotFoundException;
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
import org.apache.maven.model.PomClassicDomainModel;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
public class PomTestWrapper
{
private PomClassicDomainModel domainModel;
private File pomFile;
private JXPathContext context;
private MavenProject mavenProject;
static
{
JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() );
}
public PomTestWrapper( PomClassicDomainModel domainModel )
throws IOException
{
this( null, domainModel );
}
public PomTestWrapper( File pomFile, PomClassicDomainModel domainModel )
throws IOException
{
if ( domainModel == null )
{
throw new IllegalArgumentException( "domainModel: null" );
}
this.domainModel = domainModel;
this.pomFile = pomFile;
try {
context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream()));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage());
}
}
public PomTestWrapper( File pomFile, MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{
throw new IllegalArgumentException( "mavenProject: null" );
}
this.mavenProject = mavenProject;
this.pomFile = pomFile;
context = JXPathContext.newContext( mavenProject.getModel() );
}
public PomTestWrapper( MavenProject mavenProject )
throws IOException
{
if ( mavenProject == null )
{
throw new IllegalArgumentException( "mavenProject: null" );
}
this.mavenProject = mavenProject;
context = JXPathContext.newContext( mavenProject.getModel() );
}
public PomTestWrapper( File file )
throws IOException
{
if ( file == null )
{
throw new IllegalArgumentException( "file: null" );
}
this.domainModel = new PomClassicDomainModel( file );
try {
context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream()));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage());
}
}
public MavenProject getMavenProject()
{
return mavenProject;
}
public PomClassicDomainModel getDomainModel()
{
if ( domainModel == null && mavenProject != null )
{
try
{
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;
}
public File getBasedir()
{
return ( pomFile != null ) ? pomFile.getParentFile() : null;
}
public void setValueOnModel( String expression, Object value )
{
context.setValue( expression, value );
}
public Iterator<?> getIteratorForXPathExpression( String expression )
{
return context.iterate( expression );
}
public boolean containsXPathExpression( String expression )
{
return context.getValue( expression ) != null;
}
public Object getValue( String expression )
{
try
{
return context.getValue( expression );
}
catch ( JXPathNotFoundException e )
{
return null;
}
}
public boolean xPathExpressionEqualsValue( String expression, String value )
{
return context.getValue( expression ) != null && context.getValue( expression ).equals( value );
}
}

View File

@ -0,0 +1,90 @@
package org.apache.maven.project.harness;
/*
* 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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* An attribute iterator for JXPath to support <code>Xpp3Dom</code>.
*
* @author Benjamin Bentmann
* @version $Id: Xpp3DomAttributeIterator.java 747943 2009-02-25 22:28:48Z bentmann $
*/
class Xpp3DomAttributeIterator
implements NodeIterator
{
private NodePointer parent;
private Xpp3Dom node;
private List<Map.Entry<String, String>> attributes;
private Map.Entry<String, String> attribute;
private int position;
public Xpp3DomAttributeIterator( NodePointer parent, QName qname )
{
this.parent = parent;
this.node = (Xpp3Dom) parent.getNode();
Map<String, String> map = new LinkedHashMap<String, String>();
for ( String name : this.node.getAttributeNames() )
{
if ( name.equals( qname.getName() ) || "*".equals( qname.getName() ) )
{
String value = this.node.getAttribute( name );
map.put( name, value );
}
}
this.attributes = new ArrayList<Map.Entry<String, String>>( map.entrySet() );
}
public NodePointer getNodePointer()
{
if ( position == 0 )
{
setPosition( 1 );
}
return ( attribute == null ) ? null : new Xpp3DomAttributePointer( parent, attribute );
}
public int getPosition()
{
return position;
}
public boolean setPosition( int position )
{
this.position = position;
attribute = ( position > 0 && position <= attributes.size() ) ? attributes.get( position - 1 ) : null;
return attribute != null;
}
}

View File

@ -0,0 +1,105 @@
package org.apache.maven.project.harness;
/*
* 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.Map;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
/**
* An attribute pointer for JXPath to support <code>Xpp3Dom</code>.
*
* @author Benjamin Bentmann
*/
class Xpp3DomAttributePointer
extends NodePointer
{
private Map.Entry<String, String> attrib;
public Xpp3DomAttributePointer( NodePointer parent, Map.Entry<String, String> attrib )
{
super( parent );
this.attrib = attrib;
}
@Override
public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2 )
{
// should never happen because attributes have no children
return 0;
}
@Override
public Object getValue()
{
return attrib.getValue();
}
@Override
public Object getBaseValue()
{
return attrib;
}
@Override
public Object getImmediateNode()
{
return attrib;
}
@Override
public int getLength()
{
return 1;
}
@Override
public QName getName()
{
return new QName( null, attrib.getKey() );
}
@Override
public boolean isActual()
{
return true;
}
@Override
public boolean isCollection()
{
return false;
}
@Override
public boolean isLeaf()
{
return true;
}
@Override
public void setValue( Object value )
{
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,161 @@
package org.apache.maven.project.harness;
/*
* 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 org.apache.commons.jxpath.ri.Compiler;
import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
import org.apache.commons.jxpath.ri.compiler.NodeTest;
import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* A node iterator for JXPath to support <code>Xpp3Dom</code>.
*
* @author Benjamin Bentmann
* @version $Id: Xpp3DomNodeIterator.java 737056 2009-01-23 15:35:43Z bentmann $
*/
class Xpp3DomNodeIterator
implements NodeIterator
{
private NodePointer parent;
private NodeTest test;
private Xpp3Dom node;
private Xpp3Dom[] children;
private List<Xpp3Dom> filteredChildren = new ArrayList<Xpp3Dom>();
private int filteredIndex;
private Xpp3Dom child;
private int position;
public Xpp3DomNodeIterator( NodePointer parent, NodeTest test, boolean reverse, NodePointer startWith )
{
this.parent = parent;
this.node = (Xpp3Dom) parent.getNode();
this.children = this.node.getChildren();
if ( startWith != null )
{
for ( ; filteredIndex < children.length; filteredIndex++ )
{
if ( startWith.equals( children[filteredIndex] ) )
{
filteredIndex++;
break;
}
}
}
this.test = test;
if ( reverse )
{
throw new UnsupportedOperationException();
}
}
public NodePointer getNodePointer()
{
if ( position == 0 )
{
setPosition( 1 );
}
return ( child == null ) ? null : new Xpp3DomNodePointer( parent, child );
}
public int getPosition()
{
return position;
}
public boolean setPosition( int position )
{
this.position = position;
filterChildren( position );
child = ( position > 0 && position <= filteredChildren.size() ) ? filteredChildren.get( position - 1 ) : null;
return child != null;
}
private void filterChildren( int position )
{
for ( ; position > filteredChildren.size() && filteredIndex < children.length; filteredIndex++ )
{
Xpp3Dom child = children[filteredIndex];
if ( testNode( child ) )
{
filteredChildren.add( child );
}
}
}
private boolean testNode( Xpp3Dom node )
{
if ( test == null )
{
return true;
}
if ( test instanceof NodeNameTest )
{
String nodeName = node.getName();
if ( StringUtils.isEmpty( nodeName ) )
{
return false;
}
NodeNameTest nodeNameTest = (NodeNameTest) test;
String namespaceURI = nodeNameTest.getNamespaceURI();
boolean wildcard = nodeNameTest.isWildcard();
String testName = nodeNameTest.getNodeName().getName();
String testPrefix = nodeNameTest.getNodeName().getPrefix();
if ( wildcard && testPrefix == null )
{
return true;
}
if ( wildcard || testName.equals( nodeName ) )
{
return StringUtils.isEmpty( namespaceURI ) || StringUtils.isEmpty( testPrefix );
}
return false;
}
if ( test instanceof NodeTypeTest )
{
switch ( ( (NodeTypeTest) test ).getNodeType() )
{
case Compiler.NODE_TYPE_NODE:
return true;
case Compiler.NODE_TYPE_TEXT:
return node.getValue() != null;
default:
return false;
}
}
return false;
}
}

View File

@ -0,0 +1,156 @@
package org.apache.maven.project.harness;
/*
* 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 org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.compiler.NodeTest;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* A node pointer for JXPath to support <code>Xpp3Dom</code>.
*
* @author Benjamin Bentmann
* @version $Id: Xpp3DomNodePointer.java 747943 2009-02-25 22:28:48Z bentmann $
*/
class Xpp3DomNodePointer
extends NodePointer
{
private Xpp3Dom node;
public Xpp3DomNodePointer( Xpp3Dom node )
{
super( null );
this.node = node;
}
public Xpp3DomNodePointer( NodePointer parent, Xpp3Dom node )
{
super( parent );
this.node = node;
}
@Override
public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2 )
{
Xpp3Dom node1 = (Xpp3Dom) pointer1.getBaseValue();
Xpp3Dom node2 = (Xpp3Dom) pointer2.getBaseValue();
if ( node1 == node2 )
{
return 0;
}
for ( int i = 0; i < node.getChildCount(); i++ )
{
Xpp3Dom child = node.getChild( i );
if ( child == node1 )
{
return -1;
}
if ( child == node2 )
{
return 1;
}
}
return 0;
}
@Override
public Object getValue()
{
return getValue(node);
}
private static Object getValue( Xpp3Dom node )
{
if ( node.getValue() != null )
{
return node.getValue().trim();
}
else
{
List<Object> children = new ArrayList<Object>();
for ( int i = 0; i < node.getChildCount(); i++ )
{
children.add( getValue( node.getChild( i ) ) );
}
return children;
}
}
@Override
public Object getBaseValue()
{
return node;
}
@Override
public Object getImmediateNode()
{
return node;
}
@Override
public int getLength()
{
return 1;
}
@Override
public QName getName()
{
return new QName( null, node.getName() );
}
@Override
public boolean isCollection()
{
return false;
}
@Override
public boolean isLeaf()
{
return node.getChildCount() <= 0;
}
@Override
public void setValue( Object value )
{
throw new UnsupportedOperationException();
}
@Override
public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith )
{
return new Xpp3DomNodeIterator( this, test, reverse, startWith );
}
@Override
public NodeIterator attributeIterator( QName qname )
{
return new Xpp3DomAttributeIterator( this, qname );
}
}

View File

@ -0,0 +1,62 @@
package org.apache.maven.project.harness;
/*
* 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.Locale;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.ri.model.NodePointerFactory;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* A node pointer factory for JXPath to support <code>Xpp3Dom</code>.
*
* @author Benjamin Bentmann
* @version $Id: Xpp3DomPointerFactory.java 737056 2009-01-23 15:35:43Z bentmann $
*/
class Xpp3DomPointerFactory
implements NodePointerFactory
{
public int getOrder()
{
return 200;
}
public NodePointer createNodePointer( QName name, Object object, Locale locale )
{
if ( object instanceof Xpp3Dom )
{
return new Xpp3DomNodePointer( (Xpp3Dom) object );
}
return null;
}
public NodePointer createNodePointer( NodePointer parent, QName name, Object object )
{
if ( object instanceof Xpp3Dom )
{
return new Xpp3DomNodePointer( parent, (Xpp3Dom) object );
}
return null;
}
}

View File

@ -0,0 +1,124 @@
package org.apache.maven.settings;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.List;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.Profile;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.project.DefaultMavenProjectBuilder;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
public class PomConstructionWithSettingsTest
extends PlexusTestCase
{
private static String BASE_DIR = "src/test";
private static String BASE_POM_DIR = BASE_DIR + "/resources-settings";
private DefaultMavenProjectBuilder mavenProjectBuilder;
private File testDirectory;
protected void setUp()
throws Exception
{
testDirectory = new File( getBasedir(), BASE_POM_DIR );
mavenProjectBuilder = (DefaultMavenProjectBuilder) lookup( MavenProjectBuilder.class );
}
public void testSettingsNoPom() throws Exception
{
PomTestWrapper pom = buildPom( "settings-no-pom" );
assertEquals( "local-profile-prop-value", pom.getValue( "properties/local-profile-prop" ) );
}
/**MNG-4107 */
public void testPomAndSettingsInterpolation() throws Exception
{
PomTestWrapper pom = buildPom( "test-pom-and-settings-interpolation" );
assertEquals("applied", pom.getValue( "properties/settingsProfile" ) );
assertEquals("applied", pom.getValue( "properties/pomProfile" ) );
assertEquals("settings", pom.getValue( "properties/pomVsSettings" ) );
assertEquals("settings", pom.getValue( "properties/pomVsSettingsInterpolated" ) );
}
/**MNG-4107 */
public void testRepositories() throws Exception
{
PomTestWrapper pom = buildPom( "repositories" );
assertEquals("maven-core-it-0", pom.getValue( "repositories[1]/id" ));
System.out.println(pom.getDomainModel().asString());
}
private PomTestWrapper buildPom( String pomPath )
throws Exception
{
File pomFile = new File( testDirectory + File.separator + pomPath , "pom.xml" );
File settingsFile = new File( testDirectory + File.separator + pomPath, "settings.xml" );
Settings settings = readSettingsFile(settingsFile);
ProfileActivationContext pCtx = new ProfileActivationContext(null, true);
ProfileManager profileManager = new DefaultProfileManager(pCtx);
for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
{
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
profileManager.addProfile( profile );
}
List<String> settingsActiveProfileIds = settings.getActiveProfiles();
if ( settingsActiveProfileIds != null )
{
for ( String profileId : settingsActiveProfileIds )
{
profileManager.getProfileActivationContext().setActive( profileId );
}
}
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
config.setLocalRepository(new DefaultArtifactRepository("default", "", new DefaultRepositoryLayout()));
config.setGlobalProfileManager(profileManager);
return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) );
}
private static Settings readSettingsFile(File settingsFile)
throws IOException, XmlPullParserException
{
Settings settings = null;
Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( settingsFile );
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
settings = modelReader.read( reader );
}
finally
{
IOUtil.close( reader );
}
return settings;
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4107</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<settings>
<profiles>
<profile>
<id>maven-core-it-repo</id>
<repositories>
<repository>
<id>maven-core-it-0</id>
<url>@baseurl@/repo-0</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-core-it-1</id>
<url>@baseurl@/repo-1</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>maven-core-it-repo</activeProfile>
</activeProfiles>
</settings>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3099</groupId>
<artifactId>maven-mng3099-plugin</artifactId>
<version>1</version>
<packaging>maven-plugin</packaging>
<name>maven-mng3099-plugin</name>
<description>Tests properties injected as a result of active profiles in the user settings file.</description>
</project>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>local-profile</id>
<properties>
<local-profile-prop>local-profile-prop-value</local-profile-prop>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>local-profile</activeProfile>
</activeProfiles>
</settings>

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng4107</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Integration Test :: MNG-4107</name>
<description>
Test that POM interpolation uses the property values from the dominant profile source (POM vs. profiles.xml
vs. settings.xml). This boils down to the proper order of profile injection and interpolation, i.e.
interpolate after profiles from all sources are injected.
</description>
<properties>
<!-- collect the effective property values as derived by interpolation -->
<pomVsSettingsInterpolated>${pomVsSettings}</pomVsSettingsInterpolated>
</properties>
<profiles>
<profile>
<id>pom</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<pomProfile>applied</pomProfile>
<pomVsSettings>pom</pomVsSettings>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>eval</goal>
</goals>
<configuration>
<outputFile>target/pom.properties</outputFile>
<expressions>
<expression>project/properties</expression>
</expressions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<settings>
<profiles>
<profile>
<id>settings</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<settingsProfile>applied</settingsProfile>
<pomVsSettings>settings</pomVsSettings>
</properties>
</profile>
</profiles>
</settings>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
@ -8,15 +9,20 @@
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -64,10 +70,11 @@
<artifactId>easymock</artifactId>
</dependency>
<dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>

View File

@ -76,6 +76,8 @@ public class CLIManager
public static final String ALTERNATE_GLOBAL_SETTINGS = "gs";
public static final char ALTERNATE_USER_TOOLCHAINS = 't';
public static final String FAIL_FAST = "ff";
public static final String FAIL_AT_END = "fae";
@ -111,6 +113,7 @@ public CLIManager()
options.addOption( OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create( CHECKSUM_WARNING_POLICY ) );
options.addOption( OptionBuilder.withLongOpt( "settings" ).withDescription( "Alternate path for the user settings file" ).hasArg().create( ALTERNATE_USER_SETTINGS ) );
options.addOption( OptionBuilder.withLongOpt( "global-settings" ).withDescription( "Alternate path for the global settings file" ).hasArg().create( ALTERNATE_GLOBAL_SETTINGS ) );
options.addOption( OptionBuilder.withLongOpt( "toolchains" ).withDescription( "Alternate path for the user toolchains file" ).hasArg().create( ALTERNATE_USER_TOOLCHAINS ) );
options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription( "Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription( "Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );
options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription( "NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );

View File

@ -22,7 +22,6 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
@ -30,6 +29,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@ -77,7 +77,7 @@ else if ( commandLine.hasOption( CLIManager.SUPPRESS_PLUGIN_UPDATES ) )
//
// ----------------------------------------------------------------------
List goals = commandLine.getArgList();
List<String> goals = commandLine.getArgList();
boolean recursive = true;
@ -139,9 +139,9 @@ else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
// Profile Activation
// ----------------------------------------------------------------------
List activeProfiles = new ArrayList();
List<String> activeProfiles = new ArrayList<String>();
List inactiveProfiles = new ArrayList();
List<String> inactiveProfiles = new ArrayList<String>();
if ( commandLine.hasOption( CLIManager.ACTIVATE_PROFILES ) )
{
@ -222,6 +222,16 @@ else if ( quiet )
Properties userProperties = new Properties();
populateProperties( commandLine, executionProperties, userProperties );
File userToolchainsFile;
if ( commandLine.hasOption( CLIManager.ALTERNATE_USER_TOOLCHAINS ) )
{
userToolchainsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_TOOLCHAINS ) );
}
else
{
userToolchainsFile = MavenEmbedder.DEFAULT_USER_TOOLCHAINS_FILE;
}
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setBaseDirectory( baseDirectory )
.setGoals( goals )
@ -239,7 +249,9 @@ else if ( quiet )
.setTransferListener( transferListener ) // default: batch mode which goes along with interactive
.setUpdateSnapshots( updateSnapshots ) // default: false
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
.setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
.setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn
.setUserToolchainsFile( userToolchainsFile );
if ( alternatePomFile != null )
{
@ -261,10 +273,8 @@ static void populateProperties( CommandLine commandLine, Properties executionPro
try
{
Properties envVars = CommandLineUtils.getSystemEnvVars();
Iterator i = envVars.entrySet().iterator();
while ( i.hasNext() )
for ( Entry<Object, Object> e : envVars.entrySet() )
{
Entry e = (Entry) i.next();
executionProperties.setProperty( "env." + e.getKey().toString(), e.getValue().toString() );
}
}

View File

@ -83,6 +83,8 @@ public class MavenEmbedder
public static final File DEFAULT_GLOBAL_SETTINGS_FILE =
new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" );
// ----------------------------------------------------------------------------
//
// ----------------------------------------------------------------------------

View File

@ -29,10 +29,12 @@
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileActivationException;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.MavenSettingsBuilder;
@ -41,6 +43,7 @@
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.toolchain.ToolchainsBuilder;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -71,6 +74,9 @@ public class DefaultMavenExecutionRequestPopulator
@Requirement
private RepositorySystem repositorySystem;
@Requirement
private ToolchainsBuilder toolchainsBuilder;
// 2009-03-05 Oleg: this component is defined sub-classed in this package
@Requirement(hint = "maven")
private SecDispatcher securityDispatcher;
@ -84,6 +90,8 @@ public MavenExecutionRequest populateDefaults( MavenExecutionRequest request, Co
localRepository( request, configuration );
toolchains( request, configuration );
artifactTransferMechanism( request, configuration );
profileManager( request, configuration );
@ -150,21 +158,41 @@ private void processSettings( MavenExecutionRequest request, Configuration confi
Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile );
profileManager.addProfile( profile );
}
// We need to convert profile repositories to artifact repositories
for ( Repository r : profile.getRepositories() )
// We need to convert profile repositories to artifact repositories
try
{
for ( Profile profile : profileManager.getActiveProfiles() )
{
try
for ( Repository r : profile.getRepositories() )
{
request.addRemoteRepository( repositorySystem.buildArtifactRepository( r ) );
try
{
request.addRemoteRepository( repositorySystem.buildArtifactRepository( r ) );
}
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create remote repository " + r.getId(), e );
}
}
catch ( InvalidRepositoryException e )
for ( Repository r : profile.getPluginRepositories() )
{
throw new MavenEmbedderException( "Cannot create remote repository " + r.getId(), e );
}
try
{
request.addRemoteRepository( repositorySystem.buildArtifactRepository( r ) );
}
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create remote repository " + r.getId(), e );
}
}
}
}
catch ( ProfileActivationException e )
{
throw new MavenEmbedderException( "Cannot determine active profiles", e );
}
}
injectDefaultRepositories( request );
@ -391,9 +419,15 @@ private void profileManager( MavenExecutionRequest request, Configuration config
activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() );
activationContext.setExplicitlyInactiveProfileIds( request.getInactiveProfiles() );
ProfileManager globalProfileManager = new DefaultProfileManager( container, activationContext );
ProfileManager globalProfileManager = new DefaultProfileManager( activationContext );
request.setProfileManager( globalProfileManager );
request.setProfileActivationContext( activationContext );
}
private void toolchains( MavenExecutionRequest request, Configuration configuration )
{
toolchainsBuilder.setUserToolchainsFile( request.getUserToolchainsFile() );
}
}

View File

@ -354,18 +354,19 @@ public void testProjectReading()
artifacts.iterator().next();
}
/**TODO - FIX
public void testProjectReading_FromChildLevel_ScmInheritanceCalculations()
throws Exception
{
File pomFile = new File( basedir, "src/test/projects/readProject-withScmInheritance/modules/child1/pom.xml" );
MavenProject project = mavenEmbedder.readProject( pomFile );
assertNotNull(project.getScm());
assertEquals( "http://host/viewer?path=/trunk/parent/child1", project.getScm().getUrl() );
assertEquals( "scm:svn:http://host/trunk/parent/child1", project.getScm().getConnection() );
assertEquals( "scm:svn:https://host/trunk/parent/child1", project.getScm().getDeveloperConnection() );
}
*/
public void testProjectReading_SkipMissingModuleSilently()
throws Exception
{

View File

@ -11,13 +11,16 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-mercury</artifactId>
<name>Maven Mercury</name>
<dependencies>
@ -34,7 +37,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project-builder</artifactId>
<artifactId>maven-model-builder</artifactId>
</dependency>
<dependency>
@ -42,11 +45,6 @@
<artifactId>plexus-component-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.spice</groupId>
<artifactId>model-builder</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.apache.maven.mercury</groupId>
@ -85,6 +83,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -99,14 +103,14 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
<goal>generate-test-metadata</goal>
</goals>
</execution>
</executions>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
<goal>generate-test-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -21,7 +21,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -30,14 +29,11 @@
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.shared.model.DomainModel;
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.ModelTransformerContext;
import org.apache.maven.model.DomainModel;
import org.apache.maven.model.ProcessorContext;
import org.apache.maven.model.interpolator.DefaultInterpolator;
import org.apache.maven.model.interpolator.InterpolatorProperty;
import org.apache.maven.model.interpolator.PomInterpolatorTag;
import org.codehaus.plexus.component.annotations.Component;
/**
@ -49,9 +45,13 @@
*
*/
@Component( role=DependencyProcessor.class, hint="maven" )
public final class MavenDependencyProcessor
public class MavenDependencyProcessor
implements DependencyProcessor
{
/**
* Over-ride this method to change how dependencies are obtained
*/
public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataReader mdReader, Map system,
Map user )
throws MetadataReaderException, DependencyProcessorException
@ -66,20 +66,7 @@ public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataRea
throw new IllegalArgumentException( "mdReader: null" );
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT",
PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
if ( system != null )
{
interpolatorProperties.addAll(
InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
}
if ( user != null )
{
interpolatorProperties.addAll(
InterpolatorProperty.toInterpolatorProperties( user, PomInterpolatorTag.USER_PROPERTIES.name() ) );
}
List<InterpolatorProperty> interpolatorProperties = createInterpolatorProperties(system, user);
List<DomainModel> domainModels = new ArrayList<DomainModel>();
try
@ -98,14 +85,14 @@ public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataRea
MavenDomainModel domainModel = new MavenDomainModel( superBytes );
domainModel.setMostSpecialized(true);
domainModels.add( domainModel );
/*TODO: Profiles
Collection<ModelContainer> activeProfiles = domainModel.getActiveProfileContainers( interpolatorProperties );
for ( ModelContainer mc : activeProfiles )
{
domainModels.add( new MavenDomainModel( transformProfiles( mc.getProperties() ) ) );
}
*/
List<DomainModel> parentModels = getParentsOfDomainModel( domainModel, mdReader );
if ( parentModels == null )
@ -120,24 +107,35 @@ public List<ArtifactMetadata> getDependencies( ArtifactMetadata bmd, MetadataRea
throw new MetadataReaderException( "Failed to create domain model. Message = " + e.getMessage(), e );
}
PomTransformer transformer = new PomTransformer( new MavenDomainModelFactory() );
ModelTransformerContext ctx =
new ModelTransformerContext( PomTransformer.MODEL_CONTAINER_INFOS );
try {
return new MavenDomainModel(new DefaultInterpolator().interpolateDomainModel(ProcessorContext.build(domainModels, null),
interpolatorProperties)).getDependencyMetadata();
} catch (IOException e) {
throw new DependencyProcessorException();
}
try
}
protected final List<InterpolatorProperty> createInterpolatorProperties(Map system, Map user)
{
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.add( new InterpolatorProperty( "${mavenVersion}", "3.0-SNAPSHOT",
PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
if ( system != null )
{
MavenDomainModel model =
( (MavenDomainModel) ctx.transform( domainModels, transformer, transformer, null,
interpolatorProperties, null ) );
return model.getDependencyMetadata();
interpolatorProperties.addAll(
InterpolatorProperty.toInterpolatorProperties( system, PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
}
catch ( IOException e )
if ( user != null )
{
throw new MetadataReaderException( "Unable to transform model", e );
interpolatorProperties.addAll(
InterpolatorProperty.toInterpolatorProperties( user, PomInterpolatorTag.USER_PROPERTIES.name() ) );
}
return interpolatorProperties;
}
private static List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
protected final List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
throws IOException, MetadataReaderException, DependencyProcessorException
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
@ -156,20 +154,4 @@ private static List<DomainModel> getParentsOfDomainModel( MavenDomainModel domai
}
return domainModels;
}
private static List<ModelProperty> transformProfiles( List<ModelProperty> modelProperties )
{
List<ModelProperty> properties = new ArrayList<ModelProperty>();
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.Profiles.Profile.xUri )
&& !mp.getUri().equals( ProjectUri.Profiles.Profile.id )
&& !mp.getUri().startsWith( ProjectUri.Profiles.Profile.Activation.xUri ) )
{
properties.add( new ModelProperty( mp.getUri().replace( ProjectUri.Profiles.Profile.xUri,
ProjectUri.xUri ), mp.getResolvedValue() ) );
}
}
return properties;
}
}

View File

@ -21,44 +21,19 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
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.profile.ProfileContext;
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.ModelDataSource;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Parent;
import org.apache.maven.model.PomClassicDomainModel;
/**
* Provides a wrapper for the maven model.
*/
public final class MavenDomainModel
extends PomClassicDomainModel
{
/**
* Bytes containing the underlying model
*/
private final List<ModelProperty> modelProperties;
/**
* History of joins and deletes of model properties
*/
private String eventHistory;
private ArtifactMetadata parentMetadata;
/**
@ -69,99 +44,74 @@ public final class MavenDomainModel
public MavenDomainModel( byte[] bytes )
throws IOException
{
this( new ByteArrayInputStream( bytes ) );
super( new ByteArrayInputStream( bytes ) );
}
/**
* Constructor
*
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel( InputStream inputStream )
throws IOException
public MavenDomainModel(PomClassicDomainModel model)
throws IOException
{
this( ModelMarshaller.marshallXmlToModelProperties( inputStream, ProjectUri.baseUri, PomTransformer.URIS ) );
}
/**
* Constructor
*
* @throws IOException if there is a problem constructing the model
*/
public MavenDomainModel( List<ModelProperty> modelProperties )
throws IOException
{
super(modelProperties);
this.modelProperties = new ArrayList<ModelProperty>( modelProperties );
}
super(model.getModel());
}
public boolean hasParent()
{
// TODO: Expensive call if no parent
return getParentMetadata() != null;
}
public List<ArtifactMetadata> getDependencyMetadata()
throws DataSourceException
{
List<ArtifactMetadata> metadatas = new ArrayList<ArtifactMetadata>();
ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
for ( ModelContainer modelContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) )
for(Dependency d: model.getDependencies())
{
metadatas.add( transformContainerToMetadata( modelContainer ) );
ArtifactMetadata metadata = new ArtifactMetadata();
metadata.setArtifactId(d.getArtifactId());
metadata.setClassifier(d.getClassifier());
metadata.setGroupId(d.getGroupId());
metadata.setScope( (d.getScope() == null) ? "runtime" : d.getScope());
metadata.setVersion(d.getVersion());
metadata.setOptional(d.isOptional());
if( "test-jar".equals( d.getType() ) )
{
metadata.setType( "jar" );
metadata.setClassifier( "tests" );
}
else
{
metadata.setType( d.getType() );
}
List<ArtifactMetadata> exclusions = new ArrayList<ArtifactMetadata>();
for( Exclusion e : d.getExclusions() )
{
ArtifactMetadata md = new ArtifactMetadata();
md.setArtifactId(e.getArtifactId());
md.setGroupId(e.getGroupId());
exclusions.add(md);
}
metadata.setExclusions(exclusions);
metadatas.add(metadata);
}
return metadatas;
}
public Collection<ModelContainer> getActiveProfileContainers( List<InterpolatorProperty> properties )
throws DataSourceException
{
ModelDataSource dataSource = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES );
return new ProfileContext( dataSource, null, null, properties ).getActiveProfiles();
}
public ArtifactMetadata getParentMetadata()
{
if ( parentMetadata != null )
if(parentMetadata == null)
{
return copyArtifactBasicMetadata( parentMetadata );
Parent parent = model.getParent();
if(parent != null)
{
parentMetadata = new ArtifactMetadata();
parentMetadata.setArtifactId( parent.getArtifactId() );
parentMetadata.setVersion( parent.getVersion() );
parentMetadata.setGroupId( parent.getGroupId() );
}
}
String groupId = null, artifactId = null, version = null;
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().equals( ProjectUri.Parent.version ) )
{
version = mp.getResolvedValue();
}
else if ( mp.getUri().equals( ProjectUri.Parent.artifactId ) )
{
artifactId = mp.getResolvedValue();
}
else if ( mp.getUri().equals( ProjectUri.Parent.groupId ) )
{
groupId = mp.getResolvedValue();
}
if ( groupId != null && artifactId != null && version != null )
{
break;
}
}
if ( groupId == null || artifactId == null || version == null )
{
return null;
}
parentMetadata = new ArtifactMetadata();
parentMetadata.setArtifactId( artifactId );
parentMetadata.setVersion( version );
parentMetadata.setGroupId( groupId );
return copyArtifactBasicMetadata( parentMetadata );
return (parentMetadata != null) ? copyArtifactBasicMetadata( parentMetadata ) : null;
}
private ArtifactMetadata copyArtifactBasicMetadata( ArtifactMetadata metadata )
@ -172,100 +122,4 @@ private ArtifactMetadata copyArtifactBasicMetadata( ArtifactMetadata metadata )
amd.setVersion( metadata.getVersion() );
return amd;
}
/**
* @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 List<ModelProperty> getModelProperties()
throws IOException
{
return new ArrayList<ModelProperty>( modelProperties );
}
private ArtifactMetadata transformContainerToMetadata( ModelContainer container )
throws DataSourceException
{
List<ModelProperty> modelProperties = container.getProperties();
ArtifactMetadata metadata = new ArtifactMetadata();
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.groupId ) )
{
metadata.setGroupId( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.artifactId ) )
{
metadata.setArtifactId( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.version ) )
{
metadata.setVersion( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.classifier ) )
{
metadata.setClassifier( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.scope ) )
{
metadata.setScope( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) )
{
metadata.setType( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.optional ) )
{
metadata.setOptional( mp.getResolvedValue() );
}
}
if ( metadata.getScope() == null )
{
metadata.setScope( "runtime" );
}
ModelDataSource dataSource = new DefaultModelDataSource( container.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(),
new ExclusionModelContainerFactory() ) );
List<ArtifactMetadata> exclusions = new ArrayList<ArtifactMetadata>();
for ( ModelContainer exclusion : dataSource.queryFor( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.xUri ) )
{
ArtifactMetadata meta = new ArtifactMetadata();
exclusions.add( meta );
for ( ModelProperty mp : exclusion.getProperties() )
{
if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.artifactId ) )
{
meta.setArtifactId( mp.getResolvedValue() );
}
else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.Exclusions.Exclusion.groupId ) )
{
meta.setGroupId( mp.getResolvedValue() );
}
}
}
metadata.setExclusions( exclusions );
return metadata;
}
}

View File

@ -1,16 +0,0 @@
package org.apache.maven.mercury;
import java.util.List;
import java.util.Map;
import org.apache.maven.mercury.artifact.ArtifactMetadata;
import org.apache.maven.mercury.builder.api.MetadataReader;
import org.apache.maven.mercury.builder.api.MetadataReaderException;
import org.apache.maven.shared.model.ModelProperty;
public interface PomProcessor
{
List<ModelProperty> getRawPom(ArtifactMetadata bmd, MetadataReader mdReader, Map<String, String> env,
Map<String, String> sysProps)
throws MetadataReaderException, PomProcessorException;
}

View File

@ -1,36 +0,0 @@
package org.apache.maven.mercury;
public class PomProcessorException
extends Exception
{
static final long serialVersionUID = 980457843528974352L;
/**
* Default constructor
*/
public PomProcessorException()
{
super();
}
/**
* Constructor
*
* @param message exception message
*/
public PomProcessorException( String message )
{
super( message );
}
/**
* Constructor
*
* @param message exception message
*/
public PomProcessorException( String message, Exception e )
{
super( message, e );
}
}

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>3.0-SNAPSHOT</version>
</parent>
<artifactId>maven-model-builder</artifactId>
<version>3.0-SNAPSHOT</version>
<name>Maven Model Builder</name>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,8 @@
package org.apache.maven.model;
public interface DomainModel {
boolean isMostSpecialized();
void setMostSpecialized(boolean isMostSpecialized);
}

View File

@ -0,0 +1,14 @@
package org.apache.maven.model;
import java.util.List;
import org.apache.maven.model.Model;
public interface ModelEventListener {
void fire(Model model);
List<String> getUris();
}

View File

@ -0,0 +1,29 @@
package org.apache.maven.model;
/*
* 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.
*/
public interface ModelListener
{
void register( Object xmlNode );
void fire( Object object );
boolean isRegistered( Object object );
}

View File

@ -0,0 +1,288 @@
package org.apache.maven.model;
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.io.Writer;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
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
{
/**
* Bytes containing the underlying model
*/
private byte[] inputBytes;
private String id;
private File file;
private File parentFile;
private File projectDirectory;
private int lineageCount;
private boolean isMostSpecialized = false;
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
protected Model model;
public Model getModel() throws IOException
{
return model;
}
private void initializeProperties(Model model)
{
String groupId = null, artifactId = null, version = null;
groupId = model.getGroupId();
artifactId = model.getArtifactId();
version = model.getVersion();
if( model.getParent() != null)
{
parentArtifactId =model.getParent().getArtifactId();
parentGroupId = model.getParent().getGroupId();
parentVersion = model.getParent().getVersion();
parentRelativePath = model.getParent().getRelativePath();
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( 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() );
}
initializeProperties( model );
}
public PomClassicDomainModel(Model model) throws IOException {
this (model, false);
}
public PomClassicDomainModel(Model model, boolean b) throws IOException {
this.model = model;
this.isMostSpecialized = b;
initializeProperties( model );
}
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() throws IOException
{
return IOUtil.toString( ReaderFactory.newXmlReader( getInputStream() ) );
}
/**
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
*/
public InputStream getInputStream() throws IOException
{
if(inputBytes != null)
{
byte[] copy = new byte[inputBytes.length];
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
return new ByteArrayInputStream( copy );
}
else
{
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();
return new ByteArrayInputStream(inputBytes);
}
}
/**
* @return file of pom. May be null.
*/
public File getFile()
{
return file;
}
public int getLineageCount()
{
return lineageCount;
}
public void setLineageCount( int lineageCount )
{
this.lineageCount = lineageCount;
}
/**
* 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 );
}
}

View File

@ -0,0 +1,36 @@
package org.apache.maven.model;
import java.util.List;
import org.apache.maven.model.Model;
/*
* 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.
*/
public interface Processor
{
void process( Object parent, Object child, Object target, boolean isChildMostSpecialized );
Object getParent();
Object getChild();
List<Model> getParentModels();
}

View File

@ -0,0 +1,352 @@
package org.apache.maven.model;
/*
* 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.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Resource;
import org.apache.maven.model.processors.BuildProcessor;
import org.apache.maven.model.processors.CiManagementProcessor;
import org.apache.maven.model.processors.ContributorsProcessor;
import org.apache.maven.model.processors.DependencyManagementProcessor;
import org.apache.maven.model.processors.DevelopersProcessor;
import org.apache.maven.model.processors.DistributionManagementProcessor;
import org.apache.maven.model.processors.IssueManagementProcessor;
import org.apache.maven.model.processors.LicensesProcessor;
import org.apache.maven.model.processors.MailingListProcessor;
import org.apache.maven.model.processors.ModelProcessor;
import org.apache.maven.model.processors.ModuleProcessor;
import org.apache.maven.model.processors.OrganizationProcessor;
import org.apache.maven.model.processors.ParentProcessor;
import org.apache.maven.model.processors.PluginsManagementProcessor;
import org.apache.maven.model.processors.PrerequisitesProcessor;
import org.apache.maven.model.processors.ProfilePropertiesProcessor;
import org.apache.maven.model.processors.ProfilesModuleProcessor;
import org.apache.maven.model.processors.ProfilesProcessor;
import org.apache.maven.model.processors.PropertiesProcessor;
import org.apache.maven.model.processors.ReportingProcessor;
import org.apache.maven.model.processors.RepositoriesProcessor;
import org.apache.maven.model.processors.ScmProcessor;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class ProcessorContext
{
/**
* Parent domain models on bottom.
*
* @param domainModels
* @param listeners
* @return
* @throws IOException
*/
public static PomClassicDomainModel build( List<DomainModel> domainModels, List<ModelEventListener> listeners )
throws IOException
{
PomClassicDomainModel child = null;
for ( DomainModel domainModel : domainModels )
{
if(domainModel.isMostSpecialized())
{
child = (PomClassicDomainModel) domainModel;
}
}
if(child == null)
{
throw new IOException("Could not find child model");
}
List<Processor> processors =
Arrays.<Processor> asList( new BuildProcessor( new ArrayList<Processor>() ), new ModuleProcessor(),
new PropertiesProcessor(), new ParentProcessor(), new OrganizationProcessor(),
new MailingListProcessor(), new IssueManagementProcessor(),
new CiManagementProcessor(), new ReportingProcessor(),
new RepositoriesProcessor(), new DistributionManagementProcessor(),
new LicensesProcessor(), new ScmProcessor(), new PrerequisitesProcessor(),
new ContributorsProcessor(), new DevelopersProcessor(), new ProfilesProcessor() );
Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ), processors );
if(listeners != null)
{
for(ModelEventListener listener : listeners)
{
listener.fire(target);
}
}
PomClassicDomainModel domainModel = new PomClassicDomainModel( target, child.isMostSpecialized() );
domainModel.setProjectDirectory(child.getProjectDirectory());
domainModel.setParentFile(child.getParentFile());
return domainModel;
}
public static PomClassicDomainModel mergeProfilesIntoModel(Collection<Profile> profiles, PomClassicDomainModel domainModel) throws IOException
{
List<Model> profileModels = new ArrayList<Model>();
List<Model> externalProfileModels = new ArrayList<Model>();
for(Profile profile : profiles)
{
if("pom".equals(profile.getSource()))
{
profileModels.add( attachProfileNodesToModel(profile) );
}
else
{
externalProfileModels.add(attachProfileNodesToModel(profile));
}
}
profileModels.addAll(externalProfileModels);//external takes precedence
Model model = domainModel.getModel();
profileModels.add( 0, model );
List<Processor> processors =
Arrays.<Processor> asList( new BuildProcessor( new ArrayList<Processor>() ), new ProfilesModuleProcessor(),
new ProfilePropertiesProcessor(), new ParentProcessor(),
new OrganizationProcessor(), new MailingListProcessor(),
new IssueManagementProcessor(), new CiManagementProcessor(),
new ReportingProcessor(), new RepositoriesProcessor(),
new DistributionManagementProcessor(), new LicensesProcessor(),
new ScmProcessor(), new PrerequisitesProcessor(), new ContributorsProcessor(),
new DevelopersProcessor(), new ProfilesProcessor() );
//Remove the plugin management and dependency management so they aren't applied again with the profile processing
PluginManagement mng = null;
if( model.getBuild() != null)
{
mng = model.getBuild().getPluginManagement();
model.getBuild().setPluginManagement( null );
}
DependencyManagement depMng = model.getDependencyManagement();
Model target = processModelsForInheritance(profileModels, processors);
PluginsManagementProcessor pmp = new PluginsManagementProcessor();
if( mng != null )
{
if(target.getBuild().getPluginManagement() != null)
{
pmp.process(null, mng.getPlugins(), target.getBuild().getPluginManagement().getPlugins(), false);
}
else
{
target.getBuild().setPluginManagement( mng );
}
}
//TODO: Merge Dependency Management
target.setDependencyManagement( depMng );
PomClassicDomainModel targetModel = new PomClassicDomainModel( target, domainModel.isMostSpecialized());
targetModel.setParentFile(domainModel.getParentFile());
targetModel.setProjectDirectory(domainModel.getProjectDirectory());
return targetModel;
}
private static Model attachProfileNodesToModel(Profile profile)
{
Profile p = copyOfProfile(profile);
Model model = new Model();
model.setModules( p.getModules() );
model.setDependencies(p.getDependencies());
model.setDependencyManagement( p.getDependencyManagement());
model.setDistributionManagement( p.getDistributionManagement() );
model.setProperties( p.getProperties() );
model.setModules( new ArrayList<String>(p.getModules() ) );
model.setRepositories(p.getRepositories());
model.setPluginRepositories(p.getPluginRepositories());
model.setReporting(p.getReporting());
BuildProcessor proc = new BuildProcessor( new ArrayList<Processor>());
proc.processWithProfile( p.getBuild(), model);
return model;
}
private static List<Model> convertDomainModelsToMavenModels(List<DomainModel> domainModels) throws IOException
{
List<Model> models = new ArrayList<Model>();
for(DomainModel domainModel : domainModels)
{
PomClassicDomainModel dm = (PomClassicDomainModel) domainModel;
if(dm.getModel() != null)
{
if(dm.isMostSpecialized())
{
models.add(0, dm.getModel() );
}
else
{
models.add( dm.getModel() );
}
}
else
{
throw new IOException( "model: null" );
}
}
return models;
}
private static Model processModelsForInheritance(List<Model> models, List<Processor> processors)
{
ModelProcessor modelProcessor = new ModelProcessor( processors );
Collections.reverse( models );
int length = models.size();
Model target = new Model();
if(length == 1)
{
modelProcessor.process( null, models.get( 0 ), target, true );
} else if( length == 2)
{
modelProcessor.process( models.get( 0 ), models.get( 1 ), target, true );
}
else {
for ( int i = 0; i < length - 1; i++ )
{
if(i == 0)
{
modelProcessor.process( null, models.get( 0 ), target, false );
}
else if ( i < length - 2 )
{
modelProcessor.process( models.get( i ), models.get( i + 1 ), target, false );
}
else
{
modelProcessor.process( models.get( i ), models.get( i + 1 ), target, true );
}
}
}
// Dependency Management
DependencyManagementProcessor depProc = new DependencyManagementProcessor();
if ( target.getDependencyManagement() != null )
{
depProc.process( null, new ArrayList<Dependency>( target.getDependencyManagement().getDependencies() ),
target.getDependencies(), true );
}
// Plugin Management
PluginsManagementProcessor procMng = new PluginsManagementProcessor();
if ( target.getBuild() != null && target.getBuild().getPluginManagement() != null)
{
procMng.process( null, new ArrayList<Plugin>( target.getBuild().getPluginManagement().getPlugins() ),
target.getBuild().getPlugins(), true );
}
return target;
}
public static Profile copyOfProfile(Profile profile)
{
Profile p = new Profile();
p.setModules( new ArrayList<String>(profile.getModules()) );
p.setDependencies(new ArrayList<Dependency>(profile.getDependencies()));
p.setDependencyManagement( profile.getDependencyManagement());
p.setDistributionManagement( profile.getDistributionManagement() );
p.setProperties( profile.getProperties() );
p.setBuild( copyBuild(profile.getBuild()) );
p.setId( profile.getId() );
p.setActivation( profile.getActivation() );
p.setRepositories(profile.getRepositories());
p.setPluginRepositories(profile.getPluginRepositories());
p.setReporting(profile.getReporting());
return p;
}
private static BuildBase copyBuild(BuildBase base)
{
if(base == null)
{
return null;
}
BuildBase b = new BuildBase();
b.setDefaultGoal( base.getDefaultGoal() );
b.setDirectory( base.getDirectory() );
b.setFilters( new ArrayList<String>(base.getFilters()) );
b.setFinalName( base.getFinalName() );
b.setPluginManagement( copyPluginManagement(base.getPluginManagement()) );
b.setPlugins( copyPlugins(base.getPlugins()) );
b.setResources( new ArrayList<Resource>(base.getResources()) );
b.setTestResources( new ArrayList<Resource>(base.getTestResources()) );
return b;
}
private static PluginManagement copyPluginManagement(PluginManagement mng)
{
if(mng == null)
{
return null;
}
PluginManagement pm = new PluginManagement();
pm.setPlugins(copyPlugins(mng.getPlugins()));
return pm;
}
private static List<Plugin> copyPlugins(List<Plugin> plugins)
{
List<Plugin> ps = new ArrayList<Plugin>();
for(Plugin p : plugins)
{
ps.add( copyPlugin(p) );
}
return ps;
}
private static Plugin copyPlugin(Plugin plugin)
{
Plugin p = new Plugin();
p.setArtifactId( plugin.getArtifactId() );
if(plugin.getConfiguration() != null)
{
p.setConfiguration( new Xpp3Dom((Xpp3Dom) plugin.getConfiguration()) );
}
p.setDependencies( new ArrayList<Dependency>(plugin.getDependencies()) );
p.setExecutions( new ArrayList<PluginExecution>(plugin.getExecutions()) );
p.setGoals( plugin.getGoals() );
p.setGroupId( plugin.getGroupId() );
p.setInherited( plugin.getInherited() );
p.setVersion( plugin.getVersion() );
return p;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -0,0 +1,811 @@
package org.apache.maven.model.interpolator;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.PomClassicDomainModel;
import org.apache.maven.model.ProjectUri;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.codehaus.plexus.component.annotations.Component;
@Component(role=Interpolator.class)
public class DefaultInterpolator implements Interpolator {
public String interpolateXmlString(String xml,
List<InterpolatorProperty> interpolatorProperties) throws IOException
{
List<ModelProperty> modelProperties = marshallXmlToModelProperties( new ByteArrayInputStream( xml.getBytes() ), ProjectUri.baseUri, URIS );
Map<String, String> aliases = new HashMap<String, String>();
aliases.put( "project.", "pom." );
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>( interpolatorProperties );
ips.addAll( createInterpolatorProperties( modelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name()) );
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null )
{
String uri = mp.getUri();
ips.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, uri.length() ) + "}", mp.getValue() ) );
}
}
interpolateModelProperties( modelProperties, ips );
return unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
}
public PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List<InterpolatorProperty> 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<ModelProperty> modelProperties = getModelProperties(dm.getInputStream());
if ("jar".equals(dm.getModel().getPackaging())) {
modelProperties.add(new ModelProperty(ProjectUri.packaging, "jar"));
}
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
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<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
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<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>(
interpolatorProperties);
ips1.addAll(standardInterpolatorProperties);
ips1.addAll(createInterpolatorProperties(
firstPassModelProperties, ProjectUri.baseUri, aliases,
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
Collections.sort(ips1, new Comparator<InterpolatorProperty>() {
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<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
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<ModelProperty, ModelProperty> e : buildDirectories
.entrySet()) {
secondPassModelProperties.remove(e.getKey());
secondPassModelProperties.add(e.getValue());
}
}
// THIRD PASS - Use build directories as interpolator properties
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>(
interpolatorProperties);
ips2.addAll(standardInterpolatorProperties);
ips2.addAll(createInterpolatorProperties(
secondPassModelProperties, ProjectUri.baseUri, aliases,
PomInterpolatorTag.PROJECT_PROPERTIES.name()));
ips2.addAll(interpolatorProperties);
Collections.sort(ips2, new Comparator<InterpolatorProperty>() {
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);
try
{
String xml = unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
PomClassicDomainModel domainModel = new PomClassicDomainModel( new ByteArrayInputStream ( xml.getBytes( "UTF-8" )));
if ( dm.getProjectDirectory() != null )
{
alignPaths(domainModel.getModel(), dm.getProjectDirectory());
}
return domainModel;
}
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))
{
}
}
}
*/
}
/**
* Post-processes the paths of build directories by aligning relative paths to the project directory and normalizing
* file separators to the platform-specific separator.
*
* @param model The model to process, must not be {@code null}.
* @param basedir The project directory, must not be {@code null}.
*/
private static void alignPaths( Model model, File basedir )
{
Build build = model.getBuild();
if ( build != null )
{
build.setDirectory( getAlignedPathFor( build.getDirectory(), basedir ) );
build.setOutputDirectory( getAlignedPathFor( build.getOutputDirectory(), basedir ) );
build.setTestOutputDirectory( getAlignedPathFor( build.getTestOutputDirectory(), basedir ) );
build.setSourceDirectory( getAlignedPathFor( build.getSourceDirectory(), basedir ) );
build.setTestSourceDirectory( getAlignedPathFor( build.getTestSourceDirectory(), basedir ) );
build.setScriptSourceDirectory( getAlignedPathFor( build.getScriptSourceDirectory(), basedir ) );
for ( Resource r : build.getResources() )
{
r.setDirectory( getAlignedPathFor( r.getDirectory(), basedir ) );
}
for ( Resource r : build.getTestResources() )
{
r.setDirectory( getAlignedPathFor( r.getDirectory(), basedir ) );
}
List<String> filters = new ArrayList<String>();
for ( String f : build.getFilters() )
{
filters.add( getAlignedPathFor( f, basedir ) );
}
build.setFilters( filters );
}
Reporting reporting = model.getReporting();
if ( reporting != null )
{
reporting.setOutputDirectory( getAlignedPathFor( reporting.getOutputDirectory(), basedir ) );
}
}
private static String getAlignedPathFor(String path, File basedir)
{
if ( path != null )
{
File file = new File( path );
if ( file.isAbsolute() )
{
// path was already absolute, just normalize file separator and we're done
path = file.getPath();
}
else if ( file.getPath().startsWith( File.separator ) )
{
// drive-relative Windows path, don't align with project directory but with drive root
path = file.getAbsolutePath();
}
else
{
// an ordinary relative path, align with project directory
path = new File( new File( basedir, path ).toURI().normalize() ).getAbsolutePath();
}
}
return path;
}
private static void interpolateModelProperties(List<ModelProperty> modelProperties,
List<InterpolatorProperty> interpolatorProperties )
{
if (modelProperties == null) {
throw new IllegalArgumentException("modelProperties: null");
}
if (interpolatorProperties == null) {
throw new IllegalArgumentException("interpolatorProperties: null");
}
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
for (ModelProperty mp : modelProperties) {
if (!mp.isResolved()) {
unresolvedProperties.add(mp);
}
}
LinkedHashSet<InterpolatorProperty> ips = new LinkedHashSet<InterpolatorProperty>();
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;
break;
}
}
}
}
}
private static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
String baseUriForModel,
Map<String, String> aliases,
String interpolatorTag)
{
if (modelProperties == null) {
throw new IllegalArgumentException("modelProperties: null");
}
if (baseUriForModel == null) {
throw new IllegalArgumentException("baseUriForModel: null");
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
for (ModelProperty mp : modelProperties) {
InterpolatorProperty ip = mp
.asInterpolatorProperty(baseUriForModel);
if (ip != null) {
ip.setTag(interpolatorTag);
interpolatorProperties.add(ip);
for (Map.Entry<String, String> a : aliases.entrySet()) {
interpolatorProperties.add(new InterpolatorProperty(ip
.getKey().replaceAll(a.getKey(), a.getValue()), ip
.getValue().replaceAll(a.getKey(), a.getValue()),
interpolatorTag));
}
}
}
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>();
for (InterpolatorProperty ip : interpolatorProperties) {
if (!ips.contains(ip)) {
ips.add(ip);
}
}
return ips;
}
private static List<ModelProperty> getModelProperties(InputStream is) throws IOException
{
Set<String> s = new HashSet<String>();
//TODO: Should add all collections from ProjectUri
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);
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);
return new ArrayList<ModelProperty>(marshallXmlToModelProperties(is, ProjectUri.baseUri, s ));
}
/**
* 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
*/
private static String unmarshalModelPropertiesToXml( List<ModelProperty> 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<String> lastUriTags = new ArrayList<String>();
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<String> 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<ModelProperty> attributes = new ArrayList<ModelProperty>();
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<String> 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<ModelProperty> 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( "</" ).append( value ).append( ">" );
return sb.toString();
}
private static final Set<String> URIS = Collections.unmodifiableSet(new HashSet<String>( 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
*/
private static List<ModelProperty> marshallXmlToModelProperties( InputStream inputStream, String baseUri,
Set<String> 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
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<String, String> attributes = new HashMap<String, String>();
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<String, String> 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<String, String> 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) {
}
}
}
private static final Map<String, String> aliases = new HashMap<String, String>();
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 boolean containsProjectVersion( List<InterpolatorProperty> interpolatorProperties )
{
InterpolatorProperty versionInterpolatorProperty =
new ModelProperty( ProjectUri.version, "" ).asInterpolatorProperty( ProjectUri.baseUri );
for ( InterpolatorProperty ip : interpolatorProperties )
{
if ( ip.equals( versionInterpolatorProperty ) )
{
return true;
}
}
return false;
}
/**
* Class for storing information about URIs.
*/
private static class Uri
{
List<String> uris;
Uri( String baseUri )
{
uris = new LinkedList<String>();
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<String>( uris.subList( 0, depth ) );
}
}
}

View File

@ -0,0 +1,17 @@
package org.apache.maven.model.interpolator;
import java.io.IOException;
import java.util.List;
import org.apache.maven.model.PomClassicDomainModel;
public interface Interpolator
{
String interpolateXmlString( String xml, List<InterpolatorProperty> interpolatorProperties )
throws IOException;
PomClassicDomainModel interpolateDomainModel( PomClassicDomainModel dm, List<InterpolatorProperty> interpolatorProperties )
throws IOException ;
}

View File

@ -0,0 +1,175 @@
package org.apache.maven.model.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<InterpolatorProperty> toInterpolatorProperties( Map<String, String> properties, String tag )
{
if( properties == null )
{
throw new IllegalArgumentException( "properties: null" );
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
for ( Map.Entry<String, String> 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<InterpolatorProperty> toInterpolatorProperties( Properties properties, String tag )
{
if( properties == null )
{
throw new IllegalArgumentException( "properties: null" );
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
for ( Map.Entry<Object, Object> e : properties.entrySet() )
{
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) );
}
return interpolatorProperties;
}
}

View File

@ -0,0 +1,255 @@
package org.apache.maven.model.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.
*/
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<String> 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<String>();
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 ("<![CDATA[")
&& (resolvedValue.contains( "=" ) || resolvedValue.contains( "<" ) || resolvedValue.contains( "&" )))
{
resolvedValue = "<![CDATA[" + resolvedValue + "]]>";
}
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();
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.model.interpolator;
public enum PomInterpolatorTag

View File

@ -0,0 +1,177 @@
package org.apache.maven.model.processors;
/*
* 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.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Model;
import org.apache.maven.model.Processor;
public abstract class BaseProcessor implements Processor
{
Object parent;
Object child;
Collection<Processor> processors;
private List<Model> parentModels;
public BaseProcessor( Collection<Processor> processors )
{
if ( processors == null )
{
throw new IllegalArgumentException( "processors: null" );
}
this.processors = processors;
parentModels = new ArrayList<Model>();
}
/**
* Ordered from least specialized to most specialized.
*/
public List<Model> getParentModels()
{
return parentModels;
}
public BaseProcessor()
{
this(new ArrayList<Processor>());
}
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
if ( target == null )
{
throw new IllegalArgumentException( "target: null" );
}
this.parent = parent;
this.child = child;
if(parent instanceof Model)
{
parentModels.add( (Model) parent );
}
for ( Processor processor : processors )
{
processor.process( parent, child, target, isChildMostSpecialized );
}
}
public Object getChild()
{
return child;
}
public Object getParent()
{
return parent;
}
protected String normalizeUriWithRelativePath(String u, String artifactId, Model parent)
{
if(u == null)
{
return null;
}
try
{
String slashes = getSlashes(new URI(u).getRawSchemeSpecificPart());
URI uri = new URI(u + "/"
+ getModulePathAdjustment(parent, artifactId));
String normalized = uri.normalize().toASCIIString();
if("file".equals(uri.getScheme()))//UNC Paths
{
normalized = normalized.replaceFirst("/", slashes);
}
return normalized;
}
catch (URISyntaxException e) {
}
return null;
}
private static String getSlashes(String uri)
{
StringBuilder sb = new StringBuilder();
for(byte b : uri.getBytes())
{
if(b == 47)
{
sb.append("/");
}
else
{
break;
}
}
return sb.toString();
}
private String getModulePathAdjustment(Model moduleProject,
String artifactId) {
Map<String, String> moduleAdjustments = new HashMap<String, String>();
List<String> modules = moduleProject.getModules();
if (modules != null) {
for (Iterator<String> it = modules.iterator(); it.hasNext();) {
String modulePath = it.next();
String moduleName = modulePath;
if (moduleName.endsWith("/") || moduleName.endsWith("\\")) {
moduleName = moduleName.substring(0,
moduleName.length() - 1);
}
int lastSlash = moduleName.lastIndexOf('/');
if (lastSlash < 0) {
lastSlash = moduleName.lastIndexOf('\\');
}
String adjustment = null;
if (lastSlash > -1) {
moduleName = moduleName.substring(lastSlash + 1);
adjustment = modulePath.substring(0, lastSlash);
}
moduleAdjustments.put(moduleName, adjustment);
}
}
String adjust = moduleAdjustments.get(artifactId);
return (adjust != null) ? adjust + "/" + artifactId : "/" + artifactId;
}
}

View File

@ -0,0 +1,264 @@
package org.apache.maven.model.processors;
/*
* 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.Collection;
import java.util.List;
import org.apache.maven.model.Build;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Extension;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelEventListener;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Processor;
import org.apache.maven.model.Resource;
public class BuildProcessor
extends BaseProcessor
{
private List<ModelEventListener> listeners;
public BuildProcessor( Collection<Processor> processors )
{
super( processors );
listeners = new ArrayList<ModelEventListener>();
}
public BuildProcessor( Collection<Processor> processors, List<ModelEventListener> listeners)
{
super( processors );
listeners = (listeners == null) ? new ArrayList<ModelEventListener>() : new ArrayList<ModelEventListener>(listeners);
}
public void processWithProfile( BuildBase build, Model target )
{
processBuild(null, build, target, false, true );
}
private void processBuild(Model p, BuildBase build, Model t, boolean isChildMostSpecialized, boolean isProfile)
{
if(t.getBuild() == null)
{
t.setBuild( new Build() );
}
PluginsProcessor pluginsProcessor = new PluginsProcessor();
if(build == null && !( p == null || p.getBuild() == null))
{
copy(p.getBuild(), t.getBuild(), isProfile);
copyFilters(p.getBuild(), t.getBuild());
pluginsProcessor.process( p.getBuild().getPlugins(), null, t.getBuild().getPlugins(), isChildMostSpecialized );
inheritManagement(p.getBuild().getPluginManagement(), null, t.getBuild());
}
else if(build != null && !( p == null || p.getBuild() == null))
{
copy(p.getBuild(), t.getBuild(), isProfile);
copy(build, t.getBuild(), isProfile);
copyFilters(build, t.getBuild());
copyFilters(p.getBuild(), t.getBuild());
pluginsProcessor.process( p.getBuild().getPlugins(), build.getPlugins(), t.getBuild().getPlugins(), isChildMostSpecialized );
inheritManagement(p.getBuild().getPluginManagement(), build.getPluginManagement(), t.getBuild());
}
else if(build != null )
{
copy(build, t.getBuild(), isProfile);
copyFilters(build, t.getBuild());
pluginsProcessor.process( null, build.getPlugins(), t.getBuild().getPlugins(), isChildMostSpecialized );
inheritManagement(null, build.getPluginManagement(), t.getBuild());
}
}
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
processBuild(p, c.getBuild(), t, isChildMostSpecialized, false );
}
private static void inheritManagement(PluginManagement parent, PluginManagement child, Build target)
{
PluginsProcessor proc = new PluginsProcessor();
List<Plugin> p = (parent == null) ? new ArrayList<Plugin>() : parent.getPlugins();
List<Plugin> c = (child == null) ? new ArrayList<Plugin>() : child.getPlugins();
if(!c.isEmpty() || !p.isEmpty())
{
if(target.getPluginManagement() == null)
{
target.setPluginManagement( new PluginManagement() );
}
proc.process( p, c, target.getPluginManagement().getPlugins(), false );
}
}
private static void copyFilters(BuildBase source, Build target)
{
List<String> filters = new ArrayList<String>(target.getFilters());
for(String filter : source.getFilters())
{
if(!filters.contains( filter ))
{
filters.add( filter );
}
}
// SortedSet<String> s = new TreeSet<String>( new ArrayList<String>( target.getFilters() ) );
// s.addAll( source.getFilters() );
// List<String> l = Arrays.asList(s.toArray( new String[s.size()]) );
target.setFilters( filters );
}
private static void copy(BuildBase source, Build target, boolean isProfile)
{
if(source.getFinalName() != null)
{
target.setFinalName( source.getFinalName() );
}
if(source.getDefaultGoal() != null)
{
target.setDefaultGoal( source.getDefaultGoal() );
}
if(source.getDirectory() != null)
{
target.setDirectory( source.getDirectory() );
}
if(!source.getResources().isEmpty())
{
List<Resource> resources = new ArrayList<Resource>();
for(Resource resource : source.getResources())
{
Resource r = new Resource();
r.setDirectory( resource.getDirectory());
r.setFilteringValue( resource.getFilteringValue() );
r.setMergeId( resource.getMergeId() );
r.setTargetPath( resource.getTargetPath() );
r.setExcludes( new ArrayList<String>(resource.getExcludes()) );
r.setIncludes( new ArrayList<String>(resource.getIncludes()) );
resources.add( r );
}
target.setResources( resources );
}
if(!source.getTestResources().isEmpty())
{
List<Resource> resources = new ArrayList<Resource>();
for(Resource resource : source.getTestResources())
{
Resource r = new Resource();
r.setDirectory( resource.getDirectory());
r.setFiltering( resource.isFiltering() );
r.setMergeId( resource.getMergeId() );
r.setTargetPath( resource.getTargetPath() );
r.setExcludes( new ArrayList<String>(resource.getExcludes()) );
r.setIncludes( new ArrayList<String>(resource.getIncludes()) );
resources.add( r );
}
target.setTestResources( resources );
}
if(!isProfile)
{
copyBuild((Build) source, target);
}
}
private static void copyBuild(Build source, Build target)
{
if(source.getOutputDirectory() != null)
{
target.setOutputDirectory( source.getOutputDirectory() );
}
if(source.getScriptSourceDirectory() != null)
{
target.setScriptSourceDirectory( source.getScriptSourceDirectory() );
}
if(source.getSourceDirectory() != null)
{
target.setSourceDirectory( source.getSourceDirectory() );
}
if(source.getTestOutputDirectory() != null)
{
target.setTestOutputDirectory( source.getTestOutputDirectory() );
}
if(source.getTestSourceDirectory() != null)
{
target.setTestSourceDirectory( source.getTestSourceDirectory() );
}
/*
List<Dependency> childDependencies =
new ArrayList<Dependency>(dependencies.subList( length - 1 , dependencies.size() ) );
dependencies.removeAll( childDependencies );
dependencies.addAll( 0, childDependencies );
*/
int i = target.getExtensions().size();
List<Extension> m = new ArrayList<Extension>();
for(Extension extension : source.getExtensions())
{
Extension match = isMatch(extension, target.getExtensions());
if(match != null)
{
match.setArtifactId( extension.getArtifactId() );
match.setGroupId( extension.getGroupId() );
match.setVersion( extension.getVersion() );
m.add( match );
}
else
{
Extension e = new Extension();
e.setArtifactId( extension.getArtifactId() );
e.setGroupId( extension.getGroupId() );
e.setVersion( extension.getVersion() );
m.add( e );
}
}
target.getExtensions().removeAll( m );
target.getExtensions().addAll( 0, m );
}
private static Extension isMatch(Extension extension, List<Extension> extensions)
{
for(Extension e : extensions)
{
if(e.getGroupId().equals( extension.getGroupId() ) && e.getArtifactId().equals( extension.getArtifactId() ))
{
return e;
}
}
return null;
}
}

View File

@ -0,0 +1,89 @@
package org.apache.maven.model.processors;
/*
* 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.Properties;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Notifier;
public class CiManagementProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( c.getCiManagement() != null )
{
CiManagement childMng = c.getCiManagement();
CiManagement mng = new CiManagement();
mng.setSystem( childMng.getSystem() );
mng.setUrl( childMng.getUrl() );
t.setCiManagement( mng );
addNotifiers( c.getCiManagement().getNotifiers(), t.getCiManagement() );
}
else if ( p != null && p.getCiManagement() != null )
{
CiManagement parentMng = p.getCiManagement();
CiManagement mng = new CiManagement();
mng.setSystem( parentMng.getSystem() );
mng.setUrl( parentMng.getUrl() );
t.setCiManagement( mng );
addNotifiers( p.getCiManagement().getNotifiers(), t.getCiManagement() );
}
}
private static void addNotifiers( List<Notifier> notifiers, CiManagement ciManagement )
{
if ( notifiers == null )
{
return;
}
List<Notifier> n = new ArrayList<Notifier>();
for ( Notifier notifier : notifiers )
{
Notifier notifierCopy = new Notifier();
Properties properties = new Properties();
properties.putAll( notifier.getConfiguration() );
notifierCopy.setConfiguration( properties );
notifierCopy.setAddress( notifier.getAddress() );
notifierCopy.setSendOnError( notifier.isSendOnError() );
notifierCopy.setSendOnFailure( notifier.isSendOnFailure() );
notifierCopy.setSendOnSuccess( notifier.isSendOnSuccess() );
notifierCopy.setSendOnWarning( notifier.isSendOnWarning() );
notifierCopy.setType( notifier.getType() );
n.add( notifierCopy );
}
ciManagement.getNotifiers().addAll( n );
}
}

View File

@ -0,0 +1,70 @@
package org.apache.maven.model.processors;
/*
* 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.Properties;
import org.apache.maven.model.Contributor;
import org.apache.maven.model.Model;
public class ContributorsProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model p = (Model) parent;
Model c = (Model) child;
Model t = (Model) target;
if ( !c.getContributors().isEmpty() )
{
copyContributors( c.getContributors(), t );
}
else if ( p != null && !p.getContributors().isEmpty() )
{
copyContributors( p.getContributors(), t );
}
}
private static void copyContributors( List<Contributor> contributors, Model target )
{
for ( Contributor contributor : contributors )
{
Contributor copy = new Contributor();
copy.setName( contributor.getName() );
copy.setEmail( contributor.getEmail() );
copy.setUrl( contributor.getUrl() );
copy.setOrganization( contributor.getOrganization() );
copy.setOrganizationUrl( contributor.getOrganizationUrl() );
copy.setTimezone( contributor.getTimezone() );
copy.setRoles( new ArrayList<String>( contributor.getRoles() ) );
Properties props = new Properties();
props.putAll( contributor.getProperties() );
copy.setProperties( props );
target.addContributor( copy );
}
}
}

View File

@ -0,0 +1,92 @@
package org.apache.maven.model.processors;
/*
* 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.Collections;
import java.util.List;
import org.apache.maven.model.Dependency;
public class DependenciesProcessor
extends BaseProcessor
{
private boolean isDependencyManagement;
public DependenciesProcessor() {}
public DependenciesProcessor(boolean isDependencyManagement) {
this.isDependencyManagement = isDependencyManagement;
}
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Dependency> c = (child != null) ? (List<Dependency>) child : new ArrayList<Dependency>() ;
List<Dependency> p = null;
if ( parent != null )
{
p = (List<Dependency>) parent;
}
List<Dependency> dependencies = (List<Dependency>) target;
DependencyProcessor processor = new DependencyProcessor(isDependencyManagement);
if ( ( p == null || p.isEmpty() ) && !c.isEmpty() )
{
for ( Dependency dependency : c )
{
processor.process( null, dependency, dependencies, isChildMostSpecialized );
}
}
else
{
if ( !c.isEmpty() )
{
for ( Dependency parentDependency : p )
{
processor.process( parentDependency, null, dependencies, isChildMostSpecialized );
}
int length = dependencies.size();
for ( Dependency childDependency : c )
{
processor.process( null, childDependency, dependencies, isChildMostSpecialized );
}
//Move elements so child dependencies are first
List<Dependency> childDependencies =
new ArrayList<Dependency>(dependencies.subList( length - 1 , dependencies.size() ) );
dependencies.removeAll( childDependencies );
dependencies.addAll( 0, childDependencies );
}
else if( p != null)
{
for ( Dependency d2 : p )
{
processor.process( d2, null, dependencies, isChildMostSpecialized );
}
}
}
}
}

View File

@ -0,0 +1,132 @@
package org.apache.maven.model.processors;
/*
* 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.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
public class DependencyManagementProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Dependency> depManagement = (List<Dependency> ) child;
List<Dependency> targetDependencies = (List<Dependency>) target;
for(Dependency depMng : depManagement)
{
for(Dependency targetDep : targetDependencies)
{
if(match(depMng, targetDep))
{
copy(depMng, targetDep );
}
}
}
}
private static void copy( Dependency dependency, Dependency targetDependency )
{
if ( targetDependency.getArtifactId() == null )
{
targetDependency.setArtifactId( dependency.getArtifactId() );
}
if ( targetDependency.getClassifier() == null )
{
targetDependency.setClassifier( dependency.getClassifier() );
}
if ( targetDependency.getGroupId() == null )
{
targetDependency.setGroupId( dependency.getGroupId() );
}
if ( targetDependency.getScope() == null )
{
targetDependency.setScope( dependency.getScope() );
}
if ( targetDependency.getSystemPath() == null )
{
targetDependency.setSystemPath( dependency.getSystemPath() );
}
if ( targetDependency.getType() == null )
{
targetDependency.setType( dependency.getType() );
}
if ( targetDependency.getVersion() == null )
{
targetDependency.setVersion( dependency.getVersion() );
}
if ( !dependency.getExclusions().isEmpty() )
{
List<Exclusion> targetExclusions = targetDependency.getExclusions();
for ( Exclusion e : dependency.getExclusions() )
{
if ( !containsExclusion( e, targetExclusions ) )
{
Exclusion e1 = new Exclusion();
e1.setArtifactId( e.getArtifactId() );
e1.setGroupId( e.getGroupId() );
targetDependency.addExclusion( e1 );
}
}
}
targetDependency.setOptional( dependency.isOptional() );
}
private static boolean containsExclusion( Exclusion exclusion, List<Exclusion> exclusions )
{
if(exclusions == null || exclusions.isEmpty())
{
return false;
}
for ( Exclusion e : exclusions )
{
if ( e.getGroupId().equals( exclusion.getGroupId() )
&& e.getArtifactId().equals( exclusion.getArtifactId() ) )
{
return true;
}
}
return false;
}
private boolean match( Dependency d1, Dependency d2 )
{
return getId( d1 ).equals( getId( d2 ) );
}
private String getId( Dependency d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() );
return sb.toString();
}
}

View File

@ -0,0 +1,225 @@
package org.apache.maven.model.processors;
/*
* 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.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
public class DependencyProcessor
extends BaseProcessor
{
private boolean isDependencyManagement;
public DependencyProcessor(){ }
public DependencyProcessor(boolean isDependencyManagement)
{
this.isDependencyManagement = isDependencyManagement;
}
/*
* Process children first
*/
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Dependency> t = (List<Dependency>) target;
if ( parent == null && child == null )
{
return;
}
else if ( parent == null && child != null )
{
boolean isAdd = true;
Dependency targetDependency = contains((Dependency) child, t);
if(targetDependency == null)
{
targetDependency = new Dependency();
}
else
{
isAdd = false;
}
if(!isAdd)
{
t.remove( targetDependency );
}
copy( (Dependency) child, targetDependency);
t.add( targetDependency );
}
else if ( parent != null && child == null )
{
boolean isAdd = true;
Dependency targetDependency = contains((Dependency) parent, t);
if(targetDependency == null)
{
targetDependency = new Dependency();
}
else
{
isAdd = false;
}
copy( (Dependency) parent, targetDependency);
if(isAdd) t.add( targetDependency );
}
else
// JOIN
{
Dependency targetDependency = new Dependency();
copy( (Dependency) parent, targetDependency );
copy( (Dependency) child, targetDependency);
/*
if( isMatch( (Dependency) child, (Dependency) parent))
{
copy( (Dependency) child, targetDependency);
}
else
{
copy( (Dependency) parent, targetDependency );
copy( (Dependency) child, targetDependency);
}
*/
t.add( targetDependency );
}
}
private static boolean isMatch(Dependency d1, Dependency d2)
{
return d1.getGroupId().equals(d2.getGroupId()) && d1.getArtifactId().equals(d2.getArtifactId());
}
private Dependency contains(Dependency d1, List<Dependency> dependencies)
{
for(Dependency d : dependencies)
{
if( match(d, d1))
{
return d;
}
}
return null;
}
private boolean match( Dependency d1, Dependency d2 )
{
// TODO: Version ranges ?
return getId( d1 ).equals( getId( d2 ) );
}
private String getId( Dependency d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() );
sb.append( ":" ).append(
d.getType() == null ? "jar"
: d.getType() ).append(
":" ).append(
d.getClassifier() );
return sb.toString();
}
private boolean isMatch(Object source, Object target, boolean isDependencyManagement)
{
return (source != null && !isDependencyManagement) || target == null;
}
private void copy( Dependency source, Dependency targetDependency)
{
if ( isMatch(source.getArtifactId(), targetDependency.getArtifactId(), isDependencyManagement) )
{
targetDependency.setArtifactId( source.getArtifactId() );
}
if ( isMatch(source.getClassifier(), targetDependency.getClassifier(), isDependencyManagement) )
{
targetDependency.setClassifier( source.getClassifier() );
}
if ( isMatch(source.getGroupId(), targetDependency.getGroupId(), isDependencyManagement) )
{
targetDependency.setGroupId( source.getGroupId() );
}
if (isMatch(source.getScope(), targetDependency.getScope(), isDependencyManagement) )
{
targetDependency.setScope( source.getScope() );
}
if ( isMatch(source.getSystemPath(), targetDependency.getSystemPath(), isDependencyManagement) )
{
targetDependency.setSystemPath( source.getSystemPath() );
}
if ( isMatch(source.getType(), targetDependency.getType(), isDependencyManagement))
{
targetDependency.setType( source.getType() );
}
if ( isMatch(source.getVersion(), targetDependency.getVersion(), isDependencyManagement) )
{
targetDependency.setVersion( source.getVersion() );
}
if ( !source.getExclusions().isEmpty() )
{
List<Exclusion> targetExclusions = targetDependency.getExclusions();
for ( Exclusion e : source.getExclusions() )
{
if ( !containsExclusion( e, targetExclusions ) )
{
Exclusion e1 = new Exclusion();
e1.setArtifactId( e.getArtifactId() );
e1.setGroupId( e.getGroupId() );
targetDependency.addExclusion( e1 );
}
}
}
targetDependency.setOptional( source.isOptional() );
}
private static boolean containsExclusion( Exclusion exclusion, List<Exclusion> exclusions )
{
if(exclusions == null || exclusions.isEmpty())
{
return false;
}
for ( Exclusion e : exclusions )
{
if ( e.getGroupId().equals( exclusion.getGroupId() )
&& e.getArtifactId().equals( exclusion.getArtifactId() ) )
{
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,71 @@
package org.apache.maven.model.processors;
/*
* 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.Properties;
import org.apache.maven.model.Developer;
import org.apache.maven.model.Model;
public class DevelopersProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model p = (Model) parent;
Model c = (Model) child;
Model t = (Model) target;
if ( !c.getDevelopers().isEmpty() )
{
copyDevelopers( c.getDevelopers(), t );
}
else if ( p != null && !p.getDevelopers().isEmpty() )
{
copyDevelopers( p.getDevelopers(), t );
}
}
private static void copyDevelopers( List<Developer> developers, Model target )
{
for ( Developer developer : developers )
{
Developer copy = new Developer();
copy.setId( developer.getId() );
copy.setName( developer.getName() );
copy.setEmail( developer.getEmail() );
copy.setUrl( developer.getUrl() );
copy.setOrganization( developer.getOrganization() );
copy.setOrganizationUrl( developer.getOrganizationUrl() );
copy.setTimezone( developer.getTimezone() );
copy.setRoles( new ArrayList<String>( developer.getRoles() ) );
Properties props = new Properties();
props.putAll( developer.getProperties() );
copy.setProperties( props );
target.addDeveloper( copy );
}
}
}

View File

@ -0,0 +1,163 @@
package org.apache.maven.model.processors;
/*
* 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.DeploymentRepository;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Relocation;
import org.apache.maven.model.Site;
public class DistributionManagementProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( t.getDependencyManagement() == null
&& ( p != null && p.getDistributionManagement() != null || c.getDistributionManagement() != null ) )
{
t.setDistributionManagement( new DistributionManagement() );
}
if ( c.getDistributionManagement() != null )
{
if ( p != null && p.getDistributionManagement() != null )
{
copy( p.getDistributionManagement(), t.getDistributionManagement(), false, c.getArtifactId(), p );
}
copy( c.getDistributionManagement(), t.getDistributionManagement(), isChildMostSpecialized,
c.getArtifactId(), p );
}
else if ( p != null && p.getDistributionManagement() != null )
{
copy( p.getDistributionManagement(), t.getDistributionManagement(), false, c.getArtifactId(), p );
}
else if(t.getDistributionManagement() != null && t.getDistributionManagement().getSite() != null)
{
copySite( t.getDistributionManagement().getSite(), t.getDistributionManagement().getSite(), false, c.getArtifactId(), p );
// copy( t.getDistributionManagement(), t.getDistributionManagement(), isChildMostSpecialized, c.getArtifactId() );
}
}
private void copy( DistributionManagement source, DistributionManagement target, boolean isChild,
String artifactId, Model parent )
{
if ( source.getDownloadUrl() != null )
{
target.setDownloadUrl( source.getDownloadUrl() );
}
if ( isChild && source.getRelocation() != null )
{
Relocation sourceRelocation = source.getRelocation();
Relocation r = new Relocation();
r.setArtifactId( sourceRelocation.getArtifactId() );
r.setGroupId( sourceRelocation.getGroupId() );
r.setMessage( sourceRelocation.getMessage() );
r.setVersion( sourceRelocation.getVersion() );
target.setRelocation( r );
}
if ( source.getStatus() != null )
{
target.setStatus( source.getStatus() );
}
if ( source.getRepository() != null )
{
target.setRepository( new DeploymentRepository() );
copyRepository( source.getRepository(), target.getRepository() );
}
if ( source.getSnapshotRepository() != null )
{
target.setSnapshotRepository( new DeploymentRepository() );
copyRepository( source.getSnapshotRepository(), target.getSnapshotRepository() );
}
if ( source.getSite() != null )
{
target.setSite( new Site() );
copySite( source.getSite(), target.getSite(), isChild, artifactId, parent );
}
}
private void copyRepository( DeploymentRepository source, DeploymentRepository target )
{
if ( source.getId() != null )
{
target.setId( source.getId() );
}
if ( source.getLayout() != null )
{
target.setLayout( source.getLayout() );
}
if ( source.getUrl() != null )
{
target.setUrl( source.getUrl() );
}
if ( source.getName() != null )
{
target.setName( source.getName() );
}
target.setUniqueVersion( source.isUniqueVersion() );
}
private void copySite( Site source, Site target, boolean isChild, String artifactId, Model parent )
{
if ( source.getId() != null )
{
target.setId( source.getId() );
}
if ( source.getName() != null )
{
target.setName( source.getName() );
}
if ( target.getUrl() == null )
{
if ( isChild )
{
target.setUrl( source.getUrl() );
}
else
{
target.setUrl(normalizeUriWithRelativePath(source.getUrl(), artifactId, parent));
}
}
else
{
target.setUrl( target.getUrl() + (target.getUrl().endsWith("/") ? "" : "/")+ artifactId );
}
}
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.model.processors;
/*
* 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.IssueManagement;
import org.apache.maven.model.Model;
public class IssueManagementProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( c.getIssueManagement() != null )
{
IssueManagement childMng = c.getIssueManagement();
IssueManagement mng = new IssueManagement();
mng.setSystem( childMng.getSystem() );
mng.setUrl( childMng.getUrl() );
t.setIssueManagement( mng );
}
else if ( p != null && p.getIssueManagement() != null )
{
IssueManagement parentMng = p.getIssueManagement();
IssueManagement mng = new IssueManagement();
mng.setSystem( parentMng.getSystem() );
mng.setUrl( parentMng.getUrl() );
t.setIssueManagement( mng );
}
}
}

View File

@ -0,0 +1,59 @@
package org.apache.maven.model.processors;
/*
* 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.License;
import org.apache.maven.model.Model;
public class LicensesProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if(c.getLicenses().isEmpty() && p != null)
{
for(License license : p.getLicenses())
{
License l = new License();
l.setUrl( license.getUrl());
l.setDistribution( license.getDistribution() );
l.setComments( license.getComments() );
l.setName( license.getName() );
t.addLicense( l );
}
}
else if(isChildMostSpecialized )
{
for(License license : c.getLicenses())
{
License l = new License();
l.setUrl( license.getUrl());
l.setDistribution( license.getDistribution() );
l.setComments( license.getComments() );
l.setName( license.getName() );
t.addLicense( l );
}
}
}
}

View File

@ -0,0 +1,64 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
public class MailingListProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( !c.getMailingLists().isEmpty() )
{
copyMailingLists( c.getMailingLists(), t );
}
else if ( p != null && !p.getMailingLists().isEmpty() )
{
copyMailingLists( p.getMailingLists(), t );
}
}
private static void copyMailingLists( List<MailingList> mailingLists, Model target )
{
List<MailingList> targetList = target.getMailingLists();
for ( MailingList mailingList : mailingLists )
{
MailingList listCopy = new MailingList();
listCopy.setArchive( mailingList.getArchive() );
listCopy.setName( mailingList.getName() );
listCopy.setOtherArchives( new ArrayList<String>( mailingList.getOtherArchives() ) );
listCopy.setPost( mailingList.getPost() );
listCopy.setSubscribe( mailingList.getSubscribe() );
listCopy.setUnsubscribe( mailingList.getUnsubscribe() );
targetList.add( listCopy );
}
}
}

View File

@ -0,0 +1,177 @@
package org.apache.maven.model.processors;
/*
* 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.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Processor;
/*
* hold original pom
* Track where a property is from
*/
public class ModelProcessor
extends BaseProcessor
{
public ModelProcessor( Collection<Processor> processors )
{
super( processors );
}
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model c = (Model) child;
Model t = (Model) target;
Model p = null;
if ( parent != null )
{
p = (Model) parent;
}
// Version
if ( c.getVersion() == null )
{
if ( c.getParent() != null )
{
t.setVersion( c.getParent().getVersion() );
}
}
else
{
t.setVersion( c.getVersion() );
}
// GroupId
if ( c.getGroupId() == null )
{
if ( c.getParent() != null )
{
t.setGroupId( c.getParent().getGroupId() );
}
}
else
{
t.setGroupId( c.getGroupId() );
}
// ArtifactId
if ( c.getArtifactId() == null )
{
if ( c.getParent() != null )
{
t.setArtifactId( c.getParent().getArtifactId() );
}
}
else
{
t.setArtifactId( c.getArtifactId() );
}
t.setModelVersion( c.getModelVersion() );
if(c.getPackaging() != null)
{
t.setPackaging( c.getPackaging() );
}
else
{
t.setPackaging( "jar" );
}
if ( isChildMostSpecialized )
{
t.setName( c.getName() );
}
if(c.getDescription() != null)
{
t.setDescription( c.getDescription() );
}
else if(p != null && p.getDescription() != null)
{
t.setDescription(p.getDescription());
}
if ( c.getInceptionYear() != null )
{
t.setInceptionYear( c.getInceptionYear() );
}
else if ( p != null )
{
t.setInceptionYear( p.getInceptionYear() );
}
if ( c.getUrl() != null )
{
t.setUrl( c.getUrl() );
}
else if(p != null && p.getUrl() != null)
{
t.setUrl( normalizeUriWithRelativePath(p.getUrl(), t.getArtifactId(), p) );
}
else if (t.getUrl() != null)
{
t.setUrl( t.getUrl() + "/" + t.getArtifactId() );
}
//Dependencies
List<Dependency> deps = new ArrayList<Dependency>();
DependenciesProcessor dependenciesProcessor = new DependenciesProcessor();
dependenciesProcessor.process( (p != null) ? p.getDependencies() : null, c.getDependencies(), deps, isChildMostSpecialized );
if(deps.size() > 0)
{
t.setDependencies(deps);
// t.getDependencies().addAll( deps );
}
//Dependency Management
List<Dependency> mngDeps = new ArrayList<Dependency>();
dependenciesProcessor.process( (p != null && p.getDependencyManagement() != null) ? p.getDependencyManagement().getDependencies(): null,
(c.getDependencyManagement() != null) ? c.getDependencyManagement().getDependencies(): null, mngDeps, isChildMostSpecialized );
if(mngDeps.size() > 0)
{
if(t.getDependencyManagement() == null)
{
t.setDependencyManagement( new DependencyManagement() );
}
t.getDependencyManagement().getDependencies().addAll( mngDeps );
}
}
private static List<String> getParentNames(List<Model> models)
{
List<String> names = new ArrayList<String>();
for(Model m : models)
{
names.add(m.getArtifactId());
}
Collections.reverse(names);
return names;
}
}

View File

@ -0,0 +1,43 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Model;
public class ModuleProcessor
extends BaseProcessor
{
/**
* No parent
*/
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
if ( isChildMostSpecialized )
{
Model t = (Model) target;
Model c = (Model) child;
t.setModules( new ArrayList<String>( c.getModules() ) );
}
}
}

View File

@ -0,0 +1,54 @@
package org.apache.maven.model.processors;
/*
* 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.Organization;
public class OrganizationProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if ( c.getOrganization() != null )
{
copy( c.getOrganization(), t );
}
else if ( p != null && p.getOrganization() != null )
{
copy( p.getOrganization(), t );
}
}
private static void copy( Organization source, Model target )
{
Organization o = new Organization();
o.setName( source.getName() );
o.setUrl( source.getUrl() );
target.setOrganization( o );
}
}

View File

@ -0,0 +1,48 @@
package org.apache.maven.model.processors;
/*
* 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.Parent;
public class ParentProcessor
extends BaseProcessor
{
public ParentProcessor()
{
}
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
if ( c.getParent() != null )
{
Parent p = new Parent();
p.setGroupId( c.getParent().getGroupId() );
p.setArtifactId( c.getParent().getArtifactId() );
p.setVersion( c.getParent().getVersion() );
p.setRelativePath( c.getParent().getRelativePath() );
t.setParent( p );
}
}
}

View File

@ -0,0 +1,359 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class PluginProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Plugin> t = (List<Plugin>) target;
if ( parent == null && child == null )
{
return;
}
else if ( parent == null && child != null )
{
boolean isAdd = true;
Plugin targetPlugin = find((Plugin) child, t);
if(targetPlugin == null)
{
targetPlugin = new Plugin();
}
else
{
isAdd = false;
}
copy( (Plugin) child, targetPlugin, true );
copyDependencies( new ArrayList<Dependency>(),
new ArrayList<Dependency>(( (Plugin) child).getDependencies() ), targetPlugin, true );
if(isAdd) t.add( targetPlugin );
}
else if ( parent != null && child == null )
{
boolean isAdd = true;
Plugin targetPlugin = find((Plugin) parent, t);
if(targetPlugin == null)
{
targetPlugin = new Plugin();
}
else
{
isAdd = false;
}
copy( (Plugin) parent, targetPlugin, false );
copyDependencies( new ArrayList<Dependency>(( (Plugin) parent).getDependencies() ), new ArrayList<Dependency>(),
targetPlugin, true );
if(isAdd) t.add( targetPlugin );
}
else
// JOIN
{
if( match( (Plugin) parent, (Plugin) child) )
{
boolean isAdd = true;
Plugin targetPlugin = find((Plugin) parent, t);
if(targetPlugin == null)
{
targetPlugin = new Plugin();
}
else
{
isAdd = false;
}
copy( (Plugin) parent, targetPlugin, false );
copy( (Plugin) child, targetPlugin, true );
copyDependencies( new ArrayList<Dependency>(( (Plugin) parent).getDependencies() ),
new ArrayList<Dependency>(( (Plugin) child).getDependencies() ), targetPlugin, true );
if(isAdd) t.add( targetPlugin );
}
else
{
Plugin targetPlugin = new Plugin();
copy( (Plugin) parent, targetPlugin, false );
copy( (Plugin) child, targetPlugin, true );
copyDependencies( new ArrayList<Dependency>(( (Plugin) parent).getDependencies() ),
new ArrayList<Dependency>(( (Plugin) child).getDependencies() ), targetPlugin, true );
// copyDependencies( (Plugin) parent, targetPlugin, false );
t.add( targetPlugin );
}
}
}
public void process( Plugin parent, List<Plugin> t, boolean isChildMostSpecialized )
{
if (parent == null) {
return;
}
boolean isAdd = true;
Plugin targetPlugin = find((Plugin) parent, t);
if (targetPlugin == null) {
targetPlugin = new Plugin();
} else {
isAdd = false;
}
copy2((Plugin) parent, targetPlugin, false);
copyDependencies(new ArrayList<Dependency>(((Plugin) parent)
.getDependencies()), new ArrayList<Dependency>(), targetPlugin,
true);
if (isAdd)
t.add(targetPlugin);
}
private static Plugin find(Plugin p1, List<Plugin> plugins)
{
for(Plugin t : plugins)
{
if(match(p1, t)){
return t;
}
}
return null;
}
private static boolean match( Plugin d1, Plugin d2 )
{
return getId( d1 ).equals( getId( d2 ));
}
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( (d.getGroupId() != null) ? d.getGroupId() : "org.apache.maven.plugins").append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
private static void copyDependencies(List<Dependency> parent, List<Dependency> child, Plugin target, boolean isChild)
{
if(parent.isEmpty() && child.isEmpty())
{
return;
}
DependenciesProcessor proc = new DependenciesProcessor();
proc.process( parent, child, target.getDependencies(), isChild );
}
/**
* Don't overwrite values
*
* @param source
* @param target
* @param isChild
*/
private static void copy2(Plugin source, Plugin target, boolean isChild)
{
if(!isChild && source.getInherited() != null && !source.getInherited().equalsIgnoreCase( "true" ))
{
return;
}
if(target.getArtifactId() == null)
{
target.setArtifactId( source.getArtifactId() );
}
if(target.getGroupId() == null)
{
target.setGroupId( source.getGroupId() );
}
if(target.getInherited() == null)
{
target.setInherited( source.getInherited() );
}
if(target.getVersion() == null)
{
target.setVersion( source.getVersion() );
}
for( PluginExecution pe : source.getExecutions())
{
PluginExecution idMatch = contains(pe, target.getExecutions());
if(idMatch != null)//Join
{
copyPluginExecution(pe, idMatch, isChild);
}
else
{
PluginExecution targetPe = new PluginExecution();
copyPluginExecution(pe, targetPe, isChild);
target.addExecution( targetPe );
}
}
if(source.getConfiguration() != null)
{
//TODO: Not copying
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
// p2.setConfiguration( configuration ) merge nodes
//Goals
target.setExtensions(source.isExtensions());
}
private static void copy(Plugin source, Plugin target, boolean isChild)
{
if(!isChild && source.getInherited() != null && !source.getInherited().equalsIgnoreCase( "true" ))
{
return;
}
if(source.getArtifactId() != null)
{
target.setArtifactId( source.getArtifactId() );
}
target.setGroupId( source.getGroupId() );
if(source.getInherited() != null)
{
target.setInherited( source.getInherited() );
}
if(source.getVersion() != null)
{
target.setVersion( source.getVersion() );
}
for( PluginExecution pe : source.getExecutions())
{
PluginExecution idMatch = contains(pe, target.getExecutions());
if(idMatch != null)//Join
{
copyPluginExecution(pe, idMatch, isChild);
}
else
{
PluginExecution targetPe = new PluginExecution();
copyPluginExecution(pe, targetPe, isChild);
target.addExecution( targetPe );
}
}
if(source.getConfiguration() != null)
{
//TODO: Not copying
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
// p2.setConfiguration( configuration ) merge nodes
//Goals
target.setExtensions(source.isExtensions());
}
private static PluginExecution contains(PluginExecution pe, List<PluginExecution> executions)
{
String executionId = (pe.getId() != null) ? pe.getId() : "";
for(PluginExecution e : executions)
{
String id = (e.getId() != null) ? e.getId() : "";
if(executionId.equals( id ))
{
return e;
}
}
return null;
}
private static void copyPluginExecution(PluginExecution source, PluginExecution target, boolean isChild)
{
if(!isChild && source.getInherited() != null && !source.getInherited().equalsIgnoreCase( "true" ))
{
return;
}
target.setId( source.getId() );
if(isChild && source.getInherited() != null)
{
target.setInherited( source.getInherited() );
}
if(source.getPhase() != null)
{
target.setPhase( source.getPhase() );
}
List<String> targetGoals = new ArrayList<String>(target.getGoals());
List<String> setGoals = new ArrayList<String>();
for(String goal : source.getGoals())
{
if(targetGoals.contains( goal ))
{
targetGoals.remove( goal );
}
}
setGoals.addAll( source.getGoals() );
setGoals.addAll( targetGoals );
target.setGoals( setGoals );
if(source.getConfiguration() != null)
{
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
}
}

View File

@ -0,0 +1,189 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
* Used for applying plugin management to the pom (not for inheritance).
*
*/
public class PluginsManagementProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Plugin> pluginManagement = (List<Plugin> ) child;
List<Plugin> targetPlugin = (List<Plugin>) target;
for(Plugin depMng : pluginManagement)
{
for(Plugin targetDep : targetPlugin)
{ //PluginManagement is first in ordering
if(match(depMng, targetDep) )
{
copy(depMng, targetDep );
}
}
}
}
private static boolean match( Plugin d1, Plugin d2 )
{
return getId( d1 ).equals( getId( d2 ) ) ;
}
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() );
return sb.toString();
}
private static void copy(Plugin source, Plugin target)
{
if(target.getArtifactId() == null)
{
target.setArtifactId( source.getArtifactId() );
}
target.setGroupId( source.getGroupId() );
if(target.getInherited() == null)
{
target.setInherited( source.getInherited() );
}
if(target.getVersion() == null)
{
target.setVersion( source.getVersion() );
}
List<PluginExecution> executions = new ArrayList<PluginExecution>();
for( PluginExecution pe : source.getExecutions())
{
PluginExecution idMatch = contains(pe, target.getExecutions());
if(idMatch != null)//Join
{
copyPluginExecution(pe, idMatch);
target.getExecutions().remove( idMatch );
executions.add( idMatch );
}
else
{
PluginExecution targetPe = new PluginExecution();
copyPluginExecution(pe, targetPe);
executions.add( targetPe );
}
}
executions.addAll( target.getExecutions() );
target.setExecutions( executions );
DependenciesProcessor proc = new DependenciesProcessor(true);
if(target.getDependencies().isEmpty())
{
proc.process( new ArrayList<Dependency>(), new ArrayList<Dependency>(source.getDependencies()), target.getDependencies(), false );
}
else
{
proc.process( new ArrayList<Dependency>(source.getDependencies()), new ArrayList<Dependency>(), target.getDependencies(), false );
}
if(source.getConfiguration() != null)
{
//TODO: Not copying
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) target.getConfiguration(), (Xpp3Dom) source.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
target.setExtensions(source.isExtensions());
}
private static PluginExecution contains(PluginExecution pe, List<PluginExecution> executions)
{
String executionId = (pe.getId() != null) ? pe.getId() : "";
for(PluginExecution e : executions)
{
String id = (e.getId() != null) ? e.getId() : "";
if(executionId.equals( id ))
{
return e;
}
}
return null;
}
private static void copyPluginExecution(PluginExecution source, PluginExecution target)
{
if(target.getId() != null)
{
target.setId( source.getId() );
}
if ( target.getInherited() == null )
{
target.setInherited( source.getInherited() );
}
if ( target.getPhase() == null )
{
target.setPhase( source.getPhase() );
}
List<String> goals = new ArrayList<String>(target.getGoals());
for(String goal : source.getGoals())
{
if(!goals.contains( goal ))
{
goals.add( goal );
}
}
target.setGoals( goals );
if(source.getConfiguration() != null)
{
if(target.getConfiguration() != null)
{
//Target is dominant
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) target.getConfiguration(), (Xpp3Dom) source.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
}
}

View File

@ -0,0 +1,107 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Plugin;
public class PluginsProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
List<Plugin> c = (child != null) ? (List<Plugin>) child : new ArrayList<Plugin>() ;
List<Plugin> p = null;
if ( parent != null )
{
p = (List<Plugin>) parent;
}
List<Plugin> plugins = (List<Plugin>) target;
PluginProcessor processor = new PluginProcessor();
if ( ( p == null || p.isEmpty() ) && !c.isEmpty() )
{
for ( Plugin plugin : c )
{
processor.process( null, plugin, plugins, isChildMostSpecialized );
}
}
else
{
if ( !c.isEmpty() )
{
List<Plugin> parentDependencies = new ArrayList<Plugin>();
for ( Plugin childPlugin : c)
{
for ( Plugin parentPlugin : p)
{
if ( match( childPlugin, parentPlugin ) )
{
processor.process( parentPlugin, childPlugin, plugins, isChildMostSpecialized );// JOIN
}
else
{
processor.process( null, childPlugin, plugins, isChildMostSpecialized );
if(!parentDependencies.contains(parentPlugin))
{
parentDependencies.add( parentPlugin );
}
}
}
}
/**
* Process Parents after child to keep plugin order but don't want to overwrite the child values. Use different method
*/
for ( Plugin d2 : parentDependencies )
{
processor.process( d2, plugins, isChildMostSpecialized );
}
}
else if( p != null)
{
for ( Plugin d2 : p )
{
processor.process( d2, null, plugins, isChildMostSpecialized );
}
}
}
}
private static boolean match( Plugin d1, Plugin d2 )
{
return getId( d1 ).equals( getId( d2 ));
}
private static String getId( Plugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( (d.getGroupId() != null) ? d.getGroupId() : "org.apache.maven.plugins").append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
}

View File

@ -0,0 +1,45 @@
package org.apache.maven.model.processors;
/*
* 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.Prerequisites;
public class PrerequisitesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
if ( isChildMostSpecialized )
{
Model t = (Model) target;
Model c = (Model) child;
if ( c.getPrerequisites() == null )
{
return;
}
Prerequisites prerequisites = new Prerequisites();
prerequisites.setMaven( c.getPrerequisites().getMaven() );
t.setPrerequisites( prerequisites );
}
}
}

View File

@ -0,0 +1,58 @@
package org.apache.maven.model.processors;
import java.util.Properties;
import org.apache.maven.model.Model;
public class ProfilePropertiesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target, c = (Model) child, p = (Model) parent;
Properties properties = new Properties();
if ( c.getProperties() != null )
{
properties.putAll( c.getProperties() );
}
if ( p != null && p.getProperties() != null )
{
properties.putAll( p.getProperties() );
}
if ( !properties.isEmpty() )
{
if(t.getProperties().isEmpty())
{
t.setProperties( properties );
}
else
{
add(properties, t.getProperties());
//t.getProperties().putAll( properties );
}
}
}
/**
* Add source properties to target if the property does not exist: parent over child
*
* @param source
* @param target
*/
private static void add(Properties source, Properties target)
{
for(Object key : source.keySet())
{
if(!target.containsKey(key))
{
target.put(key, source.get(key));
}
}
}
}

View File

@ -0,0 +1,57 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Model;
public class ProfilesModuleProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
List<String> modules = new ArrayList<String>();
for ( String module : c.getModules() )
{
if(!modules.contains( module ))
{
modules.add(module);
}
}
if(p != null)
{
for ( String module : p.getModules() )
{
if(!modules.contains( module ))
{
modules.add(module);
}
}
}
t.setModules( modules );
}
}

View File

@ -0,0 +1,45 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Model;
import org.apache.maven.model.ProcessorContext;
import org.apache.maven.model.Profile;
public class ProfilesProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
List<Profile> profiles = ((Model) child).getProfiles();
List<Profile> copies = new ArrayList<Profile>();
for(Profile p : profiles)
{
copies.add( ProcessorContext.copyOfProfile(p) );
}
t.setProfiles( copies );
//TODO - copy
}
}

View File

@ -0,0 +1,58 @@
package org.apache.maven.model.processors;
/*
* 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.Properties;
import org.apache.maven.model.Model;
public class PropertiesProcessor
extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target, c = (Model) child, p = (Model) parent;
Properties properties = new Properties();
if ( p != null && p.getProperties() != null )
{
properties.putAll( p.getProperties() );
}
if ( c.getProperties() != null )
{
properties.putAll( c.getProperties() );
}
if ( !properties.isEmpty() )
{
if(t.getProperties().isEmpty())
{
t.setProperties( properties );
}
else
{
t.getProperties().putAll( properties );
}
}
}
}

View File

@ -0,0 +1,163 @@
package org.apache.maven.model.processors;
/*
* 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 org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.codehaus.plexus.util.xml.Xpp3Dom;
public class ReportingProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target, c = (Model) child, p = (Model) parent;
if(p != null && p.getReporting() != null)
{
if(t.getReporting() == null)
{
t.setReporting( new Reporting() );
}
copy(p.getReporting(), t.getReporting());
}
if(c.getReporting() != null)
{
if(t.getReporting() == null)
{
t.setReporting( new Reporting() );
}
copy(c.getReporting(), t.getReporting());
}
}
private static void copy(Reporting source, Reporting target)
{
if(source.getOutputDirectory() != null)
{
target.setOutputDirectory( source.getOutputDirectory() );
}
target.setExcludeDefaults( source.isExcludeDefaults() );
for ( ReportPlugin plugin : source.getPlugins() )
{
ReportPlugin match = contains(plugin, target.getPlugins());
if(match == null)
{
target.addPlugin( copyNewPlugin( plugin ) );
}
else
{
copyPluginToPlugin(plugin, match);
}
}
}
private static ReportPlugin contains(ReportPlugin plugin, List<ReportPlugin> list)
{
for(ReportPlugin p :list)
{
if(match(p, plugin))
{
return p;
}
}
return null;
}
private static void copyPluginToPlugin(ReportPlugin source, ReportPlugin target)
{
if(source.getInherited() != null)
{
target.setInherited( source.getInherited() );
}
if(source.getVersion() != null)
{
target.setVersion( source.getVersion() );
}
if(source.getConfiguration() != null)
{
if(target.getConfiguration() != null)
{
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
}
else
{
target.setConfiguration( source.getConfiguration() );
}
}
for(ReportSet rs : source.getReportSets())
{
ReportSet r = new ReportSet();
r.setId( rs.getId() );
r.setInherited( rs.getInherited() );
r.setReports( new ArrayList<String>(rs.getReports()) );
r.setConfiguration( rs.getConfiguration() );
target.addReportSet( r );
}
}
private static ReportPlugin copyNewPlugin(ReportPlugin plugin)
{
ReportPlugin rp = new ReportPlugin();
rp.setArtifactId( plugin.getArtifactId() );
rp.setGroupId( plugin.getGroupId() );
rp.setInherited( plugin.getInherited() );
rp.setVersion( plugin.getVersion() );
rp.setConfiguration( plugin.getConfiguration() );
for(ReportSet rs : plugin.getReportSets())
{
ReportSet r = new ReportSet();
r.setId( rs.getId() );
r.setInherited( rs.getInherited() );
r.setReports( new ArrayList<String>(rs.getReports()) );
r.setConfiguration( rs.getConfiguration() );
rp.addReportSet( r );
}
return rp;
}
private static boolean match( ReportPlugin d1, ReportPlugin d2 )
{
return getId( d1 ).equals( getId( d2 ));
}
private static String getId( ReportPlugin d )
{
StringBuilder sb = new StringBuilder();
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() ).append( ":" );
return sb.toString();
}
}

View File

@ -0,0 +1,98 @@
package org.apache.maven.model.processors;
/*
* 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.List;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
public class RepositoriesProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target, c = (Model) child, p = (Model) parent;
if(p != null)
{
copy( p.getRepositories(), t.getRepositories() );
copy( p.getPluginRepositories(), t.getPluginRepositories() );
}
copy(c.getPluginRepositories(), t.getPluginRepositories());
copy( c.getRepositories(), t.getRepositories() );
}
private static void copy(List<Repository> sources, List<Repository> targets)
{
for(Repository repository : sources)
{
Repository match = matches(repository, targets);
Repository r = null;
if(match != null)
{
r = match;
}
else
{
r = new Repository();
}
r.setId( repository.getId() );
r.setLayout( repository.getLayout() );
r.setName( repository.getName() );
r.setUrl( repository.getUrl() );
if(repository.getReleases() != null)
{
r.setReleases( copy(repository.getReleases()) );
}
if(repository.getSnapshots() != null)
{
r.setSnapshots( copy(repository.getSnapshots()) );
}
if (match == null)
{
targets.add( r );
}
}
}
private static Repository matches(Repository repository, List<Repository> targets)
{
for(Repository r : targets)
{
if(r.getId() != null && r.getId().equals(repository.getId()))
{
return r;
}
}
return null;
}
private static RepositoryPolicy copy(RepositoryPolicy policy)
{
RepositoryPolicy p = new RepositoryPolicy();
p.setChecksumPolicy( policy.getChecksumPolicy() );
p.setEnabledValue(policy.getEnabledValue());
p.setUpdatePolicy( policy.getUpdatePolicy() );
return p;
}
}

View File

@ -0,0 +1,107 @@
package org.apache.maven.model.processors;
/*
* 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.Scm;
public class ScmProcessor extends BaseProcessor
{
public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized )
{
super.process( parent, child, target, isChildMostSpecialized );
Model t = (Model) target;
Model c = (Model) child;
Model p = (Model) parent;
if((p == null || p.getScm() == null) && (c == null || c.getScm() == null))
{
//return;
}
Scm targetScm = (t.getScm() == null) ? new Scm() : t.getScm();
copyUrl( ((p != null) ? p.getScm() : null), c.getScm(), targetScm, c.getArtifactId(), p);
copyConnection( ((p != null) ? p.getScm() : null), c.getScm(), targetScm, c.getArtifactId(), p);
copyDeveloperConnection( ((p != null) ? p.getScm() : null), c.getScm(), targetScm, c.getArtifactId(), p);
copyTag( ( ( p != null ) ? p.getScm() : null ), c.getScm(), targetScm );
if(t.getScm() ==null && (targetScm.getConnection() !=null || targetScm.getDeveloperConnection() != null || targetScm.getUrl() != null))
{
t.setScm(targetScm);
}
}
private void copyUrl(Scm p, Scm c, Scm t, String artifactId, Model parent )
{
if(c != null && c.getUrl() != null)
{
t.setUrl( c.getUrl() );
}
else if(p != null && p.getUrl() != null)
{
t.setUrl( normalizeUriWithRelativePath(p.getUrl(), artifactId, parent));
}
else if(t.getUrl() != null) {
t.setUrl( t.getUrl() + "/" + artifactId );
}
}
private void copyConnection(Scm p, Scm c, Scm t, String artifactId, Model parent )
{
if(c!= null && c.getConnection() != null)
{
t.setConnection( c.getConnection() );
}
else if(p != null && p.getConnection() != null)
{
t.setConnection( normalizeUriWithRelativePath(p.getConnection(), artifactId, parent));
}
else if(t.getConnection() != null) {
t.setConnection( t.getConnection() + "/" + artifactId );
}
}
private void copyDeveloperConnection(Scm p, Scm c, Scm t, String artifactId, Model parent )
{
if(c!= null && c.getDeveloperConnection() != null)
{
t.setDeveloperConnection( c.getDeveloperConnection() );
}
else if(p != null && p.getDeveloperConnection() != null)
{
t.setDeveloperConnection( normalizeUriWithRelativePath(p.getDeveloperConnection(), artifactId, parent) );
}
else if(t.getDeveloperConnection() != null){
t.setDeveloperConnection( t.getDeveloperConnection() + "/" + artifactId );
}
}
private static void copyTag( Scm p, Scm c, Scm t )
{
if ( c != null && c.getTag() != null )
{
t.setTag( c.getTag() );
}
else if ( p != null && p.getTag() != null )
{
t.setTag( p.getTag() );
}
}
}

View File

@ -22,47 +22,45 @@
import org.apache.maven.model.Activation;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.interpolator.InterpolatorProperty;
import org.apache.maven.model.interpolator.PomInterpolatorTag;
import org.apache.maven.profiles.ProfileActivationContext;
import org.apache.maven.profiles.ProfileActivationException;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.project.builder.factories.IdModelContainerFactory;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.PomTransformer;
import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.project.builder.profile.*;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import org.codehaus.plexus.util.xml.pull.MXSerializer;
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Method;
import org.apache.maven.profiles.matchers.DefaultMatcher;
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public class DefaultProfileManager
implements ProfileManager
{
private MutablePlexusContainer container;
private Map<String, Profile> profilesById = new LinkedHashMap<String, Profile>();
private ProfileActivationContext profileActivationContext;
private static final ProfileMatcher defaultMatcher = new DefaultMatcher();
private static final List<ProfileMatcher> matchers =
Collections.unmodifiableList( Arrays.asList( new PropertyMatcher(), new FileMatcher(), new JdkMatcher() ) );
/**
* the properties passed to the profile manager are the props that
* are passed to maven, possibly containing profile activator properties
*/
public DefaultProfileManager( PlexusContainer container, ProfileActivationContext profileActivationContext )
public DefaultProfileManager( ProfileActivationContext profileActivationContext )
{
this.container = (MutablePlexusContainer) container;
if ( profileActivationContext == null )
{
this.profileActivationContext = createDefaultActivationContext();
@ -73,17 +71,6 @@ public DefaultProfileManager( PlexusContainer container, ProfileActivationContex
}
}
// TODO: Remove this, if possible. It uses system properties, which are not safe for IDE and other embedded environments.
/**
* @deprecated Using this is dangerous when extensions or non-global system properties are in play.
*/
public DefaultProfileManager( PlexusContainer container )
{
this.container = (MutablePlexusContainer) container;
profileActivationContext = createDefaultActivationContext();
}
private ProfileActivationContext createDefaultActivationContext()
{
@ -112,10 +99,10 @@ public void addProfile( Profile profile )
{
String profileId = profile.getId();
Profile existing = (Profile) profilesById.get( profileId );
Profile existing = profilesById.get( profileId );
if ( existing != null )
{
container.getLogger().warn( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() +
System.out.println( "Overriding profile: \'" + profileId + "\' (source: " + existing.getSource() +
") with new instance from source: " + profile.getSource() );
}
@ -129,31 +116,22 @@ public void addProfile( Profile profile )
}
}
// TODO: Portions of this logic are duplicated in o.a.m.p.b.p.ProfileContext, something is wrong here
public List<Profile> getActiveProfiles() throws ProfileActivationException {
return getActiveProfiles(null);
}
public List<Profile> getActiveProfiles( Model model )
throws ProfileActivationException
{
List<Profile> activeFromPom = new ArrayList<Profile>();
List<Profile> activeExternal = new ArrayList<Profile>();
for ( Iterator it = profilesById.entrySet().iterator(); it.hasNext(); )
for ( Map.Entry<String, Profile> entry : profilesById.entrySet() )
{
Map.Entry entry = (Entry) it.next();
String profileId = entry.getKey();
Profile profile = entry.getValue();
String profileId = (String) entry.getKey();
Profile profile = (Profile) entry.getValue();
boolean shouldAdd = false;
if ( profileActivationContext.isExplicitlyActive( profileId ) )
{
shouldAdd = true;
}
else if ( isActive( profile, profileActivationContext ) )
{
shouldAdd = true;
}
if ( !profileActivationContext.isExplicitlyInactive( profileId ) && shouldAdd )
if ( !profileActivationContext.isExplicitlyInactive( profileId )
&& (profileActivationContext.isExplicitlyActive( profileId ) || isActive( profile, profileActivationContext ) ) )
{
if ( "pom".equals( profile.getSource() ) )
{
@ -180,7 +158,7 @@ else if ( isActive( profile, profileActivationContext ) )
{
continue;
}
Profile profile = (Profile) profilesById.get( profileId );
Profile profile = profilesById.get( profileId );
if ( profile != null )
{
@ -190,75 +168,120 @@ else if ( isActive( profile, profileActivationContext ) )
}
List<Profile> allActive = new ArrayList<Profile>( activeFromPom.size() + activeExternal.size() );
// System.out.println("Active From POM: " + activeFromPom.size() + ": EXTERNAL:" + activeExternal.size());
allActive.addAll( activeExternal );
allActive.addAll( activeFromPom );
List<Profile> defaults = getDefaultProfiles(allActive);
if(defaults.size() < allActive.size())
{
allActive.removeAll( defaults );
}
return allActive;
}
public static List<Profile> getActiveProfilesFrom(ProfileManager globalProfileManager, Properties properties, Model model)
throws ProfileActivationException
{
List<Profile> projectProfiles = new ArrayList<Profile>();
ProfileActivationContext profileActivationContext = (globalProfileManager == null) ? new ProfileActivationContext( new Properties(), false ):
globalProfileManager.getProfileActivationContext();
profileActivationContext.getExecutionProperties().putAll(properties);
if(globalProfileManager != null)
{
projectProfiles.addAll( globalProfileManager.getActiveProfiles() );
}
private static List<ActiveProfileMatcher> matchers = Arrays.asList(new FileMatcher(),
new JdkMatcher(), new OperatingSystemMatcher(), new PropertyMatcher());
ProfileManager profileManager = new DefaultProfileManager( profileActivationContext );
profileManager.addProfiles( model.getProfiles() );
projectProfiles.addAll( profileManager.getActiveProfiles() );
return projectProfiles;
}
public static Collection<Profile> getActiveProfiles(List<Profile> profiles, ProfileManagerInfo profileContextInfo)
{
List<InterpolatorProperty> properties = profileContextInfo.getInterpolatorProperties();
Collection<String> activeProfileIds = profileContextInfo.getActiveProfileIds();
Collection<String> inactiveProfileIds = profileContextInfo.getInactiveProfileIds();
List<Profile> matchedProfiles = new ArrayList<Profile>();
List<Profile> defaultProfiles = new ArrayList<Profile>();
for ( Profile profile : profiles )
{
String profileId = profile.getId();
if ( !inactiveProfileIds.contains( profileId ) )
{
if ( activeProfileIds.contains( profileId ) )
{
matchedProfiles.add( profile );
}
else if ( defaultMatcher.isMatch( profile, properties ) )
{
defaultProfiles.add( profile );
}
else
{
for ( ProfileMatcher matcher : matchers )
{
if ( matcher.isMatch( profile, properties ) )
{
matchedProfiles.add( profile );
break;
}
}
}
}
}
if ( matchedProfiles.isEmpty() )
{
matchedProfiles = defaultProfiles;
}
return matchedProfiles;
}
/* (non-Javadoc)
* @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
*/
public void addProfiles( List<Profile> profiles )
{
for ( Profile profile : profiles )
{
addProfile( profile );
}
}
private static List<Profile> getDefaultProfiles(List<Profile> profiles)
{
List<Profile> defaults = new ArrayList<Profile>();
for(Profile p : profiles)
{
if ( p.getActivation() != null && p.getActivation().isActiveByDefault() )
{
defaults.add( p );
}
}
return defaults;
}
private boolean isActive( Profile profile, ProfileActivationContext context )
throws ProfileActivationException
{
//TODO: Using reflection now. Need to replace with custom mapper
StringWriter writer = new StringWriter();
XmlSerializer serializer = new MXSerializer();
serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
try
{
serializer.setOutput( writer );
serializer.startDocument("UTF-8", null );
} catch (IOException e) {
}
try {
MavenXpp3Writer w = new MavenXpp3Writer();
Class c = Class.forName("org.apache.maven.model.io.xpp3.MavenXpp3Writer");
Class partypes[] = new Class[3];
partypes[0] = Profile.class;
partypes[1] = String.class;
partypes[2] = XmlSerializer.class;
Method meth = c.getDeclaredMethod(
"writeProfile", partypes);
meth.setAccessible(true);
Object arglist[] = new Object[3];
arglist[0] = profile;
arglist[1] = "profile";
arglist[2] = serializer;
meth.invoke(w, arglist);
serializer.endDocument();
} catch (Exception e)
{
throw new ProfileActivationException(e.getMessage(), e);
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(
context.getExecutionProperties(),
PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
List<ModelProperty> p;
try
{
p = ModelMarshaller.marshallXmlToModelProperties(new ByteArrayInputStream(writer.getBuffer().toString().getBytes()),
ProjectUri.Profiles.xUri, PomTransformer.URIS);
} catch (IOException e) {
throw new ProfileActivationException(e.getMessage());
}
ModelContainer mc = new IdModelContainerFactory(ProjectUri.Profiles.Profile.xUri).create(p);
for(ActiveProfileMatcher matcher : matchers)
if(context.getExecutionProperties() != null)
{
if(matcher.isMatch(mc, interpolatorProperties))
interpolatorProperties.addAll(InterpolatorProperty.toInterpolatorProperties(
context.getExecutionProperties(),
PomInterpolatorTag.EXECUTION_PROPERTIES.name()));
}
for(ProfileMatcher matcher : matchers)
{
if(matcher.isMatch(profile, interpolatorProperties))
{
return true;
}
@ -266,40 +289,13 @@ private boolean isActive( Profile profile, ProfileActivationContext context )
return false;
}
/* (non-Javadoc)
* @see org.apache.maven.project.ProfileManager#addProfiles(java.util.List)
*/
public void addProfiles( List<Profile> profiles )
{
for ( Iterator it = profiles.iterator(); it.hasNext(); )
{
Profile profile = (Profile) it.next();
addProfile( profile );
}
}
private void activateAsDefault( String profileId )
{
List defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
List<String> defaultIds = profileActivationContext.getActiveByDefaultProfileIds();
if ( !defaultIds.contains( profileId ) )
{
profileActivationContext.setActiveByDefault( profileId );
}
}
public static String getGroupId( Model model )
{
Parent parent = model.getParent();
String groupId = model.getGroupId();
if ( ( parent != null ) && ( groupId == null ) )
{
groupId = parent.getGroupId();
}
return groupId;
}
}

View File

@ -27,7 +27,6 @@
public class ProfileActivationContext
{
private boolean isCustomActivatorFailureSuppressed;
private final Properties executionProperties;
@ -40,7 +39,7 @@ public class ProfileActivationContext
public ProfileActivationContext( Properties executionProperties, boolean isCustomActivatorFailureSuppressed )
{
this.executionProperties = executionProperties;
this.executionProperties = (executionProperties != null) ? executionProperties : new Properties();
this.isCustomActivatorFailureSuppressed = isCustomActivatorFailureSuppressed;
}

View File

@ -35,6 +35,10 @@ public interface ProfileManager
Map<String, Profile> getProfilesById();
@Deprecated
List<Profile> getActiveProfiles( Model model )
throws ProfileActivationException;
List<Profile> getActiveProfiles( )
throws ProfileActivationException;
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.profiles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.maven.model.interpolator.InterpolatorProperty;
public class ProfileManagerInfo
{
private List<InterpolatorProperty> interpolatorProperties;
private Collection<String> activeProfileIds;
private Collection<String> inactiveProfileIds;
public ProfileManagerInfo(List<InterpolatorProperty> interpolatorProperties, Collection<String> activeProfileIds, Collection<String> inactiveProfileIds)
{
this.interpolatorProperties = (interpolatorProperties != null) ? interpolatorProperties : new ArrayList<InterpolatorProperty>();
this.activeProfileIds = (activeProfileIds != null) ? activeProfileIds : new ArrayList<String>();
this.inactiveProfileIds = (inactiveProfileIds != null) ? inactiveProfileIds : new ArrayList<String>();
}
public List<InterpolatorProperty> getInterpolatorProperties() {
return interpolatorProperties;
}
public Collection<String> getActiveProfileIds() {
return activeProfileIds;
}
public Collection<String> getInactiveProfileIds() {
return inactiveProfileIds;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.mercury;
package org.apache.maven.profiles.matchers;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,20 +19,20 @@
* under the License.
*/
import java.io.IOException;
import java.util.List;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.DomainModelFactory;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.model.Profile;
import org.apache.maven.model.interpolator.InterpolatorProperty;
public class MavenDomainModelFactory
implements DomainModelFactory
public class DefaultMatcher implements ProfileMatcher
{
public DomainModel createDomainModel( List<ModelProperty> modelProperties )
throws IOException
public boolean isMatch( Profile profile, List<InterpolatorProperty> properties )
{
return new MavenDomainModel( modelProperties );
if(profile.getActivation() == null)
{
return false;
}
return profile.getActivation().isActiveByDefault();
}
}

View File

@ -0,0 +1,34 @@
package org.apache.maven.profiles.matchers;
import java.io.File;
import java.util.List;
import org.apache.maven.model.ActivationFile;
import org.apache.maven.model.Profile;
import org.apache.maven.model.interpolator.InterpolatorProperty;
public class FileMatcher implements ProfileMatcher {
public boolean isMatch(Profile profile, List<InterpolatorProperty> properties) {
if (profile == null) {
throw new IllegalArgumentException("profile: null");
}
if(profile.getActivation() == null || profile.getActivation().getFile() == null)
{
return false;
}
ActivationFile f = profile.getActivation().getFile();
if (f.getExists() != null && !new File(f.getExists()).exists()) {
return false;
}
if (f.getMissing() != null && new File(f.getMissing()).exists()) {
return false;
}
return true;
}
}

View File

@ -1,60 +1,56 @@
package org.apache.maven.project.builder.profile;
import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.project.builder.ProjectUri;
package org.apache.maven.profiles.matchers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class JdkMatcher
implements ActiveProfileMatcher
{
public boolean isMatch( ModelContainer modelContainer, List<InterpolatorProperty> properties )
{
if ( modelContainer == null )
{
throw new IllegalArgumentException( "modelContainer: null" );
}
import org.apache.maven.model.Profile;
import org.apache.maven.model.interpolator.InterpolatorProperty;
if ( properties == null )
public class JdkMatcher
implements ProfileMatcher
{
private static final String JDK_VERSION = "${java.version}";
public boolean isMatch(Profile profile,
List<InterpolatorProperty> properties) {
String version = null;
for(InterpolatorProperty ip : properties)
{
if(ip.getKey().equals(JDK_VERSION))
{
version = ip.getValue();
break;
}
}
if ( version == null )
{
return false;
}
for ( InterpolatorProperty property : properties )
org.apache.maven.model.Activation activation = profile.getActivation();
if(activation == null || activation.getJdk() == null)
{
if ( property.getKey().equals( "${java.specification.version}" ) )
{
String version = property.getValue();
for ( ModelProperty modelProperty : modelContainer.getProperties() )
{
if ( modelProperty.getUri().equals( ProjectUri.Profiles.Profile.Activation.jdk ) )
{
if ( modelProperty.getResolvedValue().startsWith( "!" ) )
{
return !version.equals( modelProperty.getResolvedValue().replaceFirst( "!", "" ) );
}
else if ( isRange( modelProperty.getResolvedValue() ) )
{
return isInRange( version, getRange( modelProperty.getResolvedValue() ) );
}
else
{
return version.equals( modelProperty.getResolvedValue() );
}
}
}
return false;
}
return false;
}
String jdk = activation.getJdk();
if ( jdk.startsWith( "!" ) )
{
return !version.startsWith( jdk.replaceFirst( "!", "" ) );
}
else if ( isRange( jdk ) )
{
return isInRange( version, getRange( jdk ) );
}
else
{
return version.startsWith( jdk );
}
return false;
}
}
private static boolean isInRange( String value, List<RangeValue> range )
{
int leftRelation = getRelationOrder( value, range.get( 0 ), true );
@ -74,8 +70,13 @@ private static boolean isInRange( String value, List<RangeValue> range )
private static int getRelationOrder( String value, RangeValue rangeValue, boolean isLeft )
{
List<String> valueTokens = Arrays.asList( value.split( "." ) );
List<String> rangeValueTokens = Arrays.asList( rangeValue.value.split( "." ) );
if ( rangeValue.value.length() <= 0 )
{
return isLeft ? 1 : -1;
}
List<String> valueTokens = new ArrayList<String>( Arrays.asList( value.split( "\\." ) ) );
List<String> rangeValueTokens = new ArrayList<String>( Arrays.asList( rangeValue.value.split( "\\." ) ) );
int max = Math.max( valueTokens.size(), rangeValueTokens.size() );
addZeroTokens( valueTokens, max );
@ -83,13 +84,17 @@ private static int getRelationOrder( String value, RangeValue rangeValue, boolea
if ( value.equals( rangeValue.value ) )
{
return ( rangeValue.isClosed() ) ? 0 : -1;
if ( !rangeValue.isClosed() )
{
return isLeft ? -1 : 1;
}
return 0;
}
for ( int i = 0; i < valueTokens.size(); i++ )
{
int x = Integer.getInteger( valueTokens.get( i ) );
int y = Integer.getInteger( rangeValueTokens.get( i ) );
int x = Integer.parseInt( valueTokens.get( i ) );
int y = Integer.parseInt( rangeValueTokens.get( i ) );
if ( x < y )
{
return -1;
@ -99,6 +104,10 @@ else if ( x > y )
return 1;
}
}
if ( !rangeValue.isClosed() )
{
return isLeft ? -1 : 1;
}
return 0;
}
@ -140,7 +149,10 @@ else if ( token.endsWith( ")" ) )
{
ranges.add( new RangeValue( token.replace( ")", "" ), false ) );
}
else if ( token.length() <= 0 )
{
ranges.add( new RangeValue( "", false ) );
}
}
if ( ranges.size() < 2 )
{
@ -170,5 +182,10 @@ public boolean isClosed()
{
return isClosed;
}
}
public String toString()
{
return value;
}
}
}

View File

@ -0,0 +1,30 @@
package org.apache.maven.profiles.matchers;
/*
* 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.List;
import org.apache.maven.model.Profile;
import org.apache.maven.model.interpolator.InterpolatorProperty;
public interface ProfileMatcher
{
boolean isMatch( Profile profile, List<InterpolatorProperty> properties );
}

View File

@ -0,0 +1,60 @@
package org.apache.maven.profiles.matchers;
/*
* 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.List;
import org.apache.maven.model.Profile;
import org.apache.maven.model.interpolator.InterpolatorProperty;
public class PropertyMatcher implements ProfileMatcher
{
public boolean isMatch( Profile profile, List<InterpolatorProperty> properties )
{
if (profile == null) {
throw new IllegalArgumentException("profile: null");
}
if(profile.getActivation() == null || profile.getActivation().getProperty() == null)
{
return false;
}
String value = profile.getActivation().getProperty().getValue();
String name = profile.getActivation().getProperty().getName();
if(name == null )
{
return false;
}
if(value == null)
{
return !name.startsWith("!");
}
for(InterpolatorProperty ip : properties) {
if(ip.getKey().equals("${" + name + "}")) {
return ip.getValue().equals(value);
}
}
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More