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    *      http://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 class DistributionDetachmentProjectStub extends MavenProjectStub {
40  
41      private List<Artifact> attachedArtifacts;
42  
43      @Override
44      public String getArtifactId() {
45          return "commons-text";
46      }
47  
48      @Override
49      public String getGroupId() {
50          return "org.apache.commons";
51      }
52  
53      @Override
54      public String getVersion() {
55          return "1.4";
56      }
57  
58      @Override
59      public String getUrl() {
60          return "https://commons.apache.org/proper/commons-text/";
61      }
62  
63      @Override
64      public List<Artifact> getAttachedArtifacts() {
65          attachedArtifacts = new ArrayList<>();
66          attachedArtifacts.add(
67              new DistributionDetachmentArtifactStub(
68                  new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.tar.gz"),
69                  "tar.gz",
70                  "org.apache.commons",
71                  "commons-text",
72                  "bin", "1.4"
73              )
74          );
75          attachedArtifacts.add(
76              new DistributionDetachmentArtifactStub(
77                  new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.tar.gz.asc"),
78                  "tar.gz.asc",
79                  "org.apache.commons",
80                  "commons-text",
81                  "bin", "1.4"
82              )
83          );
84          attachedArtifacts.add(
85              new DistributionDetachmentArtifactStub(
86                  new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.zip"),
87                  "zip",
88                  "org.apache.commons",
89                  "commons-text",
90                  "bin", "1.4"
91              )
92          );
93          attachedArtifacts.add(
94              new DistributionDetachmentArtifactStub(
95                  new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-bin.zip.asc"),
96                  "zip.asc",
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-src.tar.gz"),
105                 "tar.gz",
106                 "org.apache.commons",
107                 "commons-text",
108                 "src", "1.4"
109             )
110         );
111         attachedArtifacts.add(
112             new DistributionDetachmentArtifactStub(
113                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.tar.gz.asc"),
114                 "tar.gz.asc",
115                 "org.apache.commons",
116                 "commons-text",
117                 "src", "1.4"
118             )
119         );
120         attachedArtifacts.add(
121             new DistributionDetachmentArtifactStub(
122                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-src.zip"),
123                 "zip",
124                 "org.apache.commons",
125                 "commons-text",
126                 "src", "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.zip.asc"),
132                 "zip.asc",
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.jar"),
141                 "jar",
142                 "org.apache.commons",
143                 "commons-text",
144                 "jar", "1.4"
145             )
146         );
147         attachedArtifacts.add(
148             new DistributionDetachmentArtifactStub(
149                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.jar.asc"),
150                 "jar.asc",
151                 "org.apache.commons",
152                 "commons-text",
153                 "jar", "1.4"
154             )
155         );
156         attachedArtifacts.add(
157             new DistributionDetachmentArtifactStub(
158                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.pom"),
159                 "pom",
160                 "org.apache.commons",
161                 "commons-text",
162                 "pom", "1.4"
163             )
164         );
165         attachedArtifacts.add(
166             new DistributionDetachmentArtifactStub(
167                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4.pom.asc"),
168                 "pom.asc",
169                 "org.apache.commons",
170                 "commons-text",
171                 "pom", "1.4"
172             )
173         );
174         attachedArtifacts.add(
175             new DistributionDetachmentArtifactStub(
176                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-javadoc.jar"),
177                 "jar",
178                 "org.apache.commons",
179                 "commons-text",
180                 "javadoc", "1.4"
181             )
182         );
183         attachedArtifacts.add(
184             new DistributionDetachmentArtifactStub(
185                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-javadoc.jar.asc"),
186                 "jar.asc",
187                 "org.apache.commons",
188                 "commons-text",
189                 "javadoc", "1.4"
190             )
191         );
192         attachedArtifacts.add(
193             new DistributionDetachmentArtifactStub(
194                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-sources.jar"),
195                 "jar",
196                 "org.apache.commons",
197                 "commons-text",
198                 "sources", "1.4"
199             )
200         );
201         attachedArtifacts.add(
202             new DistributionDetachmentArtifactStub(
203                 new File("src/test/resources/mojos/detach-distributions/target/commons-text-1.4-sources.jar.asc"),
204                 "jar.asc",
205                 "org.apache.commons",
206                 "commons-text",
207                 "sources", "1.4"
208             )
209         );
210         return attachedArtifacts;
211     }
212 
213     public static class DistributionDetachmentArtifactStub extends ArtifactStub {
214 
215         private final File artifact;
216 
217         private final String version;
218 
219         private final String classifier;
220 
221         private final String type;
222 
223         public DistributionDetachmentArtifactStub(final File file, final String type, final String groupId,
224                 final String artifactId, final String classifier, final String version) {
225             this.setArtifactId(artifactId);
226             this.setGroupId(groupId);
227             this.setArtifactHandler(new DefaultArtifactHandlerStub(type, classifier));
228             this.artifact = file;
229             this.type = type;
230             this.classifier = classifier;
231             this.version = version;
232         }
233 
234         @Override
235         public File getFile() {
236             return this.artifact;
237         }
238 
239         @Override
240         public String getType() {
241             return this.type;
242         }
243 
244         @Override
245         public String getVersion() {
246             return this.version;
247         }
248 
249         @Override
250         public String getClassifier() {
251             return this.classifier;
252         }
253     }
254 }