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