View Javadoc
1   package org.codehaus.mojo.webstart.generator;
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.plugin.logging.Log;
23  import org.codehaus.mojo.webstart.ResolvedJarResource;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  import java.util.Collection;
27  
28  /**
29   * Generates a JNLP deployment descriptor.
30   *
31   * @author ngc
32   * @author <a href="jerome@coffeebreaks.org">Jerome Lacoste</a>
33   * @author Kevin Stembridge
34   */
35  public class JarResourcesGenerator
36      extends AbstractGenerator<JarResourceGeneratorConfig>
37  {
38  
39      public JarResourcesGenerator( Log log, GeneratorTechnicalConfig technicalConfig,
40                                    JarResourceGeneratorConfig extraConfig )
41      {
42          super( log, technicalConfig, extraConfig );
43      }
44  
45      protected String getArgumentsText()
46      {
47          StringBuilder buffer = new StringBuilder();
48  
49          if (getExtraConfig().getArguments() != null)
50          {
51              for (String argument : getExtraConfig().getArguments())
52              {
53                  buffer.append("<argument>").append(argument).append("</argument>").append(EOL);
54              }
55          }
56  
57          return buffer.toString();
58      }
59  
60      /**
61       * {@inheritDoc}
62       */
63      protected String getDependenciesText()
64      {
65  
66          String jarResourcesText = "";
67  
68          String libPath = getExtraConfig().getLibPath();
69          Collection<ResolvedJarResource> jarResources = getExtraConfig().getJarResources();
70  
71          if ( jarResources.size() != 0 )
72          {
73              final int multiplier = 100;
74              StringBuilder buffer = new StringBuilder( multiplier * jarResources.size() );
75              buffer.append( EOL );
76  
77              for ( ResolvedJarResource jarResource : jarResources )
78              {
79  
80                  if ( !jarResource.isIncludeInJnlp() )
81                  {
82                      continue;
83                  }
84  
85                  buffer.append( "<jar href=\"" );
86                  if ( StringUtils.isNotEmpty( libPath ) )
87                  {
88                      buffer.append( libPath );
89                      buffer.append( '/' );
90                  }
91                  buffer.append( jarResource.getHrefValue() );
92                  buffer.append( "\"" );
93  
94                  if ( jarResource.isOutputJarVersion() )
95                  {
96                      buffer.append( " version=\"" ).append( jarResource.getVersion() ).append( "\"" );
97                  }
98  
99                  if ( jarResource.getMainClass() != null )
100                 {
101                     buffer.append( " main=\"true\"" );
102                 }
103 
104                 buffer.append( "/>" ).append( EOL );
105             }
106             jarResourcesText = buffer.toString();
107         }
108         return jarResourcesText;
109     }
110 
111 }