From 737bc0f63b9f7982830295410e4bdf5c7d3bd297 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sat, 10 Oct 2009 13:26:44 +0000 Subject: [PATCH] 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 --- .../src/main/java/org/apache/maven/Maven.java | 1 + ...DefaultMavenExecutionRequestPopulator.java | 7 ++- .../maven/project/DefaultProjectBuilder.java | 7 ++- .../org/apache/maven/cli/CLIRequestUtils.java | 15 +------ .../model/building/DefaultModelBuilder.java | 6 ++- .../model/locator/DefaultModelLocator.java | 41 +++++++++++++++++ .../maven/model/locator/ModelLocator.java | 44 +++++++++++++++++++ 7 files changed, 102 insertions(+), 19 deletions(-) create mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/locator/DefaultModelLocator.java create mode 100644 maven-model-builder/src/main/java/org/apache/maven/model/locator/ModelLocator.java diff --git a/maven-core/src/main/java/org/apache/maven/Maven.java b/maven-core/src/main/java/org/apache/maven/Maven.java index 16fb2c1e88..05fb6edb11 100644 --- a/maven-core/src/main/java/org/apache/maven/Maven.java +++ b/maven-core/src/main/java/org/apache/maven/Maven.java @@ -27,6 +27,7 @@ import org.apache.maven.execution.MavenExecutionResult; */ public interface Maven { + @Deprecated String POMv4 = "pom.xml"; MavenExecutionResult execute( MavenExecutionRequest request ); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index bca6a4c088..3af83b3424 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -25,9 +25,9 @@ import java.util.HashSet; 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 @@ public class DefaultMavenExecutionRequestPopulator } 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 ); } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 24213577fa..f5dee0a39a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -21,7 +21,6 @@ import java.util.ArrayList; 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.ModelBuildingRequest; 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 @@ public class DefaultProjectBuilder if ( moduleFile.isDirectory() ) { - moduleFile = new File( moduleFile, Maven.POMv4 ); + moduleFile = modelLocator.locatePom( moduleFile ); } if ( !moduleFile.isFile() ) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java index 1bbaffb5ef..235bca681b 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java @@ -29,7 +29,6 @@ import java.util.StringTokenizer; 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 @@ final class CLIRequestUtils .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 ) ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 7e1ba0b9bb..67447ae63c 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -40,6 +40,7 @@ import org.apache.maven.model.inheritance.InheritanceAssembler; 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 @@ public class DefaultModelBuilder if ( pomFile.isDirectory() ) { - pomFile = new File( pomFile, "pom.xml" ); + pomFile = modelLocator.locatePom( pomFile ); } return pomFile; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/locator/DefaultModelLocator.java b/maven-model-builder/src/main/java/org/apache/maven/model/locator/DefaultModelLocator.java new file mode 100644 index 0000000000..1d9871dcfe --- /dev/null +++ b/maven-model-builder/src/main/java/org/apache/maven/model/locator/DefaultModelLocator.java @@ -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" ); + } + +} diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/locator/ModelLocator.java b/maven-model-builder/src/main/java/org/apache/maven/model/locator/ModelLocator.java new file mode 100644 index 0000000000..a5c8d040e5 --- /dev/null +++ b/maven-model-builder/src/main/java/org/apache/maven/model/locator/ModelLocator.java @@ -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 ); + +}