Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 224370 | Differences between
and this patch

Collapse All | Expand All

(-)a/css.editor/src/org/netbeans/modules/css/resources/layer.xml (+4 lines)
 Lines 164-169    Link Here 
164
            </folder>
164
            </folder>
165
        </folder>
165
        </folder>
166
    </folder>
166
    </folder>
167
168
    <folder name="OptionsExport">
169
	<attr name="translate" stringvalue="config/Editors/text/x-css=>config/Editors/text/css"/>
170
    </folder>
167
    
171
    
168
    <folder name="Templates">
172
    <folder name="Templates">
169
        <folder name="Other">
173
        <folder name="Other">
(-)a/nbbuild/antsrc/org/netbeans/nbbuild/LayerOptionsImport.java (-2 / +7 lines)
 Lines 146-152    Link Here 
146
                        log(origin);
146
                        log(origin);
147
                    }
147
                    }
148
                    for (String name : name2value.keySet()) {
148
                    for (String name : name2value.keySet()) {
149
                        if (name.matches("(in|ex)clude")) {
149
                        if (name.matches("(in|ex)clude") || name.equals("translate")) {
150
                            String value = name2value.get(name);
150
                            String value = name2value.get(name);
151
                            if (value != null && value.length() > 0) {
151
                            if (value != null && value.length() > 0) {
152
                                String line = String.format("%s %s", name, value);
152
                                String line = String.format("%s %s", name, value);
 Lines 198-206    Link Here 
198
                    String n = attributes.getValue("name");
198
                    String n = attributes.getValue("name");
199
                    prefix += n;
199
                    prefix += n;
200
                    register(prefix);
200
                    register(prefix);
201
                } else if (qName.equals("attr") && attributes.getValue("name").matches("(in|ex)clude")) {
201
                } else if (qName.equals("attr") && (attributes.getValue("name").matches("(in|ex)clude")
202
			|| attributes.getValue("name").equals("translate"))) {
202
                    String attrName = attributes.getValue("name");
203
                    String attrName = attributes.getValue("name");
203
                    String attrValue = attributes.getValue("stringvalue");
204
                    String attrValue = attributes.getValue("stringvalue");
205
		    if(attrName.equals("translate")) {
206
			prefix = "OptionsExport/".concat(cnb);
207
			register(prefix);
208
		    }
204
                    Map<String, String> name2value = attributesMap.get(prefix);
209
                    Map<String, String> name2value = attributesMap.get(prefix);
205
                    if (name2value == null) {
210
                    if (name2value == null) {
206
                        name2value = new HashMap<String, String>();
211
                        name2value = new HashMap<String, String>();
(-)a/o.n.upgrader/arch.xml (-1 / +15 lines)
 Lines 1115-1121    Link Here 
1115
-->
1115
-->
1116
 <answer id="resources-read">
1116
 <answer id="resources-read">
1117
  <p>
1117
  <p>
1118
   XXX no answer for resources-read
1118
   <api name="OptionsExportLayers"
1119
        group="layer"
1120
        type="export"
1121
        category="devel"
1122
        url="">
1123
        Use OptionsExport/ folder for registration of items for translation
1124
        of options. Registration in layers looks as follows
1125
 <pre style="background-color: rgb(255, 255, 153);">
1126
 &lt;folder name="OptionsExport"&gt;
1127
     &lt;attr name="translate" stringvalue="config/mymodule/foo=>config/mymodule/bar|config/mymodule/foo2=>config/mymodule/bar2"/&gt;
1128
 &lt;/folder&gt;
1129
 </pre>
1130
        Translation patterns may contain one or more regular expression, seperated by <code>|</code>, defining
1131
        files relatively to userdir.
1132
   </api>
1119
  </p>
1133
  </p>
1120
 </answer>
1134
 </answer>
1121
1135
(-)a/o.n.upgrader/src/org/netbeans/upgrade/CopyFiles.java (-9 / +27 lines)
 Lines 52-58    Link Here 
52
import java.io.InputStreamReader;
52
import java.io.InputStreamReader;
53
import java.io.OutputStream;
53
import java.io.OutputStream;
54
import java.io.Reader;
54
import java.io.Reader;
55
import java.util.HashMap;
55
import java.util.HashSet;
56
import java.util.HashSet;
57
import java.util.Map.Entry;
56
import java.util.Set;
58
import java.util.Set;
57
import java.util.logging.Level;
59
import java.util.logging.Level;
58
import java.util.logging.Logger;
60
import java.util.logging.Logger;
 Lines 67-84    Link Here 
67
 * @author Jiri Skrivanek
69
 * @author Jiri Skrivanek
68
 */
70
 */
69
final class CopyFiles extends Object {
71
final class CopyFiles extends Object {
70
    
71
    //>>> hack for http://netbeans.org/bugzilla/show_bug.cgi?id=218976
72
    private static final String CSSSP = "config/Editors/text/";
73
    private static final String ORIG_CSSSP = CSSSP + "x-css";
74
    private static final String TARG_CSSSP = CSSSP + "css";
75
    //<<<eof
76
72
77
    private File sourceRoot;
73
    private File sourceRoot;
78
    private File targetRoot;
74
    private File targetRoot;
79
    private EditableProperties currentProperties;
75
    private EditableProperties currentProperties;
80
    private Set<String> includePatterns = new HashSet<String>();
76
    private Set<String> includePatterns = new HashSet<String>();
81
    private Set<String> excludePatterns = new HashSet<String>();
77
    private Set<String> excludePatterns = new HashSet<String>();
78
    private HashMap<String, String> translatePatterns = new HashMap<String, String>(); // <originalPath, newPath>
82
    private static final Logger LOGGER = Logger.getLogger(CopyFiles.class.getName());
79
    private static final Logger LOGGER = Logger.getLogger(CopyFiles.class.getName());
83
80
84
    private CopyFiles(File source, File target, File patternsFile) {
81
    private CopyFiles(File source, File target, File patternsFile) {
 Lines 193-201    Link Here 
193
            return;
190
            return;
194
        }
191
        }
195
        
192
        
196
        //>>> hack for http://netbeans.org/bugzilla/show_bug.cgi?id=218976
193
	for (Entry<String, String> entry : translatePatterns.entrySet()) {
197
        if(relativePath.startsWith(ORIG_CSSSP)) { relativePath = TARG_CSSSP + relativePath.substring(ORIG_CSSSP.length()); } 
194
	    if (relativePath.startsWith(entry.getKey())) {
198
        //<<<
195
		String value = entry.getValue();
196
		LOGGER.log(Level.INFO, "Translating old relative path: {0}", relativePath);  //NOI18N
197
		relativePath = value + relativePath.substring(entry.getKey().length());
198
		LOGGER.log(Level.INFO, "                   to new one: {0}", relativePath);  //NOI18N
199
	    }
200
	}
199
201
200
        File targetFile = new File(targetRoot, relativePath);
202
        File targetFile = new File(targetRoot, relativePath);
201
        LOGGER.log(Level.FINE, "Path: {0}", relativePath);  //NOI18N
203
        LOGGER.log(Level.FINE, "Path: {0}", relativePath);  //NOI18N
 Lines 299-304    Link Here 
299
                if (line.length() > 0) {
301
                if (line.length() > 0) {
300
                    excludePatterns.addAll(parsePattern(line));
302
                    excludePatterns.addAll(parsePattern(line));
301
                }
303
                }
304
            } else if (line.startsWith("translate ")) {  //NOI18N
305
                line = line.substring(10);
306
                if (line.length() > 0) {
307
		    String[] translations = line.split("\\|");
308
		    for (String translation : translations) {
309
			String originalPath = translation.substring(0, translation.indexOf("=>"));
310
			String newPath = translation.substring(translation.lastIndexOf("=>") + 2);
311
			if (translatePatterns.containsKey(originalPath)) {
312
			    LOGGER.log(Level.INFO, "Translation already exists: {0}. Ignoring new translation: {1}",  //NOI18N
313
				    new Object[]{originalPath.concat("=>").concat(translatePatterns.get(originalPath)),
314
					originalPath.concat("=>").concat(newPath)});
315
			} else {
316
			    translatePatterns.put(originalPath, newPath);
317
			}
318
		    }
319
                }
302
            } else {
320
            } else {
303
                throw new java.io.IOException("Wrong line: " + line);  //NOI18N
321
                throw new java.io.IOException("Wrong line: " + line);  //NOI18N
304
            }
322
            }
(-)a/o.n.upgrader/test/unit/src/org/netbeans/upgrade/CopyFilesTest.java (+124 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.upgrade;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import org.junit.Before;
49
import org.junit.Test;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileSystem;
52
import org.openide.filesystems.FileUtil;
53
import org.openide.filesystems.LocalFileSystem;
54
55
public class CopyFilesTest extends org.netbeans.junit.NbTestCase {
56
57
    public CopyFilesTest(String name) {
58
	super(name);
59
    }
60
61
    @Before
62
    @Override
63
    public void setUp() throws Exception {
64
	super.setUp();
65
        clearWorkDir();
66
    }
67
68
    @Test
69
    public void testCopyDeep() throws Exception {
70
	ArrayList<String> fileList = new ArrayList<String>();
71
	fileList.addAll(Arrays.asList(new java.lang.String[]{"source/foo/X.txt",
72
		    "source/foo/A.txt", "source/foo/B.txt", "source/foo/foo2/C.txt"}));
73
74
	FileSystem fs = createLocalFileSystem(fileList.toArray(new String[fileList.size()]));
75
76
	FileObject path = fs.findResource("source");
77
	assertNotNull(path);
78
	FileObject tg = fs.getRoot().createFolder("target");
79
	assertNotNull(tg);
80
	FileObject patterns = FileUtil.createData(fs.getRoot(), "source/foo/etc/patterns.import");
81
	assertNotNull(patterns);
82
	String pattern = "# ignore comment\n"
83
		+ "include foo/.*\n"
84
		+ "translate foo=>bar\n";
85
	writeTo(fs, "source/foo/etc/patterns.import", pattern);
86
87
	org.netbeans.upgrade.CopyFiles.copyDeep(FileUtil.toFile(path), FileUtil.toFile(tg), FileUtil.toFile(patterns));
88
89
	assertNotNull("file not copied: " + "foo/X.txt", tg.getFileObject("bar/X.txt"));
90
	assertNotNull("file not copied: " + "foo/A.txt", tg.getFileObject("bar/A.txt"));
91
	assertNotNull("file not copied: " + "foo/B.txt", tg.getFileObject("bar/B.txt"));
92
	assertNotNull("file not copied: " + "foo/foo2/C.txt", tg.getFileObject("bar/foo2/C.txt"));
93
    }
94
95
    private static void writeTo (FileSystem fs, String res, String content) throws java.io.IOException {
96
        FileObject fo = org.openide.filesystems.FileUtil.createData (fs.getRoot (), res);
97
        org.openide.filesystems.FileLock lock = fo.lock ();
98
        java.io.OutputStream os = fo.getOutputStream (lock);
99
        os.write (content.getBytes ());
100
        os.close ();
101
        lock.releaseLock ();
102
    }
103
104
    public LocalFileSystem createLocalFileSystem(String[] resources) throws IOException {
105
        File mountPoint = new File(getWorkDir(), "tmpfs");
106
        mountPoint.mkdir();
107
108
        for (int i = 0; i < resources.length; i++) {
109
            File f = new File (mountPoint,resources[i]);
110
            if (f.isDirectory() || resources[i].endsWith("/")) {
111
              FileUtil.createFolder(f);
112
            } else {
113
              FileUtil.createData(f);
114
            }
115
        }
116
117
        LocalFileSystem lfs = new LocalFileSystem();
118
        try {
119
            lfs.setRootDirectory(mountPoint);
120
        } catch (Exception ex) {}
121
122
        return lfs;
123
    }
124
}

Return to bug 224370
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo