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.plugins.war.stub;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Set;
24  import java.util.TreeSet;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.model.Dependency;
28  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
29  
30  public class MavenProjectArtifactsStub extends MavenProjectBasicStub {
31      TreeSet<Artifact> artifacts;
32  
33      public MavenProjectArtifactsStub() throws Exception {
34          artifacts = new TreeSet<>();
35      }
36  
37      public void addArtifact(ArtifactStub stub) {
38          artifacts.add(stub);
39      }
40  
41      public Set<Artifact> getArtifacts() {
42          return artifacts;
43      }
44  
45      public List<Dependency> getDependencies() {
46          if (getArtifacts() == null) {
47              return new ArrayList<>();
48          }
49          final List<Dependency> dependencies = new ArrayList<>();
50          for (Artifact a : getArtifacts()) {
51              Dependency dependency = new Dependency();
52              dependency.setArtifactId(a.getArtifactId());
53              dependency.setGroupId(a.getGroupId());
54              dependency.setVersion(a.getVersion());
55              dependency.setScope(a.getScope());
56              dependency.setType(a.getType());
57              dependency.setClassifier(a.getClassifier());
58              dependencies.add(dependency);
59          }
60          return dependencies;
61      }
62  
63      public List<String> getRuntimeClasspathElements() {
64          List<String> artifacts = new ArrayList<>();
65  
66          artifacts.add(
67                  "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar");
68          artifacts.add(
69                  "src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar");
70  
71          return artifacts;
72      }
73  }