Skip to content

Commit

Permalink
Merge pull request #6617 from mbien/platform-to-11
Browse files Browse the repository at this point in the history
Move platform jobs to 11
  • Loading branch information
mbien committed Oct 27, 2023
2 parents 1893738 + 03af07e commit fb08355
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 177 deletions.
231 changes: 120 additions & 111 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,6 @@ public void testFailsWithoutAnIcon() throws Exception {
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "pkg.Test", src);
ByteArrayOutputStream os = new ByteArrayOutputStream();
boolean res = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
if (AnnotationProcessorTestUtils.searchClasspathBroken()) {
assertTrue("Alas, compilation succeded", res);
return;
}
assertFalse("Compilation should fail:\n" + os.toString(), res);
assertTrue("because of missing icon:\n" + os.toString(), os.toString().contains("iconBase"));
assertTrue("because of missing icon:\n" + os.toString(), os.toString().contains("Cannot find resource pkg/none-existing.png"));
Expand Down
19 changes: 10 additions & 9 deletions platform/favorites/src/org/netbeans/modules/favorites/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,23 +414,24 @@ private static DataShadow findShadow (DataFolder f, DataObject dobj) {
return null;
}

// what order is this? requires comment
public static void reorderAfterAddition(final DataFolder favourities, final DataObject[] children, final List<? extends DataObject> listAdd) {
List<DataObject> listDest = new ArrayList<>();
if (listAdd.size() > 0) {
//Insert new nodes just before last (root) node
DataObject root = null;
//Find root
for (DataObject children1 : children) {
FileObject fo = children1.getPrimaryFile();
if ("Favorites/Root.instance".equals(fo.getPath())) {
//NOI18N
root = children1;
for (DataObject child : children) {
FileObject fo = child.getPrimaryFile();
if ("Favorites/Root.instance".equals(fo.getPath())) { //NOI18N
root = child;
break;
}
}
if (root != null) {
for (DataObject children1 : children) {
if (!root.equals(children1)) {
listDest.add(children1);
for (DataObject child : children) {
if (!root.equals(child)) {
listDest.add(child);
}
}
listDest.addAll(listAdd);
Expand All @@ -440,7 +441,7 @@ public static void reorderAfterAddition(final DataFolder favourities, final Data
listDest.addAll(listAdd);
}
//Set desired order
DataObject [] newOrder = listDest.toArray(new DataObject[listDest.size()]);
DataObject [] newOrder = listDest.toArray(new DataObject[0]);
try {
favourities.setOrder(newOrder);
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.RandomlyFails;
import org.netbeans.modules.favorites.FavoritesNode;
import org.netbeans.modules.favorites.RootsTest;
import org.openide.explorer.ExplorerManager;
import static org.junit.Assert.*;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
Expand Down Expand Up @@ -68,8 +68,8 @@ public void setUp() throws IOException {
public void tearDown() throws IOException {
// setup favorites to its initial state
List<FileObject> roots = fav.getFavoriteRoots();
fav.remove(roots.toArray(new FileObject[roots.size()]));
fav.add(origFavs.toArray(new FileObject[origFavs.size()]));
fav.remove(roots.toArray(new FileObject[0]));
fav.add(origFavs.toArray(new FileObject[0]));
}

public void testBasicCycle() throws Exception {
Expand All @@ -78,16 +78,26 @@ public void testBasicCycle() throws Exception {
assertEquals("Fresh favorites contain home folder.", home, FileUtil.toFile(origFavs.get(0)));
assertTrue("isInFavorites consistent with getFavoriteRoots",
fav.isInFavorites(FileUtil.toFileObject(home)));

fav.add(wd);
assertEquals(2, fav.getFavoriteRoots().size());
fav.add(jh, file);

// this doesn't work: at some point in org.netbeans.modules.favorites.Actions, getChildren() seems to sort alphabetically,
// which makes order somewhat input dependant (JDK name!). Re-ordering is done too, but this does not influence the children.
// -> lets add them sequentially for now
fav.add(jh); fav.add(file); // TODO
// fav.add(jh, file);
assertEquals(4, fav.getFavoriteRoots().size());

fav.add(jh, file); // re-adding already contained roots does nothing
assertEquals(4, fav.getFavoriteRoots().size());

// check content
List<FileObject> expected = Arrays.asList(FileUtil.toFileObject(home), wd, jh, file);
assertEquals("unexpected favorites content", new HashSet<>(expected), new HashSet<>(fav.getFavoriteRoots()));

// check correct ordering
List<FileObject> content = Arrays.asList(FileUtil.toFileObject(home), wd, jh, file);
assertEquals("Favorites remain in the same order", content, fav.getFavoriteRoots());
assertEquals("unexpected favorites order", expected, fav.getFavoriteRoots());

// check removal of all values
fav.remove(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,6 @@ public void testSeparatorAfterIsAfter() throws IOException {

public void testWrongPointerToIcon() throws IOException {
clearWorkDir();
if (AnnotationProcessorTestUtils.searchClasspathBroken()) {
System.err.println("#196933: testWrongPointerToIcon will only pass when using JDK 7 javac, skipping");
return;
}
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A",
"import org.openide.awt.ActionRegistration;\n" +
"import org.openide.awt.ActionReference;\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,9 @@ public void testNonpublicListenerClass() throws Exception {
);
ByteArrayOutputStream os = new ByteArrayOutputStream();
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
if (!os.toString().contains("is not public")) {
fail("Nonpublic listener type must be reported" + os);
String msg = os.toString();
if (!msg.contains("cannot find symbol") && !msg.contains("is not public")) {
fail("Nonpublic listener type must be reported" + msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ public File shadowFile(String target, String folder, String name) {

/**
* Validates a resource named in an annotation.
* <p>Note that resources found in the binary classpath (if permitted)
* cannot actually be located when running inside javac on JDK 6 (see #196933 for discussion), in which case
* no exception is thrown but the return value may not permit {@link FileObject#openInputStream}.
* <span class="nonnormative">{@code AnnotationProcessorTestUtils.searchClasspathBroken} should be used in unit tests affected by this bug.</span>
* <p>Also remember that the binary compilation classpath for an Ant-based NetBeans module does
* <p>Note that the binary compilation classpath for an Ant-based NetBeans module does
* not include non-public packages.
* (As of the 7.1 harness it does include non-classfile resources from public packages of module dependencies.)
* The processorpath does contain all of these but it is not consulted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void testAbsolutizeAndValidateResourcesExistent() throws Exception {
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") ^ AnnotationProcessorTestUtils.searchClasspathBroken());
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);
Expand All @@ -339,13 +339,13 @@ public void testValidateResourceNonexistent() throws Exception {
String msgs = err.toString();
assertFalse(msgs, status);
assertTrue(msgs, msgs.contains("resourcez"));
assertTrue(msgs, msgs.contains("r1=x1") ^ AnnotationProcessorTestUtils.searchClasspathBroken());
assertTrue(msgs, msgs.contains("r1=x1"));
AnnotationProcessorTestUtils.makeSource(src, "p.C", "@" + V.class.getCanonicalName() + "(r1=\"othr/x1\", r2=\"resources/x2\") public class C {}");
err = new ByteArrayOutputStream();
status = AnnotationProcessorTestUtils.runJavac(src, null, dest, new File[] {j, BaseUtilities.toFile(LayerBuilderTest.class.getProtectionDomain().getCodeSource().getLocation().toURI())}, err);
msgs = err.toString();
assertFalse(msgs, status ^ AnnotationProcessorTestUtils.searchClasspathBroken());
assertTrue(msgs, msgs.contains("othr") ^ AnnotationProcessorTestUtils.searchClasspathBroken());
assertFalse(msgs, status);
assertTrue(msgs, msgs.contains("othr"));
}

// XXX verify that CLASS_OUTPUT may be used as well
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -58,9 +55,7 @@ private AnnotationProcessorTestUtils() {}
public static void makeSource(File dir, String clazz, String... content) throws IOException {
File f = new File(dir, clazz.replace('.', File.separatorChar) + ".java");
f.getParentFile().mkdirs();
Writer w = new FileWriter(f);
try {
PrintWriter pw = new PrintWriter(w);
try (Writer w = new FileWriter(f); PrintWriter pw = new PrintWriter(w)) {
String pkg = clazz.replaceFirst("\\.[^.]+$", "");
if (!pkg.equals(clazz) && !clazz.endsWith(".package-info")) {
pw.println("package " + pkg + ";");
Expand All @@ -69,8 +64,6 @@ public static void makeSource(File dir, String clazz, String... content) throws
pw.println(line);
}
pw.flush();
} finally {
w.close();
}
}

Expand Down Expand Up @@ -137,7 +130,7 @@ public static boolean runJavac(File src, String srcIncludes, File dest, File[] c
),
compiler);
//System.err.println("running javac with args: " + args);
return compiler.run(null, null, stderr, args.toArray(new String[args.size()])) == 0;
return compiler.run(null, null, stderr, args.toArray(new String[0])) == 0;
}
private static void scan(List<String> names, File f, String includes) {
if (f.isDirectory()) {
Expand All @@ -149,25 +142,4 @@ private static void scan(List<String> names, File f, String includes) {
}
}

/**
* Checks whether the version of javac in use suffers from #6929404.
* If so, calls to {@code LayerBuilder.validateResource(..., true)} will return normally
* even if the resource path does not exist, so tests must be more lenient.
*/
public static boolean searchClasspathBroken() {
// Cannot just check for e.g. SourceVersion.RELEASE_7 because we might be running JDK 6 javac w/ JDK 7 boot CP, and that is in JRE.
// (Anyway libs.javacapi/external/nb-javac-api.jar, in the test's normal boot CP, has this!)
// Filter.class added in 7ae4016c5938, not long after f3323b1c65ee which we rely on for this to work.
// Also cannot just check Class.forName(...) since tools.jar not in CP but ToolProvider loads it specially - not true anymore since JDK 9 ToolProvider does not look for tools.jar.
final String res = "com/sun/tools/javac/util/Filter.class"; //NOI18N
final CodeSource codeSource = ToolProvider.getSystemJavaCompiler().getClass().getProtectionDomain().getCodeSource();
if (codeSource != null) {
//Compiler from URLClassLoader - JDK7, JDK8 javac
return new URLClassLoader(new URL[] {codeSource.getLocation()}).findResource(res) == null;
} else {
//Compiler from Boot, Ext, System ClassLoader - JDK9 javac
return ClassLoader.getSystemClassLoader().getResource(res) == null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void testBadIconBase() throws Exception {
" public void removePropertyChangeListener(java.beans.PropertyChangeListener l) {}",
"}");
ByteArrayOutputStream err = new ByteArrayOutputStream();
assertFalse(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err) ^ AnnotationProcessorTestUtils.searchClasspathBroken());
assertTrue(err.toString(), err.toString().contains("no/such/icon") ^ AnnotationProcessorTestUtils.searchClasspathBroken());
assertFalse(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, err));
assertTrue(err.toString(), err.toString().contains("no/such/icon"));
TestFileUtils.writeFile(new File(src, "no/such/icon"), "whatever");
assertTrue(AnnotationProcessorTestUtils.runJavac(src, null, dest, null, null));
}
Expand Down

0 comments on commit fb08355

Please sign in to comment.