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.install.stubs;
20  
21  import java.io.File;
22  import java.util.Collection;
23  import java.util.Collections;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.maven.artifact.handler.ArtifactHandler;
28  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
29  import org.apache.maven.artifact.metadata.ArtifactMetadata;
30  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
31  
32  public class InstallArtifactStub extends ArtifactStub {
33      private Map<Object, ArtifactMetadata> metadataMap;
34  
35      private File file;
36  
37      private boolean release;
38  
39      public String getArtifactId() {
40          return "maven-install-test";
41      }
42  
43      public String getGroupId() {
44          return "org.apache.maven.test";
45      }
46  
47      public String getVersion() {
48          return "1.0-SNAPSHOT";
49      }
50  
51      public String getBaseVersion() {
52          return getVersion();
53      }
54  
55      public void setFile(File file) {
56          this.file = file;
57      }
58  
59      public File getFile() {
60          return file;
61      }
62  
63      public String getType() {
64          return "jar";
65      }
66  
67      public ArtifactHandler getArtifactHandler() {
68          return new DefaultArtifactHandler() {
69              public String getExtension() {
70                  return "jar";
71              }
72          };
73      }
74  
75      public void addMetadata(ArtifactMetadata metadata) {
76          if (metadataMap == null) {
77              metadataMap = new HashMap<>();
78          }
79  
80          ArtifactMetadata m = metadataMap.get(metadata.getKey());
81          if (m != null) {
82              m.merge(metadata);
83          } else {
84              metadataMap.put(metadata.getKey(), metadata);
85          }
86      }
87  
88      public Collection<ArtifactMetadata> getMetadataList() {
89          return metadataMap == null ? Collections.emptyList() : metadataMap.values();
90      }
91  
92      public boolean isRelease() {
93          return release;
94      }
95  
96      public void setRelease(boolean release) {
97          this.release = release;
98      }
99  }