diff --git a/java.freeform/apichanges.xml b/java.freeform/apichanges.xml --- a/java.freeform/apichanges.xml +++ b/java.freeform/apichanges.xml @@ -48,6 +48,17 @@ + + Added freeform-project-java/3 schema to support annotation processors and source levels 1.6 and 1.7 + + + + + + Added freeform-project-java/3 schema to support annotation processors and source levels 1.6 and 1.7 + + + Declare SPI packages for friends only diff --git a/java.freeform/manifest.mf b/java.freeform/manifest.mf --- a/java.freeform/manifest.mf +++ b/java.freeform/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.java.freeform/1 -OpenIDE-Module-Specification-Version: 1.15 +OpenIDE-Module-Specification-Version: 1.16 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/freeform/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/java/freeform/resources/layer.xml AutoUpdate-Show-In-Client: false diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java b/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/Classpaths.java @@ -189,7 +189,7 @@ } } // Need to create it. - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return null; } @@ -254,7 +254,7 @@ for (String type : TYPES) { _registeredClasspaths.put(type, new HashSet()); } - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return; } @@ -567,7 +567,7 @@ } private Element findCompilationUnit() { - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return null; } diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java b/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java @@ -611,7 +611,7 @@ } private List compilationUnits() { - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return Collections.emptyList(); } @@ -745,7 +745,7 @@ String findSourceLevel(String sources) { Element compilationUnitEl = findCompilationUnit(sources); if (compilationUnitEl != null) { - Element sourceLevel = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_2); + Element sourceLevel = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3); if (sourceLevel != null) { return Util.findText(sourceLevel); } diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/JavaFreeformFileBuiltQuery.java b/java.freeform/src/org/netbeans/modules/java/freeform/JavaFreeformFileBuiltQuery.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/JavaFreeformFileBuiltQuery.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/JavaFreeformFileBuiltQuery.java @@ -94,7 +94,7 @@ ERR.log(ErrorManager.INFORMATIONAL, "JavaFreeformFileBuiltQuery.createDelegateTo start"); // NOI18N } - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); List from = new ArrayList(); List to = new ArrayList(); diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java b/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java @@ -58,6 +58,7 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileUtil; +import org.openide.modules.SpecificationVersion; import org.openide.util.Exceptions; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -358,8 +359,23 @@ } Util.putPrimaryConfigurationData(helper, data); } - - + + /** + * Returns {@link Element} for {@link JavaCompilationUnit}. + * @param aux AuxiliaryConfiguration instance + * @return {@link Element} representing JavaCompilationUnit instances or null + */ + public static Element getJavaCompilationUnits (final AuxiliaryConfiguration aux) { + Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); + if (data == null) { + data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + } + if (data == null) { + data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + } + return data; + } + /** * Read Java compilation units from the project. * @param helper AntProjectHelper instance @@ -370,10 +386,7 @@ AntProjectHelper helper, AuxiliaryConfiguration aux) { //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); List list = new ArrayList(); - Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); - if (data == null) { - data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); - } + final Element data = getJavaCompilationUnits(aux); if (data == null) { return list; } @@ -432,6 +445,14 @@ AuxiliaryConfiguration aux, List compUnits) { //assert ProjectManager.mutex().isWriteAccess(); // First check whether we need /2 data. + boolean need3 = false; + for (JavaCompilationUnit unit : compUnits) { + if (needsNS3(unit)) { + need3 = true; + break; + } + } + // Second check whether we need /2 data. boolean need2 = false; for (JavaCompilationUnit unit : compUnits) { if (unit.isTests || (unit.javadoc != null && !unit.javadoc.isEmpty())) { @@ -440,26 +461,45 @@ } } String namespace; - // Look for existing /2 data. - Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + // Look for existing /3 data. + Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (data != null) { - // Fine, use it as is. - namespace = JavaProjectNature.NS_JAVA_2; - } else { - // Or, for existing /1 data. - namespace = need2 ? JavaProjectNature.NS_JAVA_2 : JavaProjectNature.NS_JAVA_1; - data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + namespace = JavaProjectNature.NS_JAVA_3; + } + else { + // Look for existing /2 data and possibly update to /3 + data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); if (data != null) { - if (need2) { - // Have to upgrade. - aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + namespace = need3 ? JavaProjectNature.NS_JAVA_3 : JavaProjectNature.NS_JAVA_2; + if (need3) { + // Have to upgrade to /3 + aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). - createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); - } // else can use it as is + createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); + } } else { - // Create /1 or /2 data acc. to need. - data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). - createElementNS(namespace, JavaProjectNature.EL_JAVA); + //Look for existing /1 and possibly update to /2 or /3 as needed + data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + namespace = need3 ? JavaProjectNature.NS_JAVA_3 : need2 ? JavaProjectNature.NS_JAVA_2 : JavaProjectNature.NS_JAVA_1; + if (data != null) { + + if (need3) { + // Have to upgrade to /3 + aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). + createElementNS(JavaProjectNature.NS_JAVA_3, JavaProjectNature.EL_JAVA); + } + else if (need2) { + // Have to upgrade to /2 + aux.removeConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). + createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); + } // else can use it as is + } else { + // Create a new /1, /2 or /3 data acc. to need. + data = Util.getPrimaryConfigurationData(helper).getOwnerDocument(). + createElementNS(namespace, JavaProjectNature.EL_JAVA); + } } } Document doc = data.getOwnerDocument(); @@ -478,7 +518,7 @@ } } if (cu.isTests) { - assert namespace.equals(JavaProjectNature.NS_JAVA_2); + assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); cuEl.appendChild(doc.createElementNS(namespace, "unit-tests")); // NOI18N } if (cu.classpath != null) { @@ -502,7 +542,7 @@ Iterator it3 = cu.javadoc.iterator(); while (it3.hasNext()) { String javadoc = (String) it3.next(); - assert namespace.equals(JavaProjectNature.NS_JAVA_2); + assert namespace.equals(JavaProjectNature.NS_JAVA_2) || namespace.equals(JavaProjectNature.NS_JAVA_3); el = doc.createElementNS(namespace, "javadoc-built-to"); // NOI18N el.appendChild(doc.createTextNode(javadoc)); cuEl.appendChild(el); @@ -517,7 +557,6 @@ aux.putConfigurationFragment(data, true); } - /** * Structure describing compilation unit. * Data in the struct are in the same format as they are stored in XML. @@ -959,4 +998,23 @@ props.setProperty(key, value); } + private static boolean needsNS3(final JavaCompilationUnit unit) { + if (unit.classpath != null) { + for (JavaCompilationUnit.CP cp : unit.classpath) { + if ("processor".equals(cp.mode)) { //NOI18N + return true; + } + } + } + if (unit.sourceLevel != null) { + final SpecificationVersion JAVA_6 = new SpecificationVersion("1.6"); //NOI18N + final SpecificationVersion JAvA_7 = new SpecificationVersion("1.7"); //NOI18N + final SpecificationVersion current = new SpecificationVersion(unit.sourceLevel); + if (JAVA_6.equals(current) || JAvA_7.equals(current)) { + return true; + } + } + return false; + } + } diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java b/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/JavaProjectNature.java @@ -68,6 +68,7 @@ public static final String NS_JAVA_1 = "http://www.netbeans.org/ns/freeform-project-java/1"; // NOI18N public static final String NS_JAVA_2 = "http://www.netbeans.org/ns/freeform-project-java/2"; // NOI18N + public static final String NS_JAVA_3 = "http://www.netbeans.org/ns/freeform-project-java/3"; //NOI18N public static final String EL_JAVA = "java-data"; // NOI18N public static final String STYLE_PACKAGES = "packages"; // NOI18N diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/JavadocQuery.java b/java.freeform/src/org/netbeans/modules/java/freeform/JavadocQuery.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/JavadocQuery.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/JavadocQuery.java @@ -72,7 +72,7 @@ } public JavadocForBinaryQuery.Result findJavadoc(URL binaryRoot) { - Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (data != null) { for (Element cu : Util.findSubElements(data)) { assert cu.getLocalName().equals("compilation-unit") : cu; diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java b/java.freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/LookupProviderImpl.java @@ -100,8 +100,7 @@ } public static boolean isMyProject(AuxiliaryConfiguration aux) { - return aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true) != null || - aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true) != null; + return JavaProjectGenerator.getJavaCompilationUnits(aux) != null; } private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { @@ -143,12 +142,28 @@ } public Element getConfigurationFragment(String elementName, String namespace, boolean shared) { - if (elementName.equals(JavaProjectNature.EL_JAVA) && namespace.equals(JavaProjectNature.NS_JAVA_2) && shared) { - Element nue = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); - if (nue == null) { - Element old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); - if (old != null) { - nue = upgradeSchema(old); + if (elementName.equals(JavaProjectNature.EL_JAVA) && shared) { + Element nue = null; + if (namespace.equals(JavaProjectNature.NS_JAVA_3)) { + nue = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); + if (nue == null) { + Element old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + if (old != null) { + nue = upgradeSchema(old); + } else { + old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + if (old != null) { + nue = upgradeSchema(old); + } + } + } + } else if (namespace.equals(JavaProjectNature.NS_JAVA_2)) { + nue = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + if (nue == null) { + Element old = delegate.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); + if (old != null) { + nue = upgradeSchema(old, JavaProjectNature.NS_JAVA_2); + } } } return nue; @@ -166,13 +181,17 @@ } } - + static Element upgradeSchema(Element old) { + return upgradeSchema(old, JavaProjectNature.NS_JAVA_3); + } + + static Element upgradeSchema(final Element old, final String to) { Document doc = old.getOwnerDocument(); - Element nue = doc.createElementNS(JavaProjectNature.NS_JAVA_2, JavaProjectNature.EL_JAVA); - copyXMLTree(doc, old, nue, JavaProjectNature.NS_JAVA_2); + Element nue = doc.createElementNS(to, JavaProjectNature.EL_JAVA); + copyXMLTree(doc, old, nue, to); return nue; - } + } // Copied from org.netbeans.modules.java.j2seproject.UpdateHelper with changes; could be an API eventually: private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) { NodeList nl = from.getChildNodes(); diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/SourceForBinaryQueryImpl.java b/java.freeform/src/org/netbeans/modules/java/freeform/SourceForBinaryQueryImpl.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/SourceForBinaryQueryImpl.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/SourceForBinaryQueryImpl.java @@ -96,7 +96,7 @@ if (roots == null) { // Need to compute it. Easiest to compute them all at once. roots = new HashMap(); - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return null; } diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java b/java.freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/SourceLevelQueryImpl.java @@ -98,7 +98,7 @@ } } // Need to compute it. - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (java == null) { return null; } @@ -133,7 +133,7 @@ * Get the source level indicated in a compilation unit (or null if none is indicated). */ private String getLevel(Element compilationUnitEl) { - Element sourceLevelEl = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_2); + Element sourceLevelEl = Util.findElement(compilationUnitEl, "source-level", JavaProjectNature.NS_JAVA_3); if (sourceLevelEl != null) { return Util.findText(sourceLevelEl); } else { diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/TestQuery.java b/java.freeform/src/org/netbeans/modules/java/freeform/TestQuery.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/TestQuery.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/TestQuery.java @@ -115,11 +115,11 @@ private URL[][] findSourcesAndTests() { List sources = new ArrayList(); List tests = new ArrayList(); - Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); + Element data = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_3, true); if (data != null) { for (Element cu : Util.findSubElements(data)) { assert cu.getLocalName().equals("compilation-unit") : cu; - boolean isTests = Util.findElement(cu, "unit-tests", JavaProjectNature.NS_JAVA_2) != null; // NOI18N + boolean isTests = Util.findElement(cu, "unit-tests", JavaProjectNature.NS_JAVA_3) != null; // NOI18N for (Element pr : Util.findSubElements(cu)) { if (pr.getLocalName().equals("package-root")) { // NOI18N String rawtext = Util.findText(pr); diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/UsageLogger.java b/java.freeform/src/org/netbeans/modules/java/freeform/UsageLogger.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/UsageLogger.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/UsageLogger.java @@ -105,10 +105,7 @@ int compilationUnitsMissingBuiltTo = 0; int compilationUnitsMultipleRoots = 0; Set classpathEntries = new HashSet(); - Element java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, true); - if (java == null) { - java = aux.getConfigurationFragment(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_1, true); - } + Element java = JavaProjectGenerator.getJavaCompilationUnits(aux); if (java != null) { for (Element compilationUnitEl : Util.findSubElements(java)) { compilationUnits++; diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/resources/freeform-project-java-3.xsd b/java.freeform/src/org/netbeans/modules/java/freeform/resources/freeform-project-java-3.xsd new file mode 100644 --- /dev/null +++ b/java.freeform/src/org/netbeans/modules/java/freeform/resources/freeform-project-java-3.xsd @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/ui/Bundle.properties b/java.freeform/src/org/netbeans/modules/java/freeform/ui/Bundle.properties --- a/java.freeform/src/org/netbeans/modules/java/freeform/ui/Bundle.properties +++ b/java.freeform/src/org/netbeans/modules/java/freeform/ui/Bundle.properties @@ -75,6 +75,8 @@ LBL_SourceFoldersPanel_JDK13=JDK 1.3 LBL_SourceFoldersPanel_JDK14=JDK 1.4 LBL_SourceFoldersPanel_JDK15=JDK 1.5 +LBL_SourceFoldersPanel_JDK16=JDK 1.6 +LBL_SourceFoldersPanel_JDK17=JDK 1.7 LBL_SourceFoldersPanel_Package=Package Folder LBL_SourceFoldersPanel_Label=Label BTN_SourceFoldersPanel_addTestFolder=Add F&older... diff --git a/java.freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java b/java.freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java --- a/java.freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java +++ b/java.freeform/src/org/netbeans/modules/java/freeform/ui/SourceFoldersPanel.java @@ -143,9 +143,11 @@ } private void initSourceLevel() { - sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK13")); // NOI18N - sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK14")); // NOI18N - sourceLevel.addItem(org.openide.util.NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK15")); // NOI18N + sourceLevel.addItem(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK13")); // NOI18N + sourceLevel.addItem(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK14")); // NOI18N + sourceLevel.addItem(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK15")); // NOI18N + sourceLevel.addItem(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK16")); // NOI18N + sourceLevel.addItem(NbBundle.getMessage(SourceFoldersPanel.class, "LBL_SourceFoldersPanel_JDK17")); // NOI18N } private void updateButtons() { @@ -176,7 +178,11 @@ sourceLevel.setSelectedIndex(1); } else if (sourceLevelValue.equals("1.5")) { // NOI18N sourceLevel.setSelectedIndex(2); - } else { + } else if (sourceLevelValue.equals("1.6")) { // NOI18N + sourceLevel.setSelectedIndex(3); + } else if (sourceLevelValue.equals("1.7")) { // NOI18N + sourceLevel.setSelectedIndex(4); + }else { // user specified some other value in project.xml sourceLevel.addItem(sourceLevelValue); sourceLevel.setSelectedIndex(3); @@ -192,6 +198,8 @@ case 0: return "1.3"; // NOI18N case 1: return "1.4"; // NOI18N case 2: return "1.5"; // NOI18N + case 3: return "1.6"; // NOI18N + case 4: return "1.7"; // NOI18N default: return null; } } diff --git a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectNatureTest.java b/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectNatureTest.java --- a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectNatureTest.java +++ b/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectNatureTest.java @@ -59,19 +59,31 @@ super(name); } - public void testUpgradeSchema() throws Exception { + public void testUpgradeSchema1to2() throws Exception { + upgradeSchemaTestImpl(JavaProjectNature.NS_JAVA_1, JavaProjectNature.NS_JAVA_2); + } + + public void testUpgradeSchema2to3() throws Exception { + upgradeSchemaTestImpl(JavaProjectNature.NS_JAVA_2, JavaProjectNature.NS_JAVA_3); + } + + public void testUpgradeSchema1to3() throws Exception { + upgradeSchemaTestImpl(JavaProjectNature.NS_JAVA_1, JavaProjectNature.NS_JAVA_3); + } + + private void upgradeSchemaTestImpl(String from, String to) throws Exception { // Formatting has to be the same as Xerces' formatter produces for this test to pass: String xml1 = "\n" + - "\n" + + "\n" + " \n" + " hello\n" + " OK\n" + "\n"; - String xml2expected = xml1.replaceAll("/1", "/2"); + String xml2expected = xml1.replaceAll(from, to); Document doc1 = XMLUtil.parse(new InputSource(new StringReader(xml1)), false, true, null, null); Element el1 = doc1.getDocumentElement(); - Element el2 = LookupProviderImpl.upgradeSchema(el1); - Document doc2 = XMLUtil.createDocument(JavaProjectNature.EL_JAVA, JavaProjectNature.NS_JAVA_2, null, null); + Element el2 = LookupProviderImpl.upgradeSchema(el1,to); + Document doc2 = XMLUtil.createDocument(JavaProjectNature.EL_JAVA, to, null, null); doc2.removeChild(doc2.getDocumentElement()); doc2.appendChild(doc2.importNode(el2, true)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -79,5 +91,4 @@ String xml2actual = baos.toString("UTF-8").replaceAll(System.getProperty("line.separator"), "\n"); assertEquals("Correct upgrade result", xml2expected, xml2actual); } - }