Skip to content

Commit

Permalink
Fix LayerBuilder#absolutizeResource for default package and fix textm…
Browse files Browse the repository at this point in the history
…ate unittests
  • Loading branch information
matthiasblaesing committed Nov 16, 2024
1 parent d92b25c commit 4c79ffb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public void testGrammarOK() throws Exception {
content.append((char) read);
}

assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.2//EN\"\n" +
" \"http://www.netbeans.org/dtds/filesystem-1_2.dtd\">\n" +
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.2//EN\" \"http://www.netbeans.org/dtds/filesystem-1_2.dtd\">\n" +
"<filesystem>\n" +
" <folder name=\"Editors\">\n" +
" <folder name=\"text\">\n" +
Expand Down Expand Up @@ -122,9 +120,7 @@ public void testInjectionGrammarOK() throws Exception {
content.append((char) read);
}

assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.2//EN\"\n" +
" \"http://www.netbeans.org/dtds/filesystem-1_2.dtd\">\n" +
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.2//EN\" \"http://www.netbeans.org/dtds/filesystem-1_2.dtd\">\n" +
"<filesystem>\n" +
" <folder name=\"Editors\">\n" +
" <file name=\"injection-grammar.json\" url=\"nbresloc:/injection-grammar.json\">\n" +
Expand Down
1 change: 0 additions & 1 deletion platform/openide.filesystems/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test.config.stableBTD.excludes=\
**/FileUtilTest.class,\
**/FsMimeResolverTest.class,\
**/JarFileSystemTest.class,\
**/LayerBuilderTest.class,\
**/LayerGenerationExceptionTest.class,\
**/LocalFileSystemTest.class,\
**/MemoryFileSystemTest.class,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 4c79ffb

Please sign in to comment.