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 |
} |