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.plugin.testing.stubs;
20  
21  import org.apache.maven.artifact.handler.ArtifactHandler;
22  
23  /**
24   * Minimal artifact handler used by the stub factory to create unpackable archives.
25   *
26   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
27   */
28  public class DefaultArtifactHandlerStub implements ArtifactHandler {
29      private String extension;
30  
31      private String type;
32  
33      private String classifier;
34  
35      private String directory;
36  
37      private String packaging;
38  
39      private boolean includesDependencies;
40  
41      private String language;
42  
43      private boolean addedToClasspath;
44  
45      /**
46       * @param t the artifact handler type
47       * @param c the artifact handler classifier
48       */
49      public DefaultArtifactHandlerStub(String t, String c) {
50          type = t;
51          classifier = c;
52          if (t.equals("test-jar")) {
53              extension = "jar";
54          }
55      }
56  
57      /**
58       * @param type the artifact handler type
59       */
60      public DefaultArtifactHandlerStub(String type) {
61          this.type = type;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public String getExtension() {
67          if (extension == null) {
68              extension = type;
69          }
70          return extension;
71      }
72  
73      /**
74       * @return the artifact handler type
75       */
76      public String getType() {
77          return type;
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public String getClassifier() {
83          return classifier;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public String getDirectory() {
89          if (directory == null) {
90              directory = getPackaging() + "s";
91          }
92          return directory;
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public String getPackaging() {
98          if (packaging == null) {
99              packaging = getType();
100         }
101         return packaging;
102     }
103 
104     /** {@inheritDoc} */
105     @Override
106     public boolean isIncludesDependencies() {
107         return includesDependencies;
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public String getLanguage() {
113         if (language == null) {
114             language = "none";
115         }
116 
117         return language;
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public boolean isAddedToClasspath() {
123         return addedToClasspath;
124     }
125 
126     /**
127      * @param theAddedToClasspath The addedToClasspath to set.
128      */
129     public void setAddedToClasspath(boolean theAddedToClasspath) {
130         this.addedToClasspath = theAddedToClasspath;
131     }
132 
133     /**
134      * @param theClassifier The classifier to set.
135      */
136     public void setClassifier(String theClassifier) {
137         this.classifier = theClassifier;
138     }
139 
140     /**
141      * @param theDirectory The directory to set.
142      */
143     public void setDirectory(String theDirectory) {
144         this.directory = theDirectory;
145     }
146 
147     /**
148      * @param theExtension The extension to set.
149      */
150     public void setExtension(String theExtension) {
151         this.extension = theExtension;
152     }
153 
154     /**
155      * @param theIncludesDependencies The includesDependencies to set.
156      */
157     public void setIncludesDependencies(boolean theIncludesDependencies) {
158         this.includesDependencies = theIncludesDependencies;
159     }
160 
161     /**
162      * @param theLanguage The language to set.
163      */
164     public void setLanguage(String theLanguage) {
165         this.language = theLanguage;
166     }
167 
168     /**
169      * @param thePackaging The packaging to set.
170      */
171     public void setPackaging(String thePackaging) {
172         this.packaging = thePackaging;
173     }
174 
175     /**
176      * @param theType The type to set.
177      */
178     public void setType(String theType) {
179         this.type = theType;
180     }
181 }