View Javadoc
1   package org.apache.maven.plugin.testing.stubs;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.handler.ArtifactHandler;
23  
24  /**
25   * Minimal artifact handler used by the stub factory to create unpackable archives.
26   *
27   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
28   * @version $Id$
29   */
30  public class DefaultArtifactHandlerStub
31      implements ArtifactHandler
32  {
33      private String extension;
34  
35      private String type;
36  
37      private String classifier;
38  
39      private String directory;
40  
41      private String packaging;
42  
43      private boolean includesDependencies;
44  
45      private String language;
46  
47      private boolean addedToClasspath;
48  
49      /**
50       * @param t the artifact handler type
51       * @param c the artifact handler classifier
52       */
53      public DefaultArtifactHandlerStub( String t, String c )
54      {
55          type = t;
56          classifier = c;
57          if ( t.equals( "test-jar" ) )
58          {
59              extension = "jar";
60          }
61  
62      }
63  
64      /**
65       * @param type the artifact handler type
66       */
67      public DefaultArtifactHandlerStub( String type )
68      {
69          this.type = type;
70      }
71  
72      /** {@inheritDoc} */
73      public String getExtension()
74      {
75          if ( extension == null )
76          {
77              extension = type;
78          }
79          return extension;
80      }
81  
82      /**
83       * @return the artifact handler type
84       */
85      public String getType()
86      {
87          return type;
88      }
89  
90      /** {@inheritDoc} */
91      public String getClassifier()
92      {
93          return classifier;
94      }
95  
96      /** {@inheritDoc} */
97      public String getDirectory()
98      {
99          if ( directory == null )
100         {
101             directory = getPackaging() + "s";
102         }
103         return directory;
104     }
105 
106     /** {@inheritDoc} */
107     public String getPackaging()
108     {
109         if ( packaging == null )
110         {
111             packaging = getType();
112         }
113         return packaging;
114     }
115 
116     /** {@inheritDoc} */
117     public boolean isIncludesDependencies()
118     {
119         return includesDependencies;
120     }
121 
122     /** {@inheritDoc} */
123     public String getLanguage()
124     {
125         if ( language == null )
126         {
127             language = "none";
128         }
129 
130         return language;
131     }
132 
133     /** {@inheritDoc} */
134     public boolean isAddedToClasspath()
135     {
136         return addedToClasspath;
137     }
138 
139     /**
140      * @param theAddedToClasspath The addedToClasspath to set.
141      */
142     public void setAddedToClasspath( boolean theAddedToClasspath )
143     {
144         this.addedToClasspath = theAddedToClasspath;
145     }
146 
147     /**
148      * @param theClassifier The classifier to set.
149      */
150     public void setClassifier( String theClassifier )
151     {
152         this.classifier = theClassifier;
153     }
154 
155     /**
156      * @param theDirectory The directory to set.
157      */
158     public void setDirectory( String theDirectory )
159     {
160         this.directory = theDirectory;
161     }
162 
163     /**
164      * @param theExtension The extension to set.
165      */
166     public void setExtension( String theExtension )
167     {
168         this.extension = theExtension;
169     }
170 
171     /**
172      * @param theIncludesDependencies The includesDependencies to set.
173      */
174     public void setIncludesDependencies( boolean theIncludesDependencies )
175     {
176         this.includesDependencies = theIncludesDependencies;
177     }
178 
179     /**
180      * @param theLanguage The language to set.
181      */
182     public void setLanguage( String theLanguage )
183     {
184         this.language = theLanguage;
185     }
186 
187     /**
188      * @param thePackaging The packaging to set.
189      */
190     public void setPackaging( String thePackaging )
191     {
192         this.packaging = thePackaging;
193     }
194 
195     /**
196      * @param theType The type to set.
197      */
198     public void setType( String theType )
199     {
200         this.type = theType;
201     }
202 }