# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/mkozeny/NetBeans_workspace/codehaus/nbm-maven/nbm-maven-plugin # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/main/java/org/codehaus/mojo/nbm/BrandingMojo.java --- src/main/java/org/codehaus/mojo/nbm/BrandingMojo.java Base (BASE) +++ src/main/java/org/codehaus/mojo/nbm/BrandingMojo.java Locally Modified (Based On LOCAL) @@ -17,11 +17,21 @@ package org.codehaus.mojo.nbm; import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.archiver.FileSet; import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; @@ -139,24 +149,34 @@ for ( String jarDirectoryPath : scanner.getIncludedDirectories() ) { - - // move nnn.jar directory to nnn.jar.tmp + DirectoryScanner ds = new DirectoryScanner(); + ds.setIncludes( new String[] + { + "**/*.*" + } ); + ds.setBasedir( new File(clusterDir, jarDirectoryPath) ); + ds.scan(); + String [] includedFiles = ds.getIncludedFiles(); + Map> brandingFilesGroupByLocale = groupBrandingFilesByLocale( includedFiles); File jarDirectory = new File( clusterDir, jarDirectoryPath ); - - // jars should be placed in locales/ under the same directory the jar-directories are + for(Map.Entry> entryIter: brandingFilesGroupByLocale.entrySet()) { + String locale = entryIter.getKey(); + Set brandingFiles = entryIter.getValue(); File destinationJar = new File( jarDirectory.getParentFile().getAbsolutePath() + File.separator + "locale" - + File.separator + destinationFileName( jarDirectory.getName(), brandingToken ) ); - - // create nnn.jar archive of contents + + File.separator + destinationJarName( jarDirectory.getName(), brandingToken + (locale!=null? ("_" + locale): "") ) ); JarArchiver archiver = new JarArchiver(); archiver.setDestFile( destinationJar ); - archiver.addDirectory( jarDirectory ); + for(File brandingFileIter:brandingFiles) { + archiver.addDirectory( jarDirectory, new String[] + { + "**/"+brandingFileIter.getName() + }, new String[]{}); + } archiver.createArchive(); - + } FileUtils.deleteDirectory( jarDirectory ); } - } catch ( Exception ex ) { @@ -168,14 +188,101 @@ static String destinationFileName( String brandingFilePath, String branding ) { // use first underscore in filename + String locale = ""; + String brandingFilename = ""; int lastSeparator = brandingFilePath.lastIndexOf( File.separator ); + if(lastSeparator != -1) { + brandingFilename = brandingFilePath.substring( lastSeparator + 1); + } else { + brandingFilename = brandingFilePath; + } + + //pass files to be localized + if(brandingFilename.matches("([a-zA-z][a-zA-Z0-9]*)+_[a-z]{2}(_[a-z]{2})?.[a-zA-Z][a-zA-Z0-9]+")) { + //last index of '_' exists according to pattern + locale = brandingFilename.substring( brandingFilename.lastIndexOf( '_') + 1, brandingFilename.lastIndexOf( '.')); + String subBrandingFileIterName = brandingFilename.substring( 0, brandingFilename.lastIndexOf('_') ); + + //not sure about existing of last index of '_' + int lastUnderscore = subBrandingFileIterName.lastIndexOf( '_' ); + if(lastUnderscore != -1) { + locale = brandingFilename.substring( subBrandingFileIterName.lastIndexOf('_') + 1, brandingFilename.lastIndexOf( '.')); + } + brandingFilePath = brandingFilePath.substring( 0, brandingFilePath.lastIndexOf( '.') - (locale.length() +1)) + + brandingFilePath.substring( brandingFilePath.lastIndexOf( '.')); + } + + String infix = "_" + branding + (!"".equals( locale )?("_" + locale) : ""); + + // no underscores, use dot + int lastDot = brandingFilePath.lastIndexOf( '.' ); + if (lastDot == -1 || lastDot < lastSeparator) { + return brandingFilePath + infix; + } + return brandingFilePath.substring( 0, lastDot ) + infix + brandingFilePath.substring( lastDot ); + } + + static String destinationJarName( String brandingFilePath, String branding ) + { + // use first underscore in filename + int lastSeparator = brandingFilePath.lastIndexOf( File.separator ); String infix = "_" + branding; // no underscores, use dot - int lastDot = brandingFilePath.lastIndexOf( "." ); + int lastDot = brandingFilePath.lastIndexOf( '.' ); if (lastDot == -1 || lastDot < lastSeparator) { return brandingFilePath + infix; } return brandingFilePath.substring( 0, lastDot ) + infix + brandingFilePath.substring( lastDot ); } + + static Map> groupBrandingFilesByLocale(String [] brandingFiles) { + + Map> result = new HashMap>(); + for(String brandingFileStrIter:brandingFiles) { + + File brandingFileIter = new File(brandingFileStrIter); + String locale = ""; + + //pass files to be localized + if(brandingFileIter.getName().matches("([a-zA-z][a-zA-Z0-9]*)+_[a-zA-z][a-zA-Z0-9]*_[a-z]{2}(_[a-z]{2})?.[a-zA-Z][a-zA-Z0-9]+")) { + + int lastSeparator = brandingFileStrIter.lastIndexOf( File.separator ); + String brandingFilename = ""; + if(lastSeparator != -1) { + brandingFilename = brandingFileStrIter.substring( lastSeparator + 1); + } else { + brandingFilename = brandingFileStrIter; } + + locale = brandingFilename.substring( brandingFilename.lastIndexOf('_') + 1, brandingFilename.lastIndexOf( '.')); + + //last index of '_' exists according to pattern + String subBrandingFileIterName = brandingFilename.substring( 0, brandingFilename.lastIndexOf('_') ); + + //not sure about existing of last index of '_' + int lastUnderscore = subBrandingFileIterName.lastIndexOf( "_" ); + if(lastUnderscore != -1) { + locale = brandingFilename.substring( lastUnderscore + 1, brandingFilename.lastIndexOf( '.')); + } + + if(result.get( locale)==null) { + Set newFileLst = new HashSet(); + newFileLst.add( brandingFileIter ); + result.put( locale, newFileLst); + } else { + result.get( locale).add( brandingFileIter ); + } + } else { + if(result.get( null)==null) { + Set newFileLst = new HashSet(); + newFileLst.add( brandingFileIter ); + result.put( null, newFileLst); + } else { + result.get( null).add( brandingFileIter ); + } + } + } + return result; + } +} Index: src/test/java/org/codehaus/mojo/nbm/BrandingMojoTest.java --- src/test/java/org/codehaus/mojo/nbm/BrandingMojoTest.java Base (BASE) +++ src/test/java/org/codehaus/mojo/nbm/BrandingMojoTest.java Locally Modified (Based On LOCAL) @@ -36,6 +36,7 @@ @Test public void testDestinationFileName() { + assertEquals( "Bundle_project_en_us.properties", BrandingMojo.destinationFileName( "Bundle_en_us.properties", "project")); assertEquals( "cut_brandingToken.gif", BrandingMojo.destinationFileName( "cut.gif", "brandingToken" ) ); assertEquals( "cut_brandingToken", BrandingMojo.destinationFileName( "cut", "brandingToken" ) ); assertEquals( "cut_pressed_brandingToken.gif", BrandingMojo.destinationFileName( "cut_pressed.gif", "brandingToken" ) );