Lines 51-62
Link Here
|
51 |
import java.io.InputStreamReader; |
51 |
import java.io.InputStreamReader; |
52 |
import java.io.PrintWriter; |
52 |
import java.io.PrintWriter; |
53 |
import java.io.StringReader; |
53 |
import java.io.StringReader; |
|
|
54 |
import java.text.Collator; |
54 |
import java.util.ArrayList; |
55 |
import java.util.ArrayList; |
|
|
56 |
import java.util.Arrays; |
55 |
import java.util.Comparator; |
57 |
import java.util.Comparator; |
56 |
import java.util.Enumeration; |
58 |
import java.util.Enumeration; |
57 |
import java.util.HashMap; |
59 |
import java.util.HashMap; |
58 |
import java.util.HashSet; |
60 |
import java.util.HashSet; |
59 |
import java.util.List; |
61 |
import java.util.List; |
|
|
62 |
import java.util.Locale; |
60 |
import java.util.Map; |
63 |
import java.util.Map; |
61 |
import java.util.Properties; |
64 |
import java.util.Properties; |
62 |
import java.util.Set; |
65 |
import java.util.Set; |
Lines 110-115
Link Here
|
110 |
serviceOutput = f; |
113 |
serviceOutput = f; |
111 |
} |
114 |
} |
112 |
|
115 |
|
|
|
116 |
private File templatesOutput; |
117 |
public void setTemplatesOutput(File f) { |
118 |
templatesOutput = f; |
119 |
} |
120 |
|
113 |
private String resourceId; |
121 |
private String resourceId; |
114 |
private List<ZipResource> resources; |
122 |
private List<ZipResource> resources; |
115 |
/** If this parameter is provided, then this tasks creates a resource |
123 |
/** If this parameter is provided, then this tasks creates a resource |
Lines 129-134
Link Here
|
129 |
SortedMap<String,String> files = new TreeMap<String,String>(); // layer path -> cnb |
137 |
SortedMap<String,String> files = new TreeMap<String,String>(); // layer path -> cnb |
130 |
SortedMap<String,SortedMap<String,String>> labels = new TreeMap<String,SortedMap<String,String>>(); // layer path -> cnb -> label |
138 |
SortedMap<String,SortedMap<String,String>> labels = new TreeMap<String,SortedMap<String,String>>(); // layer path -> cnb -> label |
131 |
final Map<String,Integer> positions = new TreeMap<String,Integer>(); // layer path -> position |
139 |
final Map<String,Integer> positions = new TreeMap<String,Integer>(); // layer path -> position |
|
|
140 |
SortedMap<String,Set<String>> templateCategories = new TreeMap<String,Set<String>>(Collator.getInstance(Locale.ENGLISH)); // templateCategory item (or "") -> layer paths |
132 |
SortedMap<String,SortedMap<String,Set<String>>> serviceImpls = new TreeMap<String,SortedMap<String,Set<String>>>(); // path -> interface -> [impl] |
141 |
SortedMap<String,SortedMap<String,Set<String>>> serviceImpls = new TreeMap<String,SortedMap<String,Set<String>>>(); // path -> interface -> [impl] |
133 |
Map<String,Integer> servicePositions = new HashMap<String,Integer>(); // impl -> position |
142 |
Map<String,Integer> servicePositions = new HashMap<String,Integer>(); // impl -> position |
134 |
for (FileSet fs : filesets) { |
143 |
for (FileSet fs : filesets) { |
Lines 154-160
Link Here
|
154 |
ZipResource res = new LayerResource(jar, layer, layer.replaceFirst("/[^/]+$", "").replace('/', '.') + ".xml"); |
163 |
ZipResource res = new LayerResource(jar, layer, layer.replaceFirst("/[^/]+$", "").replace('/', '.') + ".xml"); |
155 |
resources.add(res); |
164 |
resources.add(res); |
156 |
} else { |
165 |
} else { |
157 |
parse(jf.getInputStream(jf.getEntry(layer)), files, labels, positions, cnb, jf); |
166 |
parse(jf.getInputStream(jf.getEntry(layer)), files, labels, positions, templateCategories, cnb, jf); |
158 |
} |
167 |
} |
159 |
} |
168 |
} |
160 |
ZipEntry generatedLayer = jf.getEntry("META-INF/generated-layer.xml"); |
169 |
ZipEntry generatedLayer = jf.getEntry("META-INF/generated-layer.xml"); |
Lines 163-169
Link Here
|
163 |
ZipResource res = new LayerResource(jar, generatedLayer.getName(), cnb + "-generated.xml"); |
172 |
ZipResource res = new LayerResource(jar, generatedLayer.getName(), cnb + "-generated.xml"); |
164 |
resources.add(res); |
173 |
resources.add(res); |
165 |
} else { |
174 |
} else { |
166 |
parse(jf.getInputStream(generatedLayer), files, labels, positions, cnb + "@", jf); |
175 |
parse(jf.getInputStream(generatedLayer), files, labels, positions, templateCategories, cnb + "@", jf); |
167 |
} |
176 |
} |
168 |
} |
177 |
} |
169 |
if (serviceOutput != null) { |
178 |
if (serviceOutput != null) { |
Lines 189-194
Link Here
|
189 |
if (serviceOutput != null) { |
198 |
if (serviceOutput != null) { |
190 |
writeServiceIndex(serviceImpls, servicePositions); |
199 |
writeServiceIndex(serviceImpls, servicePositions); |
191 |
} |
200 |
} |
|
|
201 |
if (templatesOutput != null) { |
202 |
writeTemplateIndex(templateCategories, labels, positions); |
203 |
} |
192 |
} catch (IOException x) { |
204 |
} catch (IOException x) { |
193 |
throw new BuildException(x, getLocation()); |
205 |
throw new BuildException(x, getLocation()); |
194 |
} |
206 |
} |
Lines 213-224
Link Here
|
213 |
} |
225 |
} |
214 |
|
226 |
|
215 |
private void parse(InputStream is, final Map<String,String> files, final SortedMap<String,SortedMap<String,String>> labels, |
227 |
private void parse(InputStream is, final Map<String,String> files, final SortedMap<String,SortedMap<String,String>> labels, |
216 |
final Map<String,Integer> positions, final String cnb, final JarFile jf) throws Exception { |
228 |
final Map<String,Integer> positions, final Map<String,Set<String>> templateCategories, final String cnb, final JarFile jf) throws Exception { |
217 |
SAXParserFactory f = SAXParserFactory.newInstance(); |
229 |
SAXParserFactory f = SAXParserFactory.newInstance(); |
218 |
f.setValidating(false); |
230 |
f.setValidating(false); |
219 |
f.setNamespaceAware(false); |
231 |
f.setNamespaceAware(false); |
220 |
f.newSAXParser().parse(is, new DefaultHandler() { |
232 |
f.newSAXParser().parse(is, new DefaultHandler() { |
221 |
String prefix = ""; |
233 |
String prefix = ""; |
|
|
234 |
List<String> templateCategory; |
235 |
boolean template; |
222 |
void register(String path) { |
236 |
void register(String path) { |
223 |
if (!files.containsKey(path)) { |
237 |
if (!files.containsKey(path)) { |
224 |
files.put(path, cnb); |
238 |
files.put(path, cnb); |
Lines 270-275
Link Here
|
270 |
throw new SAXException(x); |
284 |
throw new SAXException(x); |
271 |
} |
285 |
} |
272 |
} |
286 |
} |
|
|
287 |
} else if (qName.equals("attr") && attributes.getValue("name").equals("template")) { |
288 |
template = Boolean.parseBoolean(attributes.getValue("boolvalue")); |
289 |
} else if (qName.equals("attr") && attributes.getValue("name").equals("templateCategory")) { |
290 |
templateCategory = Arrays.asList(attributes.getValue("stringvalue").split(" *, *")); |
273 |
} |
291 |
} |
274 |
} |
292 |
} |
275 |
private void loadDisplayName(String bundle, String key) throws SAXException { |
293 |
private void loadDisplayName(String bundle, String key) throws SAXException { |
Lines 308-316
Link Here
|
308 |
if (qName.equals("folder")) { |
326 |
if (qName.equals("folder")) { |
309 |
prefix = prefix.replaceFirst("[^/]+/$", ""); |
327 |
prefix = prefix.replaceFirst("[^/]+/$", ""); |
310 |
} else if (qName.equals("file")) { |
328 |
} else if (qName.equals("file")) { |
|
|
329 |
// XXX really want to track simple=false, and templateCategory on folders |
330 |
if (template && prefix.matches("Templates/(?!Project/|Licenses/|Services/|JSF/JSF_From_Entity_Wizard/|JSF/JSF_From_Entity_Snippets/).+")) { |
331 |
if (templateCategory != null) { |
332 |
for (String category : templateCategory) { |
333 |
if (category.equals("invisible")) { |
334 |
continue; |
335 |
} |
336 |
registerTemplateCategory(category); |
337 |
} |
338 |
} else { |
339 |
registerTemplateCategory(""); |
340 |
} |
341 |
template = false; |
342 |
} |
343 |
templateCategory = null; |
311 |
prefix = prefix.replaceFirst("[^/]+$", ""); |
344 |
prefix = prefix.replaceFirst("[^/]+$", ""); |
312 |
} |
345 |
} |
313 |
} |
346 |
} |
|
|
347 |
void registerTemplateCategory(String category) { |
348 |
Set<String> paths = templateCategories.get(category); |
349 |
if (paths == null) { |
350 |
paths = new TreeSet<String>(); |
351 |
templateCategories.put(category, paths); |
352 |
} |
353 |
paths.add(prefix); |
354 |
} |
314 |
@Override |
355 |
@Override |
315 |
public InputSource resolveEntity(String pub, String sys) throws IOException, SAXException { |
356 |
public InputSource resolveEntity(String pub, String sys) throws IOException, SAXException { |
316 |
return new InputSource(new StringReader("")); |
357 |
return new InputSource(new StringReader("")); |
Lines 615-618
Link Here
|
615 |
} |
656 |
} |
616 |
} |
657 |
} |
617 |
|
658 |
|
|
|
659 |
private void writeTemplateIndex(Map<String,Set<String>> templateCategories, SortedMap<String,SortedMap<String,String>> labels, Map<String,Integer> positions) throws IOException { |
660 |
PrintWriter pw = new PrintWriter(templatesOutput, "UTF-8"); |
661 |
Comparator<String> order = new LayerPathComparator(positions); |
662 |
for (Map.Entry<String,Set<String>> categoryEntry : templateCategories.entrySet()) { |
663 |
pw.print("CATEGORY "); |
664 |
String category = categoryEntry.getKey(); |
665 |
pw.println(category.isEmpty() ? "<any>" : "'" + category + "'"); |
666 |
SortedMap<String,SortedSet<String>> templatesByFolder = new TreeMap<String,SortedSet<String>>(order); |
667 |
for (String path : categoryEntry.getValue()) { |
668 |
int slash = path.lastIndexOf('/'); |
669 |
String folder = path.substring(0, slash + 1); |
670 |
SortedSet<String> templates = templatesByFolder.get(folder); |
671 |
if (templates == null) { |
672 |
templates = new TreeSet<String>(order); |
673 |
templatesByFolder.put(folder, templates); |
674 |
} |
675 |
templates.add(path); |
676 |
} |
677 |
for (Map.Entry<String,SortedSet<String>> folderEntry : templatesByFolder.entrySet()) { |
678 |
String folder = folderEntry.getKey(); |
679 |
pw.print(" FOLDER " + folder); |
680 |
printlnLabel(pw, folder, labels); |
681 |
for (String template : folderEntry.getValue()) { |
682 |
pw.print(" " + template.substring(folder.length())); |
683 |
printlnLabel(pw, template, labels); |
684 |
} |
685 |
} |
686 |
} |
687 |
pw.close(); |
688 |
log(templatesOutput + ": template index written"); |
689 |
} |
690 |
private static void printlnLabel(PrintWriter pw, String path, SortedMap<String,SortedMap<String,String>> labels) { |
691 |
SortedMap<String,String> possibilities = labels.get(path); |
692 |
if (possibilities != null && possibilities.size() == 1) { |
693 |
pw.print(" (\"" + possibilities.values().iterator().next() + "\")"); |
694 |
} |
695 |
pw.println(); |
696 |
} |
697 |
|
618 |
} |
698 |
} |