# 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: apisupport.ant/src/org/netbeans/modules/apisupport/project/ApisupportAntUtils.java --- apisupport.ant/src/org/netbeans/modules/apisupport/project/ApisupportAntUtils.java No Base Revision +++ apisupport.ant/src/org/netbeans/modules/apisupport/project/ApisupportAntUtils.java Locally New Index: apisupport.ant/src/org/netbeans/modules/apisupport/project/NbRefactoringProviderImpl.java --- apisupport.ant/src/org/netbeans/modules/apisupport/project/NbRefactoringProviderImpl.java No Base Revision +++ apisupport.ant/src/org/netbeans/modules/apisupport/project/NbRefactoringProviderImpl.java Locally New @@ -0,0 +1,230 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.apisupport.project; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.api.project.Sources; +import org.netbeans.modules.apisupport.project.api.EditableManifest; +import org.netbeans.modules.apisupport.project.api.ManifestManager; +import org.netbeans.modules.apisupport.project.api.Util; +import org.netbeans.modules.apisupport.project.spi.NbRefactoringContext; +import org.netbeans.modules.apisupport.project.spi.NbRefactoringProvider; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.xml.XMLUtil; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +/** + * + * @author mkozeny + */ +public class NbRefactoringProviderImpl implements NbRefactoringProvider { + + private final Project project; + + NbRefactoringProviderImpl(Project project) { + this.project = project; + } + + @Override + public Map getManifestRefactoringElements(NbRefactoringContext context) { + Sources srcs = org.netbeans.api.project.ProjectUtils.getSources(project); + SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); + for (SourceGroup gr : grps) { + if (!FileUtil.isParentOf(gr.getRootFolder(), context.getFileToRefactored())) { + return null; + } + } + Map result = null; + if (context.getOldPackagePath() != null && context.getNewPackagePath() != null) { + result = new HashMap(); + try { + NbModuleProject nbmProject = project.getLookup().lookup(NbModuleProject.class); + FileObject manifest; + if (nbmProject != null && (manifest = nbmProject.getManifestFile()) != null) { + EditableManifest em = Util.loadManifest(manifest); + String oldCodeNameBase = em.getAttribute(ManifestManager.OPENIDE_MODULE, null); + if (oldCodeNameBase != null && oldCodeNameBase.equals(context.getOldPackagePath())) { + result.put(ManifestManager.OPENIDE_MODULE, context.getNewPackagePath()); + } + String oldBundlePath = em.getAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, null); + if (oldBundlePath != null && oldBundlePath.equals(context.getOldPackagePath() + "/Bundle.properties")) { + result.put(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, context.getNewPackagePath() + + "/Bundle.properties"); + } + String oldLayerPath = em.getAttribute(ManifestManager.OPENIDE_MODULE_LAYER, null); + if (oldLayerPath != null && oldLayerPath.equals(context.getOldPackagePath() + "/layer.xml")) { + result.put(ManifestManager.OPENIDE_MODULE_LAYER, context.getNewPackagePath() + + "/layer.xml"); + } + } + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return result; + } + + @Override + public List getProjectXmlFilesRefactoring(NbRefactoringContext context) { + Sources srcs = org.netbeans.api.project.ProjectUtils.getSources(project); + SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); + for (SourceGroup gr : grps) { + if (!FileUtil.isParentOf(gr.getRootFolder(), context.getFileToRefactored())) { + return null; + } + } + List result = new ArrayList(); + NbModuleProject nbmProject = project.getLookup().lookup(NbModuleProject.class); + if (nbmProject != null) { + FileObject buildFileObj = FileUtil.toFileObject(nbmProject.getHelper().resolveFile("build.xml")); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + File buildFile = FileUtil.toFile(buildFileObj); + synchronized (buildFile) { + try { + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document buildScript = dBuilder.parse(buildFile); + if (buildScript.getDocumentElement().getAttribute("name").equals(context.getOldPackagePath())) { + Map> resultElements = new HashMap>(1); + HashMap elements = new HashMap(1); + elements.put("name", context.getNewPackagePath()); + resultElements.put("project", elements); + result.add(new ProjectFileRefactoring(buildFileObj, resultElements)); + } + } catch (ParserConfigurationException ex) { + Exceptions.printStackTrace(ex); + } catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + FileObject projectFileObj = FileUtil.toFileObject(new File(nbmProject.getProjectDirectoryFile(), "nbproject/project.xml")); + File projectFile = FileUtil.toFile(projectFileObj); + synchronized (projectFile) { + try { + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document projectXmlFile = dBuilder.parse(projectFile); + Node elementNode = projectXmlFile.getElementsByTagName("code-name-base").item(0); + if (elementNode.getTextContent().equals(context.getOldPackagePath())) { + Map> resultElements = new HashMap>(1); + HashMap elements = new HashMap(1); + elements.put(null, context.getNewPackagePath()); + resultElements.put("code-name-base", elements); + result.add(new ProjectFileRefactoring(projectFileObj, resultElements)); + } + } catch (ParserConfigurationException ex) { + Exceptions.printStackTrace(ex); + } catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + return result; + } + + @Override + public void doProjectXmlFilesRefactoring(final FileObject projectFileObj, final String element, final String attrName, final String value) { + try { + projectFileObj.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { + @Override + public void run() throws IOException { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + File projectFile = FileUtil.toFile(projectFileObj); + synchronized (projectFile) { + try { + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document buildScript = dBuilder.parse(projectFile); + Node elementNode = buildScript.getElementsByTagName(element).item(0); + if (attrName != null) { + NamedNodeMap attr = elementNode.getAttributes(); + Node nodeAttr = attr.getNamedItem(attrName); + nodeAttr.setTextContent(value); + buildScript.getDocumentElement().setAttribute(attrName, value); + } else { + elementNode.setTextContent(value); + } + OutputStream os = projectFileObj.getOutputStream(); + try { + XMLUtil.write(buildScript, os, "UTF-8"); // NOI18N + } finally { + os.close(); + } + } catch (ParserConfigurationException ex) { + Exceptions.printStackTrace(ex); + } catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } + } + } + }); + } catch (FileStateInvalidException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + +} Index: apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringContext.java --- apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringContext.java No Base Revision +++ apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringContext.java Locally New @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.apisupport.project.spi; + +import org.openide.filesystems.FileObject; + +/** + * + * @author mkozeny + */ +public final class NbRefactoringContext { + + private FileObject fileToRefactored; + + private String oldPackagePath; + + private String newPackagePath; + + public NbRefactoringContext(FileObject fileToRefactored, String newPackagePath, String oldPackagePath) { + this.fileToRefactored = fileToRefactored; + this.newPackagePath = newPackagePath; + this.oldPackagePath = oldPackagePath; + } + + public FileObject getFileToRefactored() { + return fileToRefactored; + } + + public String getOldPackagePath() { + return oldPackagePath; + } + + public String getNewPackagePath() { + return newPackagePath; + } + + +} Index: apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringProvider.java --- apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringProvider.java No Base Revision +++ apisupport.project/src/org/netbeans/modules/apisupport/project/spi/NbRefactoringProvider.java Locally New @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.apisupport.project.spi; + +import java.util.List; +import java.util.Map; +import org.openide.filesystems.FileObject; + +/** + * Interface to be implemented by NetBeans module projects. + * + * @author Martin Kozeny + * @since org.netbeans.modules.apisupport.project 1.65 + */ +public interface NbRefactoringProvider { + + /** + * Refactors project's manifest file according to passed context + * @param context refactoring context + * @return + */ + Map getManifestRefactoringElements(final NbRefactoringContext context); + + /** + * Returns list of xml files and its elements to refactor + * @param context refactoring context + * @return + */ + List getProjectXmlFilesRefactoring(final NbRefactoringContext context); + + /** + * Refactors project's xml file according to passed element, attribute and value + * @param projectFile + * @param element + * @param attrName + * @param value + */ + void doProjectXmlFilesRefactoring(final FileObject projectFile, final String element, final String attrName, final String value); + + public final class ProjectFileRefactoring { + + private FileObject refactoredFile; + + private Map> refactoredElements; + + public ProjectFileRefactoring(FileObject refactoredFile, Map> refactoredElements) { + this.refactoredFile = refactoredFile; + this.refactoredElements = refactoredElements; + } + + public FileObject getRefactoredFile() { + return refactoredFile; + } + + public Map> getRefactoredElements() { + return refactoredElements; + } + + } +} Index: maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenRefactoringProviderImpl.java --- maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenRefactoringProviderImpl.java No Base Revision +++ maven.apisupport/src/org/netbeans/modules/maven/apisupport/MavenRefactoringProviderImpl.java Locally New @@ -0,0 +1,121 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.maven.apisupport; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.api.project.Sources; +import org.netbeans.modules.apisupport.project.api.EditableManifest; +import org.netbeans.modules.apisupport.project.api.ManifestManager; +import org.netbeans.modules.apisupport.project.api.Util; +import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; +import org.netbeans.modules.apisupport.project.spi.NbRefactoringContext; +import org.netbeans.modules.apisupport.project.spi.NbRefactoringProvider; +import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.spi.project.ProjectServiceProvider; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; + +/** + * + * @author mkozeny + */ +@ProjectServiceProvider(service = NbRefactoringProvider.class, projectType = "org-netbeans-modules-maven/" + NbMavenProject.TYPE_NBM) +public class MavenRefactoringProviderImpl implements NbRefactoringProvider { + + private Project project; + + public MavenRefactoringProviderImpl(Project project) { + this.project = project; + } + + @Override + public Map getManifestRefactoringElements(final NbRefactoringContext context) { + Sources srcs = org.netbeans.api.project.ProjectUtils.getSources(project); + SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES); + for (SourceGroup gr : grps) { + if (!FileUtil.isParentOf(gr.getRootFolder(), context.getFileToRefactored())) { + return null; + } + } + Map result = null; + if (context.getOldPackagePath() != null && context.getNewPackagePath() != null) { + result = new HashMap(); + try { + NbModuleProvider provider = project.getLookup().lookup(NbModuleProvider.class); + FileObject manifest = provider.getManifestFile(); + if (manifest != null) { + EditableManifest em = Util.loadManifest(manifest); + String oldBundlePath = em.getAttribute(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, null); + if (oldBundlePath != null && oldBundlePath.equals(context.getOldPackagePath() + "/Bundle.properties")) { + result.put(ManifestManager.OPENIDE_MODULE_LOCALIZING_BUNDLE, context.getNewPackagePath() + + "/Bundle.properties"); + } + String oldLayerPath = em.getAttribute(ManifestManager.OPENIDE_MODULE_LAYER, null); + if (oldLayerPath != null && oldLayerPath.equals(context.getOldPackagePath() + "/layer.xml")) { + result.put(ManifestManager.OPENIDE_MODULE_LAYER, context.getNewPackagePath() + + "/layer.xml"); + } + } + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + return result; + } + + @Override + public List getProjectXmlFilesRefactoring(NbRefactoringContext context) { + return null; + } + + @Override + public void doProjectXmlFilesRefactoring(FileObject projectFile, String element, String attrName, String attrValue) { + } + +} 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,97 @@ 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('_') ); + + if(subBrandingFileIterName.matches( "([a-zA-z][a-zA-Z0-9]*)+_[a-z]{2}")) { + 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('_') ); + + if(subBrandingFileIterName.matches( "([a-zA-z][a-zA-Z0-9]*)+_[a-zA-z][a-zA-Z0-9]*_[a-z]{2}")) { + locale = brandingFilename.substring( subBrandingFileIterName.lastIndexOf( "_" ) + 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" ) );