This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 196933
Collapse All | Expand All

(-)a/openide.awt/src/org/netbeans/modules/openide/awt/ActionProcessor.java (-8 / +29 lines)
Lines 65-70 Link Here
65
import javax.swing.Action;
65
import javax.swing.Action;
66
import javax.swing.JSeparator;
66
import javax.swing.JSeparator;
67
import javax.swing.KeyStroke;
67
import javax.swing.KeyStroke;
68
import javax.tools.Diagnostic.Kind;
68
import javax.tools.FileObject;
69
import javax.tools.FileObject;
69
import javax.tools.StandardLocation;
70
import javax.tools.StandardLocation;
70
import org.openide.awt.ActionID;
71
import org.openide.awt.ActionID;
Lines 255-276 Link Here
255
                    }
256
                    }
256
                }
257
                }
257
                if (ar.iconBase().length() > 0) {
258
                if (ar.iconBase().length() > 0) {
258
                    boolean found = false;
259
                    FileObject res = null;
259
                    for (StandardLocation l : StandardLocation.values()) {
260
                    for (StandardLocation l : StandardLocation.values()) {
261
                        if (res != null) {
262
                            break;
263
                        }
260
                        try {
264
                        try {
261
                            processingEnv.getFiler().getResource(l, "", ar.iconBase());
265
                            FileObject fo = processingEnv.getFiler().getResource(l, "", ar.iconBase());
262
                            found = true;
266
                            final InputStream is = fo.openInputStream();
263
                            break;
267
                            if (is != null) {
268
                                res = fo;
269
                                is.close();
270
                            }
271
                        } catch (NullPointerException ex) {
272
                            continue;
264
                        } catch (IOException ex) {
273
                        } catch (IOException ex) {
265
                            continue;
274
                            continue;
266
                        } catch (IllegalArgumentException x) {
275
                        } catch (IllegalArgumentException x) {
267
                            throw new LayerGenerationException("Problem with " + ar.iconBase() + " (should be resource path with no leading slash)", e);
276
                            throw new LayerGenerationException("Problem with " + ar.iconBase() + " (should be resource path with no leading slash)", e);
268
                        }
277
                        }
269
                    }
278
                    }
270
                    if (!found) {
279
                    if (res == null) {
271
                        throw new LayerGenerationException(
280
                        String msg = "Cannot find iconBase file at " + ar.iconBase(); // NOI18N
272
                            "Cannot find iconBase file at " + ar.iconBase(), e
281
                        if (isJDK7()) {
273
                        );
282
                            throw new LayerGenerationException(msg, e);
283
                        } else {
284
                            processingEnv.getMessager().printMessage(Kind.MANDATORY_WARNING, msg, e);
285
                        }
274
                    }
286
                    }
275
                    f.stringvalue("iconBase", ar.iconBase());
287
                    f.stringvalue("iconBase", ar.iconBase());
276
                }
288
                }
Lines 446-449 Link Here
446
            before.write();
458
            before.write();
447
        }
459
        }
448
    }
460
    }
461
462
    static boolean isJDK7() {
463
        try {
464
            Class.forName("java.lang.AutoCloseable"); // NOI18N
465
            return true;
466
        } catch (ClassNotFoundException ex) {
467
            return false;
468
        }
469
    }
449
}
470
}
(-)a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/ActionProcessorTest.java (-4 / +33 lines)
Lines 39-44 Link Here
39
39
40
package org.netbeans.modules.openide.awt;
40
package org.netbeans.modules.openide.awt;
41
41
42
import java.io.File;
42
import java.awt.Component;
43
import java.awt.Component;
43
import javax.swing.JComponent;
44
import javax.swing.JComponent;
44
import javax.swing.JMenuItem;
45
import javax.swing.JMenuItem;
Lines 843-849 Link Here
843
        assertFalse("Compilation has to fail:\n" + os, r);
844
        assertFalse("Compilation has to fail:\n" + os, r);
844
    }
845
    }
