--- a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java Wed Mar 23 06:34:05 2011 +0300 +++ a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java Wed Mar 23 11:13:09 2011 +0100 @@ -65,6 +65,7 @@ import javax.swing.Action; import javax.swing.JSeparator; import javax.swing.KeyStroke; +import javax.tools.Diagnostic.Kind; import javax.tools.FileObject; import javax.tools.StandardLocation; import org.openide.awt.ActionID; @@ -255,22 +256,33 @@ } } if (ar.iconBase().length() > 0) { - boolean found = false; + FileObject res = null; for (StandardLocation l : StandardLocation.values()) { + if (res != null) { + break; + } try { - processingEnv.getFiler().getResource(l, "", ar.iconBase()); - found = true; - break; + FileObject fo = processingEnv.getFiler().getResource(l, "", ar.iconBase()); + final InputStream is = fo.openInputStream(); + if (is != null) { + res = fo; + is.close(); + } + } catch (NullPointerException ex) { + continue; } catch (IOException ex) { continue; } catch (IllegalArgumentException x) { throw new LayerGenerationException("Problem with " + ar.iconBase() + " (should be resource path with no leading slash)", e); } } - if (!found) { - throw new LayerGenerationException( - "Cannot find iconBase file at " + ar.iconBase(), e - ); + if (res == null) { + String msg = "Cannot find iconBase file at " + ar.iconBase(); // NOI18N + if (isJDK7()) { + throw new LayerGenerationException(msg, e); + } else { + processingEnv.getMessager().printMessage(Kind.MANDATORY_WARNING, msg, e); + } } f.stringvalue("iconBase", ar.iconBase()); } @@ -446,4 +458,13 @@ before.write(); } } + + static boolean isJDK7() { + try { + Class.forName("java.lang.AutoCloseable"); // NOI18N + return true; + } catch (ClassNotFoundException ex) { + return false; + } + } } --- a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java Wed Mar 23 06:34:05 2011 +0300 +++ a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java Wed Mar 23 11:13:09 2011 +0100 @@ -39,6 +39,7 @@ package org.netbeans.modules.openide.awt; +import java.io.File; import java.awt.Component; import javax.swing.JComponent; import javax.swing.JMenuItem; @@ -843,7 +844,6 @@ assertFalse("Compilation has to fail:\n" + os, r); } - /* #196933: will only pass when using JDK 7 javac: public void testWrongPointerToIcon() throws IOException { clearWorkDir(); AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", @@ -863,11 +863,40 @@ ); ByteArrayOutputStream os = new ByteArrayOutputStream(); boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); - assertFalse("Compilation has to fail:\n" + os, r); + if (ActionProcessor.isJDK7()) { + assertFalse("Compilation has to fail:\n" + os, r); + } else { + assertTrue("Too bad on JDK6 we have to succeed:\n" + os, r); + } if (!os.toString().contains("does/not/exist.png")) { fail("Shall contain warning about does/not/exist.png resource:\n" + os); } } - */ - + public void testGoodPointerToIcon() throws IOException { + clearWorkDir(); + + File icons = new File(getWorkDir(), "icons"); + File existsPng = new File(new File(icons, "does"), "exist.png"); + existsPng.getParentFile().mkdirs(); + existsPng.createNewFile(); + + AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", + "import org.openide.awt.ActionRegistration;\n" + + "import org.openide.awt.ActionReference;\n" + + "import org.openide.awt.ActionID;\n" + + "import org.openide.util.actions.Presenter;\n" + + "import java.awt.event.*;\n" + + "import java.util.List;\n" + + "import javax.swing.*;\n" + + "@ActionID(category=\"Tools\",id=\"my.action\")" + + "@ActionRegistration(displayName=\"AAA\", key=\"K\", iconBase=\"does/exist.png\") " + + "@ActionReference(path=\"manka\", position=11)" + + "public class A implements ActionListener {\n" + + " public void actionPerformed(ActionEvent e) {}" + + "}\n" + ); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), new File[] { icons, null }, os); + assertTrue("Compilation has to succeed:\n" + os, r); + } } --- a/openide.util.lookup/test/unit/src/org/openide/util/test/AnnotationProcessorTestUtils.java Wed Mar 23 06:34:05 2011 +0300 +++ a/openide.util.lookup/test/unit/src/org/openide/util/test/AnnotationProcessorTestUtils.java Wed Mar 23 11:13:09 2011 +0100 @@ -100,7 +100,7 @@ * @param src a source root (runs javac on all *.java it finds matching {@code srcIncludes}) * @param srcIncludes a pattern of source files names without path to compile (useful for testing incremental compiles), or null for all * @param dest a dest dir to compile classes to - * @param cp classpath entries; if null, use Java classpath of test + * @param cp classpath entries; if null, use Java classpath of test; if one of the elements is null => append Java classpath of the test * @param stderr output stream to print messages to, or null for test console (i.e. do not capture) * @return true if compilation succeeded, false if it failed */ @@ -110,6 +110,11 @@ if (cp != null) { StringBuilder b = new StringBuilder(); for (File entry : cp) { + if (entry == null) { + b.append(File.pathSeparatorChar); + b.append(System.getProperty("java.class.path")); + continue; + } b.append(File.pathSeparatorChar); b.append(entry.getAbsolutePath()); }