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.api;
20
21 import java.nio.file.Path;
22 import java.util.List;
23 import java.util.Optional;
24
25 import org.apache.maven.api.annotations.Experimental;
26 import org.apache.maven.api.annotations.Nonnull;
27 import org.apache.maven.api.model.Build;
28 import org.apache.maven.api.model.Model;
29
30 /**
31 * Interface representing a Maven project.
32 * Projects can be built using the {@link org.apache.maven.api.services.ProjectBuilder} service.
33 *
34 * @since 4.0
35 */
36 @Experimental
37 public interface Project {
38
39 @Nonnull
40 String getGroupId();
41
42 @Nonnull
43 String getArtifactId();
44
45 @Nonnull
46 String getVersion();
47
48 @Nonnull
49 String getPackaging();
50
51 @Nonnull
52 Artifact getArtifact();
53
54 @Nonnull
55 Model getModel();
56
57 @Nonnull
58 default Build getBuild() {
59 Build build = getModel().getBuild();
60 return build != null ? build : Build.newInstance();
61 }
62
63 /**
64 * Returns the path to the pom file for this project.
65 * A project is usually read from the file system and this will point to
66 * the file. In some cases, a transient project can be created which
67 * will not point to an actual pom file.
68 * @return the path of the pom
69 */
70 @Nonnull
71 Optional<Path> getPomPath();
72
73 @Nonnull
74 default Optional<Path> getBasedir() {
75 return getPomPath().map(Path::getParent);
76 }
77
78 @Nonnull
79 List<DependencyCoordinate> getDependencies();
80
81 @Nonnull
82 List<DependencyCoordinate> getManagedDependencies();
83
84 @Nonnull
85 default String getId() {
86 return getModel().getId();
87 }
88
89 boolean isExecutionRoot();
90
91 @Nonnull
92 Optional<Project> getParent();
93
94 @Nonnull
95 List<RemoteRepository> getRemoteProjectRepositories();
96
97 @Nonnull
98 List<RemoteRepository> getRemotePluginRepositories();
99 }