View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.release.plugin.stubs;
18  
19  import java.io.File;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.apache.commons.release.plugin.mojos.CommonsDistributionDetachmentMojoTest;
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
26  import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  import org.apache.maven.project.MavenProject;
29  
30  /**
31   * Stub for {@link MavenProject} for the {@link CommonsDistributionDetachmentMojoTest}. See the
32   * testing pom,
33   * <code>src/test/resources/detach-distributions/detach-distributions.xml</code> for the declared
34   * usage of
35   * this class.
36   *
37   * @since 1.0
38   */
39  public final class DistributionDetachmentProjectStub extends MavenProjectStub {
40  
41      public static final class DistributionDetachmentArtifactStub extends ArtifactStub {
42  
43          private final File artifact;
44  
45          private final String version;
46  
47          private final String classifier;
48  
49          private final String type;
50  
51          public DistributionDetachmentArtifactStub(final File file, final String type, final String groupId,
52                  final String artifactId, final String classifier, final String version) {
53              this.setArtifactId(artifactId);
54              this.setGroupId(groupId);
55              this.setArtifactHandler(new DefaultArtifactHandlerStub(type, classifier));
56              this.artifact = file;
57              this.type = type;
58              this.classifier = classifier;
59              this.version = version;
60          }
61  
62          @Override
63          public String getClassifier() {
64              return this.classifier;
65          }
66  
67          @Override
68          public File getFile() {
69              return this.artifact;
70          }
71  
72          @Override
73          public String getType() {
74              return this.type;
75          }
76  
77          @Override
78          public String getVersion() {
79              return this.version;
80          }
81      }
82  
83      private List<Artifact> attachedArtifacts;
84  
85      @Override
86      public String getArtifactId() {
87          return "commons-text";
88      }
89  
90      @Override
91      public List<Artifact> getAttachedArtifacts() {
92          attachedArtifacts = new ArrayList<>();
93          attachedArtifacts.add(
94              new DistributionDetachmentArtifactStub(
95                  new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.tar.gz"),
96                  "tar.gz",
97                  "org.apache.commons",
98                  "commons-text",
99                  "bin", "1.4"
100             )
101         );
102         attachedArtifacts.add(
103             new DistributionDetachmentArtifactStub(
104                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.tar.gz.asc"),
105                 "tar.gz.asc",
106                 "org.apache.commons",
107                 "commons-text",
108                 "bin", "1.4"
109             )
110         );
111         attachedArtifacts.add(
112             new DistributionDetachmentArtifactStub(
113                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.zip"),
114                 "zip",
115                 "org.apache.commons",
116                 "commons-text",
117                 "bin", "1.4"
118             )
119         );
120         attachedArtifacts.add(
121             new DistributionDetachmentArtifactStub(
122                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.zip.asc"),
123                 "zip.asc",
124                 "org.apache.commons",
125                 "commons-text",
126                 "bin", "1.4"
127             )
128         );
129         attachedArtifacts.add(
130             new DistributionDetachmentArtifactStub(
131                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.tar.gz"),
132                 "tar.gz",
133                 "org.apache.commons",
134                 "commons-text",
135                 "src", "1.4"
136             )
137         );
138         attachedArtifacts.add(
139             new DistributionDetachmentArtifactStub(
140                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.tar.gz.asc"),
141                 "tar.gz.asc",
142                 "org.apache.commons",
143                 "commons-text",
144                 "src", "1.4"
145             )
146         );
147         attachedArtifacts.add(
148             new DistributionDetachmentArtifactStub(
149                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.zip"),
150                 "zip",
151                 "org.apache.commons",
152                 "commons-text",
153                 "src", "1.4"
154             )
155         );
156         attachedArtifacts.add(
157             new DistributionDetachmentArtifactStub(
158                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.zip.asc"),
159                 "zip.asc",
160                 "org.apache.commons",
161                 "commons-text",
162                 "src", "1.4"
163             )
164         );
165         attachedArtifacts.add(
166             new DistributionDetachmentArtifactStub(
167                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.jar"),
168                 "jar",
169                 "org.apache.commons",
170                 "commons-text",
171                 "jar", "1.4"
172             )
173         );
174         attachedArtifacts.add(
175             new DistributionDetachmentArtifactStub(
176                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.jar.asc"),
177                 "jar.asc",
178                 "org.apache.commons",
179                 "commons-text",
180                 "jar", "1.4"
181             )
182         );
183         attachedArtifacts.add(
184             new DistributionDetachmentArtifactStub(
185                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.pom"),
186                 "pom",
187                 "org.apache.commons",
188                 "commons-text",
189                 "pom", "1.4"
190             )
191         );
192         attachedArtifacts.add(
193             new DistributionDetachmentArtifactStub(
194                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.pom.asc"),
195                 "pom.asc",
196                 "org.apache.commons",
197                 "commons-text",
198                 "pom", "1.4"
199             )
200         );
201         attachedArtifacts.add(
202             new DistributionDetachmentArtifactStub(
203                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-javadoc.jar"),
204                 "jar",
205                 "org.apache.commons",
206                 "commons-text",
207                 "javadoc", "1.4"
208             )
209         );
210         attachedArtifacts.add(
211             new DistributionDetachmentArtifactStub(
212                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-javadoc.jar.asc"),
213                 "jar.asc",
214                 "org.apache.commons",
215                 "commons-text",
216                 "javadoc", "1.4"
217             )
218         );
219         attachedArtifacts.add(
220             new DistributionDetachmentArtifactStub(
221                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-sources.jar"),
222                 "jar",
223                 "org.apache.commons",
224                 "commons-text",
225                 "sources", "1.4"
226             )
227         );
228         attachedArtifacts.add(
229             new DistributionDetachmentArtifactStub(
230                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-sources.jar.asc"),
231                 "jar.asc",
232                 "org.apache.commons",
233                 "commons-text",
234                 "sources", "1.4"
235             )
236         );
237         return attachedArtifacts;
238     }
239 
240     @Override
241     public String getGroupId() {
242         return "org.apache.commons";
243     }
244 
245     @Override
246     public String getUrl() {
247         return "https://commons.apache.org/proper/commons-text/";
248     }
249 
250     @Override
251     public String getVersion() {
252         return "1.4";
253     }
254 }