/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/ package org.netbeans.nbbuild;
/** * This task was created to create L10N kits. The xml to call this task might * look like: * <l10nTask nbmsdir="nbms" tmpdir="tmp" patternsFile="l10n.patterns" * kitFile="build/l10n.zip"/> * * * Resulting kitFile will contain the files according the patterns from * patternsFile * * @author Michal Zlamal
*/ publicclass L10nTask extends Task {
@Override publicvoid execute() throws BuildException {
LineNumberReader lnr = null; try { if (nbmsDir == null) { thrownew BuildException("Required variable not set. Set 'nbmsdir' in the calling build script file");
} if (!nbmsDir.exists() || !nbmsDir.isDirectory()) { thrownew BuildException("'nbmsdir' has to exist and be directory where are all NBMs stored");
} if (patternsFile == null) { thrownew BuildException("Required variable not set. Set 'patternsFile' in the calling build script file");
} if (!patternsFile.exists() || !patternsFile.isFile()) { thrownew BuildException("'patternsFile' has to exist and be file with patterns what should be included in the kit");
} if (kitFile == null) { thrownew BuildException("Required variable not set. Set 'kitFile' in the calling build script file");
}
lnr = new LineNumberReader(new FileReader(patternsFile));
String line;
Map<String, Set<String>> includes = new HashMap<>();
Map<String, Set<String>> excludes = new HashMap<>();
Set<String> excludeFiles = new HashSet<>();
//Read all the patterns from patternsFile while ((line = lnr.readLine()) != null) { if (line.trim().length() == 0) { continue;
} if (line.startsWith("#")) { continue;
} if (!line.startsWith("exclude ")) { //Include pattern
String[] p = line.split(":"); if (p.length != 2) { if (line.endsWith(":")) {
includes.put(line.substring(0, line.length() - 1), null); continue;
} else { thrownew BuildException("Wrong pattern '" + line + "' found in pattern file: " + patternsFile.getAbsolutePath());
}
}
Set<String> files = includes.get(p[0]); if (files == null) {
files = new HashSet<>();
includes.put(p[0], files);
}
files.add(p[1]);
} else { //Exlude pattern
List<String> lines = new ArrayList<> ();
String lineRaw = line.substring("exclude ".length()); if (lineRaw.contains(LOCALES_TOKEN)) { for (String locale : getLocales(locales)) { if (! locale.isEmpty()) {
lines.add(lineRaw.replace(LOCALES_TOKEN, locale));
}
} if (lines.isEmpty()) {
lines.add(lineRaw.replace(LOCALES_TOKEN, "*")); // NOI18N
}
} else {
lines.add(lineRaw); // NOI18N
} for (String oneLine : lines) {
String[] p = oneLine.split(":"); if (p.length != 2) { if (oneLine.endsWith(":")) {
excludes.put(oneLine.substring(0, oneLine.length() - 1), null);
excludeFiles.add(oneLine.substring(0, oneLine.length() - 1)); continue;
} else { thrownew BuildException("Wrong pattern '" + oneLine + "' found in pattern file: " + patternsFile.getAbsolutePath());
}
}
Set<String> files = excludes.get(p[0]); if (files == null) {
files = new HashSet<>();
excludes.put(p[0], files);
}
files.add(p[1]);
}
}
}
lnr.close();
//Unzip all the NBMs
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(nbmsDir);
ds.setIncludes(new String[]{"**/*.nbm"});
ds.scan();
String[] nbms = ds.getIncludedFiles();
Expand unzip = (Expand) getProject().createTask("unzip"); for (String nbm : nbms) {
File nbmFile = new File(nbmsDir, nbm);
File nbmDir = new File(tmpDir, nbm);
nbmDir.mkdirs();
unzip.setSrc(nbmFile);
unzip.setDest(nbmDir);
unzip.execute();
privatestatic String[] getLocales(String locales) {
StringTokenizer en = new StringTokenizer(locales, ","); // NOI18N
String[] res = new String[en.countTokens()]; int i = 0; while (en.hasMoreTokens()) {
res[i++] = en.nextToken();
} return res;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-04-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.