Lines 375-388
Link Here
|
375 |
* @return {@link Element} representing JavaCompilationUnit instances or null |
375 |
* @return {@link Element} representing JavaCompilationUnit instances or null |
376 |
*/ |
376 |
*/ |
377 |
public static Element getJavaCompilationUnits (final AuxiliaryConfiguration aux) { |
377 |
public static Element getJavaCompilationUnits (final AuxiliaryConfiguration aux) { |
378 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); |
378 |
for (String ns : JavaProjectNature.JAVA_NAMESPACES) { |
379 |
if (data == null) { |
379 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, ns, true); |
380 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
380 |
if (data != null) return data; |
381 |
} |
381 |
} |
382 |
if (data == null) { |
382 |
return null; |
383 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
|
|
384 |
} |
385 |
return data; |
386 |
} |
383 |
} |
387 |
|
384 |
|
388 |
/** |
385 |
/** |
Lines 436-442
Link Here
|
436 |
continue; |
433 |
continue; |
437 |
} |
434 |
} |
438 |
if ("annotation-processing".equals(el.getLocalName())&& //NOI18N |
435 |
if ("annotation-processing".equals(el.getLocalName())&& //NOI18N |
439 |
JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { |
436 |
JavaProjectNature.namespaceAtLeast(el.getNamespaceURI(), JavaProjectNature.NS_JAVA_3)) { |
440 |
cu.annotationPorocessing = new JavaCompilationUnit.AnnotationProcessing(); |
437 |
cu.annotationPorocessing = new JavaCompilationUnit.AnnotationProcessing(); |
441 |
cu.annotationPorocessing.trigger = EnumSet.<AnnotationProcessingQuery.Trigger>noneOf(AnnotationProcessingQuery.Trigger.class); |
438 |
cu.annotationPorocessing.trigger = EnumSet.<AnnotationProcessingQuery.Trigger>noneOf(AnnotationProcessingQuery.Trigger.class); |
442 |
cu.annotationPorocessing.processors = new ArrayList<String>(); |
439 |
cu.annotationPorocessing.processors = new ArrayList<String>(); |
Lines 445-461
Link Here
|
445 |
final String localName = apEl.getLocalName(); |
442 |
final String localName = apEl.getLocalName(); |
446 |
if ("scan-trigger".equals(localName)) { //NOI18N |
443 |
if ("scan-trigger".equals(localName)) { //NOI18N |
447 |
cu.annotationPorocessing.trigger.add(AnnotationProcessingQuery.Trigger.ON_SCAN); |
444 |
cu.annotationPorocessing.trigger.add(AnnotationProcessingQuery.Trigger.ON_SCAN); |
448 |
} else if ("editor-trigger".equals(localName) && JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { //NOI18N |
445 |
} else if ("editor-trigger".equals(localName)) { //NOI18N |
449 |
cu.annotationPorocessing.trigger.add(AnnotationProcessingQuery.Trigger.IN_EDITOR); |
446 |
cu.annotationPorocessing.trigger.add(AnnotationProcessingQuery.Trigger.IN_EDITOR); |
450 |
} else if ("source-output".equals(localName) && JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { |
447 |
} else if ("source-output".equals(localName)) { |
451 |
cu.annotationPorocessing.sourceOutput = XMLUtil.findText(apEl); |
448 |
cu.annotationPorocessing.sourceOutput = XMLUtil.findText(apEl); |
452 |
} else if ("processor-path".equals(localName) && JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { //NOI18N |
449 |
} else if ("processor-path".equals(localName)) { //NOI18N |
453 |
cu.annotationPorocessing.processorPath = XMLUtil.findText(apEl); |
450 |
cu.annotationPorocessing.processorPath = XMLUtil.findText(apEl); |
454 |
} else if ("processor".equals(localName) && JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { //NOI18N |
451 |
} else if ("processor".equals(localName)) { //NOI18N |
455 |
cu.annotationPorocessing.processors.add(XMLUtil.findText(apEl)); |
452 |
cu.annotationPorocessing.processors.add(XMLUtil.findText(apEl)); |
456 |
} else if ("processor-option".equals(localName) && JavaProjectNature.NS_JAVA_3.equals(el.getNamespaceURI())) { //NOI18N |
453 |
} else if ("processor-option".equals(localName)) { //NOI18N |
457 |
final Element keyEl = XMLUtil.findElement(apEl, "key", JavaProjectNature.NS_JAVA_3); //NOI18N |
454 |
final Element keyEl = XMLUtil.findElement(apEl, "key", el.getNamespaceURI()); //NOI18N |
458 |
final Element valueEl = XMLUtil.findElement(apEl, "value", JavaProjectNature.NS_JAVA_3); //NOI18N |
455 |
final Element valueEl = XMLUtil.findElement(apEl, "value", el.getNamespaceURI()); //NOI18N |
459 |
if (keyEl != null && valueEl != null) { |
456 |
if (keyEl != null && valueEl != null) { |
460 |
final String key = XMLUtil.findText(keyEl); |
457 |
final String key = XMLUtil.findText(keyEl); |
461 |
final String value = XMLUtil.findText(valueEl); |
458 |
final String value = XMLUtil.findText(valueEl); |
Lines 486-548
Link Here
|
486 |
public static void putJavaCompilationUnits(AntProjectHelper helper, |
483 |
public static void putJavaCompilationUnits(AntProjectHelper helper, |
487 |
AuxiliaryConfiguration aux, List<JavaCompilationUnit> compUnits) { |
484 |
AuxiliaryConfiguration aux, List<JavaCompilationUnit> compUnits) { |
488 |
//assert ProjectManager.mutex().isWriteAccess(); |
485 |
//assert ProjectManager.mutex().isWriteAccess(); |
489 |
// First check if we need /3 data. |
486 |
int requiredVersion = 1; |
490 |
boolean need3 = false; |
487 |
|
|
|
488 |
// detect minimal required namespace: |
491 |
for (JavaCompilationUnit unit : compUnits) { |
489 |
for (JavaCompilationUnit unit : compUnits) { |
492 |
if (needsNS3(unit)) { |
490 |
requiredVersion = Math.max(requiredVersion, minimalNS(unit)); |
493 |
need3 = true; |
491 |
} |
494 |
break; |
492 |
|
|
|
493 |
String namespace; |
494 |
|
495 |
switch (requiredVersion) { |
496 |
case 4: namespace = JavaProjectNature.NS_JAVA_4; break; |
497 |
case 3: namespace = JavaProjectNature.NS_JAVA_3; break; |
498 |
case 2: namespace = JavaProjectNature.NS_JAVA_2; break; |
499 |
default: namespace = JavaProjectNature.NS_JAVA_1; break; |
500 |
} |
501 |
|
502 |
Element data = getJavaCompilationUnits(aux); |
503 |
|
504 |
if (data == null || !JavaProjectNature.namespaceAtLeast(data.getNamespaceURI(), namespace)) { |
505 |
if (data != null) { |
506 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, data.getNamespaceURI(), true); |
495 |
} |
507 |
} |
496 |
} |
508 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
497 |
// Second check whether we need /2 data. |
509 |
createElementNS(namespace, JavaProjectNature.EL_JAVA); |
498 |
boolean need2 = false; |
|
|
499 |
for (JavaCompilationUnit unit : compUnits) { |
500 |
if (unit.isTests || (unit.javadoc != null && !unit.javadoc.isEmpty())) { |
501 |
need2 = true; |
502 |
break; |
503 |
} |
504 |
} |
505 |
String namespace; |
506 |
// Look for existing /3 data. |
507 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); |
508 |
if (data != null) { |
509 |
namespace = JavaProjectNature.NS_JAVA_3; |
510 |
} |
511 |
else { |
512 |
// Look for existing /2 data and possibly update to /3 |
513 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
514 |
if (data != null) { |
515 |
namespace = need3 ? JavaProjectNature.NS_JAVA_3 : JavaProjectNature.NS_JAVA_2; |
516 |
if (need3) { |
517 |
// Have to upgrade to /3 |
518 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
519 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
520 |
createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); |
521 |
} |
522 |
} else { |
523 |
//Look for existing /1 and possibly update to /2 or /3 as needed |
524 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
525 |
namespace = need3 ? JavaProjectNature.NS_JAVA_3 : need2 ? JavaProjectNature.NS_JAVA_2 : JavaProjectNature.NS_JAVA_1; |
526 |
if (data != null) { |
527 |
|
528 |
if (need3) { |
529 |
// Have to upgrade to /3 |
530 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
531 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
532 |
createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); |
533 |
} |
534 |
else if (need2) { |
535 |
// Have to upgrade to /2 |
536 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
537 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
538 |
createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); |
539 |
} // else can use it as is |
540 |
} else { |
541 |
// Create a new /1, /2 or /3 data acc. to need. |
542 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
543 |
createElementNS(namespace, JavaProjectNature.EL_JAVA); |
544 |
} |
545 |
} |
546 |
} |
510 |
} |
547 |
Document doc = data.getOwnerDocument(); |
511 |
Document doc = data.getOwnerDocument(); |
548 |
for (Element cuEl : XMLUtil.findSubElements(data)) { |
512 |
for (Element cuEl : XMLUtil.findSubElements(data)) { |
Lines 560-566
Link Here
|
560 |
} |
524 |
} |
561 |
} |
525 |
} |
562 |
if (cu.isTests) { |
526 |
if (cu.isTests) { |
563 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); |
527 |
assert JavaProjectNature.namespaceAtLeast(namespace, JavaProjectNature.NS_JAVA_2); |
564 |
cuEl.appendChild(doc.createElementNS(namespace, "unit-tests")); // NOI18N |
528 |
cuEl.appendChild(doc.createElementNS(namespace, "unit-tests")); // NOI18N |
565 |
} |
529 |
} |
566 |
if (cu.classpath != null) { |
530 |
if (cu.classpath != null) { |
Lines 584-590
Link Here
|
584 |
Iterator it3 = cu.javadoc.iterator(); |
548 |
Iterator it3 = cu.javadoc.iterator(); |
585 |
while (it3.hasNext()) { |
549 |
while (it3.hasNext()) { |
586 |
String javadoc = (String) it3.next(); |
550 |
String javadoc = (String) it3.next(); |
587 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); |
551 |
assert JavaProjectNature.namespaceAtLeast(namespace, JavaProjectNature.NS_JAVA_2); |
588 |
el = doc.createElementNS(namespace, "javadoc-built-to"); // NOI18N |
552 |
el = doc.createElementNS(namespace, "javadoc-built-to"); // NOI18N |
589 |
el.appendChild(doc.createTextNode(javadoc)); |
553 |
el.appendChild(doc.createTextNode(javadoc)); |
590 |
cuEl.appendChild(el); |
554 |
cuEl.appendChild(el); |
Lines 1099-1121
Link Here
|
1099 |
props.setProperty(key, value); |
1063 |
props.setProperty(key, value); |
1100 |
} |
1064 |
} |
1101 |
|
1065 |
|
1102 |
private static boolean needsNS3(final JavaCompilationUnit unit) { |
1066 |
private static int minimalNS(final JavaCompilationUnit unit) { |
|
|
1067 |
if (unit.isTests || (unit.javadoc != null && !unit.javadoc.isEmpty())) { |
1068 |
return 2; |
1069 |
} |
1103 |
if (unit.classpath != null) { |
1070 |
if (unit.classpath != null) { |
1104 |
for (JavaCompilationUnit.CP cp : unit.classpath) { |
1071 |
for (JavaCompilationUnit.CP cp : unit.classpath) { |
1105 |
if ("processor".equals(cp.mode)) { //NOI18N |
1072 |
if ("processor".equals(cp.mode)) { //NOI18N |
1106 |
return true; |
1073 |
return 3; |
1107 |
} |
1074 |
} |
1108 |
} |
1075 |
} |
1109 |
} |
1076 |
} |
1110 |
if (unit.sourceLevel != null) { |
1077 |
if (unit.sourceLevel != null) { |
|
|
1078 |
final SpecificationVersion JAVA_8 = new SpecificationVersion("1.8"); //NOI18N |
1079 |
final SpecificationVersion current = new SpecificationVersion(unit.sourceLevel); |
1080 |
if (JAVA_8.compareTo(current) >= 0) { |
1081 |
return 4; |
1082 |
} |
1111 |
final SpecificationVersion JAVA_6 = new SpecificationVersion("1.6"); //NOI18N |
1083 |
final SpecificationVersion JAVA_6 = new SpecificationVersion("1.6"); //NOI18N |
1112 |
final SpecificationVersion JAvA_7 = new SpecificationVersion("1.7"); //NOI18N |
1084 |
final SpecificationVersion JAvA_7 = new SpecificationVersion("1.7"); //NOI18N |
1113 |
final SpecificationVersion current = new SpecificationVersion(unit.sourceLevel); |
|
|
1114 |
if (JAVA_6.equals(current) || JAvA_7.equals(current)) { |
1085 |
if (JAVA_6.equals(current) || JAvA_7.equals(current)) { |
1115 |
return true; |
1086 |
return 3; |
1116 |
} |
1087 |
} |
1117 |
} |
1088 |
} |
1118 |
return false; |
1089 |
return 1; |
1119 |
} |
1090 |
} |
1120 |
|
1091 |
|
1121 |
} |
1092 |
} |