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.artifact.handler;
20  
21  import static java.util.Objects.requireNonNull;
22  
23  /**
24   */
25  public class DefaultArtifactHandler implements ArtifactHandler {
26      private final String type;
27  
28      private String extension;
29  
30      private String classifier;
31  
32      private String directory;
33  
34      private String packaging;
35  
36      private boolean includesDependencies;
37  
38      private String language;
39  
40      private boolean addedToClasspath;
41  
42      /**
43       * Default ctor for Plexus compatibility, as many plugins have artifact handlers declared in legacy Plexus XML.
44       * Do not use directly!
45       *
46       * @deprecated This ctor is present only for Plexus XML defined component compatibility, do not use it.
47       */
48      @Deprecated
49      public DefaultArtifactHandler() {
50          this.type = null;
51      }
52  
53      public DefaultArtifactHandler(final String type) {
54          this(type, null, null, null, null, false, null, false);
55      }
56  
57      @SuppressWarnings("checkstyle:ParameterNumber")
58      public DefaultArtifactHandler(
59              final String type,
60              final String extension,
61              final String classifier,
62              final String directory,
63              final String packaging,
64              final boolean includesDependencies,
65              final String language,
66              final boolean addedToClasspath) {
67          this.type = requireNonNull(type);
68          this.extension = extension;
69          this.classifier = classifier;
70          this.directory = directory;
71          this.packaging = packaging;
72          this.includesDependencies = includesDependencies;
73          this.language = language;
74          this.addedToClasspath = addedToClasspath;
75      }
76  
77      public String getType() {
78          return type;
79      }
80  
81      @Override
82      public String getExtension() {
83          if (extension == null) {
84              return type;
85          }
86          return extension;
87      }
88  
89      public void setExtension(final String extension) {
90          this.extension = extension;
91      }
92  
93      @Override
94      public String getClassifier() {
95          return classifier;
96      }
97  
98      public void setClassifier(final String classifier) {
99          this.classifier = classifier;
100     }
101 
102     @Override
103     public String getDirectory() {
104         if (directory == null) {
105             return getPackaging() + "s";
106         }
107         return directory;
108     }
109 
110     public void setDirectory(final String directory) {
111         this.directory = directory;
112     }
113 
114     @Override
115     public String getPackaging() {
116         if (packaging == null) {
117             return type;
118         }
119         return packaging;
120     }
121 
122     public void setPackaging(final String packaging) {
123         this.packaging = packaging;
124     }
125 
126     @Override
127     public boolean isIncludesDependencies() {
128         return includesDependencies;
129     }
130 
131     public void setIncludesDependencies(final boolean includesDependencies) {
132         this.includesDependencies = includesDependencies;
133     }
134 
135     @Override
136     public String getLanguage() {
137         if (language == null) {
138             return "none";
139         }
140 
141         return language;
142     }
143 
144     public void setLanguage(final String language) {
145         this.language = language;
146     }
147 
148     @Override
149     public boolean isAddedToClasspath() {
150         return addedToClasspath;
151     }
152 
153     public void setAddedToClasspath(final boolean addedToClasspath) {
154         this.addedToClasspath = addedToClasspath;
155     }
156 }