Lines 58-63
Link Here
|
58 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
58 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
59 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
59 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
60 |
import org.openide.filesystems.FileUtil; |
60 |
import org.openide.filesystems.FileUtil; |
|
|
61 |
import org.openide.modules.SpecificationVersion; |
61 |
import org.openide.util.Exceptions; |
62 |
import org.openide.util.Exceptions; |
62 |
import org.w3c.dom.Document; |
63 |
import org.w3c.dom.Document; |
63 |
import org.w3c.dom.Element; |
64 |
import org.w3c.dom.Element; |
Lines 358-365
Link Here
|
358 |
} |
359 |
} |
359 |
Util.putPrimaryConfigurationData(helper, data); |
360 |
Util.putPrimaryConfigurationData(helper, data); |
360 |
} |
361 |
} |
361 |
|
362 |
|
362 |
|
363 |
/** |
|
|
364 |
* Returns {@link Element} for {@link JavaCompilationUnit}. |
365 |
* @param aux AuxiliaryConfiguration instance |
366 |
* @return {@link Element} representing JavaCompilationUnit instances or null |
367 |
*/ |
368 |
public static Element getJavaCompilationUnits (final AuxiliaryConfiguration aux) { |
369 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); |
370 |
if (data == null) { |
371 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
372 |
} |
373 |
if (data == null) { |
374 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
375 |
} |
376 |
return data; |
377 |
} |
378 |
|
363 |
/** |
379 |
/** |
364 |
* Read Java compilation units from the project. |
380 |
* Read Java compilation units from the project. |
365 |
* @param helper AntProjectHelper instance |
381 |
* @param helper AntProjectHelper instance |
Lines 370-379
Link Here
|
370 |
AntProjectHelper helper, AuxiliaryConfiguration aux) { |
386 |
AntProjectHelper helper, AuxiliaryConfiguration aux) { |
371 |
//assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); |
387 |
//assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); |
372 |
List<JavaCompilationUnit> list = new ArrayList<JavaCompilationUnit>(); |
388 |
List<JavaCompilationUnit> list = new ArrayList<JavaCompilationUnit>(); |
373 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
389 |
final Element data = getJavaCompilationUnits(aux); |
374 |
if (data == null) { |
|
|
375 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
376 |
} |
377 |
if (data == null) { |
390 |
if (data == null) { |
378 |
return list; |
391 |
return list; |
379 |
} |
392 |
} |
Lines 432-437
Link Here
|
432 |
AuxiliaryConfiguration aux, List<JavaCompilationUnit> compUnits) { |
445 |
AuxiliaryConfiguration aux, List<JavaCompilationUnit> compUnits) { |
433 |
//assert ProjectManager.mutex().isWriteAccess(); |
446 |
//assert ProjectManager.mutex().isWriteAccess(); |
434 |
// First check whether we need /2 data. |
447 |
// First check whether we need /2 data. |
|
|
448 |
boolean need3 = false; |
449 |
for (JavaCompilationUnit unit : compUnits) { |
450 |
if (needsNS3(unit)) { |
451 |
need3 = true; |
452 |
break; |
453 |
} |
454 |
} |
455 |
// Second check whether we need /2 data. |
435 |
boolean need2 = false; |
456 |
boolean need2 = false; |
436 |
for (JavaCompilationUnit unit : compUnits) { |
457 |
for (JavaCompilationUnit unit : compUnits) { |
437 |
if (unit.isTests || (unit.javadoc != null && !unit.javadoc.isEmpty())) { |
458 |
if (unit.isTests || (unit.javadoc != null && !unit.javadoc.isEmpty())) { |
Lines 440-465
Link Here
|
440 |
} |
461 |
} |
441 |
} |
462 |
} |
442 |
String namespace; |
463 |
String namespace; |
443 |
// Look for existing /2 data. |
464 |
// Look for existing /3 data. |
444 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
465 |
Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); |
445 |
if (data != null) { |
466 |
if (data != null) { |
446 |
// Fine, use it as is. |
467 |
namespace = JavaProjectNature.NS_JAVA_3; |
447 |
namespace = JavaProjectNature.NS_JAVA_2; |
468 |
} |
448 |
} else { |
469 |
else { |
449 |
// Or, for existing /1 data. |
470 |
// Look for existing /2 data and possibly update to /3 |
450 |
namespace = need2 ? JavaProjectNature.NS_JAVA_2 : JavaProjectNature.NS_JAVA_1; |
471 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
451 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
|
|
452 |
if (data != null) { |
472 |
if (data != null) { |
453 |
if (need2) { |
473 |
namespace = need3 ? JavaProjectNature.NS_JAVA_3 : JavaProjectNature.NS_JAVA_2; |
454 |
// Have to upgrade. |
474 |
if (need3) { |
455 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
475 |
// Have to upgrade to /3 |
|
|
476 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); |
456 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
477 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
457 |
createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); |
478 |
createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); |
458 |
} // else can use it as is |
479 |
} |
459 |
} else { |
480 |
} else { |
460 |
// Create /1 or /2 data acc. to need. |
481 |
//Look for existing /1 and possibly update to /2 or /3 as needed |
461 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
482 |
data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
462 |
createElementNS(namespace, JavaProjectNature.EL_JAVA); |
483 |
namespace = need3 ? JavaProjectNature.NS_JAVA_3 : need2 ? JavaProjectNature.NS_JAVA_2 : JavaProjectNature.NS_JAVA_1; |
|
|
484 |
if (data != null) { |
485 |
|
486 |
if (need3) { |
487 |
// Have to upgrade to /3 |
488 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
489 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
490 |
createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); |
491 |
} |
492 |
else if (need2) { |
493 |
// Have to upgrade to /2 |
494 |
aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); |
495 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
496 |
createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); |
497 |
} // else can use it as is |
498 |
} else { |
499 |
// Create a new /1, /2 or /3 data acc. to need. |
500 |
data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). |
501 |
createElementNS(namespace, JavaProjectNature.EL_JAVA); |
502 |
} |
463 |
} |
503 |
} |
464 |
} |
504 |
} |
465 |
Document doc = data.getOwnerDocument(); |
505 |
Document doc = data.getOwnerDocument(); |
Lines 478-484
Link Here
|
478 |
} |
518 |
} |
479 |
} |
519 |
} |
480 |
if (cu.isTests) { |
520 |
if (cu.isTests) { |
481 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2); |
521 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); |
482 |
cuEl.appendChild(doc.createElementNS(namespace, "unit-tests")); // NOI18N |
522 |
cuEl.appendChild(doc.createElementNS(namespace, "unit-tests")); // NOI18N |
483 |
} |
523 |
} |
484 |
if (cu.classpath != null) { |
524 |
if (cu.classpath != null) { |
Lines 502-508
Link Here
|
502 |
Iterator it3 = cu.javadoc.iterator(); |
542 |
Iterator it3 = cu.javadoc.iterator(); |
503 |
while (it3.hasNext()) { |
543 |
while (it3.hasNext()) { |
504 |
String javadoc = (String) it3.next(); |
544 |
String javadoc = (String) it3.next(); |
505 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2); |
545 |
assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); |
506 |
el = doc.createElementNS(namespace, "javadoc-built-to"); // NOI18N |
546 |
el = doc.createElementNS(namespace, "javadoc-built-to"); // NOI18N |
507 |
el.appendChild(doc.createTextNode(javadoc)); |
547 |
el.appendChild(doc.createTextNode(javadoc)); |
508 |
cuEl.appendChild(el); |
548 |
cuEl.appendChild(el); |
Lines 517-523
Link Here
|
517 |
aux.putConfigurationFragment(data, true); |
557 |
aux.putConfigurationFragment(data, true); |
518 |
} |
558 |
} |
519 |
|
559 |
|
520 |
|
|
|
521 |
/** |
560 |
/** |
522 |
* Structure describing compilation unit. |
561 |
* Structure describing compilation unit. |
523 |
* Data in the struct are in the same format as they are stored in XML. |
562 |
* Data in the struct are in the same format as they are stored in XML. |
Lines 959-962
Link Here
|
959 |
props.setProperty(key, value); |
998 |
props.setProperty(key, value); |
960 |
} |
999 |
} |
961 |
|
1000 |
|
|
|
1001 |
private static boolean needsNS3(final JavaCompilationUnit unit) { |
1002 |
if (unit.classpath != null) { |
1003 |
for (JavaCompilationUnit.CP cp : unit.classpath) { |
1004 |
if ("processor".equals(cp.mode)) { //NOI18N |
1005 |
return true; |
1006 |
} |
1007 |
} |
1008 |
} |
1009 |
if (unit.sourceLevel != null) { |
1010 |
final SpecificationVersion JAVA_6 = new SpecificationVersion("1.6"); //NOI18N |
1011 |
final SpecificationVersion JAvA_7 = new SpecificationVersion("1.7"); //NOI18N |
1012 |
final SpecificationVersion current = new SpecificationVersion(unit.sourceLevel); |
1013 |
if (JAVA_6.equals(current) || JAvA_7.equals(current)) { |
1014 |
return true; |
1015 |
} |
1016 |
} |
1017 |
return false; |
1018 |
} |
1019 |
|
962 |
} |
1020 |
} |