mirror of https://github.com/apache/maven.git
o Set svn:eol-style=native
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@713049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1249c89962
commit
cd04c1d85a
|
@ -1,161 +1,161 @@
|
|||
package org.apache.maven.execution;
|
||||
|
||||
/*
|
||||
* 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 junit.framework.TestCase;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.execution.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test sorting projects by dependencies.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id: ProjectSorterTest.java 513038 2007-02-28 22:54:19Z jvanzyl $
|
||||
*/
|
||||
public class ProjectSorterTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testShouldNotFailWhenProjectReferencesNonExistentProject()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
MavenProject project = createProject( "group", "artifact", "1.0" );
|
||||
Model model = project.getModel();
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
if ( build == null )
|
||||
{
|
||||
build = new Build();
|
||||
model.setBuild( build );
|
||||
}
|
||||
|
||||
Extension extension = new Extension();
|
||||
|
||||
extension.setArtifactId( "other-artifact" );
|
||||
extension.setGroupId( "other.group" );
|
||||
extension.setVersion( "1.0" );
|
||||
|
||||
build.addExtension( extension );
|
||||
|
||||
new ReactorManager.ProjectSorter( Collections.singletonList( project ) );
|
||||
}
|
||||
|
||||
public void testMatchingArtifactIdsDifferentGroupIds()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId1", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId2", "artifactId", "1.0" );
|
||||
projects.add( project2 );
|
||||
project1.getDependencies().add( createDependency( project2 ) );
|
||||
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
|
||||
assertEquals( project2, projects.get( 0 ) );
|
||||
assertEquals( project1, projects.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testMatchingGroupIdsDifferentArtifactIds()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId1", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId2", "1.0" );
|
||||
projects.add( project2 );
|
||||
project1.getDependencies().add( createDependency( project2 ) );
|
||||
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
|
||||
assertEquals( project2, projects.get( 0 ) );
|
||||
assertEquals( project1, projects.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndDifferentVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "2.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
private Dependency createDependency( MavenProject project )
|
||||
{
|
||||
Dependency depdendency = new Dependency();
|
||||
depdendency.setArtifactId( project.getArtifactId() );
|
||||
depdendency.setGroupId( project.getGroupId() );
|
||||
depdendency.setVersion( project.getVersion() );
|
||||
return depdendency;
|
||||
}
|
||||
|
||||
private static MavenProject createProject( String groupId, String artifactId, String version )
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( groupId );
|
||||
model.setArtifactId( artifactId );
|
||||
model.setVersion( version );
|
||||
return new MavenProject( model );
|
||||
}
|
||||
}
|
||||
package org.apache.maven.execution;
|
||||
|
||||
/*
|
||||
* 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 junit.framework.TestCase;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.execution.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test sorting projects by dependencies.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id: ProjectSorterTest.java 513038 2007-02-28 22:54:19Z jvanzyl $
|
||||
*/
|
||||
public class ProjectSorterTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
public void testShouldNotFailWhenProjectReferencesNonExistentProject()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
MavenProject project = createProject( "group", "artifact", "1.0" );
|
||||
Model model = project.getModel();
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
if ( build == null )
|
||||
{
|
||||
build = new Build();
|
||||
model.setBuild( build );
|
||||
}
|
||||
|
||||
Extension extension = new Extension();
|
||||
|
||||
extension.setArtifactId( "other-artifact" );
|
||||
extension.setGroupId( "other.group" );
|
||||
extension.setVersion( "1.0" );
|
||||
|
||||
build.addExtension( extension );
|
||||
|
||||
new ReactorManager.ProjectSorter( Collections.singletonList( project ) );
|
||||
}
|
||||
|
||||
public void testMatchingArtifactIdsDifferentGroupIds()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId1", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId2", "artifactId", "1.0" );
|
||||
projects.add( project2 );
|
||||
project1.getDependencies().add( createDependency( project2 ) );
|
||||
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
|
||||
assertEquals( project2, projects.get( 0 ) );
|
||||
assertEquals( project1, projects.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testMatchingGroupIdsDifferentArtifactIds()
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId1", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId2", "1.0" );
|
||||
projects.add( project2 );
|
||||
project1.getDependencies().add( createDependency( project2 ) );
|
||||
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
|
||||
assertEquals( project2, projects.get( 0 ) );
|
||||
assertEquals( project1, projects.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndDifferentVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "2.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ReactorManager.ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
private Dependency createDependency( MavenProject project )
|
||||
{
|
||||
Dependency depdendency = new Dependency();
|
||||
depdendency.setArtifactId( project.getArtifactId() );
|
||||
depdendency.setGroupId( project.getGroupId() );
|
||||
depdendency.setVersion( project.getVersion() );
|
||||
return depdendency;
|
||||
}
|
||||
|
||||
private static MavenProject createProject( String groupId, String artifactId, String version )
|
||||
{
|
||||
Model model = new Model();
|
||||
model.setGroupId( groupId );
|
||||
model.setArtifactId( artifactId );
|
||||
model.setVersion( version );
|
||||
return new MavenProject( model );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,230 +1,230 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelContainerFactory;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class ArtifactModelContainerFactory
|
||||
implements ModelContainerFactory
|
||||
{
|
||||
|
||||
private static final Collection<String> uris = Collections.unmodifiableList( Arrays.asList(
|
||||
|
||||
ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, ProjectUri.Dependencies.Dependency.xUri,
|
||||
ProjectUri.Reporting.Plugins.Plugin.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri,
|
||||
|
||||
ProjectUri.Build.Plugins.Plugin.xUri, ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri,
|
||||
ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri
|
||||
) );
|
||||
|
||||
public Collection<String> getUris()
|
||||
{
|
||||
return uris;
|
||||
}
|
||||
|
||||
public ModelContainer create( List<ModelProperty> modelProperties )
|
||||
{
|
||||
if ( modelProperties == null || modelProperties.size() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelProperties: null or empty" );
|
||||
}
|
||||
return new ArtifactModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
private static class ArtifactModelContainer
|
||||
implements ModelContainer
|
||||
{
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String type;
|
||||
|
||||
private List<ModelProperty> properties;
|
||||
|
||||
private static String findBaseUriFrom( List<ModelProperty> modelProperties )
|
||||
{
|
||||
String baseUri = null;
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( baseUri == null || mp.getUri().length() < baseUri.length() )
|
||||
{
|
||||
baseUri = mp.getUri();
|
||||
}
|
||||
}
|
||||
return baseUri;
|
||||
}
|
||||
|
||||
private ArtifactModelContainer( List<ModelProperty> properties )
|
||||
{
|
||||
this.properties = new ArrayList<ModelProperty>( properties );
|
||||
this.properties = Collections.unmodifiableList( this.properties );
|
||||
String uri = findBaseUriFrom( this.properties );
|
||||
|
||||
for ( ModelProperty mp : this.properties )
|
||||
{
|
||||
if ( version == null && mp.getUri().equals( uri + "/version" ) )
|
||||
{
|
||||
this.version = mp.getResolvedValue();
|
||||
}
|
||||
else if ( artifactId == null && mp.getUri().equals( uri + "/artifactId" ) )
|
||||
{
|
||||
this.artifactId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( groupId == null && mp.getUri().equals( uri + "/groupId" ) )
|
||||
{
|
||||
this.groupId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( type == null && mp.getUri().equals( ProjectUri.Dependencies.Dependency.type )
|
||||
|| mp.getUri().equals(ProjectUri.DependencyManagement.Dependencies.Dependency.type)
|
||||
|| mp.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.type)
|
||||
|| mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.type))
|
||||
{
|
||||
this.type = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
if ( groupId == null )
|
||||
{
|
||||
groupId = "org.apache.maven.plugins";
|
||||
// throw new IllegalArgumentException("properties does not contain group id. Artifact ID = "
|
||||
// + artifactId + ", Version = " + version);
|
||||
}
|
||||
|
||||
if ( artifactId == null )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
sb.append( mp ).append( "\r\n" );
|
||||
}
|
||||
throw new IllegalArgumentException( "Properties does not contain artifact id. Group ID = " + groupId +
|
||||
", Version = " + version + ", Base = " + uri + ":\r\n" + sb );
|
||||
}
|
||||
|
||||
if ( type == null )
|
||||
{
|
||||
type = "";
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction( ModelContainer modelContainer )
|
||||
{
|
||||
if ( modelContainer == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: null" );
|
||||
}
|
||||
|
||||
if ( !( modelContainer instanceof ArtifactModelContainer ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: wrong type" );
|
||||
}
|
||||
|
||||
ArtifactModelContainer c = (ArtifactModelContainer) modelContainer;
|
||||
if ( c.groupId.equals( groupId ) && c.artifactId.equals( artifactId ) )
|
||||
{
|
||||
if ( c.version == null )
|
||||
{
|
||||
if ( version == null )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
if ( version == null )
|
||||
{
|
||||
if ( c.version == null )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
if ( c.version.equals( version ) )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.DELETE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new ArtifactModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "Group ID = " ).append( groupId ).append( ", Artifact ID = " ).append( artifactId )
|
||||
.append( ", Version" ).append( version ).append( "\r\n" );
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
sb.append( mp ).append( "\r\n" );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelContainerFactory;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class ArtifactModelContainerFactory
|
||||
implements ModelContainerFactory
|
||||
{
|
||||
|
||||
private static final Collection<String> uris = Collections.unmodifiableList( Arrays.asList(
|
||||
|
||||
ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, ProjectUri.Dependencies.Dependency.xUri,
|
||||
ProjectUri.Reporting.Plugins.Plugin.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri,
|
||||
ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.xUri,
|
||||
|
||||
ProjectUri.Build.Plugins.Plugin.xUri, ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.xUri,
|
||||
ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.Exclusions.Exclusion.xUri
|
||||
) );
|
||||
|
||||
public Collection<String> getUris()
|
||||
{
|
||||
return uris;
|
||||
}
|
||||
|
||||
public ModelContainer create( List<ModelProperty> modelProperties )
|
||||
{
|
||||
if ( modelProperties == null || modelProperties.size() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelProperties: null or empty" );
|
||||
}
|
||||
return new ArtifactModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
private static class ArtifactModelContainer
|
||||
implements ModelContainer
|
||||
{
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String type;
|
||||
|
||||
private List<ModelProperty> properties;
|
||||
|
||||
private static String findBaseUriFrom( List<ModelProperty> modelProperties )
|
||||
{
|
||||
String baseUri = null;
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( baseUri == null || mp.getUri().length() < baseUri.length() )
|
||||
{
|
||||
baseUri = mp.getUri();
|
||||
}
|
||||
}
|
||||
return baseUri;
|
||||
}
|
||||
|
||||
private ArtifactModelContainer( List<ModelProperty> properties )
|
||||
{
|
||||
this.properties = new ArrayList<ModelProperty>( properties );
|
||||
this.properties = Collections.unmodifiableList( this.properties );
|
||||
String uri = findBaseUriFrom( this.properties );
|
||||
|
||||
for ( ModelProperty mp : this.properties )
|
||||
{
|
||||
if ( version == null && mp.getUri().equals( uri + "/version" ) )
|
||||
{
|
||||
this.version = mp.getResolvedValue();
|
||||
}
|
||||
else if ( artifactId == null && mp.getUri().equals( uri + "/artifactId" ) )
|
||||
{
|
||||
this.artifactId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( groupId == null && mp.getUri().equals( uri + "/groupId" ) )
|
||||
{
|
||||
this.groupId = mp.getResolvedValue();
|
||||
}
|
||||
else if ( type == null && mp.getUri().equals( ProjectUri.Dependencies.Dependency.type )
|
||||
|| mp.getUri().equals(ProjectUri.DependencyManagement.Dependencies.Dependency.type)
|
||||
|| mp.getUri().equals(ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.type)
|
||||
|| mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Dependencies.Dependency.type))
|
||||
{
|
||||
this.type = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
if ( groupId == null )
|
||||
{
|
||||
groupId = "org.apache.maven.plugins";
|
||||
// throw new IllegalArgumentException("properties does not contain group id. Artifact ID = "
|
||||
// + artifactId + ", Version = " + version);
|
||||
}
|
||||
|
||||
if ( artifactId == null )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
sb.append( mp ).append( "\r\n" );
|
||||
}
|
||||
throw new IllegalArgumentException( "Properties does not contain artifact id. Group ID = " + groupId +
|
||||
", Version = " + version + ", Base = " + uri + ":\r\n" + sb );
|
||||
}
|
||||
|
||||
if ( type == null )
|
||||
{
|
||||
type = "";
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction( ModelContainer modelContainer )
|
||||
{
|
||||
if ( modelContainer == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: null" );
|
||||
}
|
||||
|
||||
if ( !( modelContainer instanceof ArtifactModelContainer ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: wrong type" );
|
||||
}
|
||||
|
||||
ArtifactModelContainer c = (ArtifactModelContainer) modelContainer;
|
||||
if ( c.groupId.equals( groupId ) && c.artifactId.equals( artifactId ) )
|
||||
{
|
||||
if ( c.version == null )
|
||||
{
|
||||
if ( version == null )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
if ( version == null )
|
||||
{
|
||||
if ( c.version == null )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
if ( c.version.equals( version ) )
|
||||
{
|
||||
if ( c.type.equals( type ) )
|
||||
{
|
||||
return ModelContainerAction.JOIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.DELETE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new ArtifactModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append( "Group ID = " ).append( groupId ).append( ", Artifact ID = " ).append( artifactId )
|
||||
.append( ", Version" ).append( version ).append( "\r\n" );
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
sb.append( mp ).append( "\r\n" );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,112 +1,112 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelContainerFactory;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class IdModelContainerFactory
|
||||
implements ModelContainerFactory
|
||||
{
|
||||
|
||||
private static final Collection<String> uris = Collections.unmodifiableList( Arrays.asList(
|
||||
ProjectUri.PluginRepositories.PluginRepository.xUri, ProjectUri.Repositories.Repository.xUri,
|
||||
ProjectUri.Profiles.Profile.xUri) );
|
||||
|
||||
public Collection<String> getUris()
|
||||
{
|
||||
return uris;
|
||||
}
|
||||
|
||||
public ModelContainer create( List<ModelProperty> modelProperties )
|
||||
{
|
||||
if ( modelProperties == null || modelProperties.size() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelProperties: null or empty" );
|
||||
}
|
||||
return new IdModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
private static class IdModelContainer
|
||||
implements ModelContainer
|
||||
{
|
||||
|
||||
private String id;
|
||||
|
||||
private List<ModelProperty> properties;
|
||||
|
||||
private IdModelContainer( List<ModelProperty> properties )
|
||||
{
|
||||
this.properties = new ArrayList<ModelProperty>( properties );
|
||||
this.properties = Collections.unmodifiableList( this.properties );
|
||||
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
if ( mp.getUri().endsWith( "/id" ) )
|
||||
{
|
||||
this.id = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction( ModelContainer modelContainer )
|
||||
{
|
||||
if ( modelContainer == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: null" );
|
||||
}
|
||||
|
||||
if ( !( modelContainer instanceof IdModelContainer ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: wrong type" );
|
||||
}
|
||||
|
||||
IdModelContainer c = (IdModelContainer) modelContainer;
|
||||
if ( c.id == null || id == null )
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
return ( c.id.equals( id ) ) ? ModelContainerAction.JOIN : ModelContainerAction.NOP;
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new IdModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "ID = " + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.shared.model.ModelContainer;
|
||||
import org.apache.maven.shared.model.ModelContainerAction;
|
||||
import org.apache.maven.shared.model.ModelContainerFactory;
|
||||
import org.apache.maven.shared.model.ModelProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class IdModelContainerFactory
|
||||
implements ModelContainerFactory
|
||||
{
|
||||
|
||||
private static final Collection<String> uris = Collections.unmodifiableList( Arrays.asList(
|
||||
ProjectUri.PluginRepositories.PluginRepository.xUri, ProjectUri.Repositories.Repository.xUri,
|
||||
ProjectUri.Profiles.Profile.xUri) );
|
||||
|
||||
public Collection<String> getUris()
|
||||
{
|
||||
return uris;
|
||||
}
|
||||
|
||||
public ModelContainer create( List<ModelProperty> modelProperties )
|
||||
{
|
||||
if ( modelProperties == null || modelProperties.size() == 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelProperties: null or empty" );
|
||||
}
|
||||
return new IdModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
private static class IdModelContainer
|
||||
implements ModelContainer
|
||||
{
|
||||
|
||||
private String id;
|
||||
|
||||
private List<ModelProperty> properties;
|
||||
|
||||
private IdModelContainer( List<ModelProperty> properties )
|
||||
{
|
||||
this.properties = new ArrayList<ModelProperty>( properties );
|
||||
this.properties = Collections.unmodifiableList( this.properties );
|
||||
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
if ( mp.getUri().endsWith( "/id" ) )
|
||||
{
|
||||
this.id = mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction( ModelContainer modelContainer )
|
||||
{
|
||||
if ( modelContainer == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: null" );
|
||||
}
|
||||
|
||||
if ( !( modelContainer instanceof IdModelContainer ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "modelContainer: wrong type" );
|
||||
}
|
||||
|
||||
IdModelContainer c = (IdModelContainer) modelContainer;
|
||||
if ( c.id == null || id == null )
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
return ( c.id.equals( id ) ) ? ModelContainerAction.JOIN : ModelContainerAction.NOP;
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new IdModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties()
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "ID = " + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides methods for resolving of artifacts.
|
||||
*/
|
||||
public class PomArtifactResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* Local repository used in resolving artifacts
|
||||
*/
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
/**
|
||||
* Remote repositories used in resolving artifacts
|
||||
*/
|
||||
private List<ArtifactRepository> remoteRepositories;
|
||||
|
||||
/**
|
||||
* Artifact resolver used to resolve artifacts
|
||||
*/
|
||||
private ArtifactResolver resolver;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param localRepository local repository used in resolving artifacts
|
||||
* @param remoteRepositories remote repositories used in resolving artifacts
|
||||
* @param resolver artifact resolver used to resolve artifacts
|
||||
*/
|
||||
public PomArtifactResolver( ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
ArtifactResolver resolver )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
this.remoteRepositories = remoteRepositories;
|
||||
this.resolver = resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the specified artifact
|
||||
*
|
||||
* @param artifact the artifact to resolve
|
||||
* @throws IOException if there is a problem resolving the artifact
|
||||
*/
|
||||
public void resolve( Artifact artifact )
|
||||
throws IOException
|
||||
{
|
||||
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
||||
artifact.setFile( artifactFile );
|
||||
|
||||
try
|
||||
{
|
||||
resolver.resolve( artifact, remoteRepositories, localRepository );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides methods for resolving of artifacts.
|
||||
*/
|
||||
public class PomArtifactResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* Local repository used in resolving artifacts
|
||||
*/
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
/**
|
||||
* Remote repositories used in resolving artifacts
|
||||
*/
|
||||
private List<ArtifactRepository> remoteRepositories;
|
||||
|
||||
/**
|
||||
* Artifact resolver used to resolve artifacts
|
||||
*/
|
||||
private ArtifactResolver resolver;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param localRepository local repository used in resolving artifacts
|
||||
* @param remoteRepositories remote repositories used in resolving artifacts
|
||||
* @param resolver artifact resolver used to resolve artifacts
|
||||
*/
|
||||
public PomArtifactResolver( ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
ArtifactResolver resolver )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
this.remoteRepositories = remoteRepositories;
|
||||
this.resolver = resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the specified artifact
|
||||
*
|
||||
* @param artifact the artifact to resolve
|
||||
* @throws IOException if there is a problem resolving the artifact
|
||||
*/
|
||||
public void resolve( Artifact artifact )
|
||||
throws IOException
|
||||
{
|
||||
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
||||
artifact.setFile( artifactFile );
|
||||
|
||||
try
|
||||
{
|
||||
resolver.resolve( artifact, remoteRepositories, localRepository );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,307 +1,307 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides a wrapper for the maven model.
|
||||
*/
|
||||
public final class PomClassicDomainModel
|
||||
implements InputStreamDomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Bytes containing the underlying model
|
||||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
/**
|
||||
* History of joins and deletes of model properties
|
||||
*/
|
||||
private String eventHistory;
|
||||
|
||||
/**
|
||||
* Maven model
|
||||
*/
|
||||
private Model model;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param model maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( Model model )
|
||||
throws IOException
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "model: null" );
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Writer out = null;
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
try
|
||||
{
|
||||
out = WriterFactory.newXmlWriter( baos );
|
||||
writer.write( out, model );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( out != null )
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
inputBytes = baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param inputStream input stream of the maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( InputStream inputStream )
|
||||
throws IOException
|
||||
{
|
||||
if ( inputStream == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "inputStream: null" );
|
||||
}
|
||||
this.inputBytes = IOUtil.toByteArray( inputStream );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( File file )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
{
|
||||
return parentFile;
|
||||
}
|
||||
|
||||
public void setParentFile( File parentFile )
|
||||
{
|
||||
this.parentFile = parentFile;
|
||||
}
|
||||
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
|
||||
* otherwise returns false.
|
||||
*
|
||||
* @param a model to compare
|
||||
* @return true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
|
||||
* otherwise returns false.
|
||||
*/
|
||||
public boolean matchesModel( Model a )
|
||||
{
|
||||
if ( a == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "a: null" );
|
||||
}
|
||||
if ( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
model = getModel();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return a.getId().equals( this.getId() );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
if ( id == null )
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
model = getModel();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
String groupId = ( model.getGroupId() == null && model.getParent() != null )
|
||||
? model.getParent().getGroupId()
|
||||
: model.getGroupId();
|
||||
String artifactId = ( model.getArtifactId() == null && model.getParent() != null )
|
||||
? model.getParent().getArtifactId()
|
||||
: model.getArtifactId();
|
||||
String version = ( model.getVersion() == null && model.getParent() != null )
|
||||
? model.getParent().getVersion()
|
||||
: model.getVersion();
|
||||
|
||||
id = groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public boolean matchesParent( Parent parent )
|
||||
{
|
||||
if ( parent == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "parent: null" );
|
||||
}
|
||||
return getId().equals( parent.getGroupId() + ":" + parent.getArtifactId() + ":" + parent.getVersion() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML model as string
|
||||
*
|
||||
* @return XML model as string
|
||||
*/
|
||||
public String asString()
|
||||
{
|
||||
try
|
||||
{
|
||||
return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
{
|
||||
// should not occur: everything is in-memory
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maven model
|
||||
*
|
||||
* @return maven model
|
||||
*/
|
||||
public Model getModel()
|
||||
throws IOException
|
||||
{
|
||||
if ( model != null )
|
||||
{
|
||||
return model;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||
*/
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return file of pom. May be null.
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
|
||||
}
|
||||
|
||||
}
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Provides a wrapper for the maven model.
|
||||
*/
|
||||
public final class PomClassicDomainModel
|
||||
implements InputStreamDomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Bytes containing the underlying model
|
||||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
/**
|
||||
* History of joins and deletes of model properties
|
||||
*/
|
||||
private String eventHistory;
|
||||
|
||||
/**
|
||||
* Maven model
|
||||
*/
|
||||
private Model model;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param model maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( Model model )
|
||||
throws IOException
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "model: null" );
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Writer out = null;
|
||||
MavenXpp3Writer writer = new MavenXpp3Writer();
|
||||
try
|
||||
{
|
||||
out = WriterFactory.newXmlWriter( baos );
|
||||
writer.write( out, model );
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( out != null )
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
inputBytes = baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param inputStream input stream of the maven model
|
||||
* @throws IOException if there is a problem constructing the model
|
||||
*/
|
||||
public PomClassicDomainModel( InputStream inputStream )
|
||||
throws IOException
|
||||
{
|
||||
if ( inputStream == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "inputStream: null" );
|
||||
}
|
||||
this.inputBytes = IOUtil.toByteArray( inputStream );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( File file )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
{
|
||||
return parentFile;
|
||||
}
|
||||
|
||||
public void setParentFile( File parentFile )
|
||||
{
|
||||
this.parentFile = parentFile;
|
||||
}
|
||||
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
|
||||
* otherwise returns false.
|
||||
*
|
||||
* @param a model to compare
|
||||
* @return true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
|
||||
* otherwise returns false.
|
||||
*/
|
||||
public boolean matchesModel( Model a )
|
||||
{
|
||||
if ( a == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "a: null" );
|
||||
}
|
||||
if ( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
model = getModel();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return a.getId().equals( this.getId() );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
if ( id == null )
|
||||
{
|
||||
if ( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
model = getModel();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
String groupId = ( model.getGroupId() == null && model.getParent() != null )
|
||||
? model.getParent().getGroupId()
|
||||
: model.getGroupId();
|
||||
String artifactId = ( model.getArtifactId() == null && model.getParent() != null )
|
||||
? model.getParent().getArtifactId()
|
||||
: model.getArtifactId();
|
||||
String version = ( model.getVersion() == null && model.getParent() != null )
|
||||
? model.getParent().getVersion()
|
||||
: model.getVersion();
|
||||
|
||||
id = groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public boolean matchesParent( Parent parent )
|
||||
{
|
||||
if ( parent == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "parent: null" );
|
||||
}
|
||||
return getId().equals( parent.getGroupId() + ":" + parent.getArtifactId() + ":" + parent.getVersion() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML model as string
|
||||
*
|
||||
* @return XML model as string
|
||||
*/
|
||||
public String asString()
|
||||
{
|
||||
try
|
||||
{
|
||||
return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
|
||||
}
|
||||
catch ( IOException ioe )
|
||||
{
|
||||
// should not occur: everything is in-memory
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maven model
|
||||
*
|
||||
* @return maven model
|
||||
*/
|
||||
public Model getModel()
|
||||
throws IOException
|
||||
{
|
||||
if ( model != null )
|
||||
{
|
||||
return model;
|
||||
}
|
||||
try
|
||||
{
|
||||
return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||
*/
|
||||
public InputStream getInputStream()
|
||||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return file of pom. May be null.
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,60 +1,60 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.shared.model.ImportModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides services for building maven projects from models.
|
||||
*/
|
||||
public interface ProjectBuilder
|
||||
{
|
||||
|
||||
String ROLE = ProjectBuilder.class.getName();
|
||||
|
||||
/**
|
||||
* Returns a maven project for the specified input stream.
|
||||
*
|
||||
* @param pom input stream of the model
|
||||
* @param inheritedModels list of models containing additional parent models in order from most to least specialized
|
||||
* @param interpolatorProperties properties used for interpolation of properties within the model
|
||||
* @param resolver artifact resolver used in resolving artifacts
|
||||
* @param baseDirectory the base directory of the model
|
||||
* @param projectBuilderConfiguration
|
||||
* @return a maven project for the specified input stream
|
||||
* @throws IOException if there is a problem in the construction of the maven project
|
||||
*/
|
||||
MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels, Collection<ImportModel> importModels,
|
||||
Collection<InterpolatorProperty> interpolatorProperties,
|
||||
PomArtifactResolver resolver, File baseDirectory,
|
||||
ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws IOException;
|
||||
|
||||
}
|
||||
package org.apache.maven.project.builder;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.shared.model.ImportModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides services for building maven projects from models.
|
||||
*/
|
||||
public interface ProjectBuilder
|
||||
{
|
||||
|
||||
String ROLE = ProjectBuilder.class.getName();
|
||||
|
||||
/**
|
||||
* Returns a maven project for the specified input stream.
|
||||
*
|
||||
* @param pom input stream of the model
|
||||
* @param inheritedModels list of models containing additional parent models in order from most to least specialized
|
||||
* @param interpolatorProperties properties used for interpolation of properties within the model
|
||||
* @param resolver artifact resolver used in resolving artifacts
|
||||
* @param baseDirectory the base directory of the model
|
||||
* @param projectBuilderConfiguration
|
||||
* @return a maven project for the specified input stream
|
||||
* @throws IOException if there is a problem in the construction of the maven project
|
||||
*/
|
||||
MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels, Collection<ImportModel> importModels,
|
||||
Collection<InterpolatorProperty> interpolatorProperties,
|
||||
PomArtifactResolver resolver, File baseDirectory,
|
||||
ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws IOException;
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,350 +1,350 @@
|
|||
package org.apache.maven.project.builder.impl;
|
||||
|
||||
/*
|
||||
* 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.MavenTools;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.IdModelContainerFactory;
|
||||
import org.apache.maven.project.builder.PomArtifactResolver;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.project.builder.ProjectBuilder;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.ImportModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelTransformerContext;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Default implementation of the project builder.
|
||||
*/
|
||||
public final class DefaultProjectBuilder
|
||||
implements ProjectBuilder, LogEnabled
|
||||
{
|
||||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
/**
|
||||
* Logger instance
|
||||
*/
|
||||
private Logger logger;
|
||||
|
||||
private ModelValidator validator;
|
||||
|
||||
private MavenTools mavenTools;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DefaultProjectBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param artifactFactory the artifact factory
|
||||
*/
|
||||
protected DefaultProjectBuilder( ArtifactFactory artifactFactory )
|
||||
{
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: null" );
|
||||
}
|
||||
this.artifactFactory = artifactFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File, org.apache.maven.project.ProjectBuilderConfiguration)
|
||||
*/
|
||||
public MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels,
|
||||
Collection<ImportModel> importModels,
|
||||
Collection<InterpolatorProperty> interpolatorProperties,
|
||||
PomArtifactResolver resolver, File projectDirectory,
|
||||
ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws IOException
|
||||
{
|
||||
if ( pom == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "pom: null" );
|
||||
}
|
||||
|
||||
if ( resolver == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "resolver: null" );
|
||||
}
|
||||
|
||||
if ( projectDirectory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "projectDirectory: null" );
|
||||
}
|
||||
|
||||
if ( inheritedModels == null )
|
||||
{
|
||||
inheritedModels = new ArrayList<Model>();
|
||||
}
|
||||
else
|
||||
{
|
||||
inheritedModels = new ArrayList<Model>( inheritedModels );
|
||||
Collections.reverse( inheritedModels );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> properties;
|
||||
if ( interpolatorProperties == null )
|
||||
{
|
||||
properties = new ArrayList<InterpolatorProperty>();
|
||||
}
|
||||
else
|
||||
{
|
||||
properties = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
}
|
||||
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
|
||||
domainModel.setProjectDirectory( projectDirectory );
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
domainModels.add( domainModel );
|
||||
|
||||
File parentFile = null;
|
||||
if ( domainModel.getModel().getParent() != null )
|
||||
{
|
||||
List<DomainModel> mavenParents;
|
||||
if ( isParentLocal( domainModel.getModel().getParent(), projectDirectory ) )
|
||||
{
|
||||
mavenParents = getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory );
|
||||
}
|
||||
else
|
||||
{
|
||||
mavenParents = getDomainModelParentsFromRepository( domainModel, resolver );
|
||||
}
|
||||
|
||||
if ( mavenParents.size() > 0 )
|
||||
{
|
||||
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
||||
parentFile = dm.getFile();
|
||||
domainModel.setParentFile( parentFile );
|
||||
}
|
||||
|
||||
domainModels.addAll( mavenParents );
|
||||
}
|
||||
|
||||
for ( Model model : inheritedModels )
|
||||
{
|
||||
domainModels.add( new PomClassicDomainModel( model ) );
|
||||
}
|
||||
|
||||
PomClassicTransformer transformer = new PomClassicTransformer( null );
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(
|
||||
Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
|
||||
|
||||
PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
|
||||
transformer,
|
||||
transformer,
|
||||
importModels,
|
||||
properties ) );
|
||||
try
|
||||
{
|
||||
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
||||
mavenTools, null,
|
||||
projectBuilderConfiguration );
|
||||
mavenProject.setParentFile( parentFile );
|
||||
return mavenProject;
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the relative path of the specified parent references a pom, otherwise returns false.
|
||||
*
|
||||
* @param parent the parent model info
|
||||
* @param projectDirectory the project directory of the child pom
|
||||
* @return true if the relative path of the specified parent references a pom, otherwise returns fals
|
||||
*/
|
||||
private boolean isParentLocal( Parent parent, File projectDirectory )
|
||||
{
|
||||
try
|
||||
{
|
||||
File f = new File( projectDirectory, parent.getRelativePath() ).getCanonicalFile();
|
||||
if ( f.isDirectory() )
|
||||
{
|
||||
f = new File( f, "pom.xml" );
|
||||
}
|
||||
return f.exists();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
|
||||
PomArtifactResolver artifactResolver )
|
||||
throws IOException
|
||||
{
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: not initialized" );
|
||||
}
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
|
||||
Parent parent = domainModel.getModel().getParent();
|
||||
|
||||
if ( parent == null )
|
||||
{
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
Artifact artifactParent =
|
||||
artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
|
||||
artifactResolver.resolve( artifactParent );
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
|
||||
{
|
||||
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
|
||||
": Child ID = " + domainModel.getModel().getId() );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
domainModels.add( parentDomainModel );
|
||||
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver ) );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of domain model parents of the specified domain model. The parent domain models are part
|
||||
*
|
||||
* @param domainModel
|
||||
* @param artifactResolver
|
||||
* @param projectDirectory
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private List<DomainModel> getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
|
||||
PomArtifactResolver artifactResolver,
|
||||
File projectDirectory )
|
||||
throws IOException
|
||||
{
|
||||
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: not initialized" );
|
||||
}
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
|
||||
Parent parent = domainModel.getModel().getParent();
|
||||
|
||||
if ( parent == null )
|
||||
{
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
Model model = domainModel.getModel();
|
||||
|
||||
File parentFile = new File( projectDirectory, model.getParent().getRelativePath() ).getCanonicalFile();
|
||||
if ( parentFile.isDirectory() )
|
||||
{
|
||||
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
|
||||
}
|
||||
|
||||
if ( !parentFile.exists() )
|
||||
{
|
||||
throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
|
||||
}
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
|
||||
parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
|
||||
{
|
||||
logger.debug( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
|
||||
+ parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
|
||||
+ domainModel.getModel().getParent().getId() );
|
||||
List<DomainModel> parentDomainModels = getDomainModelParentsFromRepository( domainModel, artifactResolver );
|
||||
if(parentDomainModels.size() == 0)
|
||||
{
|
||||
throw new IOException("Unable to find parent pom on local path or repo: "
|
||||
+ domainModel.getModel().getParent().getId());
|
||||
}
|
||||
//logger.info("Attempting to lookup from the repository: Found parents: " + parentDomainModels.size());
|
||||
domainModels.addAll( parentDomainModels );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
domainModels.add( parentDomainModel );
|
||||
if ( parentDomainModel.getModel().getParent() != null )
|
||||
{
|
||||
if ( isParentLocal( parentDomainModel.getModel().getParent(), parentFile.getParentFile() ) )
|
||||
{
|
||||
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
|
||||
parentFile.getParentFile() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver ) );
|
||||
}
|
||||
}
|
||||
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
|
||||
public void enableLogging( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private void validateModel( Model model )
|
||||
throws IOException
|
||||
{
|
||||
ModelValidationResult validationResult = validator.validate( model );
|
||||
|
||||
if ( validationResult.getMessageCount() > 0 )
|
||||
{
|
||||
throw new IOException( "Failed to validate: " + validationResult.toString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.apache.maven.project.builder.impl;
|
||||
|
||||
/*
|
||||
* 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.MavenTools;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Parent;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
|
||||
import org.apache.maven.project.builder.IdModelContainerFactory;
|
||||
import org.apache.maven.project.builder.PomArtifactResolver;
|
||||
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||
import org.apache.maven.project.builder.PomClassicTransformer;
|
||||
import org.apache.maven.project.builder.ProjectBuilder;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.shared.model.DomainModel;
|
||||
import org.apache.maven.shared.model.ImportModel;
|
||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
||||
import org.apache.maven.shared.model.ModelTransformerContext;
|
||||
import org.codehaus.plexus.logging.LogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Default implementation of the project builder.
|
||||
*/
|
||||
public final class DefaultProjectBuilder
|
||||
implements ProjectBuilder, LogEnabled
|
||||
{
|
||||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
/**
|
||||
* Logger instance
|
||||
*/
|
||||
private Logger logger;
|
||||
|
||||
private ModelValidator validator;
|
||||
|
||||
private MavenTools mavenTools;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DefaultProjectBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param artifactFactory the artifact factory
|
||||
*/
|
||||
protected DefaultProjectBuilder( ArtifactFactory artifactFactory )
|
||||
{
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: null" );
|
||||
}
|
||||
this.artifactFactory = artifactFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File, org.apache.maven.project.ProjectBuilderConfiguration)
|
||||
*/
|
||||
public MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels,
|
||||
Collection<ImportModel> importModels,
|
||||
Collection<InterpolatorProperty> interpolatorProperties,
|
||||
PomArtifactResolver resolver, File projectDirectory,
|
||||
ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws IOException
|
||||
{
|
||||
if ( pom == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "pom: null" );
|
||||
}
|
||||
|
||||
if ( resolver == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "resolver: null" );
|
||||
}
|
||||
|
||||
if ( projectDirectory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "projectDirectory: null" );
|
||||
}
|
||||
|
||||
if ( inheritedModels == null )
|
||||
{
|
||||
inheritedModels = new ArrayList<Model>();
|
||||
}
|
||||
else
|
||||
{
|
||||
inheritedModels = new ArrayList<Model>( inheritedModels );
|
||||
Collections.reverse( inheritedModels );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> properties;
|
||||
if ( interpolatorProperties == null )
|
||||
{
|
||||
properties = new ArrayList<InterpolatorProperty>();
|
||||
}
|
||||
else
|
||||
{
|
||||
properties = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
}
|
||||
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pom );
|
||||
domainModel.setProjectDirectory( projectDirectory );
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
domainModels.add( domainModel );
|
||||
|
||||
File parentFile = null;
|
||||
if ( domainModel.getModel().getParent() != null )
|
||||
{
|
||||
List<DomainModel> mavenParents;
|
||||
if ( isParentLocal( domainModel.getModel().getParent(), projectDirectory ) )
|
||||
{
|
||||
mavenParents = getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory );
|
||||
}
|
||||
else
|
||||
{
|
||||
mavenParents = getDomainModelParentsFromRepository( domainModel, resolver );
|
||||
}
|
||||
|
||||
if ( mavenParents.size() > 0 )
|
||||
{
|
||||
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
||||
parentFile = dm.getFile();
|
||||
domainModel.setParentFile( parentFile );
|
||||
}
|
||||
|
||||
domainModels.addAll( mavenParents );
|
||||
}
|
||||
|
||||
for ( Model model : inheritedModels )
|
||||
{
|
||||
domainModels.add( new PomClassicDomainModel( model ) );
|
||||
}
|
||||
|
||||
PomClassicTransformer transformer = new PomClassicTransformer( null );
|
||||
ModelTransformerContext ctx = new ModelTransformerContext(
|
||||
Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
|
||||
|
||||
PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
|
||||
transformer,
|
||||
transformer,
|
||||
importModels,
|
||||
properties ) );
|
||||
try
|
||||
{
|
||||
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
||||
mavenTools, null,
|
||||
projectBuilderConfiguration );
|
||||
mavenProject.setParentFile( parentFile );
|
||||
return mavenProject;
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the relative path of the specified parent references a pom, otherwise returns false.
|
||||
*
|
||||
* @param parent the parent model info
|
||||
* @param projectDirectory the project directory of the child pom
|
||||
* @return true if the relative path of the specified parent references a pom, otherwise returns fals
|
||||
*/
|
||||
private boolean isParentLocal( Parent parent, File projectDirectory )
|
||||
{
|
||||
try
|
||||
{
|
||||
File f = new File( projectDirectory, parent.getRelativePath() ).getCanonicalFile();
|
||||
if ( f.isDirectory() )
|
||||
{
|
||||
f = new File( f, "pom.xml" );
|
||||
}
|
||||
return f.exists();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel,
|
||||
PomArtifactResolver artifactResolver )
|
||||
throws IOException
|
||||
{
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: not initialized" );
|
||||
}
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
|
||||
Parent parent = domainModel.getModel().getParent();
|
||||
|
||||
if ( parent == null )
|
||||
{
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
Artifact artifactParent =
|
||||
artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
|
||||
artifactResolver.resolve( artifactParent );
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
|
||||
{
|
||||
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
|
||||
": Child ID = " + domainModel.getModel().getId() );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
domainModels.add( parentDomainModel );
|
||||
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver ) );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of domain model parents of the specified domain model. The parent domain models are part
|
||||
*
|
||||
* @param domainModel
|
||||
* @param artifactResolver
|
||||
* @param projectDirectory
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private List<DomainModel> getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
|
||||
PomArtifactResolver artifactResolver,
|
||||
File projectDirectory )
|
||||
throws IOException
|
||||
{
|
||||
|
||||
if ( artifactFactory == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "artifactFactory: not initialized" );
|
||||
}
|
||||
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
|
||||
Parent parent = domainModel.getModel().getParent();
|
||||
|
||||
if ( parent == null )
|
||||
{
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
Model model = domainModel.getModel();
|
||||
|
||||
File parentFile = new File( projectDirectory, model.getParent().getRelativePath() ).getCanonicalFile();
|
||||
if ( parentFile.isDirectory() )
|
||||
{
|
||||
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
|
||||
}
|
||||
|
||||
if ( !parentFile.exists() )
|
||||
{
|
||||
throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
|
||||
}
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
|
||||
parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
|
||||
{
|
||||
logger.debug( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
|
||||
+ parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
|
||||
+ domainModel.getModel().getParent().getId() );
|
||||
List<DomainModel> parentDomainModels = getDomainModelParentsFromRepository( domainModel, artifactResolver );
|
||||
if(parentDomainModels.size() == 0)
|
||||
{
|
||||
throw new IOException("Unable to find parent pom on local path or repo: "
|
||||
+ domainModel.getModel().getParent().getId());
|
||||
}
|
||||
//logger.info("Attempting to lookup from the repository: Found parents: " + parentDomainModels.size());
|
||||
domainModels.addAll( parentDomainModels );
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
domainModels.add( parentDomainModel );
|
||||
if ( parentDomainModel.getModel().getParent() != null )
|
||||
{
|
||||
if ( isParentLocal( parentDomainModel.getModel().getParent(), parentFile.getParentFile() ) )
|
||||
{
|
||||
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
|
||||
parentFile.getParentFile() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
domainModels.addAll( getDomainModelParentsFromRepository( parentDomainModel, artifactResolver ) );
|
||||
}
|
||||
}
|
||||
|
||||
return domainModels;
|
||||
}
|
||||
|
||||
|
||||
public void enableLogging( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private void validateModel( Model model )
|
||||
throws IOException
|
||||
{
|
||||
ModelValidationResult validationResult = validator.validate( model );
|
||||
|
||||
if ( validationResult.getMessageCount() > 0 )
|
||||
{
|
||||
throw new IOException( "Failed to validate: " + validationResult.toString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue