o Replaced hard-coded use of "pom.xml" with a component to enable customizers using other formats to use other file names as well

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@823852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-10 13:26:44 +00:00
parent b55562328b
commit 737bc0f63b
7 changed files with 102 additions and 19 deletions

View File

@ -27,6 +27,7 @@
*/
public interface Maven
{
@Deprecated
String POMv4 = "pom.xml";
MavenExecutionResult execute( MavenExecutionRequest request );

View File

@ -25,9 +25,9 @@
import java.util.List;
import java.util.Set;
import org.apache.maven.Maven;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.locator.ModelLocator;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
@ -55,6 +55,9 @@ public class DefaultMavenExecutionRequestPopulator
@Requirement( hint = "maven" )
private SecDispatcher securityDispatcher;
@Requirement
private ModelLocator modelLocator;
public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings )
throws MavenExecutionRequestPopulationException
{
@ -177,7 +180,7 @@ private void pom( MavenExecutionRequest request )
}
else if ( ( request.getPom() == null ) && ( request.getBaseDirectory() != null ) )
{
File pom = new File( request.getBaseDirectory(), Maven.POMv4 );
File pom = modelLocator.locatePom( new File( request.getBaseDirectory() ) );
request.setPom( pom );
}

View File

@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.List;
import org.apache.maven.Maven;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
@ -39,6 +38,7 @@
import org.apache.maven.model.building.ModelBuildingResult;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.UrlModelSource;
import org.apache.maven.model.locator.ModelLocator;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.apache.maven.repository.RepositorySystem;
@ -58,6 +58,9 @@ public class DefaultProjectBuilder
@Requirement
private ModelBuilder modelBuilder;
@Requirement
private ModelLocator modelLocator;
@Requirement
private ProjectBuildingHelper projectBuildingHelper;
@ -341,7 +344,7 @@ private boolean build( List<ProjectBuildingResult> results, List<InterimResult>
if ( moduleFile.isDirectory() )
{
moduleFile = new File( moduleFile, Maven.POMv4 );
moduleFile = modelLocator.locatePom( moduleFile );
}
if ( !moduleFile.isFile() )

View File

@ -29,7 +29,6 @@
import java.util.Map.Entry;
import org.apache.commons.cli.CommandLine;
import org.apache.maven.Maven;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.codehaus.plexus.util.StringUtils;
@ -246,21 +245,9 @@ else if ( quiet )
.setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn
.setUserToolchainsFile( userToolchainsFile );
File pom;
if ( alternatePomFile != null )
{
pom = new File( alternatePomFile );
pom = resolveFile( pom, workingDirectory );
}
else
{
pom = new File( baseDirectory, Maven.POMv4 );
}
if ( pom.exists() )
{
request.setPom( pom );
request.setPom( resolveFile( new File( alternatePomFile ), workingDirectory ) );
}
if ( commandLine.hasOption( CLIManager.RESUME_FROM ) )

View File

@ -40,6 +40,7 @@
import org.apache.maven.model.interpolation.ModelInterpolator;
import org.apache.maven.model.io.ModelParseException;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.locator.ModelLocator;
import org.apache.maven.model.management.DependencyManagementInjector;
import org.apache.maven.model.management.PluginManagementInjector;
import org.apache.maven.model.normalization.ModelNormalizer;
@ -67,6 +68,9 @@ public class DefaultModelBuilder
implements ModelBuilder
{
@Requirement
private ModelLocator modelLocator;
@Requirement
private ModelReader modelReader;
@ -519,7 +523,7 @@ private File getParentPomFile( Model childModel )
if ( pomFile.isDirectory() )
{
pomFile = new File( pomFile, "pom.xml" );
pomFile = modelLocator.locatePom( pomFile );
}
return pomFile;

View File

@ -0,0 +1,41 @@
package org.apache.maven.model.locator;
/*
* 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.File;
import org.codehaus.plexus.component.annotations.Component;
/**
* Locates a POM file within a project base directory.
*
* @author Benjamin Bentmann
*/
@Component( role = ModelLocator.class )
public class DefaultModelLocator
implements ModelLocator
{
public File locatePom( File projectDirectory )
{
return new File( projectDirectory, "pom.xml" );
}
}

View File

@ -0,0 +1,44 @@
package org.apache.maven.model.locator;
/*
* 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.File;
/**
* Locates a POM file within a project base directory.
*
* @author Benjamin Bentmann
*/
public interface ModelLocator
{
/**
* Locates the POM file within the specified project directory. In case the given project directory does not exist
* or does not contain a POM file, the return value indicates the expected path to the POM file. Sub directories of
* the project directory will not be considered when locating the POM file. The return value will be an absolute
* path if the project directory is given as an absolute path.
*
* @param projectDirectory The (possibly non-existent) base directory to locate the POM file in, must not be {@code
* null}.
* @return The path to the (possibly non-existent) POM file, never {@code null}.
*/
File locatePom( File projectDirectory );
}