Lines 17-27
Link Here
|
17 |
package org.codehaus.mojo.nbm; |
17 |
package org.codehaus.mojo.nbm; |
18 |
|
18 |
|
19 |
import java.io.File; |
19 |
import java.io.File; |
|
|
20 |
import java.util.ArrayList; |
21 |
import java.util.Collection; |
22 |
import java.util.Collections; |
23 |
import java.util.HashMap; |
24 |
import java.util.HashSet; |
25 |
import java.util.List; |
26 |
import java.util.Locale; |
27 |
import java.util.Map; |
28 |
import java.util.Set; |
20 |
import org.apache.maven.plugin.MojoExecutionException; |
29 |
import org.apache.maven.plugin.MojoExecutionException; |
21 |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
30 |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
22 |
import org.apache.maven.plugins.annotations.Mojo; |
31 |
import org.apache.maven.plugins.annotations.Mojo; |
23 |
import org.apache.maven.plugins.annotations.Parameter; |
32 |
import org.apache.maven.plugins.annotations.Parameter; |
24 |
import org.apache.maven.project.MavenProject; |
33 |
import org.apache.maven.project.MavenProject; |
|
|
34 |
import org.codehaus.plexus.archiver.FileSet; |
25 |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
35 |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
26 |
import org.codehaus.plexus.util.DirectoryScanner; |
36 |
import org.codehaus.plexus.util.DirectoryScanner; |
27 |
import org.codehaus.plexus.util.FileUtils; |
37 |
import org.codehaus.plexus.util.FileUtils; |
Lines 139-162
Link Here
|
139 |
|
149 |
|
140 |
for ( String jarDirectoryPath : scanner.getIncludedDirectories() ) |
150 |
for ( String jarDirectoryPath : scanner.getIncludedDirectories() ) |
141 |
{ |
151 |
{ |
142 |
|
152 |
DirectoryScanner ds = new DirectoryScanner(); |
143 |
// move nnn.jar directory to nnn.jar.tmp |
153 |
ds.setIncludes( new String[] |
|
|
154 |
{ |
155 |
"**/*.*" |
156 |
} ); |
157 |
ds.setBasedir( new File(clusterDir, jarDirectoryPath) ); |
158 |
ds.scan(); |
159 |
String [] includedFiles = ds.getIncludedFiles(); |
160 |
Map<String, Set<File>> brandingFilesGroupByLocale = groupBrandingFilesByLocale( includedFiles); |
144 |
File jarDirectory = new File( clusterDir, jarDirectoryPath ); |
161 |
File jarDirectory = new File( clusterDir, jarDirectoryPath ); |
145 |
|
162 |
for(Map.Entry<String, Set<File>> entryIter: brandingFilesGroupByLocale.entrySet()) { |
146 |
// jars should be placed in locales/ under the same directory the jar-directories are |
163 |
String locale = entryIter.getKey(); |
|
|
164 |
Set<File> brandingFiles = entryIter.getValue(); |
147 |
File destinationJar = |
165 |
File destinationJar = |
148 |
new File( jarDirectory.getParentFile().getAbsolutePath() + File.separator + "locale" |
166 |
new File( jarDirectory.getParentFile().getAbsolutePath() + File.separator + "locale" |
149 |
+ File.separator + destinationFileName( jarDirectory.getName(), brandingToken ) ); |
167 |
+ File.separator + destinationJarName( jarDirectory.getName(), brandingToken + (locale!=null? ("_" + locale): "") ) ); |
150 |
|
|
|
151 |
// create nnn.jar archive of contents |
152 |
JarArchiver archiver = new JarArchiver(); |
168 |
JarArchiver archiver = new JarArchiver(); |
153 |
archiver.setDestFile( destinationJar ); |
169 |
archiver.setDestFile( destinationJar ); |
154 |
archiver.addDirectory( jarDirectory ); |
170 |
for(File brandingFileIter:brandingFiles) { |
|
|
171 |
archiver.addDirectory( jarDirectory, new String[] |
172 |
{ |
173 |
"**/"+brandingFileIter.getName() |
174 |
}, new String[]{}); |
175 |
} |
155 |
archiver.createArchive(); |
176 |
archiver.createArchive(); |
156 |
|
177 |
} |
157 |
FileUtils.deleteDirectory( jarDirectory ); |
178 |
FileUtils.deleteDirectory( jarDirectory ); |
158 |
} |
179 |
} |
159 |
|
|
|
160 |
} |
180 |
} |
161 |
catch ( Exception ex ) |
181 |
catch ( Exception ex ) |
162 |
{ |
182 |
{ |
Lines 168-181
Link Here
|
168 |
static String destinationFileName( String brandingFilePath, String branding ) |
188 |
static String destinationFileName( String brandingFilePath, String branding ) |
169 |
{ |
189 |
{ |
170 |
// use first underscore in filename |
190 |
// use first underscore in filename |
|
|
191 |
String locale = ""; |
192 |
String brandingFilename = ""; |
171 |
int lastSeparator = brandingFilePath.lastIndexOf( File.separator ); |
193 |
int lastSeparator = brandingFilePath.lastIndexOf( File.separator ); |
|
|
194 |
if(lastSeparator != -1) { |
195 |
brandingFilename = brandingFilePath.substring( lastSeparator + 1); |
196 |
} else { |
197 |
brandingFilename = brandingFilePath; |
198 |
} |
199 |
if(brandingFilename.matches("([a-zA-z][a-zA-Z0-9]*)+(_[a-z]{2})(_[a-z]{2})?.[a-zA-Z][a-zA-Z0-9]+")) { |
200 |
//last index of '_' exists according to pattern |
201 |
locale = brandingFilename.substring( brandingFilename.lastIndexOf( '_') + 1, brandingFilename.lastIndexOf( '.')); |
202 |
String subBrandingFileIterName = brandingFilename.substring( 0, brandingFilename.lastIndexOf('_') ); |
203 |
|
204 |
//not sure about existing of last index of '_' |
205 |
int lastUnderscore = subBrandingFileIterName.lastIndexOf( '_' ); |
206 |
if(lastUnderscore != -1) { |
207 |
locale = brandingFilename.substring( subBrandingFileIterName.lastIndexOf('_') + 1, brandingFilename.lastIndexOf( '.')); |
208 |
} |
209 |
brandingFilePath = brandingFilePath.substring( 0, brandingFilePath.lastIndexOf( '.') - (locale.length() +1)) + |
210 |
brandingFilePath.substring( brandingFilePath.lastIndexOf( '.')); |
211 |
} |
212 |
|
213 |
String infix = "_" + branding + (!"".equals( locale )?("_" + locale) : ""); |
214 |
|
215 |
// no underscores, use dot |
216 |
int lastDot = brandingFilePath.lastIndexOf( '.' ); |
217 |
if (lastDot == -1 || lastDot < lastSeparator) { |
218 |
return brandingFilePath + infix; |
219 |
} |
220 |
return brandingFilePath.substring( 0, lastDot ) + infix + brandingFilePath.substring( lastDot ); |
221 |
} |
222 |
|
223 |
static String destinationJarName( String brandingFilePath, String branding ) |
224 |
{ |
225 |
// use first underscore in filename |
226 |
int lastSeparator = brandingFilePath.lastIndexOf( File.separator ); |
172 |
String infix = "_" + branding; |
227 |
String infix = "_" + branding; |
173 |
|
228 |
|
174 |
// no underscores, use dot |
229 |
// no underscores, use dot |
175 |
int lastDot = brandingFilePath.lastIndexOf( "." ); |
230 |
int lastDot = brandingFilePath.lastIndexOf( '.' ); |
176 |
if (lastDot == -1 || lastDot < lastSeparator) { |
231 |
if (lastDot == -1 || lastDot < lastSeparator) { |
177 |
return brandingFilePath + infix; |
232 |
return brandingFilePath + infix; |
178 |
} |
233 |
} |
179 |
return brandingFilePath.substring( 0, lastDot ) + infix + brandingFilePath.substring( lastDot ); |
234 |
return brandingFilePath.substring( 0, lastDot ) + infix + brandingFilePath.substring( lastDot ); |
180 |
} |
235 |
} |
|
|
236 |
|
237 |
static Map<String, Set<File>> groupBrandingFilesByLocale(String [] brandingFiles) { |
238 |
|
239 |
Map<String, Set<File>> result = new HashMap<String, Set<File>>(); |
240 |
for(String brandingFileStrIter:brandingFiles) { |
241 |
|
242 |
File brandingFileIter = new File(brandingFileStrIter); |
243 |
String locale = ""; |
244 |
|
245 |
//pass suspicious files to be localized |
246 |
if(brandingFileIter.getName().matches("([a-zA-z][a-zA-Z0-9]*)+(_[a-z]{2})(_[a-z]{2})?_[a-zA-z][a-zA-Z0-9]*.[a-zA-Z][a-zA-Z0-9]+")) { |
247 |
|
248 |
int lastSeparator = brandingFileIter.getAbsolutePath().lastIndexOf( File.separator ); |
249 |
String brandingFilename = ""; |
250 |
if(lastSeparator != -1) { |
251 |
brandingFilename = brandingFileIter.getAbsolutePath().substring( lastSeparator + 1); |
252 |
} else { |
253 |
brandingFilename = brandingFileIter.getAbsolutePath(); |
181 |
} |
254 |
} |
|
|
255 |
|
256 |
locale = brandingFilename.substring( brandingFilename.lastIndexOf('_') + 1, brandingFilename.lastIndexOf( '.')); |
257 |
|
258 |
//last index of '_' exists according to pattern |
259 |
String subBrandingFileIterName = brandingFilename.substring( 0, brandingFilename.lastIndexOf('_') ); |
260 |
|
261 |
//not sure about existing of last index of '_' |
262 |
int lastUnderscore = subBrandingFileIterName.lastIndexOf( "_" ); |
263 |
if(lastUnderscore != -1) { |
264 |
locale = brandingFilename.substring( lastUnderscore + 1, brandingFilename.lastIndexOf( '.')); |
265 |
} |
266 |
|
267 |
if(result.get( locale)==null) { |
268 |
Set<File> newFileLst = new HashSet<File>(); |
269 |
newFileLst.add( brandingFileIter ); |
270 |
result.put( locale, newFileLst); |
271 |
} else { |
272 |
result.get( locale).add( brandingFileIter ); |
273 |
} |
274 |
} else { |
275 |
if(result.get( null)==null) { |
276 |
Set<File> newFileLst = new HashSet<File>(); |
277 |
newFileLst.add( brandingFileIter ); |
278 |
result.put( null, newFileLst); |
279 |
} else { |
280 |
result.get( null).add( brandingFileIter ); |
281 |
} |
282 |
} |
283 |
} |
284 |
return result; |
285 |
} |
286 |
} |