This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 201433
Collapse All | Expand All

(-)56f61f356ea2 (+252 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
package org.netbeans.nbbuild;
42
43
import java.io.File;
44
import java.util.ArrayList;
45
import java.util.Collection;
46
import java.util.List;
47
import java.util.Locale;
48
import java.util.StringTokenizer;
49
import org.apache.tools.ant.BuildException;
50
import org.apache.tools.ant.DirectoryScanner;
51
import org.apache.tools.ant.Project;
52
import org.apache.tools.ant.Task;
53
import org.apache.tools.ant.taskdefs.Jar;
54
import org.apache.tools.ant.taskdefs.Mkdir;
55
import org.apache.tools.ant.types.PatternSet;
56
57
public final class LocFiles extends Task {
58
    private String patternset;
59
    public void setPatternSet(String s) {
60
        patternset = s;
61
    }
62
    
63
    private String cluster;
64
    public void setCluster(String cluster) {
65
        this.cluster = cluster;
66
    }
67
    
68
    private String locales;
69
    public void setLocales(String locales) {
70
        this.locales = locales;
71
    }
72
    
73
    private File srcDir;
74
75
    public void setSrc(File f) {
76
        srcDir = f;
77
    }
78
    File distDir = null;
79
80
    public void setDestDir(File d) {
81
        distDir = d;
82
    }
83
    String cnbDashes;
84
85
    public void setCodeNameBase(String d) {
86
        cnbDashes = d;
87
    }
88
    File nbmsLocation = null;
89
90
    public void setNBMs(File f) {
91
        nbmsLocation = f;
92
    }
93
94
    @Override
95
    public void execute() throws BuildException {
96
        if (locales == null || locales.isEmpty()) {
97
            locales = Locale.getDefault().toString();
98
        }
99
        
100
        List<String> includes = new ArrayList<String>();
101
        StringTokenizer tok = new StringTokenizer(locales, ",");
102
        while (tok.hasMoreElements()) {
103
            String l = tok.nextToken();
104
            do { 
105
                processLocale(l, includes);
106
                l = trailingUnderscore(l);
107
            } while (l != null);
108
        }
109
        
110
        if (patternset != null) {
111
            PatternSet ps = new PatternSet();
112
            ps.setProject(getProject());
113
            for (String s : includes) {
114
                ps.createInclude().setName(s);
115
            }
116
            getProject().addReference(patternset, ps);
117
        }
118
        
119
    }
120
    
121
    private static String trailingUnderscore(String s) {
122
        int under = s.lastIndexOf('_');
123
        if (under == -1) {
124
            return null;
125
        }
126
        return s.substring(0, under);
127
    }
128
    
129
    private static String findModuleDir(String cnbDashes) {
130
        String pref = "org-netbeans-modules-";
131
        if (cnbDashes.startsWith(pref)) {
132
            return cnbDashes.substring(pref.length());
133
        }
134
        return cnbDashes;
135
    }
136
    
137
    private void processLocale(String locale, Collection<? super String> toAdd) {
138
        File baseSrcDir = new File(srcDir, locale);
139
        if (!baseSrcDir.exists()) {
140
            log("No files for locale: " + locale);
141
            return;
142
        }
143
        log("Found L10N dir " + baseSrcDir, Project.MSG_VERBOSE);
144
        
145
        final String moduleDir = findModuleDir(cnbDashes);
146
        File locBaseDir = new File(new File(baseSrcDir, cluster), moduleDir);
147
        if (!locBaseDir.exists()) {
148
            log("Can't find directory " + locBaseDir, Project.MSG_WARN);
149
            return;
150
        }
151
152
        File[] ch = locBaseDir.listFiles();
153
        if (ch == null || ch.length != 1) {
154
            throw new BuildException("Surprising content of " + locBaseDir);
155
        }
156
        
157
        if (ch[0].getName().equals(moduleDir)) {
158
            //locBaseDir = ch[0];
159
        } else {
160
            assert ch[0].getName().equals("netbeans");
161
        }
162
        
163
        DirectoryScanner ds = new DirectoryScanner();
164
        ds.setIncludes(new String[] {
165
            moduleDir,
166
            "netbeans/*/*"
167
        });
168
        ds.setBasedir(locBaseDir);
169
        ds.scan();
170
        for (String dir : ds.getIncludedDirectories()) {
171
            Jar jar = (Jar) getProject().createTask("jar");
172
            Mkdir mkdir = (Mkdir) getProject().createTask("mkdir");
173
            Task locJH = getProject().createTask("locjhindexer");
174
            
175
            String jarFileName;
176
            String subPath = "";
177
            File jarDir;
178
            String prefixDir;
179
            if (dir.equals(moduleDir)) {
180
                jarDir = new File(new File(new File(distDir, cluster), "modules"), "locale");
181
                prefixDir = "modules/locale";
182
                jar.setBasedir(new File(locBaseDir, dir));
183
                jarFileName = cnbDashes + "_" + locale + ".jar";
184
            } else {
185
                // netbeans/*/* case
186
                jar.setBasedir(new File(locBaseDir, dir));
187
                String[] arr = dir.split("/");
188
                assert arr.length == 3 : "Expected three segments: " + dir;
189
                jarFileName = arr[2] + "_" + locale + ".jar";
190
                jarDir = new File(new File(new File(distDir, cluster), arr[1]), "locale");
191
                prefixDir = arr[1] + '/' + "locale";
192
            }
193
            
194
            /*
195
            String subPath = dir.substring((cluster + File.separator + nbm + File.separator).length() - 1, dir.lastIndexOf(File.separator));
196
            if (!subPath.startsWith(File.separator + "netbeans")) {
197
                subPath = File.separator + "modules" + subPath;
198
                if (!name.startsWith("org-") && !(subPath.endsWith(File.separator + "ext") || subPath.endsWith(File.separator + "ext" + File.separator + "locale"))) {
199
                    name = "org-netbeans-modules-" + name;
200
                } else {
201
                    // Handle exception from ext/
202
                    if (name.startsWith("web-httpmonitor") || name.startsWith("deployment-deviceanywhere")) {
203
                        name = "org-netbeans-modules-" + name;
204
                    }
205
                }
206
            } else {
207
                subPath = subPath.substring((File.separator + "netbeans").length());
208
                //Handle exceptions form nblib
209
                if (name.startsWith("j2ee-ant") || name.startsWith("deployment-deviceanywhere") || name.startsWith("mobility-project") || name.startsWith("java-j2seproject-copylibstask")) {
210
                    name = "org-netbeans-modules-" + name;
211
                }
212
            }
213
            nbm = nbm.replaceAll("^vw-rh", "visualweb-ravehelp-rave_nbpack");
214
            nbm = nbm.replaceAll("^vw-", "visualweb-");
215
            if (!nbm.startsWith("org-") && !nbm.startsWith("com-")) {
216
                nbm = "org-netbeans-modules-" + nbm;
217
            }
218
            */
219
            
220
            if (subPath.matches(".*/docs$")) {
221
                ds.setBasedir(new File(baseSrcDir, dir));
222
                ds.setIncludes(new String[]{"**/*.hs"});
223
                ds.setExcludes(new String[]{""});
224
                ds.scan();
225
                if (ds.getIncludedFilesCount() != 1) {
226
                    throw new BuildException("Can't find .hs file for " + cnbDashes + " module.");
227
                }
228
                File hsFile = new File(new File(baseSrcDir, dir), ds.getIncludedFiles()[0]);
229
                File baseJHDir = hsFile.getParentFile();
230
231
                try {
232
                    System.out.println("Basedir: " + baseJHDir.getAbsolutePath());
233
                    locJH.getClass().getMethod("setBasedir", File.class).invoke(locJH, baseJHDir);
234
                    locJH.getClass().getMethod("setLocales", String.class).invoke(locJH, locale);
235
                    locJH.getClass().getMethod("setDbdir", String.class).invoke(locJH, "JavaHelpSearch");
236
              //      ((Path)locJH.getClass().getMethod("createClasspath").invoke(locJH)).add(classpath);
237
238
                } catch (Exception ex) {
239
                    throw new BuildException("Can't run locJHInxeder", ex);
240
                }
241
                locJH.execute();
242
            }
243
            mkdir.setDir(jarDir);
244
            mkdir.execute();
245
            jar.setDestFile(new File(jarDir, jarFileName));
246
            jar.execute();
247
            
248
            String fullName = prefixDir + '/' + jarFileName;
249
            toAdd.add(fullName);
250
        }
251
    }
252
}
(-)a/nbbuild/default.xml (+3 lines)
Lines 80-85 Link Here
80
    <taskdef name="locjhindexer"
80
    <taskdef name="locjhindexer"
81
         classname="org.netbeans.nbbuild.LocJHIndexer"
81
         classname="org.netbeans.nbbuild.LocJHIndexer"
82
         classpath="${nbantext.jar}"/>
82
         classpath="${nbantext.jar}"/>
83
    <taskdef name="locfiles"
84
         classname="org.netbeans.nbbuild.LocFiles"
85
         classpath="${nbantext.jar}"/>
83
    <taskdef name="locmakenbm"
86
    <taskdef name="locmakenbm"
84
         classname="org.netbeans.nbbuild.LocMakeNBM"
87
         classname="org.netbeans.nbbuild.LocMakeNBM"
85
         classpath="${nbantext.jar}"/>
88
         classpath="${nbantext.jar}"/>
(-)a/nbbuild/templates/projectized.xml (-80 / +17 lines)
Lines 435-526 Link Here
435
        </jar>
435
        </jar>
436
    </target>
436
    </target>
437
437
438
    <target name="netbeans-ml" depends="check-run-mlbuild,jar-ml,netbeans-extra-ml,javahelp-ml,files-init">
438
    <target name="jar-ml" depends="jar">
439
        <property name="locales" value=""/>
440
        <locfiles 
441
            cluster="${cluster.dir}" locales="${locales}" src="${nb_all}/l10n/src"
442
            codenamebase="${code.name.base.dashes}" destdir="${netbeans.dest.dir}"
443
            patternset="module.l10n.files"
444
        />
445
    </target>
446
447
    <target name="netbeans" depends="init,jar,jar-ml,netbeans-extra,javahelp,module-auto-deps,release,module-xml-regular,
448
            module-xml-autoload,module-xml-eager,chmod-executables,verify-class-linkage,
449
            -validate-layers,-verify-apichanges">            
439
        <property name="module.files.toString" refid="module.files"/>
450
        <property name="module.files.toString" refid="module.files"/>
440
        <echo level="verbose">Basic matching module files: ${module.files.toString}</echo>
451
        <property name="module.l10n.files.toString" refid="module.l10n.files"/>
441
        <genlist outputfiledir="${cluster}" module="${module.jar}" locales="${locales}" brandings="${brandings}">
452
        <echo level="verbose">Basic matching module files: ${module.files.toString} and ${module.l10n.files.toString}"</echo>
453
        <genlist outputfiledir="${cluster}" module="${module.jar}">
442
            <fileset dir="${cluster}">
454
            <fileset dir="${cluster}">
443
                <patternset refid="module.files"/>
455
                <patternset refid="module.files"/>
456
                <patternset refid="module.l10n.files"/>
444
            </fileset>
457
            </fileset>
445
        </genlist>
458
        </genlist>
446
    </target>
459
    </target>
447
    
460
448
    <target name="netbeans-extra-ml"/>
449
    
450
    <target name="check-run-mlbuild" depends="build-init">
451
        <!-- try to determine if src.dir property has been set
452
             in project.properties or build-init target -->
453
        <property name="default.src.dir" location="${nb_all}/${module.name}/src"/>
454
        <condition property="used.default.src.dir" value="true">
455
            <equals arg1="${src.dir}" arg2="${default.src.dir}"/>
456
        </condition>
457
        <property name="nb_all.native" location="${nb_all}"/>
458
        <property name="nb_all.tfsrc.native" location="${nb_all}/translatedfiles/src"/>
459
        <!-- convert custom src.dir path to path in translatedfiles module -->
460
        <path id="src.dir">
461
            <pathelement location="${src.dir}"/>
462
        </path>
463
        <pathconvert property="custom.src.dir" refid="src.dir">
464
            <map from="${nb_all.native}" to="${nb_all.tfsrc.native}"/>
465
        </pathconvert>
466
        <condition property="translated.src.candir" value="${custom.src.dir}">
467
            <not>
468
                <isset property="used.default.src.dir"/>
469
            </not>
470
        </condition>
471
        <condition property="translated.src.candir" value="${nb_all}/translatedfiles/src/${module.name}/src">
472
            <isset property="used.default.src.dir"/>
473
        </condition>
474
        <property name="translated.src.dir" location="${translated.src.candir}"/>
475
        <available file="${translated.src.dir}" type="dir" property="translated.src.dir.exist"/>
476
        <condition property="run.ml.build" value="true">
477
            <and>
478
                <isset property="translated.src.dir.exist"/>
479
                <isset property="locjar.locales"/>
480
                <length string="${locjar.locales}" when="greater" length="0"/>
481
            </and>
482
        </condition>
483
    </target>
484
    
485
    <target name="pre-jar-ml" depends="build-init,check-run-mlbuild" if="run.ml.build"/>
486
    
487
    <target name="jar-ml" depends="build-init,check-run-mlbuild,pre-jar-ml" if="run.ml.build">
488
        <mkdir dir="${build.classes.dir.ml}"/>
489
        <copy todir="${build.classes.dir.ml}">
490
            <fileset dir="${translated.src.dir}" excludes="**/*.properties"/>
491
        </copy>
492
        <locjar jarfile="${cluster}/${module.jar}"
493
                basedir="${build.classes.dir.ml}"
494
                compress="${build.package.compress}"/>
495
    </target>
496
    
497
    
498
    <target name="check-run-ml-javahelp" if="run.ml.build">
499
        <condition property="run.ml.javahelp">
500
            <and>
501
                <available file="${nb_all}/translatedfiles/src/${module.name}/javahelp" type="dir"/>
502
                <isset property="locjar.locales"/>
503
                <isset property="locjhindexer.locales"/>
504
                <isset property="has.javahelp"/>
505
                <isset property="run.ml.build"/>
506
            </and>
507
        </condition>
508
    </target>
509
    
510
    <target name="javahelp-ml" depends="build-init,check-run-ml-javahelp" if="run.ml.javahelp">
511
        <mkdir dir="${build.javahelp.dir}-ml/"/>
512
        <copy todir="${build.javahelp.dir}-ml">
513
            <fileset dir="${nb_all}/translatedfiles/src/${module.name}/javahelp"/>
514
        </copy>
515
        <property name="locjhindexer.jhall" value="${nb_all}/apisupport.harness/external/jsearch*.jar"/>
516
        <locjhindexer locales="${locales}"
517
                      basedir="${build.javahelp.dir}-ml/${javahelp.base}"
518
                      dbdir="${javahelp.search}"/>
519
        <mkdir dir="${cluster}/${javahelp.jar.dir}/locale"/>
520
        <locjar basedir="${build.javahelp.dir}-ml"
521
                compress="${build.package.compress}"
522
                jarfile="${cluster}/${javahelp.jar.dir}/${code.name.base.dashes}.jar"/>
523
    </target>
524
461
525
    <target name="check-javahelp" depends="javahelp" description="Validate helpset for various errors." if="has.javahelp">
462
    <target name="check-javahelp" depends="javahelp" description="Validate helpset for various errors." if="has.javahelp">
526
        <fail unless="javahelp.hs">Must set javahelp.hs property</fail>
463
        <fail unless="javahelp.hs">Must set javahelp.hs property</fail>
(-)56f61f356ea2 (+153 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.nbbuild;
43
44
import java.io.File;
45
import java.io.IOException;
46
import java.util.Arrays;
47
import java.util.Enumeration;
48
import java.util.HashSet;
49
import java.util.List;
50
import java.util.Set;
51
import java.util.jar.JarEntry;
52
import java.util.jar.JarFile;
53
import org.apache.tools.ant.Project;
54
import org.apache.tools.ant.types.PatternSet;
55
import org.netbeans.junit.NbTestCase;
56
57
public class LocFilesTest extends NbTestCase {
58
    private File src;
59
    private File dist;
60
    private LocFiles task;
61
    
62
    public LocFilesTest(String n) {
63
        super(n);
64
    }
65
66
    @Override
67
    protected void setUp() throws Exception {
68
        clearWorkDir();
69
        dist = new File(getWorkDir(), "dist");
70
        dist.mkdirs();
71
        src = new File(getWorkDir(), "src");
72
        src.mkdirs();
73
        
74
        Project p = new Project();
75
        task = new LocFiles();
76
        task.setProject(p);
77
        task.setCluster("platform");
78
        task.setLocales("cs");
79
        task.setPatternSet("pattern.set");
80
        task.setSrc(src);
81
        task.setDestDir(dist);
82
    }
83
    
84
    public void testOpenideUtilLookup() throws Exception {
85
        createSource("cs/platform/org-openide-util-lookup/netbeans/lib/org-openide-util-lookup/org/openide/util/lookup/Bundle_cs.properties");
86
        task.setCodeNameBase("org-openide-util-lookup");
87
        task.execute();
88
        assertDist("platform/lib/locale/org-openide-util-lookup_cs.jar", "org/openide/util/lookup/Bundle_cs.properties");
89
        assertPattern("platform", "lib/locale/org-openide-util-lookup_cs.jar");
90
    }
91
92
    public void testSettings() throws Exception {
93
        createSource("cs/platform/settings/settings/org/netbeans/modules/settings/resources/Bundle_cs.properties");
94
        task.setCodeNameBase("org-netbeans-modules-settings");
95
        task.execute();
96
        assertDist("platform/modules/locale/org-netbeans-modules-settings_cs.jar", "org/netbeans/modules/settings/resources/Bundle_cs.properties");
97
        assertPattern("platform", "modules/locale/org-netbeans-modules-settings_cs.jar");
98
    }
99
    
100
    public void testCoreWindows() throws Exception {
101
        final String pref = "cs/platform/org-netbeans-core-windows/org-netbeans-core-windows/org/netbeans/core/windows/";
102
        createSource(
103
            pref + "resources/Bundle_cs.properties",
104
            pref + "actions/Bundle_cs.properties",
105
            pref + "services/Bundle_cs.properties",
106
            pref + "options/Bundle_cs.properties",
107
            pref + "view/ui/Bundle_cs.properties",
108
            pref + "persistence/Bundle_cs.properties"
109
        );
110
        task.setCodeNameBase("org-netbeans-core-windows");
111
        task.execute();
112
        assertDist("platform/modules/locale/org-netbeans-core-windows_cs.jar", 
113
            "org/netbeans/core/windows/resources/Bundle_cs.properties",
114
            "org/netbeans/core/windows/actions/Bundle_cs.properties",
115
            "org/netbeans/core/windows/services/Bundle_cs.properties",
116
            "org/netbeans/core/windows/options/Bundle_cs.properties",
117
            "org/netbeans/core/windows/view/ui/Bundle_cs.properties",
118
            "org/netbeans/core/windows/persistence/Bundle_cs.properties"
119
        );
120
        assertPattern("platform", "modules/locale/org-netbeans-core-windows_cs.jar");
121
    }
122
123
    private void createSource(String... files) throws IOException {
124
        for (String f : files) {
125
            File c = new File(src, f.replace('/', File.separatorChar));
126
            c.getParentFile().mkdirs();
127
            c.createNewFile();
128
        }
129
    }
130
131
    private void assertDist(String jar, String... files) throws IOException {
132
        File f = new File(dist, jar.replace('/', File.separatorChar));
133
        assertTrue("File is created", f.exists());
134
        JarFile jf = new JarFile(f);
135
        Set<String> expected = new HashSet<String>(Arrays.asList(files));
136
        Enumeration<JarEntry> en = jf.entries();
137
        while (en.hasMoreElements()) {
138
            JarEntry e = en.nextElement();
139
            expected.remove(e.getName());
140
        }
141
        assertTrue("All files are present: " + expected, expected.isEmpty());
142
    }
143
144
    private void assertPattern(String cluster, String file) {
145
        Object ref = task.getProject().getReference("pattern.set");
146
        assertNotNull("Reference is found", ref);
147
        assertTrue("Right instance: " + ref, ref instanceof PatternSet);
148
        PatternSet ps = (PatternSet)ref;
149
        
150
        List<String> arr = Arrays.asList(ps.getIncludePatterns(task.getProject()));
151
        assertTrue(file + " is there: " + arr, arr.contains(file));
152
    }
153
}

Return to bug 201433