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