diff --git a/css.editor/src/org/netbeans/modules/css/resources/layer.xml b/css.editor/src/org/netbeans/modules/css/resources/layer.xml --- a/css.editor/src/org/netbeans/modules/css/resources/layer.xml +++ b/css.editor/src/org/netbeans/modules/css/resources/layer.xml @@ -164,6 +164,10 @@ + + + + diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/LayerOptionsImport.java b/nbbuild/antsrc/org/netbeans/nbbuild/LayerOptionsImport.java --- a/nbbuild/antsrc/org/netbeans/nbbuild/LayerOptionsImport.java +++ b/nbbuild/antsrc/org/netbeans/nbbuild/LayerOptionsImport.java @@ -146,7 +146,7 @@ log(origin); } for (String name : name2value.keySet()) { - if (name.matches("(in|ex)clude")) { + if (name.matches("(in|ex)clude") || name.equals("translate")) { String value = name2value.get(name); if (value != null && value.length() > 0) { String line = String.format("%s %s", name, value); @@ -198,9 +198,14 @@ String n = attributes.getValue("name"); prefix += n; register(prefix); - } else if (qName.equals("attr") && attributes.getValue("name").matches("(in|ex)clude")) { + } else if (qName.equals("attr") && (attributes.getValue("name").matches("(in|ex)clude") + || attributes.getValue("name").equals("translate"))) { String attrName = attributes.getValue("name"); String attrValue = attributes.getValue("stringvalue"); + if(attrName.equals("translate")) { + prefix = "OptionsExport/".concat(cnb); + register(prefix); + } Map name2value = attributesMap.get(prefix); if (name2value == null) { name2value = new HashMap(); diff --git a/o.n.upgrader/arch.xml b/o.n.upgrader/arch.xml --- a/o.n.upgrader/arch.xml +++ b/o.n.upgrader/arch.xml @@ -1115,7 +1115,21 @@ -->

- XXX no answer for resources-read + + Use OptionsExport/ folder for registration of items for translation + of options. Registration in layers looks as follows +

+ <folder name="OptionsExport">
+     <attr name="translate" stringvalue="config/mymodule/foo=>config/mymodule/bar|config/mymodule/foo2=>config/mymodule/bar2"/>
+ </folder>
+ 
+ Translation patterns may contain one or more regular expression, seperated by |, defining + files relatively to userdir. +

diff --git a/o.n.upgrader/src/org/netbeans/upgrade/CopyFiles.java b/o.n.upgrader/src/org/netbeans/upgrade/CopyFiles.java --- a/o.n.upgrader/src/org/netbeans/upgrade/CopyFiles.java +++ b/o.n.upgrader/src/org/netbeans/upgrade/CopyFiles.java @@ -52,7 +52,9 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -67,18 +69,13 @@ * @author Jiri Skrivanek */ final class CopyFiles extends Object { - - //>>> hack for http://netbeans.org/bugzilla/show_bug.cgi?id=218976 - private static final String CSSSP = "config/Editors/text/"; - private static final String ORIG_CSSSP = CSSSP + "x-css"; - private static final String TARG_CSSSP = CSSSP + "css"; - //<< includePatterns = new HashSet(); private Set excludePatterns = new HashSet(); + private HashMap translatePatterns = new HashMap(); // private static final Logger LOGGER = Logger.getLogger(CopyFiles.class.getName()); private CopyFiles(File source, File target, File patternsFile) { @@ -193,9 +190,14 @@ return; } - //>>> hack for http://netbeans.org/bugzilla/show_bug.cgi?id=218976 - if(relativePath.startsWith(ORIG_CSSSP)) { relativePath = TARG_CSSSP + relativePath.substring(ORIG_CSSSP.length()); } - //<<< + for (Entry entry : translatePatterns.entrySet()) { + if (relativePath.startsWith(entry.getKey())) { + String value = entry.getValue(); + LOGGER.log(Level.INFO, "Translating old relative path: {0}", relativePath); //NOI18N + relativePath = value + relativePath.substring(entry.getKey().length()); + LOGGER.log(Level.INFO, " to new one: {0}", relativePath); //NOI18N + } + } File targetFile = new File(targetRoot, relativePath); LOGGER.log(Level.FINE, "Path: {0}", relativePath); //NOI18N @@ -299,6 +301,22 @@ if (line.length() > 0) { excludePatterns.addAll(parsePattern(line)); } + } else if (line.startsWith("translate ")) { //NOI18N + line = line.substring(10); + if (line.length() > 0) { + String[] translations = line.split("\\|"); + for (String translation : translations) { + String originalPath = translation.substring(0, translation.indexOf("=>")); + String newPath = translation.substring(translation.lastIndexOf("=>") + 2); + if (translatePatterns.containsKey(originalPath)) { + LOGGER.log(Level.INFO, "Translation already exists: {0}. Ignoring new translation: {1}", //NOI18N + new Object[]{originalPath.concat("=>").concat(translatePatterns.get(originalPath)), + originalPath.concat("=>").concat(newPath)}); + } else { + translatePatterns.put(originalPath, newPath); + } + } + } } else { throw new java.io.IOException("Wrong line: " + line); //NOI18N } diff --git a/o.n.upgrader/test/unit/src/org/netbeans/upgrade/CopyFilesTest.java b/o.n.upgrader/test/unit/src/org/netbeans/upgrade/CopyFilesTest.java new file mode 100644 --- /dev/null +++ b/o.n.upgrader/test/unit/src/org/netbeans/upgrade/CopyFilesTest.java @@ -0,0 +1,124 @@ +/* + * 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.upgrade; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import org.junit.Before; +import org.junit.Test; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.LocalFileSystem; + +public class CopyFilesTest extends org.netbeans.junit.NbTestCase { + + public CopyFilesTest(String name) { + super(name); + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + clearWorkDir(); + } + + @Test + public void testCopyDeep() throws Exception { + ArrayList fileList = new ArrayList(); + fileList.addAll(Arrays.asList(new java.lang.String[]{"source/foo/X.txt", + "source/foo/A.txt", "source/foo/B.txt", "source/foo/foo2/C.txt"})); + + FileSystem fs = createLocalFileSystem(fileList.toArray(new String[fileList.size()])); + + FileObject path = fs.findResource("source"); + assertNotNull(path); + FileObject tg = fs.getRoot().createFolder("target"); + assertNotNull(tg); + FileObject patterns = FileUtil.createData(fs.getRoot(), "source/foo/etc/patterns.import"); + assertNotNull(patterns); + String pattern = "# ignore comment\n" + + "include foo/.*\n" + + "translate foo=>bar\n"; + writeTo(fs, "source/foo/etc/patterns.import", pattern); + + org.netbeans.upgrade.CopyFiles.copyDeep(FileUtil.toFile(path), FileUtil.toFile(tg), FileUtil.toFile(patterns)); + + assertNotNull("file not copied: " + "foo/X.txt", tg.getFileObject("bar/X.txt")); + assertNotNull("file not copied: " + "foo/A.txt", tg.getFileObject("bar/A.txt")); + assertNotNull("file not copied: " + "foo/B.txt", tg.getFileObject("bar/B.txt")); + assertNotNull("file not copied: " + "foo/foo2/C.txt", tg.getFileObject("bar/foo2/C.txt")); + } + + private static void writeTo (FileSystem fs, String res, String content) throws java.io.IOException { + FileObject fo = org.openide.filesystems.FileUtil.createData (fs.getRoot (), res); + org.openide.filesystems.FileLock lock = fo.lock (); + java.io.OutputStream os = fo.getOutputStream (lock); + os.write (content.getBytes ()); + os.close (); + lock.releaseLock (); + } + + public LocalFileSystem createLocalFileSystem(String[] resources) throws IOException { + File mountPoint = new File(getWorkDir(), "tmpfs"); + mountPoint.mkdir(); + + for (int i = 0; i < resources.length; i++) { + File f = new File (mountPoint,resources[i]); + if (f.isDirectory() || resources[i].endsWith("/")) { + FileUtil.createFolder(f); + } else { + FileUtil.createData(f); + } + } + + LocalFileSystem lfs = new LocalFileSystem(); + try { + lfs.setRootDirectory(mountPoint); + } catch (Exception ex) {} + + return lfs; + } +}