Issue #188686: permit Java identifiers as path components in module code name bases. diff --git a/openide.modules/apichanges.xml b/openide.modules/apichanges.xml --- a/openide.modules/apichanges.xml +++ b/openide.modules/apichanges.xml @@ -50,6 +50,23 @@ Modules API + + + Module names can contain java keywords + + + + + +

+ Naming rules for module code name bases are now relaxed. + The name of a module can contain a Java keyword like + org.mysite.import.something, etc. +

+
+ + +
New native library lookup mechanism diff --git a/openide.modules/manifest.mf b/openide.modules/manifest.mf --- a/openide.modules/manifest.mf +++ b/openide.modules/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.modules OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties -OpenIDE-Module-Specification-Version: 7.18 +OpenIDE-Module-Specification-Version: 7.19 diff --git a/openide.modules/src/org/openide/modules/Dependency.java b/openide.modules/src/org/openide/modules/Dependency.java --- a/openide.modules/src/org/openide/modules/Dependency.java +++ b/openide.modules/src/org/openide/modules/Dependency.java @@ -51,6 +51,7 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import java.util.regex.Pattern; import org.openide.util.Utilities; /** A dependency a module can have. Since version 7.10 this class is @@ -196,32 +197,13 @@ } // Now check that the rest is a valid package. - StringTokenizer tok = new StringTokenizer(base, ".", true); // NOI18N - - if ((tok.countTokens() % 2) == 0) { - throw new NumberFormatException("Even number of pieces: " + base); // NOI18N - } - - boolean expectingPath = true; - - while (tok.hasMoreTokens()) { - if (expectingPath) { - expectingPath = false; - - String nt = tok.nextToken(); - if (!Utilities.isJavaIdentifier(nt) && !"enum".equals (nt)) { // NOI18N - throw new IllegalArgumentException("Bad package component in " + base); // NOI18N - } - } else { - if (!".".equals(tok.nextToken())) { // NOI18N - throw new NumberFormatException("Expected dot in code name: " + base); // NOI18N - } - - expectingPath = true; - } + if (!FQN.matcher(base).matches()) { + throw new IllegalArgumentException("Malformed dot-separated identifier: " + base); } } - + private static final String IDENTIFIER = "(?:\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)"; // NOI18N + private static final Pattern FQN = Pattern.compile(IDENTIFIER + "(?:[.]" + IDENTIFIER + ")*"); // NOI18N + /** Parse dependencies from tags. * @param type like Dependency.type * @param body actual text of tag body; if null, returns nothing diff --git a/openide.modules/test/unit/src/org/openide/modules/DependencyTest.java b/openide.modules/test/unit/src/org/openide/modules/DependencyTest.java --- a/openide.modules/test/unit/src/org/openide/modules/DependencyTest.java +++ b/openide.modules/test/unit/src/org/openide/modules/DependencyTest.java @@ -137,6 +137,11 @@ assertEquals(Dependency.COMPARE_ANY, d2.getComparison()); } + public void testAllowJavaIdentifiers() throws Exception { + Set single = Dependency.create(Dependency.TYPE_MODULE, "acme.j2ee.webapp.import"); + assertEquals("One item created: " + single, 1, single.size()); + } + private void misparse(int type, String s) { try { Dependency.create(type, s); @@ -222,6 +227,11 @@ misparse(Dependency.TYPE_JAVA, "Java > 1.4.0, Java = 1.4.0_01"); } + public void testMisparseNumbers() throws Exception { + misparse(Dependency.TYPE_MODULE, "acme.2.webapp.importing"); + misparse(Dependency.TYPE_MODULE, "acme.2xyz.webapp.importing"); + } + public void testConstants() throws Exception { assertEquals("Java", Dependency.JAVA_NAME); assertNotNull(Dependency.JAVA_SPEC);