845
846
846
    /* #196933: will only pass when using JDK 7 javac:
847
    public void testWrongPointerToIcon() throws IOException {
847
    public void testWrongPointerToIcon() throws IOException {
848
        clearWorkDir();
848
        clearWorkDir();
849
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
849
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
Lines 863-873 Link Here
863
        );
863
        );
864
        ByteArrayOutputStream os = new ByteArrayOutputStream();
864
        ByteArrayOutputStream os = new ByteArrayOutputStream();
865
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
865
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
866
        assertFalse("Compilation has to fail:\n" + os, r);
866
        if (ActionProcessor.isJDK7()) {
867
            assertFalse("Compilation has to fail:\n" + os, r);
868
        } else {
869
            assertTrue("Too bad on JDK6 we have to succeed:\n" + os, r);
870
        }
867
        if (!os.toString().contains("does/not/exist.png")) {
871
        if (!os.toString().contains("does/not/exist.png")) {
868
            fail("Shall contain warning about does/not/exist.png resource:\n" + os);
872
            fail("Shall contain warning about does/not/exist.png resource:\n" + os);
869
        }
873
        }
870
    }
874
    }
871
     */
875
    public void testGoodPointerToIcon() throws IOException {
872
    
876
        clearWorkDir();
877
        
878
        File icons = new File(getWorkDir(), "icons");
879
        File existsPng = new File(new File(icons, "does"), "exist.png");
880
        existsPng.getParentFile().mkdirs();
881
        existsPng.createNewFile();
882
        
883
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
884
            "import org.openide.awt.ActionRegistration;\n" +
885
            "import org.openide.awt.ActionReference;\n" +
886
            "import org.openide.awt.ActionID;\n" +
887
            "import org.openide.util.actions.Presenter;\n" +
888
            "import java.awt.event.*;\n" +
889
            "import java.util.List;\n" +
890
            "import javax.swing.*;\n" +
891
            "@ActionID(category=\"Tools\",id=\"my.action\")" +
892
            "@ActionRegistration(displayName=\"AAA\", key=\"K\", iconBase=\"does/exist.png\") " +
893
            "@ActionReference(path=\"manka\", position=11)" +
894
            "public class A implements ActionListener {\n" +
895
            "    public void actionPerformed(ActionEvent e) {}" +
896
            "}\n"
897
        );
898
        ByteArrayOutputStream os = new ByteArrayOutputStream();
899
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), new File[] { icons, null }, os);
900
        assertTrue("Compilation has to succeed:\n" + os, r);
901
    }
873
}
902
}
(-)a/openide.util.lookup/test/unit/src/org/openide/util/test/AnnotationProcessorTestUtils.java (-1 / +6 lines)
Lines 100-106 Link Here
100
     * @param src a source root (runs javac on all *.java it finds matching {@code srcIncludes})
100
     * @param src a source root (runs javac on all *.java it finds matching {@code srcIncludes})
101
     * @param srcIncludes a pattern of source files names without path to compile (useful for testing incremental compiles), or null for all
101
     * @param srcIncludes a pattern of source files names without path to compile (useful for testing incremental compiles), or null for all
102
     * @param dest a dest dir to compile classes to
102
     * @param dest a dest dir to compile classes to
103
     * @param cp classpath entries; if null, use Java classpath of test
103
     * @param cp classpath entries; if null, use Java classpath of test; if one of the elements is null => append Java classpath of the test
104
     * @param stderr output stream to print messages to, or null for test console (i.e. do not capture)
104
     * @param stderr output stream to print messages to, or null for test console (i.e. do not capture)
105
     * @return true if compilation succeeded, false if it failed
105
     * @return true if compilation succeeded, false if it failed
106
     */
106
     */
Lines 110-115 Link Here
110
        if (cp != null) {
110
        if (cp != null) {
111
            StringBuilder b = new StringBuilder();
111
            StringBuilder b = new StringBuilder();
112
            for (File entry : cp) {
112
            for (File entry : cp) {
113
                if (entry == null) {
114
                    b.append(File.pathSeparatorChar);
115
                    b.append(System.getProperty("java.class.path"));
116
                    continue;
117
                }
113
                b.append(File.pathSeparatorChar);
118
                b.append(File.pathSeparatorChar);
114
                b.append(entry.getAbsolutePath());
119
                b.append(entry.getAbsolutePath());
115
            }
120
            }

Return to bug 196933