1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
31
32
33 @Named
34 @Singleton
35 public class DefaultModelLocator implements ModelLocator {
36
37 @Deprecated
38 @Override
39 public File locatePom(File projectDirectory) {
40 Path path = locatePom(projectDirectory != null ? projectDirectory.toPath() : null);
41 return path != null ? path.toFile() : null;
42 }
43
44 @Override
45 public Path locatePom(Path projectDirectory) {
46 return projectDirectory != null ? projectDirectory : Paths.get(System.getProperty("user.dir"));
47 }
48
49 @Deprecated
50 @Override
51 public File locateExistingPom(File project) {
52 Path path = locateExistingPom(project != null ? project.toPath() : null);
53 return path != null ? path.toFile() : null;
54 }
55
56 @Override
57 public Path locateExistingPom(Path project) {
58 if (project == null || Files.isDirectory(project)) {
59 project = locatePom(project);
60 }
61 if (Files.isDirectory(project)) {
62 Path pom = project.resolve("pom.xml");
63 return Files.isRegularFile(pom) ? pom : null;
64 } else if (Files.isRegularFile(project)) {
65 return project;
66 } else {
67 return null;
68 }
69 }
70 }