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.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.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      /**
90       * @deprecated use {@link #isTopProject()} instead
91       */
92      @Deprecated
93      boolean isExecutionRoot();
94  
95      /**
96       * Returns a boolean indicating if the project is the top level project for
97       * this reactor build.  The top level project may be different from the
98       * {@code rootDirectory}, especially if a subtree of the project is being
99       * built, either because Maven has been launched in a subdirectory or using
100      * a {@code -f} option.
101      *
102      * @return {@code true} if the project is the top level project for this build
103      */
104     boolean isTopProject();
105 
106     /**
107      * Returns a boolean indicating if the project is a root project,
108      * meaning that the {@link #getRootDirectory()} and {@link #getBasedir()}
109      * points to the same directory, and that either {@link Model#isRoot()}
110      * is {@code true} or that {@code basedir} contains a {@code .mvn} child
111      * directory.
112      *
113      * @return {@code true} if the project is the root project
114      * @see Model#isRoot()
115      */
116     boolean isRootProject();
117 
118     /**
119      * Gets the root directory of the project, which is the parent directory
120      * containing the {@code .mvn} directory or flagged with {@code root="true"}.
121      *
122      * @throws IllegalStateException if the root directory could not be found
123      * @see Session#getRootDirectory()
124      */
125     @Nonnull
126     Path getRootDirectory();
127 
128     @Nonnull
129     Optional<Project> getParent();
130 
131     @Nonnull
132     List<RemoteRepository> getRemoteProjectRepositories();
133 
134     @Nonnull
135     List<RemoteRepository> getRemotePluginRepositories();
136 }