View Javadoc
1   package org.apache.maven.api.services;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.api.Service;
23  import org.apache.maven.api.annotations.Experimental;
24  import org.apache.maven.api.annotations.Nonnull;
25  
26  import java.nio.file.Path;
27  import java.util.Collection;
28  import java.util.List;
29  import java.util.Optional;
30  
31  import org.apache.maven.api.Artifact;
32  import org.apache.maven.api.Node;
33  import org.apache.maven.api.Project;
34  import org.apache.maven.api.RemoteRepository;
35  import org.apache.maven.api.ResolutionScope;
36  import org.apache.maven.api.Session;
37  
38  /**
39   * Interface to manage the project during its lifecycle.
40   *
41   * @since 4.0
42   */
43  @Experimental
44  public interface ProjectManager extends Service
45  {
46      /**
47       * Returns the path to the resolved file in the local repository
48       * if the artifact has been resolved.
49       *
50       * @return the path of the resolved artifact
51       */
52      @Nonnull
53      Optional<Path> getPath( Project project );
54  
55      @Nonnull
56      Collection<Artifact> getAttachedArtifacts( Project project );
57  
58      default void attachArtifact( Session session, Project project, Path path )
59      {
60          String name = path.getFileName().toString();
61          int dot = name.lastIndexOf( '.' );
62          String ext = dot >= 1 ? name.substring( dot + 1 ) : "";
63          Artifact artifact = session.createArtifact( project.getGroupId(), project.getArtifactId(),
64                  project.getVersion(), ext );
65          attachArtifact( project, artifact, path );
66      }
67  
68      default void attachArtifact( Session session, Project project, String type, Path path )
69      {
70          Artifact artifact = session.createArtifact( project.getGroupId(), project.getArtifactId(),
71                                                      project.getVersion(), null, null, type );
72          attachArtifact( project, artifact, path );
73      }
74  
75      void attachArtifact( Project project, Artifact artifact, Path path );
76  
77      List<String> getCompileSourceRoots( Project project );
78  
79      void addCompileSourceRoot( Project project, String sourceRoot );
80  
81      List<String> getTestCompileSourceRoots( Project project );
82  
83      void addTestCompileSourceRoot( Project project, String sourceRoot );
84  
85      List<RemoteRepository> getRepositories( Project project );
86  
87      List<Artifact> getResolvedDependencies( Project project, ResolutionScope scope );
88  
89      Node getCollectedDependencies( Project project, ResolutionScope scope );
90  
91      void setProperty( Project project, String key, String value );
92  
93  }