View Javadoc
1   package org.codehaus.mojo.webstart;
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.commons.lang.StringUtils;
23  
24  /**
25   * This class represents a <jarResource> configuration element from the
26   * pom.xml file. It identifies an artifact that is to be processed by the plugin
27   * for inclusion in the JNLP bundle.
28   *
29   * @author Kevin Stembridge
30   * @author $LastChangedBy$
31   * @version $Revision$
32   * @since 19 May 2007
33   */
34  public class JarResource
35  {
36  
37      private String groupId;
38  
39      private String artifactId;
40  
41      private String version;
42  
43      private String classifier;
44  
45      private String mainClass;
46  
47      private boolean outputJarVersion = true;
48  
49      private boolean includeInJnlp = true;
50  
51      private String type;
52  
53      /**
54       * The hrefValue to fill in JarResource file.
55       */
56      private String hrefValue;
57  
58      /**
59       * Returns the value of the artifactId field.
60       *
61       * @return Returns the value of the artifactId field.
62       */
63      public String getArtifactId()
64      {
65          return artifactId;
66      }
67  
68      /**
69       * Returns the value of the type field.
70       *
71       * @return Returns the value of the type field.
72       */
73      public String getType()
74      {
75          return type;
76      }
77  
78      /**
79       * Returns the value of the classifier field.
80       *
81       * @return Returns the value of the classifier field.
82       */
83      public String getClassifier()
84      {
85          return classifier;
86      }
87  
88      /**
89       * Returns the value of the groupId field.
90       *
91       * @return Returns the value of the groupId field.
92       */
93      public String getGroupId()
94      {
95          return groupId;
96      }
97  
98      /**
99       * Returns the value of the version field.
100      *
101      * @return Returns the value of the version field.
102      */
103     public String getVersion()
104     {
105         return version;
106     }
107 
108     /**
109      * Returns the fully qualified class name of the JNLP application's 'main' class but
110      * only if it is contained in the jar represented by this instance. Only one jarResource per
111      * plugin configuration can be declared with a main class. This is the value that will be
112      * populated in the generated JNLP file.
113      *
114      * @return Returns the value of the mainClass field, or null if the jar represented
115      * by this instance is not the one that contains the application's main class.
116      */
117     public String getMainClass()
118     {
119         return mainClass;
120     }
121 
122     public boolean isMandatoryField()
123     {
124         return StringUtils.isNotBlank( getGroupId() ) &&
125             StringUtils.isNotBlank( getArtifactId() ) &&
126             StringUtils.isNotBlank( getVersion() );
127     }
128 
129     /**
130      * Sets the flag that indicates whether or not the jar resource
131      * element in the generated JNLP file should include a version attribute.
132      * Default is true.
133      *
134      * @param outputJarVersion new value of field {@link #outputJarVersion}
135      */
136     protected void setOutputJarVersion( boolean outputJarVersion )
137     {
138         this.outputJarVersion = outputJarVersion;
139     }
140 
141     /**
142      * Returns the flag that indicates whether or not the jar resource
143      * element in the generated JNLP file should include a version attribute.
144      * Default is true.
145      *
146      * @return Returns the value of the outputJarVersion field.
147      */
148     public boolean isOutputJarVersion()
149     {
150         return this.outputJarVersion;
151     }
152 
153     /**
154      * Returns the flag that indicates whether or not this resource should be included
155      * in the generated JNLP file. The default is true, but you may want to exclude jars
156      * from the JNLP in cases where multiple versions of a jar are included in the JNLP bundle.
157      *
158      * @return Returns the value of the includeInJnlp field.
159      */
160     public boolean isIncludeInJnlp()
161     {
162         return this.includeInJnlp;
163     }
164 
165     /**
166      * Returns the value that should be output for this jar in the href attribute of the
167      * jar resource element in the generated JNLP file. If not set explicitly, this defaults
168      * to the file name of the underlying artifact.
169      *
170      * @return The href attribute to be output for this jar resource in the generated JNLP file definied by user.
171      */
172     public String getHrefValue()
173     {
174         return hrefValue;
175     }
176 
177     /**
178      * {@inheritDoc}
179      */
180     public String toString()
181     {
182         return "JarResource[ groupId='" + this.groupId + "', artifactId='" + this.artifactId + "', version='" +
183             this.version + "', classifier='" + this.classifier + "', mainClass='" + this.mainClass +
184             "', outputJarVersion='" + this.outputJarVersion + "' ]";
185     }
186 }