1 package org.codehaus.mojo.webstart.generator;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.logging.Log;
24 import org.apache.velocity.VelocityContext;
25 import org.codehaus.mojo.webstart.JnlpExtension;
26
27 import java.util.Collection;
28 import java.util.List;
29
30
31
32
33
34
35
36 public class Generator
37 extends AbstractGenerator<GeneratorConfig>
38 {
39
40 public Generator( Log log, GeneratorTechnicalConfig technicalConfig, GeneratorConfig extraConfig )
41 {
42 super( log, technicalConfig, extraConfig );
43 }
44
45 protected String getArgumentsText()
46 {
47 return "";
48 }
49
50
51
52
53 protected String getDependenciesText()
54 {
55 return indentText( 4, getDependenciesText( getExtraConfig() ) );
56 }
57
58 protected VelocityContext createAndPopulateContext()
59 {
60 VelocityContext context = super.createAndPopulateContext();
61 if ( getExtraConfig().hasJnlpExtensions() )
62 {
63
64 context.put( "extensions", indentText( 4, getExtensionsText( getExtraConfig() ) ) );
65 } else {
66 context.put( "extensions", "" );
67 }
68 return context;
69 }
70
71 static String getDependenciesText( GeneratorConfig config )
72 {
73 return getDependenciesText( config, config.getPackagedJnlpArtifacts() );
74 }
75
76 static String getDependenciesText( GeneratorExtraConfigWithDeps config, Collection<Artifact> artifacts )
77 {
78 String dependenciesText = "";
79 if ( !artifacts.isEmpty() )
80 {
81 StringBuilder buffer = new StringBuilder( 100 * artifacts.size() );
82 buffer.append( EOL );
83 if ( config.isPack200() )
84 {
85
86
87
88
89
90
91 buffer.append( "<property name=\"jnlp.packEnabled\" value=\"true\" />" ).append( EOL );
92 }
93 if ( config.isOutputJarVersions() )
94 {
95
96
97
98
99
100
101 buffer.append( "<property name=\"jnlp.versionEnabled\" value=\"true\" />" ).append( EOL );
102 }
103 String jarLibPath = null;
104 if ( config.getLibPath() != null )
105 {
106 jarLibPath = config.getLibPath();
107 jarLibPath = ( jarLibPath != null && jarLibPath.trim().length() != 0 ) ? jarLibPath.trim() : null;
108 }
109
110 for ( Artifact artifact : artifacts )
111 {
112 buffer.append( "<jar href=\"" );
113 if ( jarLibPath != null )
114 {
115 buffer.append( jarLibPath ).append( "/" );
116 }
117
118
119 if ( config.isOutputJarVersions() )
120 {
121 String filename = config.getDependencyFilename( artifact, null, config.isUseUniqueVersions() );
122
123
124 buffer.append( filename ).append( "\"" );
125 if (config.isUseUniqueVersions())
126 {
127 buffer.append( " version=\"" ).append( artifact.getBaseVersion() ).append( "\"" );
128 }
129 else
130 {
131 buffer.append( " version=\"" ).append( artifact.getVersion() ).append( "\"" );
132 }
133 }
134 else
135 {
136 String filename = config.getDependencyFilename( artifact, false, config.isUseUniqueVersions() );
137 buffer.append( filename ).append( "\"" );
138 }
139
140 if ( config.isArtifactWithMainClass( artifact ) )
141 {
142 buffer.append( " main=\"true\"" );
143 }
144 buffer.append( "/>" ).append( EOL );
145 }
146 dependenciesText = buffer.toString();
147 }
148 return dependenciesText;
149 }
150
151 static String getExtensionsText( GeneratorConfig config )
152 {
153 String text = "";
154 List<JnlpExtension> extensions = config.getJnlpExtensions();
155 if ( extensions != null && !extensions.isEmpty() )
156 {
157 StringBuilder buffer = new StringBuilder( 100 * extensions.size() );
158 buffer.append( "\n" );
159
160 for ( JnlpExtension extension : extensions )
161 {
162 buffer.append( "<extension name=\"" );
163 buffer.append( extension.getName() );
164 buffer.append( "\" href=\"" );
165 buffer.append( extension.getOutputFile() );
166 buffer.append( "\"/>" ).append( EOL );
167 }
168 text = buffer.toString();
169 }
170 return text;
171 }
172 }