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