View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.model.locator;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.io.File;
25  import java.nio.file.Files;
26  import java.nio.file.Path;
27  import java.nio.file.Paths;
28  
29  /**
30   * Locates a POM file within a project base directory.
31   *
32   * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
33   */
34  @Named
35  @Singleton
36  @Deprecated(since = "4.0.0")
37  public class DefaultModelLocator implements ModelLocator {
38  
39      @Deprecated
40      @Override
41      public File locatePom(File projectDirectory) {
42          Path path = locatePom(projectDirectory != null ? projectDirectory.toPath() : null);
43          return path != null ? path.toFile() : null;
44      }
45  
46      @Override
47      public Path locatePom(Path projectDirectory) {
48          return projectDirectory != null ? projectDirectory : Paths.get(System.getProperty("user.dir"));
49      }
50  
51      @Deprecated
52      @Override
53      public File locateExistingPom(File project) {
54          Path path = locateExistingPom(project != null ? project.toPath() : null);
55          return path != null ? path.toFile() : null;
56      }
57  
58      @Override
59      public Path locateExistingPom(Path project) {
60          if (project == null || Files.isDirectory(project)) {
61              project = locatePom(project);
62          }
63          if (Files.isDirectory(project)) {
64              Path pom = project.resolve("pom.xml");
65              return Files.isRegularFile(pom) ? pom : null;
66          } else if (Files.isRegularFile(project)) {
67              return project;
68          } else {
69              return null;
70          }
71      }
72  }