From 4c79ffbb7711504e7eaa1456507cae67d5197a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 17 Nov 2024 00:17:47 +0100 Subject: [PATCH] Fix LayerBuilder#absolutizeResource for default package and fix textmate unittests --- .github/workflows/main.yml | 3 +++ .../CreateRegistrationProcessorTest.java | 8 ++------ .../nbproject/project.properties | 1 - .../filesystems/annotations/LayerBuilder.java | 9 ++++++++- .../annotations/LayerBuilderTest.java | 19 +++++++++++++++++++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8144307b8d41..e52a4d63b3ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -758,6 +758,9 @@ jobs: - name: ide/team.commons run: ant $OPTS -f ide/team.commons test + - name: ide/textmate.lexer + run: ant $OPTS -f ide/textmate.lexer test + - name: ide/terminal.nb run: ant $OPTS -f ide/terminal.nb test diff --git a/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java b/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java index 89c32126dce5..4cbc268c93a7 100644 --- a/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java +++ b/ide/textmate.lexer/test/unit/src/org/netbeans/modules/textmate/lexer/CreateRegistrationProcessorTest.java @@ -74,9 +74,7 @@ public void testGrammarOK() throws Exception { content.append((char) read); } - assertEquals("\n" + - "\n" + + assertEquals("\n" + "\n" + " \n" + " \n" + @@ -122,9 +120,7 @@ public void testInjectionGrammarOK() throws Exception { content.append((char) read); } - assertEquals("\n" + - "\n" + + assertEquals("\n" + "\n" + " \n" + " \n" + diff --git a/platform/openide.filesystems/nbproject/project.properties b/platform/openide.filesystems/nbproject/project.properties index c886c67b028f..5cb94cb60350 100644 --- a/platform/openide.filesystems/nbproject/project.properties +++ b/platform/openide.filesystems/nbproject/project.properties @@ -30,7 +30,6 @@ test.config.stableBTD.excludes=\ **/FileUtilTest.class,\ **/FsMimeResolverTest.class,\ **/JarFileSystemTest.class,\ - **/LayerBuilderTest.class,\ **/LayerGenerationExceptionTest.class,\ **/LocalFileSystemTest.class,\ **/MemoryFileSystemTest.class,\ diff --git a/platform/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java b/platform/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java index 6ed92686a9f4..3dd3f57a197c 100644 --- a/platform/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java +++ b/platform/openide.filesystems/src/org/openide/filesystems/annotations/LayerBuilder.java @@ -372,7 +372,14 @@ public static String absolutizeResource(Element originatingElement, String resou return resource.substring(1); } else { try { - return new URI(null, findPackage(originatingElement).replace('.', '/') + "/", null).resolve(new URI(null, resource, null)).getPath(); + String packagePath = findPackage(originatingElement).replace('.', '/'); + String pathPrefix; + if(packagePath.isEmpty()) { + pathPrefix = ""; + } else { + pathPrefix = packagePath + "/"; + } + return new URI(null, pathPrefix, null).resolve(new URI(null, resource, null)).getPath(); } catch (URISyntaxException x) { throw new LayerGenerationException(x.toString(), originatingElement); } diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java index 915c6e86d5ab..f35df95ac31b 100644 --- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java +++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/annotations/LayerBuilderTest.java @@ -28,6 +28,7 @@ import java.lang.reflect.Array; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Set; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; @@ -42,6 +43,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; +import org.junit.Assume; import org.netbeans.junit.NbTestCase; import org.openide.filesystems.FileObject; import org.openide.filesystems.XMLFileSystem; @@ -271,6 +273,7 @@ public void testBundleKeyDefinedUsingMessages() throws Exception { * @throws Exception */ public void testWarningsFromProcessors() throws Exception { + Assume.assumeTrue("Warnings are locale specific and only configured for english locales", Locale.getDefault().getLanguage().equals("en")); AnnotationProcessorTestUtils.makeSource(src, "p.C", "@" + A.class.getCanonicalName() + "(displayName=\"#k\") @org.openide.util.NbBundle.Messages(\"k=v\") public class C {}"); File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1"); TestFileUtils.writeFile(new File(src, "p/resources/x2"), "x2"); @@ -330,6 +333,22 @@ public void testAbsolutizeAndValidateResourcesExistent() throws Exception { assertEquals("p/resources/x2", f.getAttribute("r2")); } + public void testAbsolutizeAndValidateResourcesExistentDefaultPackage() throws Exception { + AnnotationProcessorTestUtils.makeSource(src, "C", "@" + V.class.getCanonicalName() + "(r1=\"other/x1\", r2=\"x2\") public class C {}"); + File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1"); + TestFileUtils.writeFile(new File(src, "x2"), "x2"); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + boolean status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, BaseUtilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err); + String msgs = err.toString(); + assertTrue(msgs, status); + assertTrue(msgs, msgs.contains("r1=x1")); + assertTrue(msgs, msgs.contains("r2=x2")); + FileObject f = new XMLFileSystem(BaseUtilities.toURI(new File(dest, "META-INF/generated-layer.xml")).toURL()).findResource("f"); + assertNotNull(f); + assertEquals("other/x1", f.getAttribute("r1")); + assertEquals("x2", f.getAttribute("r2")); + } + public void testValidateResourceNonexistent() throws Exception { AnnotationProcessorTestUtils.makeSource(src, "p.C", "@" + V.class.getCanonicalName() + "(r1=\"other/x1\", r2=\"resourcez/x2\") public class C {}"); File j = TestFileUtils.writeZipFile(new File(getWorkDir(), "cp.jar"), "other/x1:x1");