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.project.artifact;
20  
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.apache.maven.artifact.DefaultArtifact;
25  import org.apache.maven.artifact.handler.ArtifactHandler;
26  import org.apache.maven.model.Dependency;
27  import org.apache.maven.model.DependencyManagement;
28  import org.apache.maven.project.MavenProject;
29  
30  /**
31   * ProjectArtifact
32   */
33  public class ProjectArtifact extends DefaultArtifact implements ArtifactWithDependencies {
34      private MavenProject project;
35  
36      public ProjectArtifact(MavenProject project) {
37          super(
38                  project.getGroupId(),
39                  project.getArtifactId(),
40                  project.getVersion(),
41                  null,
42                  "pom",
43                  null,
44                  new PomArtifactHandler());
45          this.project = project;
46          setFile(project.getFile());
47          setResolved(true);
48      }
49  
50      public MavenProject getProject() {
51          return project;
52      }
53  
54      public List<Dependency> getDependencies() {
55          return project.getModel().getDependencies();
56      }
57  
58      public List<Dependency> getManagedDependencies() {
59          DependencyManagement depMngt = project.getModel().getDependencyManagement();
60          return (depMngt != null) ? Collections.unmodifiableList(depMngt.getDependencies()) : Collections.emptyList();
61      }
62  
63      // TODO: this is duplicate of PomArtifactHandlerProvider provided one
64      static class PomArtifactHandler implements ArtifactHandler {
65          @Override
66          public String getClassifier() {
67              return null;
68          }
69  
70          @Override
71          public String getDirectory() {
72              return null;
73          }
74  
75          @Override
76          public String getExtension() {
77              return "pom";
78          }
79  
80          @Override
81          public String getLanguage() {
82              return "none";
83          }
84  
85          @Override
86          public String getPackaging() {
87              return "pom";
88          }
89  
90          @Override
91          @Deprecated
92          public boolean isAddedToClasspath() {
93              return false;
94          }
95  
96          @Override
97          public boolean isIncludesDependencies() {
98              return false;
99          }
100     }
101 }