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.services;
20  
21  import java.nio.file.Path;
22  import java.util.Collection;
23  import java.util.List;
24  import java.util.Optional;
25  
26  import org.apache.maven.api.Artifact;
27  import org.apache.maven.api.Node;
28  import org.apache.maven.api.Project;
29  import org.apache.maven.api.RemoteRepository;
30  import org.apache.maven.api.ResolutionScope;
31  import org.apache.maven.api.Service;
32  import org.apache.maven.api.Session;
33  import org.apache.maven.api.annotations.Experimental;
34  import org.apache.maven.api.annotations.Nonnull;
35  
36  /**
37   * Interface to manage the project during its lifecycle.
38   *
39   * @since 4.0
40   */
41  @Experimental
42  public interface ProjectManager extends Service {
43      /**
44       * Returns the path to the resolved file in the local repository
45       * if the artifact has been resolved.
46       *
47       * @return the path of the resolved artifact
48       */
49      @Nonnull
50      Optional<Path> getPath(Project project);
51  
52      @Nonnull
53      Collection<Artifact> getAttachedArtifacts(Project project);
54  
55      default void attachArtifact(Session session, Project project, Path path) {
56          String name = path.getFileName().toString();
57          int dot = name.lastIndexOf('.');
58          String ext = dot >= 1 ? name.substring(dot + 1) : "";
59          Artifact artifact =
60                  session.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), ext);
61          attachArtifact(project, artifact, path);
62      }
63  
64      default void attachArtifact(Session session, Project project, String type, Path path) {
65          Artifact artifact = session.createArtifact(
66                  project.getGroupId(), project.getArtifactId(), project.getVersion(), null, null, type);
67          attachArtifact(project, artifact, path);
68      }
69  
70      void attachArtifact(Project project, Artifact artifact, Path path);
71  
72      List<String> getCompileSourceRoots(Project project);
73  
74      void addCompileSourceRoot(Project project, String sourceRoot);
75  
76      List<String> getTestCompileSourceRoots(Project project);
77  
78      void addTestCompileSourceRoot(Project project, String sourceRoot);
79  
80      List<RemoteRepository> getRepositories(Project project);
81  
82      List<Artifact> getResolvedDependencies(Project project, ResolutionScope scope);
83  
84      Node getCollectedDependencies(Project project, ResolutionScope scope);
85  
86      void setProperty(Project project, String key, String value);
87  }