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 203519
Collapse All | Expand All

(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/Actions.java (-2 / +5 lines)
Lines 111-116 Link Here
111
     */
111
     */
112
    private static final Set<String> COMMON_IDE_GLOBAL_ACTIONS = new HashSet<String>(Arrays.asList(
112
    private static final Set<String> COMMON_IDE_GLOBAL_ACTIONS = new HashSet<String>(Arrays.asList(
113
        ActionProvider.COMMAND_DEBUG,
113
        ActionProvider.COMMAND_DEBUG,
114
        ActionProvider.COMMAND_PROFILE,
114
        ActionProvider.COMMAND_DELETE,
115
        ActionProvider.COMMAND_DELETE,
115
        ActionProvider.COMMAND_COPY,
116
        ActionProvider.COMMAND_COPY,
116
        ActionProvider.COMMAND_MOVE,
117
        ActionProvider.COMMAND_MOVE,
Lines 193-199 Link Here
193
                    // Check whether the context contains files all in this folder,
194
                    // Check whether the context contains files all in this folder,
194
                    // matching the pattern if any, and matching the arity (single/multiple).
195
                    // matching the pattern if any, and matching the arity (single/multiple).
195
                    Map<String,FileObject> selection = findSelection(contextEl, context, project,
196
                    Map<String,FileObject> selection = findSelection(contextEl, context, project,
196
                            command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || command.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD) ? new AtomicReference<String>() : null);
197
                            command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || 
198
                            command.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD) ? new AtomicReference<String>() : null);
197
                    LOG.log(Level.FINE, "detected selection {0} for command {1} in {2}", new Object[] {selection, command, project});
199
                    LOG.log(Level.FINE, "detected selection {0} for command {1} in {2}", new Object[] {selection, command, project});
198
                    if (selection.size() == 1) {
200
                    if (selection.size() == 1) {
199
                        // Definitely enabled.
201
                        // Definitely enabled.
Lines 372-378 Link Here
372
                }
374
                }
373
                Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
375
                Element contextEl = XMLUtil.findElement(actionEl, "context", FreeformProjectType.NS_GENERAL); // NOI18N
374
                if (contextEl != null) {
376
                if (contextEl != null) {
375
                    AtomicReference<String> methodName = SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) ?
377
                    AtomicReference<String> methodName = SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || 
378
                                                         SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) ?
376
                        new AtomicReference<String>() : null;
379
                        new AtomicReference<String>() : null;
377
                    Map<String,FileObject> selection = findSelection(contextEl, context, project, methodName);
380
                    Map<String,FileObject> selection = findSelection(contextEl, context, project, methodName);
378
                    if (selection.isEmpty()) {
381
                    if (selection.isEmpty()) {
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/Bundle.properties (+1 lines)
Lines 62-67 Link Here
62
CMD_run=Run
62
CMD_run=Run
63
CMD_test=Test
63
CMD_test=Test
64
CMD_debug=Debug
64
CMD_debug=Debug
65
CMD_profile=Profile
65
CMD_javadoc=Generate Javadoc
66
CMD_javadoc=Generate Javadoc
66
CMD_redeploy=Redeploy
67
CMD_redeploy=Redeploy
67
CMD_deploy=Deploy
68
CMD_deploy=Deploy
(-)a/ant.freeform/src/org/netbeans/modules/ant/freeform/resources/layer.xml (-4 lines)
Lines 74-83 Link Here
74
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
74
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
75
                    <attr name="position" intvalue="400"/>
75
                    <attr name="position" intvalue="400"/>
76
                </file>
76
                </file>
77
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
78
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.instance"/>
79
                    <attr name="position" intvalue="500"/>
80
                </file>
81
                <file name="sep-3.instance">
77
                <file name="sep-3.instance">
82
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
78
                    <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
83
                    <attr name="position" intvalue="600"/>
79
                    <attr name="position" intvalue="600"/>
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/resources/layer.xml (-4 lines)
Lines 160-169 Link Here
160
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
160
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
161
                    <attr name="position" intvalue="900"/>
161
                    <attr name="position" intvalue="900"/>
162
                </file>
162
                </file>
163
                <file name="profiler.shadow">
164
                    <attr name="originalFile" stringvalue="Projects/Profiler_Actions_temporary"/>
165
                    <attr name="position" intvalue="1000"/>
166
                </file>
167
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
163
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
168
                    <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-TestProject.instance"/>
164
                    <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-TestProject.instance"/>
169
                    <attr name="position" intvalue="1100"/>
165
                    <attr name="position" intvalue="1100"/>
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/ModuleActions.java (-19 / +66 lines)
Lines 46-61 Link Here
46
46
47
import java.io.File;
47
import java.io.File;
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.util.Arrays;
49
import java.util.*;
50
import java.util.Collection;
51
import java.util.Collections;
52
import java.util.HashMap;
53
import java.util.HashSet;
54
import java.util.LinkedList;
55
import java.util.Map;
56
import java.util.Map.Entry;
50
import java.util.Map.Entry;
57
import java.util.Properties;
58
import java.util.Set;
59
import java.util.regex.Pattern;
51
import java.util.regex.Pattern;
60
import javax.lang.model.element.TypeElement;
52
import javax.lang.model.element.TypeElement;
61
import javax.swing.Action;
53
import javax.swing.Action;
Lines 116-122 Link Here
116
108
117
    static final Set<String> bkgActions = new HashSet<String>(Arrays.asList(
109
    static final Set<String> bkgActions = new HashSet<String>(Arrays.asList(
118
        COMMAND_RUN_SINGLE,
110
        COMMAND_RUN_SINGLE,
119
        COMMAND_DEBUG_SINGLE
111
        COMMAND_DEBUG_SINGLE,
112
        COMMAND_PROFILE_SINGLE
120
    ));
113
    ));
121
114
122
    private static final String COMMAND_NBM = "nbm";
115
    private static final String COMMAND_NBM = "nbm";
Lines 162-168 Link Here
162
        }
155
        }
163
        globalCommands.put(ActionProvider.COMMAND_RUN, new String[] {"run"}); // NOI18N
156
        globalCommands.put(ActionProvider.COMMAND_RUN, new String[] {"run"}); // NOI18N
164
        globalCommands.put(ActionProvider.COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
157
        globalCommands.put(ActionProvider.COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
165
        globalCommands.put("profile", new String[] {"profile"}); // NOI18N
158
        globalCommands.put(ActionProvider.COMMAND_PROFILE, new String[] {"profile"}); // NOI18N
166
        globalCommands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc-nb"}); // NOI18N
159
        globalCommands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc-nb"}); // NOI18N
167
        globalCommands.put(ActionProvider.COMMAND_TEST, new String[] {"test-unit"}); // NOI18N
160
        globalCommands.put(ActionProvider.COMMAND_TEST, new String[] {"test-unit"}); // NOI18N
168
        globalCommands.put(COMMAND_NBM, new String[] {COMMAND_NBM});
161
        globalCommands.put(COMMAND_NBM, new String[] {COMMAND_NBM});
Lines 172-179 Link Here
172
        if (!project.supportedTestTypes().isEmpty()) {
165
        if (!project.supportedTestTypes().isEmpty()) {
173
            supportedActionsSet.add(ActionProvider.COMMAND_TEST_SINGLE);
166
            supportedActionsSet.add(ActionProvider.COMMAND_TEST_SINGLE);
174
            supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_TEST_SINGLE);
167
            supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_TEST_SINGLE);
168
            supportedActionsSet.add(ActionProvider.COMMAND_PROFILE_TEST_SINGLE);
175
            supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
169
            supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
176
            supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_SINGLE);
170
            supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_SINGLE);
171
            supportedActionsSet.add(ActionProvider.COMMAND_PROFILE_SINGLE);
177
            supportedActionsSet.add(SingleMethod.COMMAND_RUN_SINGLE_METHOD);
172
            supportedActionsSet.add(SingleMethod.COMMAND_RUN_SINGLE_METHOD);
178
            supportedActionsSet.add(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD);
173
            supportedActionsSet.add(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD);
179
        }
174
        }
Lines 212-223 Link Here
212
            if (testSources == null)
207
            if (testSources == null)
213
                    testSources = findTestSources(context, false);
208
                    testSources = findTestSources(context, false);
214
            return testSources != null && testSources.isSingle();
209
            return testSources != null && testSources.isSingle();
210
        } else if (command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
211
            TestSources testSources = findTestSourcesForSources(context);
212
            if (testSources == null)
213
                    testSources = findTestSources(context, false);
214
            return testSources != null && testSources.isSingle();
215
        } else if (command.equals(COMMAND_RUN_SINGLE)) {
215
        } else if (command.equals(COMMAND_RUN_SINGLE)) {
216
            return findTestSources(context, false) != null;
216
            return findTestSources(context, false) != null;
217
        } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
217
        } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
218
            TestSources testSources = findTestSources(context, false);
218
            TestSources testSources = findTestSources(context, false);
219
            return testSources != null && testSources.isSingle();
219
            return testSources != null && testSources.isSingle();
220
        } else if (command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || command.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)) {
220
        } else if (command.equals(COMMAND_PROFILE_SINGLE)) {
221
            TestSources testSources = findTestSources(context, false);
222
            return testSources != null && testSources.isSingle();
223
        } else if (command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || 
224
                   command.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)
225
                ) {
221
            NbPlatform plaf = project.getPlatform(false);
226
            NbPlatform plaf = project.getPlatform(false);
222
            if (plaf == null || plaf.getHarnessVersion().compareTo(HarnessVersion.V70) < 0) {
227
            if (plaf == null || plaf.getHarnessVersion().compareTo(HarnessVersion.V70) < 0) {
223
                return false;
228
                return false;
Lines 396-401 Link Here
396
401
397
                    }
402
                    }
398
                    targetNames = setupDebugTestSingle(p, testSources);
403
                    targetNames = setupDebugTestSingle(p, testSources);
404
                } else if (command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
405
                    TestSources testSources = findTestSourcesForSources(context);
406
                    if (testSources == null) {
407
                        testSources = findTestSources(context, false);
408
409
                    }
410
                    targetNames = setupProfileTestSingle(p, testSources);
399
                } else if (command.equals(COMMAND_RUN_SINGLE)) {
411
                } else if (command.equals(COMMAND_RUN_SINGLE)) {
400
                    TestSources testSources = findTestSources(context, false);
412
                    TestSources testSources = findTestSources(context, false);
401
//       TODO CoS     String enableQuickTest = project.evaluator().getProperty("quick.test.single"); // NOI18N
413
//       TODO CoS     String enableQuickTest = project.evaluator().getProperty("quick.test.single"); // NOI18N
Lines 422-427 Link Here
422
                        // fallback to "old" debug tests behavior
434
                        // fallback to "old" debug tests behavior
423
                        targetNames = setupDebugTestSingle(p, testSources);
435
                        targetNames = setupDebugTestSingle(p, testSources);
424
                    }
436
                    }
437
                } else if (command.equals(COMMAND_PROFILE_SINGLE)) {
438
                    TestSources testSources = findTestSources(context, false);
439
                    String clazz = getMainClass(context);
440
                    if (clazz != null) {
441
                        targetNames = setupProfileMain(p, testSources, context, clazz);
442
                    } else {
443
                        // fallback to "old" debug tests behavior
444
                        targetNames = setupProfileTestSingle(p, testSources);
445
                    }
425
                } else if (command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD)) {
446
                } else if (command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD)) {
426
                    TestSources testSources = findTestMethodSources(context);
447
                    TestSources testSources = findTestMethodSources(context);
427
                    p.setProperty("test.class", testClassName(testSources)); // NOI18N
448
                    p.setProperty("test.class", testClassName(testSources)); // NOI18N
Lines 461-467 Link Here
461
                    return;
482
                    return;
462
                } else {
483
                } else {
463
                    // XXX consider passing PM.fP(FU.toFO(SuiteUtils.suiteDirectory(project))) instead for a suite component project:
484
                    // XXX consider passing PM.fP(FU.toFO(SuiteUtils.suiteDirectory(project))) instead for a suite component project:
464
                    setRunArgsIde(project, SingleModuleProperties.getInstance(project), command, p, project.getTestUserDirLockFile());
465
                    if (command.equals(ActionProvider.COMMAND_REBUILD)) {
485
                    if (command.equals(ActionProvider.COMMAND_REBUILD)) {
466
                        p.setProperty("do.not.clean.module.config.xml", "true"); // #196192
486
                        p.setProperty("do.not.clean.module.config.xml", "true"); // #196192
467
                    }
487
                    }
Lines 472-477 Link Here
472
                    }
492
                    }
473
                }
493
                }
474
                try {
494
                try {
495
                    setRunArgsIde(project, SingleModuleProperties.getInstance(project), command, p, project.getTestUserDirLockFile());
475
                    ActionUtils.runTarget(findBuildXml(project), targetNames, p);
496
                    ActionUtils.runTarget(findBuildXml(project), targetNames, p);
476
                } catch (IOException e) {
497
                } catch (IOException e) {
477
                    Util.err.notify(e);
498
                    Util.err.notify(e);
Lines 483-488 Link Here
483
        } else
504
        } else
484
            runnable.run();
505
            runnable.run();
485
    }
506
    }
507
    
508
    private String[] setupProfileTestSingle(Properties p, TestSources testSources) {
509
        p.setProperty("test.includes", testSources.includes().replace("**", "**/*Test.java")); // NOI18N
510
        p.setProperty("test.type", testSources.testType); // NOI18N
511
        return new String[] {"profile-test-single-nb"}; // NOI18N
512
    }
486
513
487
    static void setRunArgsIde(Project project, ModuleProperties modprops, String command, Properties p, File testUserDirLockFile) {
514
    static void setRunArgsIde(Project project, ModuleProperties modprops, String command, Properties p, File testUserDirLockFile) {
488
        StringBuilder runArgsIde = new StringBuilder();
515
        StringBuilder runArgsIde = new StringBuilder();
Lines 491-517 Link Here
491
            mode = StartupExtender.StartMode.NORMAL;
518
            mode = StartupExtender.StartMode.NORMAL;
492
        } else if (command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_DEBUG_STEP_INTO)) {
519
        } else if (command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_DEBUG_STEP_INTO)) {
493
            mode = StartupExtender.StartMode.DEBUG;
520
            mode = StartupExtender.StartMode.DEBUG;
494
        } else if (command.equals("profile")) {
521
        } else if (command.equals(COMMAND_PROFILE) || command.equals(COMMAND_PROFILE_SINGLE) || command.equals("profile-osgi")) {
495
            mode = StartupExtender.StartMode.PROFILE;
522
            mode = StartupExtender.StartMode.PROFILE;
496
        } else if (command.equals(COMMAND_TEST) || command.equals(COMMAND_TEST_SINGLE)) {
523
        } else if (command.equals(COMMAND_TEST) || command.equals(COMMAND_TEST_SINGLE)) {
497
            mode = StartupExtender.StartMode.TEST_NORMAL;
524
            mode = StartupExtender.StartMode.TEST_NORMAL;
498
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
525
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
499
            mode = StartupExtender.StartMode.TEST_DEBUG;
526
            mode = StartupExtender.StartMode.TEST_DEBUG;
500
        } else if (command.equals("profile-test-single-nb")) {
527
        } else if (command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
501
            mode = StartupExtender.StartMode.TEST_PROFILE;
528
            mode = StartupExtender.StartMode.TEST_PROFILE;
502
        } else {
529
        } else {
503
            mode = null;
530
            mode = null;
504
        }
531
        }
532
        
533
        boolean isTest = (EnumSet.of(
534
                            StartupExtender.StartMode.TEST_PROFILE, 
535
                            StartupExtender.StartMode.TEST_NORMAL, 
536
                            StartupExtender.StartMode.TEST_DEBUG).contains(mode) || 
537
                          command.equals(COMMAND_PROFILE_SINGLE));
505
        if (mode != null) {
538
        if (mode != null) {
506
            JavaPlatform plaf = modprops.getJavaPlatform();
539
            JavaPlatform plaf = modprops.getJavaPlatform();
507
            Lookup context = Lookups.fixed(project, plaf != null ? plaf : JavaPlatformManager.getDefault().getDefaultPlatform());
540
            Lookup context = Lookups.fixed(project, plaf != null ? plaf : JavaPlatformManager.getDefault().getDefaultPlatform());
508
            for (StartupExtender group : StartupExtender.getExtenders(context, mode)) {
541
            for (StartupExtender group : StartupExtender.getExtenders(context, mode)) {
509
                for (String arg : group.getArguments()) {
542
                for (String arg : group.getArguments()) {
510
                    runArgsIde.append("-J").append(arg).append(' ');
543
                    runArgsIde.append(isTest ? "" : "-J").append(arg).append(' ');
511
                }
544
                }
512
            }
545
            }
513
        }
546
        }
514
        if ((command.equals(ActionProvider.COMMAND_RUN) || command.equals(ActionProvider.COMMAND_DEBUG)) // #63652
547
        if ((command.equals(ActionProvider.COMMAND_RUN) || 
548
             command.equals(ActionProvider.COMMAND_DEBUG) ||
549
             command.equals(ActionProvider.COMMAND_PROFILE)) // #63652
515
                && testUserDirLockFile.isFile()) {
550
                && testUserDirLockFile.isFile()) {
516
            // #141069: lock file exists, run with bogus option
551
            // #141069: lock file exists, run with bogus option
517
            runArgsIde.append(TEST_USERDIR_LOCK_PROP_VALUE);
552
            runArgsIde.append(TEST_USERDIR_LOCK_PROP_VALUE);
Lines 606-611 Link Here
606
        return  new String[] {"debug-test-main-nb"};    // NOI18N
641
        return  new String[] {"debug-test-main-nb"};    // NOI18N
607
    }
642
    }
608
    
643
    
644
    private String[] setupProfileMain(Properties p, TestSources testSources, Lookup context, String mainClass) {
645
        p.setProperty("main.class", mainClass);    // NOI18N
646
        p.setProperty("test.type", testSources.testType); // NOI18N
647
        return  new String[] {"profile-test-main-nb"};    // NOI18N
648
    }
649
    
609
    private String testClassName(TestSources testSources) {
650
    private String testClassName(TestSources testSources) {
610
        String path = testSources.includes();
651
        String path = testSources.includes();
611
        assert path.endsWith(".java") && !path.contains(",") : path;
652
        assert path.endsWith(".java") && !path.contains(",") : path;
Lines 622-633 Link Here
622
    private boolean bypassAntBuildScript(String command, FileObject[] files) throws IllegalArgumentException {
663
    private boolean bypassAntBuildScript(String command, FileObject[] files) throws IllegalArgumentException {
623
        FileObject toRun = null;
664
        FileObject toRun = null;
624
665
625
        if (COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command)) {
666
        if (COMMAND_RUN_SINGLE.equals(command) || 
667
            COMMAND_DEBUG_SINGLE.equals(command) ||
668
            COMMAND_PROFILE_SINGLE.equals(command)) {
626
            toRun = files[0];
669
            toRun = files[0];
627
        }
670
        }
628
        
671
        
629
        if (toRun != null) {
672
        if (toRun != null) {
630
            String commandToExecute = COMMAND_RUN_SINGLE.equals(command) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG;
673
            String commandToExecute = COMMAND_RUN_SINGLE.equals(command) ? 
674
                                        JavaRunner.QUICK_TEST : 
675
                                        (COMMAND_DEBUG_SINGLE.equals(command) ? 
676
                                            JavaRunner.QUICK_TEST_DEBUG :
677
                                            JavaRunner.QUICK_TEST_PROFILE);
631
            if (!JavaRunner.isSupported(commandToExecute, Collections.singletonMap(JavaRunner.PROP_EXECUTE_FILE, toRun))) {
678
            if (!JavaRunner.isSupported(commandToExecute, Collections.singletonMap(JavaRunner.PROP_EXECUTE_FILE, toRun))) {
632
                return false;
679
                return false;
633
            }
680
            }
(-)a/apisupport.ant/src/org/netbeans/modules/apisupport/project/ui/SuiteActions.java (-8 / +7 lines)
Lines 109-115 Link Here
109
    private static final String COMMAND_DEBUG_JNLP = "debug-jnlp";
109
    private static final String COMMAND_DEBUG_JNLP = "debug-jnlp";
110
    private static final String COMMAND_DEBUG_OSGI = "debug-osgi";
110
    private static final String COMMAND_DEBUG_OSGI = "debug-osgi";
111
    private static final String COMMAND_NBMS = "nbms";
111
    private static final String COMMAND_NBMS = "nbms";
112
    private static final String COMMAND_PROFILE = "profile";
113
    private static final String COMMAND_PROFILE_OSGI = "profile-osgi";
112
    private static final String COMMAND_PROFILE_OSGI = "profile-osgi";
114
    private static final String COMMAND_RUN_JNLP = "run-jnlp";
113
    private static final String COMMAND_RUN_JNLP = "run-jnlp";
115
    private static final String COMMAND_RUN_OSGI = "run-osgi";
114
    private static final String COMMAND_RUN_OSGI = "run-osgi";
Lines 242-254 Link Here
242
        return ProjectSensitiveActions.projectCommandAction(COMMAND_DEBUG_OSGI, SUITE_ACTION_debug_osgi(), null);
241
        return ProjectSensitiveActions.projectCommandAction(COMMAND_DEBUG_OSGI, SUITE_ACTION_debug_osgi(), null);
243
    }
242
    }
244
243
245
    @ActionID(category="Project", id="org.netbeans.modules.apisupport.project.suite.profileOsgi")
244
//    @ActionID(category="Project", id="org.netbeans.modules.apisupport.project.suite.profileOsgi")
246
    @ActionRegistration(displayName="#SUITE_ACTION_profile_osgi", lazy=false)
245
//    @ActionRegistration(displayName="#SUITE_ACTION_profile_osgi", lazy=false)
247
    @ActionReference(path=SUITE_OSGI_ACTIONS_PATH, position=500)
246
//    @ActionReference(path=SUITE_OSGI_ACTIONS_PATH, position=500)
248
    @Messages("SUITE_ACTION_profile_osgi=Profile in Felix")
247
//    @Messages("SUITE_ACTION_profile_osgi=Profile in Felix")
249
    public static Action profileOsgi() {
248
//    public static Action profileOsgi() {
250
        return ProjectSensitiveActions.projectCommandAction(COMMAND_PROFILE_OSGI, SUITE_ACTION_profile_osgi(), null);
249
//        return ProjectSensitiveActions.projectCommandAction(COMMAND_PROFILE_OSGI, SUITE_ACTION_profile_osgi(), null);
251
    }
250
//    }
252
251
253
    @ActionID(category="Project", id="org.netbeans.modules.apisupport.project.suite.branding")
252
    @ActionID(category="Project", id="org.netbeans.modules.apisupport.project.suite.branding")
254
    @ActionRegistration(displayName="#SUITE_ACTION_branding", lazy=false)
253
    @ActionRegistration(displayName="#SUITE_ACTION_branding", lazy=false)
(-)a/apisupport.harness/release/jnlp.xml (+14 lines)
Lines 434-439 Link Here
434
            <reference refid="cluster.path.id"/>
434
            <reference refid="cluster.path.id"/>
435
        </antcall>
435
        </antcall>
436
    </target>
436
    </target>
437
    
438
    <target name="-profile-check" if="netbeans.home">
439
        <condition property="profiler.configured">
440
            <or>
441
                <contains string="${run.jvmargs.ide}" substring="-agentpath:" casesensitive="false"/>
442
                <contains string="${run.jvmargs.ide}" substring="-javaagent:" casesensitive="false"/>
443
            </or>
444
        </condition>
445
    </target>
446
    
447
    <target name="profile" depends="-profile-check,build-jnlp-local" description="Executes this suite as JNLP application under profiler" if="profiler.configured" unless="profiler.info.jvmargs.agent">
448
        <startprofiler/>
449
        <antcall target="run"/>
450
    </target>
437
451
438
    <target name="-check-for-jnlp-userdir">
452
    <target name="-check-for-jnlp-userdir">
439
        <property name="jnlp.userdir" location="${user.home}/.nbapp-${app.name}"/>
453
        <property name="jnlp.userdir" location="${user.home}/.nbapp-${app.name}"/>
(-)a/apisupport.harness/release/osgi.xml (-3 / +20 lines)
Lines 159-166 Link Here
159
            <reference refid="cluster.path.id"/>
159
            <reference refid="cluster.path.id"/>
160
        </antcall>
160
        </antcall>
161
    </target>
161
    </target>
162
162
    
163
    <target name="profile">
163
    <target name="-profile-check">
164
        <condition property="profiler.configured" if="netbeans.home">
165
            <or>
166
                <contains string="${osgi.run.args}" substring="-agentpath:" casesensitive="false"/>
167
                <contains string="${osgi.run.args}" substring="-javaagent:" casesensitive="false"/>
168
                <contains string="${osgi.run.args.extra}" substring="-agentpath:" casesensitive="false"/>
169
                <contains string="${osgi.run.args.extra}" substring="-javaagent:" casesensitive="false"/>
170
            </or>
171
        </condition>
172
    </target>
173
    
174
    <target name="profile" depends="-profile-check,-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent" description="Profile a project in the IDE." unless="profiler.info.jvmargs.agent">        
175
        <startprofiler/>
176
        <antcall target="run">
177
            <reference refid="cluster.path.id"/>
178
        </antcall>
179
    </target>
180
    
181
    <target name="-profile-pre72" if="profiler.info.jvmargs.agent">
164
        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
182
        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
165
        <nbprofiledirect jvmargsprefix="" jvmargsproperty="profiler.jvmargs">
183
        <nbprofiledirect jvmargsprefix="" jvmargsproperty="profiler.jvmargs">
166
            <classpath>
184
            <classpath>
Lines 184-188 Link Here
184
            <reference refid="cluster.path.id"/>
202
            <reference refid="cluster.path.id"/>
185
        </antcall>
203
        </antcall>
186
    </target>
204
    </target>
187
188
</project>
205
</project>
(-)a/apisupport.harness/release/run.xml (-2 / +17 lines)
Lines 228-234 Link Here
228
        </antcall>
228
        </antcall>
229
    </target>
229
    </target>
230
    
230
    
231
    <target name="profile" description="Profile a project in the IDE.">
231
    <target name="-profile-check" if="netbeans.home">
232
        <condition property="profiler.configured">
233
            <or>
234
                <contains string="${run.args.ide}" substring="-agentpath:" casesensitive="false"/>
235
                <contains string="${run.args.ide}" substring="-javaagent:" casesensitive="false"/>
236
            </or>
237
        </condition>
238
    </target>
239
    
240
    <target name="profile" depends="-profile-check,-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent" description="Profile a project in the IDE." unless="profiler.info.jvmargs.agent">        
241
        <startprofiler/>
242
        <antcall target="run">
243
            <reference refid="cluster.path.id"/>
244
        </antcall>
245
    </target>
246
    
247
    <target name="-profile-pre72" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent">
232
        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
248
        <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
233
        <nbprofiledirect 
249
        <nbprofiledirect 
234
            jvmargsprefix="-J" 
250
            jvmargsprefix="-J" 
Lines 255-259 Link Here
255
            <reference refid="cluster.path.id"/>
271
            <reference refid="cluster.path.id"/>
256
        </antcall>
272
        </antcall>
257
    </target>
273
    </target>
258
    
259
</project>
274
</project>
(-)a/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/Deploy.java (-1 / +22 lines)
Lines 65-70 Link Here
65
     */
65
     */
66
    private boolean debugmode = false;
66
    private boolean debugmode = false;
67
    
67
    
68
    /**
69
     * Holds value of property profilemode.
70
     */
71
    private boolean profilemode = false;
72
    
68
    private boolean forceRedeploy = false;
73
    private boolean forceRedeploy = false;
69
    
74
    
70
    /**
75
    /**
Lines 104-110 Link Here
104
109
105
            try {
110
            try {
106
                String clientUrl = Deployment.getDefault ().deploy (jmp, 
111
                String clientUrl = Deployment.getDefault ().deploy (jmp, 
107
                        debugmode ? Deployment.Mode.DEBUG : Deployment.Mode.RUN,
112
                        debugmode ? Deployment.Mode.DEBUG : (profilemode ? Deployment.Mode.PROFILE : Deployment.Mode.RUN),
108
                        clientModuleUri, clientUrlPart, forceRedeploy, this);
113
                        clientModuleUri, clientUrlPart, forceRedeploy, this);
109
                if (clientUrl != null) {
114
                if (clientUrl != null) {
110
                    getProject().setProperty("client.url", clientUrl);
115
                    getProject().setProperty("client.url", clientUrl);
Lines 149-160 Link Here
149
    }
154
    }
150
    
155
    
151
    /**
156
    /**
157
     * Getter for property profilemode.
158
     * @return Value of property profilemode.
159
     */
160
    public boolean getProfilemode() {
161
        return this.profilemode;
162
    }
163
    
164
    /**
152
     * Setter for property debugmode.
165
     * Setter for property debugmode.
153
     * @param debugmode New value of property debugmode.
166
     * @param debugmode New value of property debugmode.
154
     */
167
     */
155
    public void setDebugmode(boolean debugmode) {
168
    public void setDebugmode(boolean debugmode) {
156
        this.debugmode = debugmode;
169
        this.debugmode = debugmode;
157
    }
170
    }
171
    
172
    /**
173
     * Setter for property profilemode.
174
     * @param debugmode New value of property profilemode.
175
     */
176
    public void setProfilemode(boolean profilemode) {
177
        this.profilemode = profilemode;
178
    }
158
        
179
        
159
    public boolean getForceRedeploy() {
180
    public boolean getForceRedeploy() {
160
        return this.forceRedeploy;
181
        return this.forceRedeploy;
(-)a/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartProfiledServer.java (-5 / +5 lines)
Lines 109-119 Link Here
109
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_StartupFailed");
109
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_StartupFailed");
110
            throw new BuildException(msg);
110
            throw new BuildException(msg);
111
        }
111
        }
112
        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachingProfiler"));
112
//        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachingProfiler"));
113
        if (!profiler.attachProfiler(getProject().getProperties())) {
113
//        if (!profiler.attachProfiler(getProject().getProperties())) {
114
            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachFailed");
114
//            String msg = NbBundle.getMessage(StartProfiledServer.class, "MSG_AttachFailed");
115
            throw new BuildException(msg);
115
//            throw new BuildException(msg);
116
        }
116
//        }
117
        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_ProfilerAttached"));
117
        log(NbBundle.getMessage(StartProfiledServer.class, "MSG_ProfilerAttached"));
118
        // wait for the server to finish its startup
118
        // wait for the server to finish its startup
119
        long timeout = System.currentTimeMillis() + startupTimeout;
119
        long timeout = System.currentTimeMillis() + startupTimeout;
(-)a/j2ee.ant/antsrc/org/netbeans/modules/j2ee/ant/StartServer.java (+23 lines)
Lines 69-74 Link Here
69
     */
69
     */
70
    private boolean debugmode = false;
70
    private boolean debugmode = false;
71
71
72
    /**
73
     * Holds value of property profilemode.
74
     */
75
    private boolean profilemode = false;
76
    
72
    public void execute() throws BuildException {
77
    public void execute() throws BuildException {
73
78
74
        ClassLoader originalLoader = null;
79
        ClassLoader originalLoader = null;
Lines 107-112 Link Here
107
            try {
112
            try {
108
                if (debugmode) {
113
                if (debugmode) {
109
                    si.startDebug(ui);
114
                    si.startDebug(ui);
115
                } else if (profilemode) {
116
                    si.startProfile(false, ui);
110
                } else {
117
                } else {
111
                    si.start(ui);
118
                    si.start(ui);
112
                }
119
                }
Lines 156-161 Link Here
156
    public boolean getDebugmode() {
163
    public boolean getDebugmode() {
157
        return this.debugmode;
164
        return this.debugmode;
158
    }
165
    }
166
    
167
    /**
168
     * Getter for property profilemode.
169
     * @return Value of property profilemode.
170
     */
171
    public boolean getProfilemode() {
172
        return this.profilemode;
173
    }
159
174
160
    /**
175
    /**
161
     * Setter for property debugmode.
176
     * Setter for property debugmode.
Lines 164-167 Link Here
164
    public void setDebugmode(boolean debugmode) {
179
    public void setDebugmode(boolean debugmode) {
165
        this.debugmode = debugmode;
180
        this.debugmode = debugmode;
166
    }
181
    }
182
    
183
    /**
184
     * Setter for property profilemode.
185
     * @param profilemode New value of property profilemode.
186
     */
187
    public void setProfilemode(boolean profilemode) {
188
        this.profilemode = profilemode;
189
    }
167
}
190
}
(-)a/j2ee.earproject/nbproject/project.xml (+9 lines)
Lines 112-117 Link Here
112
                    <run-dependency/>
112
                    <run-dependency/>
113
                </dependency>
113
                </dependency>
114
                <dependency>
114
                <dependency>
115
                    <code-name-base>org.netbeans.modules.extexecution</code-name-base>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
118
                    <run-dependency>
119
                        <release-version>2</release-version>
120
                        <specification-version>1.30</specification-version>
121
                    </run-dependency>
122
                </dependency>
123
                <dependency>
115
                    <code-name-base>org.netbeans.modules.j2ee.api.ejbmodule</code-name-base>
124
                    <code-name-base>org.netbeans.modules.j2ee.api.ejbmodule</code-name-base>
116
                    <build-prerequisite/>
125
                    <build-prerequisite/>
117
                    <compile-dependency/>
126
                    <compile-dependency/>
(-)a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/EarActionProvider.java (-1 / +89 lines)
Lines 45-52 Link Here
45
package org.netbeans.modules.j2ee.earproject;
45
package org.netbeans.modules.j2ee.earproject;
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.ArrayList;
49
import java.util.Collections;
48
import java.util.HashMap;
50
import java.util.HashMap;
49
import java.util.Iterator;
51
import java.util.Iterator;
52
import java.util.List;
50
import java.util.Map;
53
import java.util.Map;
51
import java.util.Properties;
54
import java.util.Properties;
52
import java.util.Set;
55
import java.util.Set;
Lines 54-60 Link Here
54
import org.netbeans.api.debugger.DebuggerManager;
57
import org.netbeans.api.debugger.DebuggerManager;
55
import org.netbeans.api.debugger.Session;
58
import org.netbeans.api.debugger.Session;
56
import org.netbeans.api.debugger.jpda.AttachingDICookie;
59
import org.netbeans.api.debugger.jpda.AttachingDICookie;
57
import org.netbeans.api.j2ee.core.Profile;
60
import org.netbeans.api.extexecution.startup.StartupExtender;
61
import org.netbeans.api.java.platform.JavaPlatform;
62
import org.netbeans.api.java.platform.JavaPlatformManager;
58
import org.netbeans.api.project.Project;
63
import org.netbeans.api.project.Project;
59
import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants;
64
import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants;
60
import org.netbeans.modules.j2ee.common.project.ui.DeployOnSaveUtils;
65
import org.netbeans.modules.j2ee.common.project.ui.DeployOnSaveUtils;
Lines 68-73 Link Here
68
import org.netbeans.modules.j2ee.earproject.ui.customizer.CustomizerProviderImpl;
73
import org.netbeans.modules.j2ee.earproject.ui.customizer.CustomizerProviderImpl;
69
import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties;
74
import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties;
70
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
75
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
76
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
71
import org.netbeans.modules.web.api.webmodule.WebModule;
77
import org.netbeans.modules.web.api.webmodule.WebModule;
72
import org.netbeans.modules.web.spi.webmodule.WebModuleProvider;
78
import org.netbeans.modules.web.spi.webmodule.WebModuleProvider;
73
import org.netbeans.spi.project.ActionProvider;
79
import org.netbeans.spi.project.ActionProvider;
Lines 82-87 Link Here
82
import org.openide.util.NbBundle;
88
import org.openide.util.NbBundle;
83
import org.openide.util.Task;
89
import org.openide.util.Task;
84
import org.openide.util.TaskListener;
90
import org.openide.util.TaskListener;
91
import org.openide.util.lookup.Lookups;
85
92
86
/**
93
/**
87
 * Action provider of the Enterprise Application project.
94
 * Action provider of the Enterprise Application project.
Lines 101-106 Link Here
101
        COMMAND_REBUILD, 
108
        COMMAND_REBUILD, 
102
        COMMAND_RUN, 
109
        COMMAND_RUN, 
103
        COMMAND_DEBUG, 
110
        COMMAND_DEBUG, 
111
        COMMAND_PROFILE,
104
        EjbProjectConstants.COMMAND_REDEPLOY,
112
        EjbProjectConstants.COMMAND_REDEPLOY,
105
        COMMAND_VERIFY,
113
        COMMAND_VERIFY,
106
        COMMAND_DELETE,
114
        COMMAND_DELETE,
Lines 124-129 Link Here
124
        commands.put(COMMAND_REBUILD, new String[] {"clean", "dist"}); // NOI18N
132
        commands.put(COMMAND_REBUILD, new String[] {"clean", "dist"}); // NOI18N
125
        commands.put(COMMAND_RUN, new String[] {"run"}); // NOI18N
133
        commands.put(COMMAND_RUN, new String[] {"run"}); // NOI18N
126
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
134
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
135
        commands.put(COMMAND_PROFILE, new String[]{"profile"}); // NOI18N
127
        commands.put(EjbProjectConstants.COMMAND_REDEPLOY, new String[] {"run-deploy"}); // NOI18N
136
        commands.put(EjbProjectConstants.COMMAND_REDEPLOY, new String[] {"run-deploy"}); // NOI18N
128
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
137
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
129
        commands.put(COMMAND_COMPILE, new String[] {"compile"}); // NOI18N
138
        commands.put(COMMAND_COMPILE, new String[] {"compile"}); // NOI18N
Lines 281-292 Link Here
281
                }
290
                }
282
                p.setProperty("ear.docbase.dirs", edbd.toString()); // NOI18N
291
                p.setProperty("ear.docbase.dirs", edbd.toString()); // NOI18N
283
            }
292
            }
293
        // PROFILING PART
294
        } else if (command.equals (COMMAND_PROFILE)) {
295
            // TODO This is basically a copy of the debugging part for now. Figure out what to do here!
296
            
297
            if (!isSelectedServer ()) {
298
                // no selected server => warning
299
                String msg = NbBundle.getMessage(
300
                        EarActionProvider.class, "MSG_No_Server_Selected"); //  NOI18N
301
                DialogDisplayer.getDefault().notify(
302
                        new NotifyDescriptor.Message(msg, NotifyDescriptor.WARNING_MESSAGE));
303
                return null;
304
            }
305
            setDirectoryDeploymentProperty(p);
306
//            
307
//            if (isDebugged()) {
308
//                p.setProperty("is.debugged", "true"); // NOI18N
309
//            }
310
311
            SubprojectProvider spp = project.getLookup().lookup(SubprojectProvider.class);
312
            if (null != spp) {
313
                StringBuilder edbd = new StringBuilder();
314
                final Set s = spp.getSubprojects();
315
                Iterator iter = s.iterator();
316
                while (iter.hasNext()) {
317
                    Project proj = (Project) iter.next();
318
                    WebModuleProvider wmp = proj.getLookup().lookup(WebModuleProvider.class);
319
                    if (null != wmp) {
320
                        WebModule wm = wmp.findWebModule(proj.getProjectDirectory());
321
                        if (null != wm) {
322
                            FileObject fo = wm.getDocumentBase();
323
                            if (null != fo) {
324
                                edbd.append(FileUtil.toFile(fo).getAbsolutePath()+":"); //NOI18N
325
                            }
326
                        }
327
                    }
328
                }
329
                p.setProperty("ear.docbase.dirs", edbd.toString()); // NOI18N
330
            }
284
        //COMPILATION PART
331
        //COMPILATION PART
285
        } else {
332
        } else {
286
            if (targetNames == null) {
333
            if (targetNames == null) {
287
                throw new IllegalArgumentException(command);
334
                throw new IllegalArgumentException(command);
288
            }
335
            }
289
        }
336
        }
337
        
338
        collectStartupExtenderArgs(p, command);
290
339
291
        return targetNames;
340
        return targetNames;
292
    }
341
    }
Lines 402-405 Link Here
402
    private boolean isCosEnabled() {
451
    private boolean isCosEnabled() {
403
        return Boolean.parseBoolean(project.evaluator().getProperty(EarProjectProperties.J2EE_COMPILE_ON_SAVE));
452
        return Boolean.parseBoolean(project.evaluator().getProperty(EarProjectProperties.J2EE_COMPILE_ON_SAVE));
404
    }
453
    }
454
    
455
    private void collectStartupExtenderArgs(Map p, String command) {
456
        StringBuilder b = new StringBuilder();
457
        for (String arg : runJvmargsIde(command)) {
458
            b.append(' ').append(arg);
459
        }
460
        if (b.length() > 0) {
461
            p.put("run.jvmargs.ide", b.toString()); // NOI18N
462
        }
463
    }
464
    
465
    private List<String> runJvmargsIde(String command) {
466
        StartupExtender.StartMode mode;
467
        if (command.equals(COMMAND_RUN) || command.equals(COMMAND_RUN_SINGLE)) {
468
            mode = StartupExtender.StartMode.NORMAL;
469
        } else if (command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_DEBUG_STEP_INTO)) {
470
            mode = StartupExtender.StartMode.DEBUG;
471
        } else if (command.equals(COMMAND_PROFILE) || command.equals(COMMAND_PROFILE_SINGLE)) {
472
            mode = StartupExtender.StartMode.PROFILE;
473
        } else if (command.equals(COMMAND_TEST) || command.equals(COMMAND_TEST_SINGLE)) {
474
            mode = StartupExtender.StartMode.TEST_NORMAL;
475
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
476
            mode = StartupExtender.StartMode.TEST_DEBUG;
477
        } else if (command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
478
            mode = StartupExtender.StartMode.TEST_PROFILE;
479
        } else {
480
            return Collections.emptyList();
481
        }
482
        List<String> args = new ArrayList<String>();
483
        JavaPlatform p = getActivePlatform();
484
        for (StartupExtender group : StartupExtender.getExtenders(Lookups.fixed(project, p != null ? p : JavaPlatformManager.getDefault().getDefaultPlatform()), mode)) {
485
            args.addAll(group.getArguments());
486
        }
487
        return args;
488
    }
489
    
490
    private JavaPlatform getActivePlatform() {
491
        return CommonProjectUtils.getActivePlatform(project.evaluator().getProperty("platform.active"));
492
    }
405
}
493
}
(-)a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/resources/build-impl.xsl (-10 / +49 lines)
Lines 305-328 Link Here
305
                </fail>
305
                </fail>
306
                <taskdef resource="org/netbeans/modules/java/j2seproject/copylibstask/antlib.xml" classpath="${{libs.CopyLibs.classpath}}"/>
306
                <taskdef resource="org/netbeans/modules/java/j2seproject/copylibstask/antlib.xml" classpath="${{libs.CopyLibs.classpath}}"/>
307
            </target>
307
            </target>
308
308
            
309
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check"/>
309
            <xsl:comment>
310
                pre NB7.2 profiling section; consider it deprecated
311
            </xsl:comment>
312
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check">
313
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
314
            </target>
310
315
311
            <target name="-profile-pre-init">
316
            <target name="-profile-pre-init">
312
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
317
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
313
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
318
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
319
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
314
            </target>
320
            </target>
315
321
316
            <target name="-profile-post-init">
322
            <target name="-profile-post-init">
317
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
323
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
318
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
324
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
325
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
319
            </target>
326
            </target>
320
            <target name="-profile-init-check">
327
            <target name="-profile-init-check">
321
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
328
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
322
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
329
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
323
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
330
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
331
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
324
            </target>
332
            </target>
325
333
            <xsl:comment>
334
                end of pre NB7.2 profiling section
335
            </xsl:comment>
336
            
326
            <target name="init">
337
            <target name="init">
327
                <xsl:attribute name="depends">pre-init,init-private,init-userdir,init-user,init-project,do-init,post-init,init-check,-init-taskdefs</xsl:attribute>
338
                <xsl:attribute name="depends">pre-init,init-private,init-userdir,init-user,init-project,do-init,post-init,init-check,-init-taskdefs</xsl:attribute>
328
            </target>
339
            </target>
Lines 848-854 Link Here
848
    =================
859
    =================
849
    </xsl:comment>
860
    </xsl:comment>
850
861
851
    <target name="profile">
862
    <xsl:comment>
863
        pre NB7.2 profiling section; consider it deprecated
864
    </xsl:comment>
865
    <target name="-profile-pre72">
866
        <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
852
        <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
867
        <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
853
        <condition>
868
        <condition>
854
            <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
869
            <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
Lines 865-871 Link Here
865
            <xsl:attribute name="target">run</xsl:attribute>
880
            <xsl:attribute name="target">run</xsl:attribute>
866
        </antcall>
881
        </antcall>
867
        <antcall>
882
        <antcall>
868
            <xsl:attribute name="target">start-loadgen</xsl:attribute>
883
            <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
869
        </antcall>
884
        </antcall>
870
    </target>
885
    </target>
871
886
Lines 899-910 Link Here
899
            </jvmarg>
914
            </jvmarg>
900
        </nbstartprofiledserver>
915
        </nbstartprofiledserver>
901
    </target>
916
    </target>
917
    <xsl:comment>
918
        end of pre NB7.2 profiling section
919
    </xsl:comment>
902
920
903
    <target name="start-loadgen" if="profiler.loadgen.path">
921
            <target name="-profile-check" if="netbeans.home">
904
            <loadgenstart>
922
                <condition property="profiler.configured">
905
                <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
923
                    <or>
906
            </loadgenstart>
924
                        <contains string="${{run.jvmargs.ide}}" substring="-agentpath:" casesensitive="false"/>
907
    </target>
925
                        <contains string="${{run.jvmargs.ide}}" substring="-javaagent:" casesensitive="false"/>
926
                    </or>
927
                </condition>
928
            </target>
929
930
            <target name="profile" depends="-profile-check,dist,-profile-pre72" if="profiler.configured">
931
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
932
                
933
                <startprofiler/>
934
                <nbstartserver profilemode="true"/>
935
                
936
                <nbdeploy profilemode="true" clientUrlPart="${{client.urlPart}}" forceRedeploy="true" />
937
                <antcall>
938
                    <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
939
                </antcall>
940
            </target>
941
942
            <target name="-profile-start-loadgen" if="profiler.loadgen.path">
943
                <loadgenstart>
944
                    <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
945
                </loadgenstart>
946
            </target>
908
947
909
    <xsl:comment>
948
    <xsl:comment>
910
    CLEANUP SECTION
949
    CLEANUP SECTION
(-)a/j2ee.earproject/src/org/netbeans/modules/j2ee/earproject/ui/resources/layer.xml (-2 / +2 lines)
Lines 174-181 Link Here
174
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
174
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
175
                    <attr name="position" intvalue="900"/>
175
                    <attr name="position" intvalue="900"/>
176
                </file>
176
                </file>
177
                <file name="Profiler_Actions_temporary.shadow">
177
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
178
                    <attr name="originalFile" stringvalue="Projects/Profiler_Actions_temporary"/>
178
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectPopup.instance"/>
179
                    <attr name="position" intvalue="1000"/>
179
                    <attr name="position" intvalue="1000"/>
180
                </file>
180
                </file>
181
                <file name="sep-3.instance">
181
                <file name="sep-3.instance">
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarActionProvider.java (-4 / +13 lines)
Lines 48-54 Link Here
48
import org.netbeans.api.debugger.DebuggerManager;
48
import org.netbeans.api.debugger.DebuggerManager;
49
import org.netbeans.api.debugger.Session;
49
import org.netbeans.api.debugger.Session;
50
import org.netbeans.api.debugger.jpda.AttachingDICookie;
50
import org.netbeans.api.debugger.jpda.AttachingDICookie;
51
import org.netbeans.api.j2ee.core.Profile;
52
import org.netbeans.api.java.classpath.ClassPath;
51
import org.netbeans.api.java.classpath.ClassPath;
53
import org.netbeans.api.java.project.JavaProjectConstants;
52
import org.netbeans.api.java.project.JavaProjectConstants;
54
import org.netbeans.api.java.project.runner.JavaRunner;
53
import org.netbeans.api.java.project.runner.JavaRunner;
Lines 95-105 Link Here
95
        COMMAND_RUN_SINGLE,
94
        COMMAND_RUN_SINGLE,
96
        COMMAND_DEBUG,
95
        COMMAND_DEBUG,
97
        COMMAND_DEBUG_SINGLE,
96
        COMMAND_DEBUG_SINGLE,
97
        COMMAND_PROFILE,
98
        COMMAND_PROFILE_SINGLE,
98
        EjbProjectConstants.COMMAND_REDEPLOY,
99
        EjbProjectConstants.COMMAND_REDEPLOY,
99
        JavaProjectConstants.COMMAND_JAVADOC,
100
        JavaProjectConstants.COMMAND_JAVADOC,
100
        COMMAND_TEST,
101
        COMMAND_TEST,
101
        COMMAND_TEST_SINGLE,
102
        COMMAND_TEST_SINGLE,
102
        COMMAND_DEBUG_TEST_SINGLE,
103
        COMMAND_DEBUG_TEST_SINGLE,
104
        COMMAND_PROFILE_TEST_SINGLE,
103
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
105
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
104
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
106
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
105
        JavaProjectConstants.COMMAND_DEBUG_FIX,
107
        JavaProjectConstants.COMMAND_DEBUG_FIX,
Lines 116-127 Link Here
116
        COMMAND_COMPILE_SINGLE,
118
        COMMAND_COMPILE_SINGLE,
117
        COMMAND_RUN_SINGLE,
119
        COMMAND_RUN_SINGLE,
118
        COMMAND_DEBUG_SINGLE,
120
        COMMAND_DEBUG_SINGLE,
121
        COMMAND_PROFILE_SINGLE,
119
        JavaProjectConstants.COMMAND_JAVADOC,
122
        JavaProjectConstants.COMMAND_JAVADOC,
120
        COMMAND_TEST,
123
        COMMAND_TEST,
121
        COMMAND_TEST_SINGLE,
124
        COMMAND_TEST_SINGLE,
122
        COMMAND_DEBUG_TEST_SINGLE,
125
        COMMAND_DEBUG_TEST_SINGLE,
126
        COMMAND_PROFILE_TEST_SINGLE,
123
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
127
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
124
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
128
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD
125
    };
129
    };
126
130
127
    private final EjbJarProject project;
131
    private final EjbJarProject project;
Lines 153-158 Link Here
153
        commands.put(COMMAND_RUN_SINGLE, new String[] {"run-main"}); // NOI18N
157
        commands.put(COMMAND_RUN_SINGLE, new String[] {"run-main"}); // NOI18N
154
        commands.put(EjbProjectConstants.COMMAND_REDEPLOY, new String[] {"run"}); // NOI18N
158
        commands.put(EjbProjectConstants.COMMAND_REDEPLOY, new String[] {"run"}); // NOI18N
155
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
159
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
160
        commands.put(COMMAND_PROFILE, new String[]{"profile"}); // NOI18N
156
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc"}); // NOI18N
161
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc"}); // NOI18N
157
        commands.put(COMMAND_TEST, new String[] {"test"}); // NOI18N
162
        commands.put(COMMAND_TEST, new String[] {"test"}); // NOI18N
158
        commands.put(COMMAND_TEST_SINGLE, new String[] {"test-single"}); // NOI18N
163
        commands.put(COMMAND_TEST_SINGLE, new String[] {"test-single"}); // NOI18N
Lines 160-165 Link Here
160
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[] {"debug-fix"}); // NOI18N
165
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[] {"debug-fix"}); // NOI18N
161
        commands.put(COMMAND_VERIFY, new String[] {"verify"}); // NOI18N
166
        commands.put(COMMAND_VERIFY, new String[] {"verify"}); // NOI18N
162
        commands.put(COMMAND_DEBUG_SINGLE, new String[] {"debug-single"}); // NOI18N
167
        commands.put(COMMAND_DEBUG_SINGLE, new String[] {"debug-single"}); // NOI18N
168
        commands.put(COMMAND_PROFILE_SINGLE, new String[]{"profile-single"}); // NOI18N
163
        this.bkgScanSensitiveActions = new HashSet<String>(Arrays.asList(
169
        this.bkgScanSensitiveActions = new HashSet<String>(Arrays.asList(
164
            COMMAND_RUN_SINGLE
170
            COMMAND_RUN_SINGLE
165
        ));
171
        ));
Lines 209-215 Link Here
209
    protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) {
215
    protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) {
210
        if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) ||
216
        if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) ||
211
            SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) ||
217
            SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) ||
212
            COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command)) {
218
            COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) ||
219
            COMMAND_PROFILE_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command)) {
213
            FileObject fo = (FileObject)execProperties.get(JavaRunner.PROP_EXECUTE_FILE);
220
            FileObject fo = (FileObject)execProperties.get(JavaRunner.PROP_EXECUTE_FILE);
214
            ClassPath cp = getCallback().findClassPath(fo, ClassPath.EXECUTE);
221
            ClassPath cp = getCallback().findClassPath(fo, ClassPath.EXECUTE);
215
            ClassPath cp2 = ClassPathFactory.createClassPath(
222
            ClassPath cp2 = ClassPathFactory.createClassPath(
Lines 243-249 Link Here
243
        if (command.equals(COMMAND_RUN_SINGLE) ||command.equals(COMMAND_RUN) ||
250
        if (command.equals(COMMAND_RUN_SINGLE) ||command.equals(COMMAND_RUN) ||
244
            command.equals(EjbProjectConstants.COMMAND_REDEPLOY) ||command.equals(COMMAND_DEBUG) ||
251
            command.equals(EjbProjectConstants.COMMAND_REDEPLOY) ||command.equals(COMMAND_DEBUG) ||
245
            command.equals(COMMAND_DEBUG_SINGLE) || command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX) ||
252
            command.equals(COMMAND_DEBUG_SINGLE) || command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX) ||
246
            command.equals( COMMAND_TEST_SINGLE) || command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
253
            command.equals( COMMAND_TEST_SINGLE) || command.equals(COMMAND_DEBUG_TEST_SINGLE) ||
254
            command.equals(COMMAND_PROFILE) || command.equals(COMMAND_PROFILE_SINGLE) ||
255
            command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
247
            setDirectoryDeploymentProperty(p);
256
            setDirectoryDeploymentProperty(p);
248
        }
257
        }
249
        if (command.equals(COMMAND_RUN) || command.equals(EjbProjectConstants.COMMAND_REDEPLOY)) {
258
        if (command.equals(COMMAND_RUN) || command.equals(EjbProjectConstants.COMMAND_REDEPLOY)) {
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/resources/build-impl.xsl (-44 / +85 lines)
Lines 663-668 Link Here
663
                            <jvmarg line="${{endorsed.classpath.cmd.line.arg}}"/>
663
                            <jvmarg line="${{endorsed.classpath.cmd.line.arg}}"/>
664
                            <jvmarg value="-ea"/>
664
                            <jvmarg value="-ea"/>
665
                            <jvmarg line="${{runmain.jvmargs}}"/>
665
                            <jvmarg line="${{runmain.jvmargs}}"/>
666
                            <jvmarg line="${{run.jvmargs.ide}}"/>
666
                        </junit>
667
                        </junit>
667
                    </sequential>
668
                    </sequential>
668
                </macrodef>
669
                </macrodef>
Lines 858-881 Link Here
858
            <target name="-init-ap-cmdline" depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported">
859
            <target name="-init-ap-cmdline" depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported">
859
                <property name="ap.cmd.line.internal" value=""/>
860
                <property name="ap.cmd.line.internal" value=""/>
860
            </target>
861
            </target>
861
862
            
862
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check"/>
863
            <xsl:comment>
864
                pre NB7.2 profiling section; consider it deprecated
865
            </xsl:comment>
866
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check">
867
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
868
            </target>
863
869
864
            <target name="-profile-pre-init">
870
            <target name="-profile-pre-init">
865
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
871
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
866
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
872
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
873
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
867
            </target>
874
            </target>
868
875
869
            <target name="-profile-post-init">
876
            <target name="-profile-post-init">
870
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
877
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
871
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
878
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
879
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
872
            </target>
880
            </target>
873
            <target name="-profile-init-check">
881
            <target name="-profile-init-check">
874
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
882
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
875
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
883
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
876
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
884
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
885
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
877
            </target>
886
            </target>
878
887
            <xsl:comment>
888
                end of pre NB7.2 profiling section
889
            </xsl:comment>
879
890
880
            <target name="init">
891
            <target name="init">
881
                <xsl:attribute name="depends">-pre-init,-init-private,-init-userdir,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-java,-init-macrodef-nbjpda,-init-macrodef-debug,-init-taskdefs,-init-ap-cmdline</xsl:attribute>
892
                <xsl:attribute name="depends">-pre-init,-init-private,-init-userdir,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-java,-init-macrodef-nbjpda,-init-macrodef-debug,-init-taskdefs,-init-ap-cmdline</xsl:attribute>
Lines 1430-1437 Link Here
1430
            =================
1441
            =================
1431
            </xsl:comment>
1442
            </xsl:comment>
1432
1443
1433
            <target name="profile">
1444
            <xsl:comment>
1445
                pre NB7.2 profiling section; consider it deprecated
1446
            </xsl:comment>
1447
            <target name="-profile-pre72">
1448
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
1434
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1449
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1450
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1435
                <condition>
1451
                <condition>
1436
                    <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
1452
                    <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
1437
                    <xsl:attribute name="value">start-profiled-server-extraargs</xsl:attribute>
1453
                    <xsl:attribute name="value">start-profiled-server-extraargs</xsl:attribute>
Lines 1447-1455 Link Here
1447
                    <xsl:attribute name="target">run</xsl:attribute>
1463
                    <xsl:attribute name="target">run</xsl:attribute>
1448
                </antcall>
1464
                </antcall>
1449
                <antcall>
1465
                <antcall>
1450
                    <xsl:attribute name="target">start-loadgen</xsl:attribute>
1466
                    <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
1451
                </antcall>
1467
                </antcall>
1452
            </target>
1468
            </target>
1469
            
1470
            <target name="-profile-test-single-pre72">
1471
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
1472
                <xsl:attribute name="depends">profile-init,compile-test-single</xsl:attribute>
1473
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1474
                <nbprofiledirect>
1475
                    <classpath>
1476
                        <path path="${{run.test.classpath}}"/>
1477
                        <path path="${{j2ee.platform.classpath}}"/>
1478
                    </classpath>
1479
                </nbprofiledirect>
1480
1481
                <junit showoutput="true" fork="true" dir="${{profiler.info.dir}}"  jvm="${{profiler.info.jvm}}" failureproperty="tests.failed" errorproperty="tests.failed">
1482
                    <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
1483
                    <jvmarg value="${{profiler.info.jvmargs.agent}}" />
1484
                    <jvmarg line="${{profiler.info.jvmargs}}"/>
1485
                    <test name="${{profile.class}}"/>
1486
                    <classpath>
1487
                        <path path="${{run.test.classpath}}"/>
1488
                        <path path="${{j2ee.platform.classpath}}"/>
1489
                    </classpath>
1490
                    <syspropertyset>
1491
                        <propertyref prefix="test-sys-prop."/>
1492
                        <mapper type="glob" from="test-sys-prop.*" to="*"/>
1493
                    </syspropertyset>
1494
                    <formatter type="brief" usefile="false"/>
1495
                    <formatter type="xml"/>
1496
                </junit>
1497
            </target>
1453
1498
1454
            <target name="start-profiled-server">
1499
            <target name="start-profiled-server">
1455
                <nbstartprofiledserver>
1500
                <nbstartprofiledserver>
Lines 1481-1491 Link Here
1481
                    </jvmarg>
1526
                    </jvmarg>
1482
                </nbstartprofiledserver>
1527
                </nbstartprofiledserver>
1483
            </target>
1528
            </target>
1529
            <xsl:comment>
1530
                end of pre NB7.2 profiling section
1531
            </xsl:comment>
1484
1532
1485
            <target name="start-loadgen" if="profiler.loadgen.path">
1533
            <target name="-profile-check" if="netbeans.home">
1486
                    <loadgenstart>
1534
                <condition property="profiler.configured">
1487
                        <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
1535
                    <or>
1488
                    </loadgenstart>
1536
                        <contains string="${{run.jvmargs.ide}}" substring="-agentpath:" casesensitive="false"/>
1537
                        <contains string="${{run.jvmargs.ide}}" substring="-javaagent:" casesensitive="false"/>
1538
                    </or>
1539
                </condition>
1540
            </target>
1541
1542
            <target name="profile" depends="-profile-check,init,compile,dist-directory-deploy,-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent">
1543
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1544
                
1545
                <startprofiler/>
1546
                <nbstartserver profilemode="true"/>
1547
                
1548
                <nbdeploy profilemode="true" clientUrlPart="${client.urlPart}" forceRedeploy="true" />
1549
                <antcall>
1550
                    <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
1551
                </antcall>
1552
            </target>
1553
            
1554
            <target name="profile-test-single" depends="-profile-test-single-pre72"/>
1555
            
1556
            <target name="profile-test" depends="-profile-check" if="profiler.configured" unless="profiler.info.jvmargs.agent">
1557
                <startprofiler/>
1558
                <antcall target="test-single"/>
1559
            </target>
1560
1561
            <target name="-profile-start-loadgen" if="profiler.loadgen.path">
1562
                <loadgenstart>
1563
                    <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
1564
                </loadgenstart>
1489
            </target>
1565
            </target>
1490
1566
1491
            <xsl:comment>
1567
            <xsl:comment>
Lines 1760-1800 Link Here
1760
                <xsl:attribute name="depends">init,-pre-debug-fix,-do-debug-fix-test</xsl:attribute>
1836
                <xsl:attribute name="depends">init,-pre-debug-fix,-do-debug-fix-test</xsl:attribute>
1761
            </target>
1837
            </target>
1762
1838
1763
        <xsl:comment>
1764
        =========================
1765
        TESTS PROFILING  SECTION
1766
        =========================
1767
        </xsl:comment>
1768
1769
          <target name="profile-test-single">
1770
              <xsl:attribute name="if">netbeans.home</xsl:attribute>
1771
              <xsl:attribute name="depends">profile-init,compile-test-single</xsl:attribute>
1772
              <nbprofiledirect>
1773
                  <classpath>
1774
                      <path path="${{run.test.classpath}}"/>
1775
                      <path path="${{j2ee.platform.classpath}}"/>
1776
                  </classpath>
1777
              </nbprofiledirect>
1778
1779
              <junit showoutput="true" fork="true" dir="${{profiler.info.dir}}"  jvm="${{profiler.info.jvm}}" failureproperty="tests.failed" errorproperty="tests.failed">
1780
                  <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
1781
                  <jvmarg value="${{profiler.info.jvmargs.agent}}" />
1782
                  <jvmarg line="${{profiler.info.jvmargs}}"/>
1783
                  <test name="${{profile.class}}"/>
1784
                  <classpath>
1785
                      <path path="${{run.test.classpath}}"/>
1786
                      <path path="${{j2ee.platform.classpath}}"/>
1787
                  </classpath>
1788
                  <syspropertyset>
1789
                      <propertyref prefix="test-sys-prop."/>
1790
                      <mapper type="glob" from="test-sys-prop.*" to="*"/>
1791
                  </syspropertyset>
1792
                  <formatter type="brief" usefile="false"/>
1793
                  <formatter type="xml"/>
1794
              </junit>
1795
          </target>
1796
1797
1798
            <xsl:comment>
1839
            <xsl:comment>
1799
                CLEANUP SECTION
1840
                CLEANUP SECTION
1800
            </xsl:comment>
1841
            </xsl:comment>
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/ui/resources/layer.xml (-2 / +2 lines)
Lines 168-175 Link Here
168
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
168
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
169
                    <attr name="position" intvalue="900"/>
169
                    <attr name="position" intvalue="900"/>
170
                </file>
170
                </file>
171
                <file name="Profiler_Actions_temporary.shadow">
171
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
172
                    <attr name="originalFile" stringvalue="Projects/Profiler_Actions_temporary"/>
172
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectPopup.instance"/>
173
                    <attr name="position" intvalue="1000"/>
173
                    <attr name="position" intvalue="1000"/>
174
                </file>
174
                </file>
175
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
175
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
(-)a/j2eeserver/src/org/netbeans/modules/j2ee/deployment/impl/ServerInstance.java (-17 / +46 lines)
Lines 67-72 Link Here
67
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
67
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
68
import org.netbeans.modules.j2ee.deployment.plugins.spi.JDBCDriverDeployer;
68
import org.netbeans.modules.j2ee.deployment.plugins.spi.JDBCDriverDeployer;
69
import java.util.*;
69
import java.util.*;
70
import java.util.concurrent.ExecutorService;
71
import java.util.concurrent.Executors;
72
import java.util.concurrent.ScheduledExecutorService;
73
import java.util.concurrent.TimeUnit;
70
import java.util.concurrent.TimeoutException;
74
import java.util.concurrent.TimeoutException;
71
import java.util.logging.Level;
75
import java.util.logging.Level;
72
import java.util.logging.Logger;
76
import java.util.logging.Logger;
Lines 373-394 Link Here
373
                    int oldState = getServerState();
377
                    int oldState = getServerState();
374
                    setServerState(STATE_WAITING);
378
                    setServerState(STATE_WAITING);
375
                    if (ServerInstance.this == profiledServerInstance) {
379
                    if (ServerInstance.this == profiledServerInstance) {
376
                        int profState = ProfilerSupport.getState();
380
                        updateStateFromProfiler();
377
                        if (profState == ProfilerSupport.STATE_STARTING) {
381
                        return;
378
                            setServerState(ServerInstance.STATE_PROFILER_STARTING);
379
                            return;
380
                        } else if (profState == ProfilerSupport.STATE_BLOCKING) {
381
                            setServerState(ServerInstance.STATE_PROFILER_BLOCKING);
382
                            return;
383
                        } else if (profState == ProfilerSupport.STATE_PROFILING
384
                                   || profState == ProfilerSupport.STATE_RUNNING) {
385
                            initCoTarget();
386
                            setServerState(ServerInstance.STATE_PROFILING);
387
                            return;
388
                        } else {
389
                            //  profiler is inactive - has been shutdown
390
                            profiledServerInstance = null;
391
                        }
392
                    }
382
                    }
393
                    if (isSuspended()) {
383
                    if (isSuspended()) {
394
                        setServerState(ServerInstance.STATE_SUSPENDED);
384
                        setServerState(ServerInstance.STATE_SUSPENDED);
Lines 1513-1523 Link Here
1513
            profiledServerInstance = null;
1503
            profiledServerInstance = null;
1514
        }
1504
        }
1515
        
1505
        
1516
        Profiler profiler = ServerRegistry.getProfiler();
1506
        final Profiler profiler = ServerRegistry.getProfiler();
1517
        if (profiler == null) {
1507
        if (profiler == null) {
1518
            // this should not occur, but better make sure
1508
            // this should not occur, but better make sure
1519
            throw new ServerException(NbBundle.getMessage(ServerInstance.class, "MSG_ProfilerNotRegistered"));
1509
            throw new ServerException(NbBundle.getMessage(ServerInstance.class, "MSG_ProfilerNotRegistered"));
1520
        }
1510
        }
1511
        
1512
        final ScheduledExecutorService statusUpdater = Executors.newSingleThreadScheduledExecutor();
1513
        statusUpdater.scheduleAtFixedRate(new Runnable() {
1514
1515
            @Override
1516
            public void run() {
1517
                updateStateFromProfiler();
1518
            }
1519
        }, 50, 100, TimeUnit.MILLISECONDS);
1520
        
1521
        final StateListener l = new StateListener() {
1522
1523
            @Override
1524
            public void stateChanged(int oldState, int newState) {
1525
                if (oldState != newState && newState == STATE_STOPPED) {
1526
                    ServerInstance.this.removeStateListener(this);
1527
                    statusUpdater.shutdownNow();
1528
                    profiledServerInstance = null;
1529
                }
1530
            }
1531
        };
1532
        
1533
        this.addStateListener(l);
1534
        
1521
        profiler.notifyStarting();
1535
        profiler.notifyStarting();
1522
        ProgressObject po = getStartServer().startProfiling(target);
1536
        ProgressObject po = getStartServer().startProfiling(target);
1523
        try {
1537
        try {
Lines 1995-1998 Link Here
1995
            }
2009
            }
1996
        }
2010
        }
1997
    }
2011
    }
2012
    
2013
    private void updateStateFromProfiler() {
2014
        int profState = ProfilerSupport.getState();
2015
        if (profState == ProfilerSupport.STATE_STARTING) {
2016
            setServerState(ServerInstance.STATE_PROFILER_STARTING);
2017
        } else if (profState == ProfilerSupport.STATE_BLOCKING) {
2018
            setServerState(ServerInstance.STATE_PROFILER_BLOCKING);
2019
        } else if (profState == ProfilerSupport.STATE_PROFILING
2020
                    || profState == ProfilerSupport.STATE_RUNNING) {
2021
            initCoTarget();
2022
            setServerState(ServerInstance.STATE_PROFILING);
2023
        } else {
2024
            setServerState(ServerInstance.STATE_STOPPED);
2025
        }
2026
    }
1998
}
2027
}
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/BaseActionProvider.java (-59 / +103 lines)
Lines 456-462 Link Here
456
                        }
456
                        }
457
                    }
457
                    }
458
458
459
                    if (targetNames.length == 1 && ("run-applet".equals(targetNames[0]) || "debug-applet".equals(targetNames[0]))) {
459
                    if (targetNames.length == 1 && (JavaRunner.QUICK_RUN_APPLET.equals(targetNames[0]) || JavaRunner.QUICK_DEBUG_APPLET.equals(targetNames[0]) || JavaRunner.QUICK_PROFILE_APPLET.equals(targetNames[0]))) {
460
                        try {
460
                        try {
461
                            final FileObject[] selectedFiles = findSources(context);
461
                            final FileObject[] selectedFiles = findSources(context);
462
                            if (selectedFiles != null) {
462
                            if (selectedFiles != null) {
Lines 464-470 Link Here
464
                                String url = p.getProperty("applet.url");
464
                                String url = p.getProperty("applet.url");
465
                                execProperties.put("applet.url", url);
465
                                execProperties.put("applet.url", url);
466
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
466
                                execProperties.put(JavaRunner.PROP_EXECUTE_FILE, file);
467
                                prepareSystemProperties(execProperties, false);
467
                                prepareSystemProperties(execProperties, command, false);
468
                                JavaRunner.execute(targetNames[0], execProperties);
468
                                JavaRunner.execute(targetNames[0], execProperties);
469
                            }
469
                            }
470
                        } catch (IOException ex) {
470
                        } catch (IOException ex) {
Lines 472-503 Link Here
472
                        }
472
                        }
473
                        return;
473
                        return;
474
                    }
474
                    }
475
                    if (!isServerExecution() && (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command))) {
475
                    if (!isServerExecution() && (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command) || COMMAND_PROFILE.equals(command))) {
476
                        prepareSystemProperties(execProperties, false);
476
                        prepareSystemProperties(execProperties, command, false);
477
                        bypassAntBuildScript(command, context, execProperties);
477
                        bypassAntBuildScript(command, context, execProperties);
478
                        return ;
478
                        return ;
479
                    }
479
                    }
480
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
480
                    // for example RUN_SINGLE Java file with Servlet must be run on server and not locally
481
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
481
                    boolean serverExecution = p.getProperty(PROPERTY_RUN_SINGLE_ON_SERVER) != null;
482
                    p.remove(PROPERTY_RUN_SINGLE_ON_SERVER);
482
                    p.remove(PROPERTY_RUN_SINGLE_ON_SERVER);
483
                    if (!serverExecution && (COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command))) {
483
                    if (!serverExecution && (COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) || COMMAND_PROFILE_SINGLE.equals(command))) {
484
                        prepareSystemProperties(execProperties, false);
484
                        prepareSystemProperties(execProperties, command, false);
485
                        if (COMMAND_RUN_SINGLE.equals(command)) {
485
                        if (COMMAND_RUN_SINGLE.equals(command)) {
486
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("run.class"));
486
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("run.class"));
487
                        } else if (COMMAND_DEBUG_SINGLE.equals(command)) {
488
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("debug.class")); 
487
                        } else {
489
                        } else {
488
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("debug.class"));
490
                            execProperties.put(JavaRunner.PROP_CLASSNAME, p.getProperty("profile.class"));
489
                        }
491
                        }
490
                        bypassAntBuildScript(command, context, execProperties);
492
                        bypassAntBuildScript(command, context, execProperties);
491
                        return;
493
                        return;
492
                    }
494
                    }
493
                    if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command)) {
495
                    if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command)) {
494
                        FileObject[] files = findTestSources(context, true);
496
                        FileObject[] files = findTestSources(context, true);
495
                        try {
497
                        try {
496
                            prepareSystemProperties(execProperties, true);
498
                            prepareSystemProperties(execProperties, command, true);
497
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
499
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
498
                            execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(evaluator.getProperty(ProjectProperties.BUILD_DIR)));   //NOI18N
500
                            execProperties.put("tmp.dir", updateHelper.getAntProjectHelper().resolvePath(evaluator.getProperty(ProjectProperties.BUILD_DIR)));   //NOI18N
499
                            updateJavaRunnerClasspath(command, execProperties);
501
                            updateJavaRunnerClasspath(command, execProperties);
500
                            JavaRunner.execute(COMMAND_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG, execProperties);
502
                            JavaRunner.execute(COMMAND_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST : (COMMAND_DEBUG_TEST_SINGLE.equals(command) ? JavaRunner.QUICK_TEST_DEBUG : JavaRunner.QUICK_TEST_PROFILE), execProperties);
501
                        } catch (IOException ex) {
503
                        } catch (IOException ex) {
502
                            Exceptions.printStackTrace(ex);
504
                            Exceptions.printStackTrace(ex);
503
                        }
505
                        }
Lines 506-530 Link Here
506
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command)) {
508
                    if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command)) {
507
                        SingleMethod methodSpec = findTestMethods(context)[0];
509
                        SingleMethod methodSpec = findTestMethods(context)[0];
508
                        try {
510
                        try {
511
                            prepareSystemProperties(execProperties, command, false);
509
                            execProperties.put("methodname", methodSpec.getMethodName());//NOI18N
512
                            execProperties.put("methodname", methodSpec.getMethodName());//NOI18N
510
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, methodSpec.getFile());
513
                            execProperties.put(JavaRunner.PROP_EXECUTE_FILE, methodSpec.getFile());
511
                            execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(evaluator.getProperty(ProjectProperties.BUILD_DIR)));   //NOI18N
514
                            execProperties.put("tmp.dir",updateHelper.getAntProjectHelper().resolvePath(evaluator.getProperty(ProjectProperties.BUILD_DIR)));   //NOI18N
512
                            updateJavaRunnerClasspath(command, execProperties);
515
                            updateJavaRunnerClasspath(command, execProperties);
513
                            JavaRunner.execute(command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : JavaRunner.QUICK_TEST_DEBUG,
516
                            JavaRunner.execute(command.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) ? JavaRunner.QUICK_TEST : (SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) ? JavaRunner.QUICK_TEST_DEBUG :JavaRunner.QUICK_TEST_PROFILE),
514
                                                  execProperties);
517
                                               execProperties);
515
                        } catch (IOException ex) {
518
                        } catch (IOException ex) {
516
                            Exceptions.printStackTrace(ex);
519
                            Exceptions.printStackTrace(ex);
517
                        }
520
                        }
518
                        return;
521
                        return;
519
                    }
522
                    }
520
                }
523
                }
521
                StringBuilder b = new StringBuilder();
524
                collectStartupExtenderArgs(p, command);
522
                for (String arg : runJvmargsIde()) {
523
                    b.append(' ').append(arg);
524
                }
525
                if (b.length() > 0) {
526
                    p.put(ProjectProperties.RUN_JVM_ARGS_IDE, b.toString());
527
                }
528
                if (targetNames.length == 0) {
525
                if (targetNames.length == 0) {
529
                    targetNames = null;
526
                    targetNames = null;
530
                }
527
                }
Lines 581-612 Link Here
581
                    ErrorManager.getDefault().notify(e);
578
                    ErrorManager.getDefault().notify(e);
582
                }
579
                }
583
            }
580
            }
584
585
            private List<String> runJvmargsIde() {
586
                StartupExtender.StartMode mode;
587
                if (command.equals(COMMAND_RUN) || command.equals(COMMAND_RUN_SINGLE)) {
588
                    mode = StartupExtender.StartMode.NORMAL;
589
                } else if (command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_DEBUG_STEP_INTO)) {
590
                    mode = StartupExtender.StartMode.DEBUG;
591
                } else if (command.equals("profile")) {
592
                    mode = StartupExtender.StartMode.PROFILE;
593
                } else if (command.equals(COMMAND_TEST) || command.equals(COMMAND_TEST_SINGLE)) {
594
                    mode = StartupExtender.StartMode.TEST_NORMAL;
595
                } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
596
                    mode = StartupExtender.StartMode.TEST_DEBUG;
597
                } else if (command.equals("profile-test-single")) {
598
                    mode = StartupExtender.StartMode.TEST_PROFILE;
599
                } else {
600
                    return Collections.emptyList();
601
                }
602
                List<String> args = new ArrayList<String>();
603
                JavaPlatform p = getActivePlatform();
604
                for (StartupExtender group : StartupExtender.getExtenders(Lookups.fixed(project, p != null ? p : JavaPlatformManager.getDefault().getDefaultPlatform()), mode)) {
605
                    args.addAll(group.getArguments());
606
                }
607
                return args;
608
            }
609
610
        }
581
        }
611
        final Action action = new Action();
582
        final Action action = new Action();
612
583
Lines 705-710 Link Here
705
                return null;
676
                return null;
706
            }
677
            }
707
            targetNames = setupDebugTestSingle(p, files);
678
            targetNames = setupDebugTestSingle(p, files);
679
        } else if ( command.equals( COMMAND_PROFILE_TEST_SINGLE ) ) {
680
            final FileObject[] files = findTestSources(context, true);
681
            if (files == null) {
682
                return null;
683
            }
684
            targetNames = setupProfileTestSingle(p, files);
708
        } else if ( command.equals( SingleMethod.COMMAND_RUN_SINGLE_METHOD ) ) {
685
        } else if ( command.equals( SingleMethod.COMMAND_RUN_SINGLE_METHOD ) ) {
709
            SingleMethod[] methodSpecs = findTestMethods(context);
686
            SingleMethod[] methodSpecs = findTestMethods(context);
710
            if ((methodSpecs == null) || (methodSpecs.length != 1)) {
687
            if ((methodSpecs == null) || (methodSpecs.length != 1)) {
Lines 737-743 Link Here
737
            }
714
            }
738
            p.setProperty("fix.includes", path); // NOI18N
715
            p.setProperty("fix.includes", path); // NOI18N
739
            p.setProperty("fix.classes", classes); // NOI18N
716
            p.setProperty("fix.classes", classes); // NOI18N
740
        } else if (!isServerExecution() && (command.equals (COMMAND_RUN) || command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_STEP_INTO))) {
717
        } else if (!isServerExecution() && (command.equals (COMMAND_RUN) || command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_STEP_INTO) || command.equals(COMMAND_PROFILE))) {
741
            String config = evaluator.getProperty(ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG);
718
            String config = evaluator.getProperty(ProjectProperties.PROP_PROJECT_CONFIGURATION_CONFIG);
742
            String path;
719
            String path;
743
            if (config == null || config.length() == 0) {
720
            if (config == null || config.length() == 0) {
Lines 789-795 Link Here
789
                }
766
                }
790
            }
767
            }
791
            if (!command.equals(COMMAND_RUN) && /* XXX should ideally look up proper mainClass in evaluator x config */ mainClass != null) {
768
            if (!command.equals(COMMAND_RUN) && /* XXX should ideally look up proper mainClass in evaluator x config */ mainClass != null) {
792
                p.setProperty("debug.class", mainClass); // NOI18N
769
                if (command.equals(COMMAND_PROFILE)) {
770
                    p.setProperty("run.class", mainClass); // NOI18N
771
                } else {
772
                    p.setProperty("debug.class", mainClass); // NOI18N
773
                }
793
            }
774
            }
794
            String[] targets = targetsFromConfig.get(command);
775
            String[] targets = targetsFromConfig.get(command);
795
            targetNames = (targets != null) ? targets : getCommands().get(command);
776
            targetNames = (targets != null) ? targets : getCommands().get(command);
Lines 797-803 Link Here
797
                throw new IllegalArgumentException(command);
778
                throw new IllegalArgumentException(command);
798
            }
779
            }
799
            prepareDirtyList(p, false);
780
            prepareDirtyList(p, false);
800
        } else if (command.equals (COMMAND_RUN_SINGLE) || command.equals (COMMAND_DEBUG_SINGLE)) {
781
        } else if (command.equals (COMMAND_RUN_SINGLE) || command.equals (COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_PROFILE_SINGLE)) {
801
            FileObject[] files = findTestSources(context, false);
782
            FileObject[] files = findTestSources(context, false);
802
            FileObject[] rootz = projectTestRoots.getRoots();
783
            FileObject[] rootz = projectTestRoots.getRoots();
803
            boolean isTest = true;
784
            boolean isTest = true;
Lines 872-882 Link Here
872
                            return null;
853
                            return null;
873
                        }
854
                        }
874
                        p.setProperty("applet.url", url.toString()); // NOI18N
855
                        p.setProperty("applet.url", url.toString()); // NOI18N
875
                        if (command.equals (COMMAND_RUN_SINGLE)) {
856
                        if (COMMAND_RUN_SINGLE.equals(command)) {
876
                            targetNames = new String[] {"run-applet"}; // NOI18N
857
                            targetNames = new String[] {"run-applet"}; // NOI18N
877
                        } else {
858
                        } else if (COMMAND_DEBUG_SINGLE.equals(command)) {
878
                            p.setProperty("debug.class", clazz); // NOI18N
859
                            p.setProperty("debug.class", clazz); // NOI18N
879
                            targetNames = new String[] {"debug-applet"}; // NOI18N
860
                            targetNames = new String[] {"debug-applet"}; // NOI18N
861
                        } else if (COMMAND_PROFILE_SINGLE.equals(command)) {
862
                            p.setProperty("run.class", clazz); // NOI18N
863
                            targetNames = new String[]{"profile-applet"}; // NOI18N
880
                        }
864
                        }
881
                    } else {
865
                    } else {
882
                        List<String> alternativeTargetNames = new ArrayList<String>();
866
                        List<String> alternativeTargetNames = new ArrayList<String>();
Lines 884-891 Link Here
884
                            //Fallback to normal (non-main-method-based) unit test run
868
                            //Fallback to normal (non-main-method-based) unit test run
885
                            if (command.equals(COMMAND_RUN_SINGLE)) {
869
                            if (command.equals(COMMAND_RUN_SINGLE)) {
886
                                targetNames = setupTestSingle(p, files);
870
                                targetNames = setupTestSingle(p, files);
871
                            } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
872
                                targetNames = setupDebugTestSingle(p, files);
887
                            } else {
873
                            } else {
888
                                targetNames = setupDebugTestSingle(p, files);
874
                                targetNames = setupProfileTestSingle(p, files);
889
                            }
875
                            }
890
                        } else if (handleJavaClass(p, file, command, alternativeTargetNames)) {
876
                        } else if (handleJavaClass(p, file, command, alternativeTargetNames)) {
891
                            if (alternativeTargetNames.size() > 0) {
877
                            if (alternativeTargetNames.size() > 0) {
Lines 916-925 Link Here
916
                        p.setProperty("run.class", clazz); // NOI18N
902
                        p.setProperty("run.class", clazz); // NOI18N
917
                        String[] targets = targetsFromConfig.get(command);
903
                        String[] targets = targetsFromConfig.get(command);
918
                        targetNames = (targets != null) ? targets : (isTest ? new String[] { "run-test-with-main" } : getCommands().get(COMMAND_RUN_SINGLE));
904
                        targetNames = (targets != null) ? targets : (isTest ? new String[] { "run-test-with-main" } : getCommands().get(COMMAND_RUN_SINGLE));
919
                    } else {
905
                    } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
920
                        p.setProperty("debug.class", clazz); // NOI18N
906
                        p.setProperty("debug.class", clazz); // NOI18N
921
                        String[] targets = targetsFromConfig.get(command);
907
                        String[] targets = targetsFromConfig.get(command);
922
                        targetNames = (targets != null) ? targets : (isTest ? new String[] {"debug-test-with-main"} : getCommands().get(COMMAND_DEBUG_SINGLE));
908
                        targetNames = (targets != null) ? targets : (isTest ? new String[] {"debug-test-with-main"} : getCommands().get(COMMAND_DEBUG_SINGLE));
909
                    } else {
910
                        p.setProperty("run.class", clazz); // NOI18N
911
                        String[] targets = targetsFromConfig.get(command);
912
                        targetNames = (targets != null) ? targets : (isTest ? new String[] {"profile-test-with-main"} : getCommands().get(COMMAND_PROFILE_SINGLE));
923
                    }
913
                    }
924
                }
914
                }
925
            }
915
            }
Lines 933-942 Link Here
933
                        p.setProperty("run.class", clazz); // NOI18N
923
                        p.setProperty("run.class", clazz); // NOI18N
934
                        String[] targets = targetsFromConfig.get(command);
924
                        String[] targets = targetsFromConfig.get(command);
935
                        targetNames = (targets != null) ? targets : (isTest ? new String[] { "run-test-with-main" } : getCommands().get(COMMAND_RUN_SINGLE));    //NOI18N
925
                        targetNames = (targets != null) ? targets : (isTest ? new String[] { "run-test-with-main" } : getCommands().get(COMMAND_RUN_SINGLE));    //NOI18N
936
                } else {
926
                } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
937
                    p.setProperty("debug.class", clazz); // NOI18N
927
                    p.setProperty("debug.class", clazz); // NOI18N
938
                    String[] targets = targetsFromConfig.get(command);
928
                    String[] targets = targetsFromConfig.get(command);
939
                    targetNames = (targets != null) ? targets : (isTest ? new String[] {"debug-test-with-main"} : getCommands().get(COMMAND_DEBUG_SINGLE));      //NOI18N
929
                    targetNames = (targets != null) ? targets : (isTest ? new String[] {"debug-test-with-main"} : getCommands().get(COMMAND_DEBUG_SINGLE));      //NOI18N
930
                } else {
931
                    p.setProperty("run.class", clazz); // NOI18N
932
                    String[] targets = targetsFromConfig.get(command);
933
                    targetNames = (targets != null) ? targets : (isTest ? new String[] {"profile-test-with-main"} : getCommands().get(COMMAND_DEBUG_SINGLE));      //NOI18N
940
                }
934
                }
941
            }
935
            }
942
        } else {
936
        } else {
Lines 958-963 Link Here
958
                dirty = null;
952
                dirty = null;
959
            }
953
            }
960
        }
954
        }
955
        
961
        return targetNames;
956
        return targetNames;
962
    }
957
    }
963
958
Lines 1076-1081 Link Here
1076
        p.setProperty("javac.includes", ActionUtils.antIncludesList(files, root)); // NOI18N
1071
        p.setProperty("javac.includes", ActionUtils.antIncludesList(files, root)); // NOI18N
1077
        return new String[] {"debug-test"}; // NOI18N
1072
        return new String[] {"debug-test"}; // NOI18N
1078
    }
1073
    }
1074
    
1075
    private String[] setupProfileTestSingle(Properties p, FileObject[] files) {
1076
        FileObject[] testSrcPath = projectTestRoots.getRoots();
1077
        FileObject root = getRoot(testSrcPath, files[0]);
1078
        p.setProperty("test.includes", ActionUtils.antIncludesList(files, root)); // NOI18N
1079
        p.setProperty("javac.includes", ActionUtils.antIncludesList(files, root)); // NOI18N
1080
        return new String[] {"profile-test"}; // NOI18N
1081
    }
1079
1082
1080
    private String[] setupRunSingleTestMethod(Properties p, SingleMethod methodSpec) {
1083
    private String[] setupRunSingleTestMethod(Properties p, SingleMethod methodSpec) {
1081
        return setupTestSingle(p, new FileObject[] {methodSpec.getFile()});
1084
        return setupTestSingle(p, new FileObject[] {methodSpec.getFile()});
Lines 1146-1153 Link Here
1146
        else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
1149
        else if ( command.equals( COMMAND_DEBUG_TEST_SINGLE ) ) {
1147
            FileObject[] fos = findTestSources(context, true);
1150
            FileObject[] fos = findTestSources(context, true);
1148
            return fos != null && fos.length == 1;
1151
            return fos != null && fos.length == 1;
1152
        } else if ( command.equals( COMMAND_PROFILE_TEST_SINGLE ) ) {
1153
            FileObject[] fos = findTestSources(context, true);
1154
            return fos != null && fos.length == 1;
1149
        } else if (command.equals(COMMAND_RUN_SINGLE) ||
1155
        } else if (command.equals(COMMAND_RUN_SINGLE) ||
1150
                        command.equals(COMMAND_DEBUG_SINGLE) ||
1156
                        command.equals(COMMAND_DEBUG_SINGLE) ||
1157
                        command.equals(COMMAND_PROFILE_SINGLE) ||
1151
                        command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
1158
                        command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
1152
            FileObject fos[] = findSources(context);
1159
            FileObject fos[] = findSources(context);
1153
            if (fos != null && fos.length == 1) {
1160
            if (fos != null && fos.length == 1) {
Lines 1356-1362 Link Here
1356
        boolean run = true;
1363
        boolean run = true;
1357
        boolean hasMainMethod = true;
1364
        boolean hasMainMethod = true;
1358
1365
1359
        if (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command)) {
1366
        if (COMMAND_RUN.equals(command) || COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command) || COMMAND_PROFILE.equals(command)) {
1360
            final String mainClass = evaluator.getProperty(ProjectProperties.MAIN_CLASS);
1367
            final String mainClass = evaluator.getProperty(ProjectProperties.MAIN_CLASS);
1361
1368
1362
            p.put(JavaRunner.PROP_CLASSNAME, mainClass);
1369
            p.put(JavaRunner.PROP_CLASSNAME, mainClass);
Lines 1382-1397 Link Here
1382
            p.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
1389
            p.put(JavaRunner.PROP_EXECUTE_FILE, files[0]);
1383
        }
1390
        }
1384
        boolean debug = COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command);
1391
        boolean debug = COMMAND_DEBUG.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) || COMMAND_DEBUG_STEP_INTO.equals(command);
1392
        boolean profile = COMMAND_PROFILE.equals(command) || COMMAND_PROFILE_SINGLE.equals(command);
1385
        try {
1393
        try {
1386
            updateJavaRunnerClasspath(command, p);
1394
            updateJavaRunnerClasspath(command, p);
1387
            if (run) {
1395
            if (run) {
1388
                copyMultiValue(ProjectProperties.APPLICATION_ARGS, p);
1396
                copyMultiValue(ProjectProperties.APPLICATION_ARGS, p);
1389
                JavaRunner.execute(debug ? JavaRunner.QUICK_DEBUG : JavaRunner.QUICK_RUN, p);
1397
                JavaRunner.execute(debug ? JavaRunner.QUICK_DEBUG : (profile ? JavaRunner.QUICK_PROFILE : JavaRunner.QUICK_RUN), p);
1390
            } else {
1398
            } else {
1391
                if (hasMainMethod) {
1399
                if (hasMainMethod) {
1392
                    JavaRunner.execute(debug ? JavaRunner.QUICK_DEBUG : JavaRunner.QUICK_RUN, p);
1400
                    JavaRunner.execute(debug ? JavaRunner.QUICK_DEBUG : (profile ? JavaRunner.QUICK_PROFILE : JavaRunner.QUICK_RUN), p);
1393
                } else {
1401
                } else {
1394
                    JavaRunner.execute(debug ? JavaRunner.QUICK_TEST_DEBUG : JavaRunner.QUICK_TEST, p);
1402
                    JavaRunner.execute(debug ? JavaRunner.QUICK_TEST_DEBUG : (profile ? JavaRunner.QUICK_TEST_PROFILE : JavaRunner.QUICK_TEST), p);
1395
                }
1403
                }
1396
            }
1404
            }
1397
        } catch (IOException ex) {
1405
        } catch (IOException ex) {
Lines 1428-1434 Link Here
1428
        it.add(val);
1436
        it.add(val);
1429
    }
1437
    }
1430
1438
1431
    private void prepareSystemProperties(Map<String, Object> properties, boolean test) {
1439
    private List<String> runJvmargsIde(String command) {
1440
        StartupExtender.StartMode mode;
1441
        if (command.equals(COMMAND_RUN) || command.equals(COMMAND_RUN_SINGLE)) {
1442
            mode = StartupExtender.StartMode.NORMAL;
1443
        } else if (command.equals(COMMAND_DEBUG) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_DEBUG_STEP_INTO)) {
1444
            mode = StartupExtender.StartMode.DEBUG;
1445
        } else if (command.equals(COMMAND_PROFILE) || command.equals(COMMAND_PROFILE_SINGLE)) {
1446
            mode = StartupExtender.StartMode.PROFILE;
1447
        } else if (command.equals(COMMAND_TEST) || command.equals(COMMAND_TEST_SINGLE)) {
1448
            mode = StartupExtender.StartMode.TEST_NORMAL;
1449
        } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
1450
            mode = StartupExtender.StartMode.TEST_DEBUG;
1451
        } else if (command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
1452
            mode = StartupExtender.StartMode.TEST_PROFILE;
1453
        } else {
1454
            return Collections.emptyList();
1455
        }
1456
        List<String> args = new ArrayList<String>();
1457
        JavaPlatform p = getActivePlatform();
1458
        for (StartupExtender group : StartupExtender.getExtenders(Lookups.fixed(project, p != null ? p : JavaPlatformManager.getDefault().getDefaultPlatform()), mode)) {
1459
            args.addAll(group.getArguments());
1460
        }
1461
        return args;
1462
    }
1463
    
1464
    private void collectStartupExtenderArgs(Map p, String command) {
1465
        StringBuilder b = new StringBuilder();
1466
        for (String arg : runJvmargsIde(command)) {
1467
            b.append(' ').append(arg);
1468
        }
1469
        if (b.length() > 0) {
1470
            p.put(ProjectProperties.RUN_JVM_ARGS_IDE, b.toString());
1471
        }
1472
    }
1473
    
1474
    private void prepareSystemProperties(Map<String, Object> properties, String command, boolean test) {
1432
        String prefix = test ? ProjectProperties.SYSTEM_PROPERTIES_TEST_PREFIX : ProjectProperties.SYSTEM_PROPERTIES_RUN_PREFIX;
1475
        String prefix = test ? ProjectProperties.SYSTEM_PROPERTIES_TEST_PREFIX : ProjectProperties.SYSTEM_PROPERTIES_RUN_PREFIX;
1433
        Map<String, String> evaluated = evaluator.getProperties();
1476
        Map<String, String> evaluated = evaluator.getProperties();
1434
1477
Lines 1440-1446 Link Here
1440
            if (e.getKey().startsWith(prefix) && e.getValue() != null) {
1483
            if (e.getKey().startsWith(prefix) && e.getValue() != null) {
1441
                putMultiValue(properties, JavaRunner.PROP_RUN_JVMARGS, "-D" + e.getKey().substring(prefix.length()) + "=" + e.getValue());
1484
                putMultiValue(properties, JavaRunner.PROP_RUN_JVMARGS, "-D" + e.getKey().substring(prefix.length()) + "=" + e.getValue());
1442
            }
1485
            }
1443
        }
1486
        }        
1487
        collectStartupExtenderArgs(properties, command);
1444
    }
1488
    }
1445
1489
1446
    private static enum MainClassStatus {
1490
    private static enum MainClassStatus {
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/Bundle.properties (+3 lines)
Lines 48-53 Link Here
48
ACTION_debug.stepinto=Debug Project
48
ACTION_debug.stepinto=Debug Project
49
ACTION_debug.fix=Apply Code Changes
49
ACTION_debug.fix=Apply Code Changes
50
ACTION_debug.test.single=Debug Test
50
ACTION_debug.test.single=Debug Test
51
ACTION_profile=Profile Project
52
ACTION_profile.single=Profile File
53
ACTION_profile.test.single=Profile Test
51
ACTION_rebuild=Rebuild Project
54
ACTION_rebuild=Rebuild Project
52
ACTION_build=Build Project
55
ACTION_build=Build Project
53
ACTION_clean=Clean Project
56
ACTION_clean=Clean Project
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/Bundle.properties (+4 lines)
Lines 61-66 Link Here
61
ACTION_compile.single=Compile File
61
ACTION_compile.single=Compile File
62
ACTION_run.single=Run File
62
ACTION_run.single=Run File
63
ACTION_debug.single=Debug File
63
ACTION_debug.single=Debug File
64
ACTION_profile.single=Profile File
64
COMMENT_edit_target=TODO: edit the following target according to your needs
65
COMMENT_edit_target=TODO: edit the following target according to your needs
65
COMMENT_more_info_x.single=(more info: http://www.netbeans.org/kb/articles/freeform-config.html#compilesingle)
66
COMMENT_more_info_x.single=(more info: http://www.netbeans.org/kb/articles/freeform-config.html#compilesingle)
66
COMMENT_more_info_run.single=(more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle)
67
COMMENT_more_info_run.single=(more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle)
Lines 74-79 Link Here
74
COMMENT_set_runtime_cp=TODO configure the runtime classpath for your project here:
75
COMMENT_set_runtime_cp=TODO configure the runtime classpath for your project here:
75
COMMENT_set_main_class=TODO configure the main class for your project here:
76
COMMENT_set_main_class=TODO configure the main class for your project here:
76
77
78
ACTION_profile=Profile Project
79
COMMENT_more_info_profile=(more info: http://www.netbeans.org/kb/articles/<freeform-config.html#debugj2se>)
80
77
CTL_SetOutput=Set Output
81
CTL_SetOutput=Set Output
78
AD_SetOutput=N/A
82
AD_SetOutput=N/A
79
# {0} - action display name
83
# {0} - action display name
(-)a/java.freeform/src/org/netbeans/modules/java/freeform/JavaActions.java (-1 / +223 lines)
Lines 118-125 Link Here
118
    private static final String[] ACTIONS = {
118
    private static final String[] ACTIONS = {
119
        ActionProvider.COMMAND_COMPILE_SINGLE,
119
        ActionProvider.COMMAND_COMPILE_SINGLE,
120
        ActionProvider.COMMAND_DEBUG,
120
        ActionProvider.COMMAND_DEBUG,
121
        ActionProvider.COMMAND_PROFILE,
121
        ActionProvider.COMMAND_RUN_SINGLE,
122
        ActionProvider.COMMAND_RUN_SINGLE,
122
        ActionProvider.COMMAND_DEBUG_SINGLE
123
        ActionProvider.COMMAND_DEBUG_SINGLE,
124
        ActionProvider.COMMAND_PROFILE_SINGLE
123
        // XXX more
125
        // XXX more
124
    };
126
    };
125
    
127
    
Lines 162-171 Link Here
162
            return findPackageRoot(context) != null;
164
            return findPackageRoot(context) != null;
163
        } else if (command.equals(ActionProvider.COMMAND_DEBUG)) {
165
        } else if (command.equals(ActionProvider.COMMAND_DEBUG)) {
164
            return true;
166
            return true;
167
        } else if (command.equals(ActionProvider.COMMAND_PROFILE)) {
168
            return true;
165
        } else if (command.equals(ActionProvider.COMMAND_RUN_SINGLE)) {
169
        } else if (command.equals(ActionProvider.COMMAND_RUN_SINGLE)) {
166
            return (findPackageRoot(context) != null) && isSingleJavaFileSelected(context);
170
            return (findPackageRoot(context) != null) && isSingleJavaFileSelected(context);
167
        } else if (command.equals(ActionProvider.COMMAND_DEBUG_SINGLE)) {
171
        } else if (command.equals(ActionProvider.COMMAND_DEBUG_SINGLE)) {
168
            return (findPackageRoot(context) != null) && isSingleJavaFileSelected(context);
172
            return (findPackageRoot(context) != null) && isSingleJavaFileSelected(context);
173
        } else if (command.equals(ActionProvider.COMMAND_PROFILE_SINGLE)) {
174
            return (findPackageRoot(context) != null) && isSingleJavaFileSelected(context);
169
        } else {
175
        } else {
170
            throw new IllegalArgumentException(command);
176
            throw new IllegalArgumentException(command);
171
        }
177
        }
Lines 180-189 Link Here
180
                            handleCompileSingle(context);
186
                            handleCompileSingle(context);
181
                        } else if (command.equals(ActionProvider.COMMAND_DEBUG)) {
187
                        } else if (command.equals(ActionProvider.COMMAND_DEBUG)) {
182
                            handleDebug();
188
                            handleDebug();
189
                        } else if (command.equals(ActionProvider.COMMAND_PROFILE)) {
190
                            handleProfile();
183
                        } else if (command.equals(ActionProvider.COMMAND_RUN_SINGLE)) {
191
                        } else if (command.equals(ActionProvider.COMMAND_RUN_SINGLE)) {
184
                            handleRunSingle(context);
192
                            handleRunSingle(context);
185
                        } else if (command.equals(ActionProvider.COMMAND_DEBUG_SINGLE)) {
193
                        } else if (command.equals(ActionProvider.COMMAND_DEBUG_SINGLE)) {
186
                            handleDebugSingle(context);
194
                            handleDebugSingle(context);
195
                        } else if (command.equals(ActionProvider.COMMAND_PROFILE_SINGLE)) {
196
                            handleProfileSingle(context);
187
                        } else {
197
                        } else {
188
                            throw new IllegalArgumentException(command);
198
                            throw new IllegalArgumentException(command);
189
                        }
199
                        }
Lines 462-467 Link Here
462
        return target;
472
        return target;
463
    }
473
    }
464
    
474
    
475
    private void handleProfile() throws IOException, SAXException {                        
476
        if (!this.setOutputsNotified) {
477
            ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(this.helper, this.evaluator),
478
                FileUtil.toFile(project.getProjectDirectory()), this.evaluator, this.helper);        
479
            List<ProjectModel.CompilationUnitKey> cuKeys = pm.createCompilationUnitKeys();
480
            assert cuKeys != null;
481
            boolean hasOutputs = false;
482
            for (Iterator it = cuKeys.iterator(); it.hasNext();) {
483
                ProjectModel.CompilationUnitKey ck = (ProjectModel.CompilationUnitKey) it.next();
484
                JavaProjectGenerator.JavaCompilationUnit cu = pm.getCompilationUnit(ck,false);
485
                if (cu.output != null && cu.output.size()>0) {
486
                    hasOutputs = true;
487
                    break;
488
                }
489
            }
490
            if (!hasOutputs) {
491
                alertOutputs (NbBundle.getMessage(JavaActions.class, "ACTION_profile")); // NOI18N           
492
                this.setOutputsNotified = true;
493
                return;
494
            }
495
        }        
496
        String[] bindings = findCommandBinding(ActionProvider.COMMAND_RUN);
497
        Element task = null;
498
        Element origTarget = null;
499
        if (bindings != null && bindings.length <= 2) {
500
            origTarget = findExistingBuildTarget(ActionProvider.COMMAND_RUN);
501
            //The origTarget may be null if the user has removed it from build.xml
502
            if (origTarget != null) {
503
                task = targetUsesTaskExactlyOnce(origTarget, "java"); // NOI18N
504
            }
505
        }
506
        
507
        if (!alert(NbBundle.getMessage(JavaActions.class, "ACTION_profile"), task != null ? GENERAL_SCRIPT_PATH : FILE_SCRIPT_PATH)) { // NOI18N
508
            return;
509
        }
510
        
511
        String generatedTargetName = "profile-nb"; // NOI18N
512
        String generatedScriptPath;
513
        Document doc;
514
        Element generatedTarget;
515
        if (task != null) {
516
            // We can copy the original run target with some modifications.
517
            generatedScriptPath = GENERAL_SCRIPT_PATH;
518
            doc = readCustomScript(GENERAL_SCRIPT_PATH);
519
            ensureImports(doc.getDocumentElement(), bindings[0]);
520
            generatedTarget = createProfileTargetFromTemplate(generatedTargetName, origTarget, task, doc);
521
        } else {
522
            // No info, need to generate a dummy profile target.
523
            generatedScriptPath = FILE_SCRIPT_PATH;
524
            doc = readCustomScript(FILE_SCRIPT_PATH);
525
            ensurePropertiesCopied(doc.getDocumentElement());
526
            generatedTarget = createProfileTargetFromScratch(generatedTargetName, doc);
527
        }
528
        Comment comm = doc.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_edit_target") + " "); // NOI18N
529
        doc.getDocumentElement().appendChild(comm);
530
        comm = doc.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_more_info_profile") + " "); // NOI18N
531
        doc.getDocumentElement().appendChild(comm);
532
        doc.getDocumentElement().appendChild(generatedTarget);
533
        writeCustomScript(doc, generatedScriptPath);
534
        addBinding(ActionProvider.COMMAND_PROFILE, generatedScriptPath, generatedTargetName, null, null, null, null, null);
535
        jumpToBinding(ActionProvider.COMMAND_PROFILE);
536
        jumpToBuildScript(generatedScriptPath, generatedTargetName);                
537
    }
538
    
539
    Element createProfileTargetFromTemplate(String generatedTargetName, Element origTarget, Element origTask, Document ownerDocument) {
540
        NodeList tasks = origTarget.getChildNodes();
541
        int taskIndex = -1;
542
        for (int i = 0; i < tasks.getLength(); i++) {
543
            if (tasks.item(i) == origTask) {
544
                taskIndex = i;
545
                break;
546
            }
547
        }
548
        assert taskIndex != -1;
549
        Element target = (Element) ownerDocument.importNode(origTarget, true);
550
        target.setAttribute("depends", "-profile-check,dist"); // NOI18N
551
        target.setAttribute("if", "profiler.configured"); // NOI18N
552
        addJdkInitDeps(target);
553
        Element task = (Element) target.getChildNodes().item(taskIndex);
554
        target.setAttribute("name", generatedTargetName); // NOI18N
555
        addProfileInit(ownerDocument, ownerDocument.getDocumentElement());
556
557
        addProfileVMArgs(task, ownerDocument);
558
        return target;
559
    }
560
    
561
    Element createProfileTargetFromScratch(String generatedTargetName, Document ownerDocument) {
562
        Element target = ownerDocument.createElement("target"); // NOI18N
563
        target.setAttribute("depends", "-profile-check,dist"); // NOI18N
564
        target.setAttribute("if", "profiler.configured"); // NOI18N
565
        addJdkInitDeps(target);
566
        target.setAttribute("name", generatedTargetName); // NOI18N
567
        Element path = ownerDocument.createElement("path"); // NOI18N
568
        // XXX would be better to determine runtime CP from project.xml and put it here instead (if that is possible)...
569
        path.setAttribute("id", "cp"); // NOI18N
570
        path.appendChild(ownerDocument.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_set_runtime_cp") + " ")); // NOI18N
571
        target.appendChild(path);
572
        addProfileInit(ownerDocument, ownerDocument.getDocumentElement());
573
574
        target.appendChild(ownerDocument.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_set_main_class") + " ")); // NOI18N
575
        Element java = ownerDocument.createElement("java"); // NOI18N
576
        java.setAttribute("classname", "some.main.Class"); // NOI18N
577
        Element classpath = ownerDocument.createElement("classpath"); // NOI18N
578
        classpath.setAttribute("refid", "cp"); // NOI18N
579
        java.appendChild(classpath);
580
        addProfileVMArgs(java, ownerDocument);
581
        target.appendChild(java);
582
        return target;
583
    }
584
    
585
    private void addProfileInit(Document ownerDocument, Element parent) {
586
        NodeList nl = ownerDocument.getElementsByTagName("target");
587
        for(int i=0;i<nl.getLength();i++) {
588
            if ("-profile-check".equals(((Element)nl.item(i)).getAttribute("name"))) {
589
                return;
590
            }
591
        }
592
        Element init = ownerDocument.createElement("target"); // NOI18N
593
        init.setAttribute("name", "-profile-check");
594
        Element profilerStart = ownerDocument.createElement("startprofiler");
595
        profilerStart.setAttribute("freeform", "true");
596
        init.appendChild(profilerStart);
597
        
598
        parent.appendChild(init);
599
    }
600
    
601
    private void addProfileVMArgs(Element java, Document ownerDocument) {
602
        //Add fork="true" if not alredy there
603
        NamedNodeMap attrs = java.getAttributes();
604
        boolean found = false;
605
        for (int i=0; i<attrs.getLength(); i++) {
606
            Attr attr = (Attr) attrs.item(i);
607
            if ("fork".equals(attr.getName())) {        //NOI18N
608
                String value = attr.getValue();
609
                if ("on".equalsIgnoreCase (value) ||    //NOI18N
610
                    "true".equalsIgnoreCase(value) ||   //NOI18N
611
                    "yes".equalsIgnoreCase(value)) {    //NOI18N
612
                    found = true;
613
                }
614
                break;
615
            }
616
        }
617
        if (!found) {
618
            java.setAttribute("fork", "true");  //NOI18N
619
        }
620
        Element jvmarg = ownerDocument.createElement("jvmarg"); // NOI18N
621
        jvmarg.setAttribute("line", "${agent.jvmargs}"); // NOI18N
622
        java.appendChild(jvmarg);
623
    }
624
    
465
    /**
625
    /**
466
     * Read a generated script if it exists, else create a skeleton.
626
     * Read a generated script if it exists, else create a skeleton.
467
     * Imports jdk.xml if appropriate.
627
     * Imports jdk.xml if appropriate.
Lines 1120-1125 Link Here
1120
        jumpToBinding(ActionProvider.COMMAND_DEBUG_SINGLE);
1280
        jumpToBinding(ActionProvider.COMMAND_DEBUG_SINGLE);
1121
        jumpToBuildScript(FILE_SCRIPT_PATH, targetName);
1281
        jumpToBuildScript(FILE_SCRIPT_PATH, targetName);
1122
    }
1282
    }
1283
    
1284
    private void handleProfileSingle(Lookup context) throws IOException, SAXException {
1285
        if (!alert(NbBundle.getMessage(JavaActions.class, "ACTION_profile.single"), FILE_SCRIPT_PATH)) { // NOI18N
1286
            return;
1287
        }
1288
        Document doc = readCustomScript(FILE_SCRIPT_PATH);
1289
        AntLocation root = handleInitials(doc, context);
1290
        assert root != null : context;
1291
        String propertyName = "profile.class"; // NOI18N
1292
        String targetName = "profile-selected-file-in-" + root.physical.getNameExt(); // NOI18N
1293
        Element targetElem = createProfileSingleTargetElem(doc, targetName, propertyName, root);
1294
        doc.getDocumentElement().appendChild(targetElem);
1295
        writeCustomScript(doc, FILE_SCRIPT_PATH);
1296
        addBinding(ActionProvider.COMMAND_PROFILE_SINGLE, FILE_SCRIPT_PATH, targetName,
1297
                propertyName, root.virtual, JAVA_FILE_PATTERN, "java-name", null); // NOI18N
1298
        jumpToBinding(ActionProvider.COMMAND_PROFILE_SINGLE);
1299
        jumpToBuildScript(FILE_SCRIPT_PATH, targetName);
1300
    }
1123
1301
1124
    Element createRunSingleTargetElem(Document doc, String tgName,
1302
    Element createRunSingleTargetElem(Document doc, String tgName,
1125
                String propName, AntLocation root) throws IOException, SAXException {
1303
                String propName, AntLocation root) throws IOException, SAXException {
Lines 1197-1202 Link Here
1197
        targetElem.appendChild(javaElem);
1375
        targetElem.appendChild(javaElem);
1198
        return targetElem;
1376
        return targetElem;
1199
    }
1377
    }
1378
    
1379
    Element createProfileSingleTargetElem(Document doc, String tgName,
1380
                String propName, AntLocation root) throws IOException, SAXException {
1381
1382
        Element targetElem = doc.createElement("target"); // NOI18N
1383
        addJdkInitDeps(targetElem);
1384
        targetElem.setAttribute("name", tgName); // NOI18N
1385
        targetElem.setAttribute("if", "profiler.configured"); // NOI18N
1386
        targetElem.setAttribute("depends", "-profile-check"); // NOI18N
1387
        Element failElem = doc.createElement("fail"); // NOI18N
1388
        failElem.setAttribute("unless", propName); // NOI18N
1389
        failElem.appendChild(doc.createTextNode(NbBundle.getMessage(JavaActions.class,
1390
                "COMMENT_must_set_property", propName)));
1391
        targetElem.appendChild(failElem);
1392
1393
        String depends[] = getRunDepends();
1394
        if (depends != null) {
1395
            targetElem.appendChild(createAntElem(doc, depends[0], depends[1]));
1396
        }
1397
1398
        Element pElem = getPathFromCU(doc, root.virtual, "path"); // NOI18N
1399
        pElem.setAttribute("id", "cp"); // NOI18N
1400
        // add comment only if there is no definition
1401
        if (pElem.getChildNodes().getLength() == 0) {
1402
            pElem.appendChild(doc.createComment(" " + NbBundle.getMessage(JavaActions.class,
1403
                    "COMMENT_set_runtime_cp") + " "));
1404
        }
1405
        targetElem.appendChild(pElem);
1406
1407
        Element cpElem = doc.createElement("classpath"); // NOI18N
1408
        cpElem.setAttribute("refid", "cp"); // NOI18N
1409
1410
        Element javaElem = doc.createElement("java"); // NOI18N
1411
        javaElem.setAttribute("classname", "${" + propName + "}"); // NOI18N
1412
1413
        cpElem = doc.createElement("classpath"); // NOI18N
1414
        cpElem.setAttribute("refid", "cp"); // NOI18N
1415
        javaElem.appendChild(cpElem);
1416
        addProfileInit(doc, doc.getDocumentElement());
1417
        addProfileVMArgs(javaElem, doc);
1418
1419
        targetElem.appendChild(javaElem);
1420
        return targetElem;
1421
    }
1200
1422
1201
    private AntLocation handleInitials(Document doc, Lookup context) {
1423
    private AntLocation handleInitials(Document doc, Lookup context) {
1202
        ensurePropertiesCopied(doc.getDocumentElement());
1424
        ensurePropertiesCopied(doc.getDocumentElement());
(-)a/java.freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaActionsTest.java (-1 / +60 lines)
Lines 166-173 Link Here
166
            Arrays.asList(new String[] {
166
            Arrays.asList(new String[] {
167
                ActionProvider.COMMAND_COMPILE_SINGLE,
167
                ActionProvider.COMMAND_COMPILE_SINGLE,
168
                ActionProvider.COMMAND_DEBUG,
168
                ActionProvider.COMMAND_DEBUG,
169
                ActionProvider.COMMAND_PROFILE,
169
                ActionProvider.COMMAND_RUN_SINGLE,
170
                ActionProvider.COMMAND_RUN_SINGLE,
170
                ActionProvider.COMMAND_DEBUG_SINGLE
171
                ActionProvider.COMMAND_DEBUG_SINGLE,
172
                ActionProvider.COMMAND_PROFILE_SINGLE
171
            }),
173
            }),
172
            Arrays.asList(ja.getSupportedActions()));
174
            Arrays.asList(ja.getSupportedActions()));
173
        /* Not really necessary; once there is a binding, the main ant/freeform Actions will mask this anyway:
175
        /* Not really necessary; once there is a binding, the main ant/freeform Actions will mask this anyway:
Lines 563-568 Link Here
563
            "</project>\n";
565
            "</project>\n";
564
        assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
566
        assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
565
    }
567
    }
568
    
569
    public void testCreateProfileTargetFromScratch() throws Exception {
570
        Document doc = XMLUtil.createDocument("project", null, null, null);
571
        Element genTarget = ja.createProfileTargetFromScratch("profile", doc);
572
        doc.getDocumentElement().appendChild(genTarget);
573
        String expectedXml =
574
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
575
            "<project>\n" +
576
            "    <target name=\"-profile-check\">\n" +
577
            "        <startprofiler freeform=\"true\"/>\n" +
578
            "    </target>\n" +
579
            "    <target depends=\"-profile-check,dist\" if=\"profiler.configured\" name=\"profile\">\n" +
580
            "        <path id=\"cp\">\n" +
581
            "            <!---->\n" +
582
            "        </path>\n" +
583
            "        <!---->\n" +
584
            "        <java classname=\"some.main.Class\" fork=\"true\">\n" +
585
            "            <classpath refid=\"cp\"/>\n" +
586
            "            <jvmarg line=\"${agent.jvmargs}\"/>\n" +
587
            "        </java>\n" +
588
            "    </target>\n" +
589
            "</project>\n";
590
        assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
591
    }
592
    
593
    public void testCreateProfileTargetFromTemplate() throws Exception {
594
        Document doc = XMLUtil.createDocument("project", null, null, null);
595
        Document origDoc = XMLUtil.createDocument("target", null, null, null);
596
        Element origTarget = origDoc.getDocumentElement();
597
        origTarget.setAttribute("name", "ignored");
598
        origTarget.setAttribute("depends", "compile");
599
        origTarget.appendChild(origDoc.createElement("task1"));
600
        Element task = origDoc.createElement("java");
601
        // XXX also test nested <classpath>:
602
        task.setAttribute("classpath", "${cp}");
603
        task.appendChild(origDoc.createElement("stuff"));
604
        origTarget.appendChild(task);
605
        origTarget.appendChild(origDoc.createElement("task2"));
606
        Element genTarget = ja.createProfileTargetFromTemplate("profile", origTarget, task, doc);
607
        doc.getDocumentElement().appendChild(genTarget);
608
        String expectedXml =
609
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
610
            "<project>\n" +
611
            "    <target name=\"-profile-check\">\n" +
612
            "        <startprofiler freeform=\"true\"/>\n" +
613
            "    </target>\n" +
614
            "    <target depends=\"-profile-check,dist\" if=\"profiler.configured\" name=\"profile\">\n" +
615
            "        <task1/>\n" +
616
            "        <java classpath=\"${cp}\" fork=\"true\">\n" +
617
            "            <stuff/>\n" +
618
            "            <jvmarg line=\"${agent.jvmargs}\"/>\n" +
619
            "        </java>\n" +
620
            "        <task2/>\n" +
621
            "    </target>\n" +
622
            "</project>\n";
623
        assertEquals(expectedXml, xmlToString(doc.getDocumentElement()));
624
    }
566
625
567
    public void testCreateRunSingleTargetElem() throws Exception {
626
    public void testCreateRunSingleTargetElem() throws Exception {
568
        Document doc = XMLUtil.createDocument("project", null, null, null);
627
        Document doc = XMLUtil.createDocument("project", null, null, null);
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEActionProvider.java (-1 / +12 lines)
Lines 80-89 Link Here
80
        COMMAND_RUN_SINGLE,
80
        COMMAND_RUN_SINGLE,
81
        COMMAND_DEBUG,
81
        COMMAND_DEBUG,
82
        COMMAND_DEBUG_SINGLE,
82
        COMMAND_DEBUG_SINGLE,
83
        COMMAND_PROFILE,
84
        COMMAND_PROFILE_SINGLE,
83
        JavaProjectConstants.COMMAND_JAVADOC,
85
        JavaProjectConstants.COMMAND_JAVADOC,
84
        COMMAND_TEST,
86
        COMMAND_TEST,
85
        COMMAND_TEST_SINGLE,
87
        COMMAND_TEST_SINGLE,
86
        COMMAND_DEBUG_TEST_SINGLE,
88
        COMMAND_DEBUG_TEST_SINGLE,
89
        COMMAND_PROFILE_TEST_SINGLE,
87
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
90
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
88
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
91
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
89
        JavaProjectConstants.COMMAND_DEBUG_FIX,
92
        JavaProjectConstants.COMMAND_DEBUG_FIX,
Lines 103-112 Link Here
103
        COMMAND_RUN_SINGLE,
106
        COMMAND_RUN_SINGLE,
104
        COMMAND_DEBUG,
107
        COMMAND_DEBUG,
105
        COMMAND_DEBUG_SINGLE,
108
        COMMAND_DEBUG_SINGLE,
109
        COMMAND_PROFILE,
110
        COMMAND_PROFILE_SINGLE,
106
        JavaProjectConstants.COMMAND_JAVADOC,
111
        JavaProjectConstants.COMMAND_JAVADOC,
107
        COMMAND_TEST,
112
        COMMAND_TEST,
108
        COMMAND_TEST_SINGLE,
113
        COMMAND_TEST_SINGLE,
109
        COMMAND_DEBUG_TEST_SINGLE,
114
        COMMAND_DEBUG_TEST_SINGLE,
115
        COMMAND_PROFILE_TEST_SINGLE,
110
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
116
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
111
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
117
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
112
        JavaProjectConstants.COMMAND_DEBUG_FIX,
118
        JavaProjectConstants.COMMAND_DEBUG_FIX,
Lines 139-148 Link Here
139
        commands.put(COMMAND_RUN_SINGLE, new String[] {"run-single"}); // NOI18N
145
        commands.put(COMMAND_RUN_SINGLE, new String[] {"run-single"}); // NOI18N
140
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
146
        commands.put(COMMAND_DEBUG, new String[] {"debug"}); // NOI18N
141
        commands.put(COMMAND_DEBUG_SINGLE, new String[] {"debug-single"}); // NOI18N
147
        commands.put(COMMAND_DEBUG_SINGLE, new String[] {"debug-single"}); // NOI18N
148
        commands.put(COMMAND_PROFILE, new String[] {"profile"}); // NOI18N
149
        commands.put(COMMAND_PROFILE_SINGLE, new String[] {"profile-single"}); // NOI18N
142
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc"}); // NOI18N
150
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[] {"javadoc"}); // NOI18N
143
        commands.put(COMMAND_TEST, new String[] {"test"}); // NOI18N
151
        commands.put(COMMAND_TEST, new String[] {"test"}); // NOI18N
144
        commands.put(COMMAND_TEST_SINGLE, new String[] {"test-single"}); // NOI18N
152
        commands.put(COMMAND_TEST_SINGLE, new String[] {"test-single"}); // NOI18N
145
        commands.put(COMMAND_DEBUG_TEST_SINGLE, new String[] {"debug-test"}); // NOI18N
153
        commands.put(COMMAND_DEBUG_TEST_SINGLE, new String[] {"debug-test"}); // NOI18N
154
        commands.put(COMMAND_PROFILE_TEST_SINGLE, new String[]{"profile-test"}); // NOI18N
146
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[] {"debug-fix"}); // NOI18N
155
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[] {"debug-fix"}); // NOI18N
147
        commands.put(COMMAND_DEBUG_STEP_INTO, new String[] {"debug-stepinto"}); // NOI18N
156
        commands.put(COMMAND_DEBUG_STEP_INTO, new String[] {"debug-stepinto"}); // NOI18N
148
157
Lines 151-157 Link Here
151
            COMMAND_RUN_SINGLE,
160
            COMMAND_RUN_SINGLE,
152
            COMMAND_DEBUG,
161
            COMMAND_DEBUG,
153
            COMMAND_DEBUG_SINGLE,
162
            COMMAND_DEBUG_SINGLE,
154
            COMMAND_DEBUG_STEP_INTO
163
            COMMAND_DEBUG_STEP_INTO,
164
            COMMAND_PROFILE,
165
            COMMAND_PROFILE_SINGLE
155
        ));
166
        ));
156
167
157
        this.needJavaModelActions = new HashSet<String>(Arrays.asList(
168
        this.needJavaModelActions = new HashSet<String>(Arrays.asList(
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl (-53 / +91 lines)
Lines 718-737 Link Here
718
                    </sequential>
718
                    </sequential>
719
                </macrodef>
719
                </macrodef>
720
            </target>
720
            </target>
721
721
            
722
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check"/>
722
            <xsl:comment>
723
                pre NB7.2 profiling section; consider it deprecated
724
            </xsl:comment>
725
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check">
726
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
727
            </target>
723
728
724
            <target name="-profile-pre-init">
729
            <target name="-profile-pre-init">
730
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
725
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
731
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
726
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
732
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
727
            </target>
733
            </target>
728
734
729
            <target name="-profile-post-init">
735
            <target name="-profile-post-init">
736
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
730
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
737
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
731
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
738
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
732
            </target>
739
            </target>
733
740
734
            <target name="-profile-init-macrodef-profile">
741
            <target name="-profile-init-macrodef-profile">
742
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
735
                <macrodef>
743
                <macrodef>
736
                  <xsl:attribute name="name">resolve</xsl:attribute>
744
                  <xsl:attribute name="name">resolve</xsl:attribute>
737
                  <attribute>
745
                  <attribute>
Lines 779-787 Link Here
779
787
780
            <target name="-profile-init-check">
788
            <target name="-profile-init-check">
781
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile</xsl:attribute>
789
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile</xsl:attribute>
790
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
782
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
791
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
783
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
792
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
784
            </target>
793
            </target>
794
            <xsl:comment>
795
                end of pre NB7.2 profiling section
796
            </xsl:comment>
785
797
786
            <target name="-init-macrodef-nbjpda" depends="-init-debug-args">
798
            <target name="-init-macrodef-nbjpda" depends="-init-debug-args">
787
                <macrodef>
799
                <macrodef>
Lines 914-919 Link Here
914
                        <xsl:attribute name="name">classpath</xsl:attribute>
926
                        <xsl:attribute name="name">classpath</xsl:attribute>
915
                        <xsl:attribute name="default">${run.classpath}</xsl:attribute>
927
                        <xsl:attribute name="default">${run.classpath}</xsl:attribute>
916
                    </attribute>
928
                    </attribute>
929
                    <attribute>
930
                        <xsl:attribute name="name">jvm</xsl:attribute>
931
                        <xsl:attribute name="default">jvm</xsl:attribute>
932
                    </attribute>
917
                    <element>
933
                    <element>
918
                        <xsl:attribute name="name">customize</xsl:attribute>
934
                        <xsl:attribute name="name">customize</xsl:attribute>
919
                        <xsl:attribute name="optional">true</xsl:attribute>
935
                        <xsl:attribute name="optional">true</xsl:attribute>
Lines 1456-1466 Link Here
1456
                PROFILING SECTION
1472
                PROFILING SECTION
1457
                =================
1473
                =================
1458
            </xsl:comment>
1474
            </xsl:comment>
1459
1475
            <xsl:comment>
1460
            <target name="profile">
1476
                pre NB7.2 profiler integration
1461
                <xsl:attribute name="if">netbeans.home</xsl:attribute>
1477
            </xsl:comment>
1462
                <xsl:attribute name="depends">profile-init,compile</xsl:attribute>
1478
            <target depends="profile-init,compile" description="Profile a project in the IDE." if="profiler.info.jvmargs.agent" name="-profile-pre72">
1463
                <xsl:attribute name="description">Profile a project in the IDE.</xsl:attribute>
1479
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1464
                <nbprofiledirect>
1480
                <nbprofiledirect>
1465
                    <classpath>
1481
                    <classpath>
1466
                        <path path="${{run.classpath}}"/>
1482
                        <path path="${{run.classpath}}"/>
Lines 1468-1541 Link Here
1468
                </nbprofiledirect>
1484
                </nbprofiledirect>
1469
                <profile/>
1485
                <profile/>
1470
            </target>
1486
            </target>
1471
1487
            <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="profiler.info.jvmargs.agent" name="-profile-single-pre72">
1472
            <target name="profile-single">
1473
                <xsl:attribute name="if">netbeans.home</xsl:attribute>
1474
                <xsl:attribute name="depends">profile-init,compile-single</xsl:attribute>
1475
                <xsl:attribute name="description">Profile a selected class in the IDE.</xsl:attribute>
1476
                <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
1488
                <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
1489
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1477
                <nbprofiledirect>
1490
                <nbprofiledirect>
1478
                    <classpath>
1491
                    <classpath>
1479
                        <path path="${{run.classpath}}"/>
1492
                        <path path="${{run.classpath}}"/>
1480
                    </classpath>
1493
                    </classpath>
1481
                </nbprofiledirect>
1494
                </nbprofiledirect>
1482
              <profile classname="${{profile.class}}"/>
1495
                <profile classname="${{profile.class}}"/>
1483
            </target>
1496
            </target>
1484
1497
            <target depends="profile-init,compile-single" if="profiler.info.jvmargs.agent" name="-profile-applet-pre72">
1485
            <xsl:comment>
1498
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1486
                =========================
1487
                APPLET PROFILING  SECTION
1488
                =========================
1489
            </xsl:comment>
1490
1491
            <target name="profile-applet">
1492
                <xsl:attribute name="if">netbeans.home</xsl:attribute>
1493
                <xsl:attribute name="depends">profile-init,compile-single</xsl:attribute>
1494
                <nbprofiledirect>
1499
                <nbprofiledirect>
1495
                    <classpath>
1500
                    <classpath>
1496
                        <path path="${{run.classpath}}"/>
1501
                        <path path="${{run.classpath}}"/>
1497
                    </classpath>
1502
                    </classpath>
1498
                </nbprofiledirect>
1503
                </nbprofiledirect>
1499
1500
                <profile classname="sun.applet.AppletViewer">
1504
                <profile classname="sun.applet.AppletViewer">
1501
                    <customize>
1505
                    <customize>
1502
                        <arg value="${{applet.url}}"/>
1506
                        <arg value="${{applet.url}}"/>
1503
                    </customize>
1507
                    </customize>
1504
                </profile>
1508
                </profile>
1505
            </target>
1509
            </target>
1506
1510
            <target depends="profile-init,compile-test-single" if="profiler.info.jvmargs.agent" name="-profile-test-single-pre72">
1511
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1512
                <nbprofiledirect>
1513
                    <classpath>
1514
                        <path path="${{run.test.classpath}}"/>
1515
                    </classpath>
1516
                </nbprofiledirect>
1517
                <junit dir="${{profiler.info.dir}}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${{profiler.info.jvm}}" showoutput="true">
1518
                    <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
1519
                    <jvmarg value="${{profiler.info.jvmargs.agent}}"/>
1520
                    <jvmarg line="${{profiler.info.jvmargs}}"/>
1521
                    <test name="${{profile.class}}"/>
1522
                    <classpath>
1523
                        <path path="${{run.test.classpath}}"/>
1524
                    </classpath>
1525
                    <syspropertyset>
1526
                        <propertyref prefix="test-sys-prop."/>
1527
                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
1528
                    </syspropertyset>
1529
                    <formatter type="brief" usefile="false"/>
1530
                    <formatter type="xml"/>
1531
                </junit>
1532
            </target>
1507
            <xsl:comment>
1533
            <xsl:comment>
1508
                =========================
1534
                end of pre NB72 profiling section
1509
                TESTS PROFILING  SECTION
1510
                =========================
1511
            </xsl:comment>
1535
            </xsl:comment>
1512
1536
            
1513
            <target name="profile-test-single">
1537
            <target name="-profile-check" if="netbeans.home">
1514
              <xsl:attribute name="if">netbeans.home</xsl:attribute>
1538
                <condition property="profiler.configured">
1515
              <xsl:attribute name="depends">profile-init,compile-test-single</xsl:attribute>
1539
                    <or>
1516
              <nbprofiledirect>
1540
                        <contains string="${{run.jvmargs.ide}}" substring="-agentpath:" casesensitive="false"/>
1517
                  <classpath>
1541
                        <contains string="${{run.jvmargs.ide}}" substring="-javaagent:" casesensitive="false"/>
1518
                      <path path="${{run.test.classpath}}"/>
1542
                    </or>
1519
                  </classpath>
1543
                </condition>
1520
              </nbprofiledirect>
1544
            </target>
1521
1545
            
1522
              <junit showoutput="true" fork="true" dir="${{profiler.info.dir}}"  jvm="${{profiler.info.jvm}}" failureproperty="tests.failed" errorproperty="tests.failed">
1546
            <target name="profile" depends="-profile-check,-profile-pre72" description="Profile a project in the IDE." if="profiler.configured" unless="profiler.info.jvmargs.agent">
1523
                  <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
1547
                <startprofiler/>
1524
                  <jvmarg value="${{profiler.info.jvmargs.agent}}" />
1548
                <antcall target="run"/>
1525
                  <jvmarg line="${{profiler.info.jvmargs}}"/>
1526
                  <test name="${{profile.class}}"/>
1527
                  <classpath>
1528
                      <path path="${{run.test.classpath}}"/>
1529
                  </classpath>
1530
                  <syspropertyset>
1531
                      <propertyref prefix="test-sys-prop."/>
1532
                      <mapper type="glob" from="test-sys-prop.*" to="*"/>
1533
                  </syspropertyset>
1534
                  <formatter type="brief" usefile="false"/>
1535
                  <formatter type="xml"/>
1536
              </junit>
1537
            </target>
1549
            </target>
1538
1550
1551
            <target name="profile-single" depends="-profile-check,-profile-single-pre72" description="Profile a selected class in the IDE." if="profiler.configured" unless="profiler.info.jvmargs.agent">
1552
                <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
1553
                <startprofiler/>
1554
                <antcall target="run-single"/>
1555
            </target>
1556
1557
            <target name="profile-test-single" depends="-profile-test-single-pre72" description="Profile a selected test in the IDE."/>
1558
1559
            <target name="profile-test" depends="-profile-check" description="Profile a selected test in the IDE." if="profiler.configured" unless="profiler.info.jvmargs">
1560
                <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
1561
                <startprofiler/>
1562
                <antcall target="test-single"/>
1563
            </target>
1564
1565
            <target name="profile-test-with-main" depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured">
1566
                <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
1567
                <startprofiler/>
1568
                <antcal target="run-test-with-main"/>
1569
            </target>
1570
            
1571
            <target name="profile-applet" depends="-profile-check,-profile-applet-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent">
1572
                <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
1573
                <startprofiler/>
1574
                <antcall target="run-applet"/>
1575
            </target>
1576
            
1539
            <xsl:comment>
1577
            <xsl:comment>
1540
                ===============
1578
                ===============
1541
                JAVADOC SECTION
1579
                JAVADOC SECTION
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/resources/layer.xml (-4 lines)
Lines 108-117 Link Here
108
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
108
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
109
                    <attr name="position" intvalue="900"/>
109
                    <attr name="position" intvalue="900"/>
110
                </file>
110
                </file>
111
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
112
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.instance"/>
113
                    <attr name="position" intvalue="1000"/>
114
                </file>
115
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
111
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
116
                    <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-TestProject.instance"/>
112
                    <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-TestProject.instance"/>
117
                    <attr name="position" intvalue="1100"/>
113
                    <attr name="position" intvalue="1100"/>
(-)a/java.j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/J2SEActionProviderTest.java (+83 lines)
Lines 296-301 Link Here
296
        assertEquals("There must be two target parameters", 2, p.keySet().size());
296
        assertEquals("There must be two target parameters", 2, p.keySet().size());
297
        assertEquals("There must be be target parameter", "foo.BarTest", p.getProperty("test.class"));
297
        assertEquals("There must be be target parameter", "foo.BarTest", p.getProperty("test.class"));
298
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
298
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
299
        
300
        // test COMMAND_PROFILE_TEST_SINGLE
301
302
        p = new Properties();
303
        context = Lookups.fixed(someSource1);
304
        targets = actionProvider.getTargetNames(ActionProvider.COMMAND_PROFILE_TEST_SINGLE, context, p);
305
        assertNotNull("Must found some targets for COMMAND_PROFILE_TEST_SINGLE", targets);
306
        assertEquals("There must be one target for COMMAND_PROFILE_TEST_SINGLE", 1, targets.length);
307
        assertEquals("Unexpected target name", "profile-test", targets[0]);
308
        assertEquals("There must be two target parameters", 2, p.keySet().size());
309
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
310
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("test.includes")); 
299
311
300
        // test COMMAND_DEBUG_FIX
312
        // test COMMAND_DEBUG_FIX
301
        actionProvider.unitTestingSupport_fixClasses = "foo/Bar";
313
        actionProvider.unitTestingSupport_fixClasses = "foo/Bar";
Lines 422-427 Link Here
422
        assertEquals("There must be two target parameters", 2, p.keySet().size());
434
        assertEquals("There must be two target parameters", 2, p.keySet().size());
423
        assertEquals("There must be be target parameter", "foo.BarTest", p.getProperty("debug.class"));
435
        assertEquals("There must be be target parameter", "foo.BarTest", p.getProperty("debug.class"));
424
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
436
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
437
        
438
        // test COMMAND_PROFILE_SINGLE
439
440
        p = new Properties();
441
        context = Lookups.fixed(someSource2);
442
        MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
443
        try {
444
            targets = actionProvider.getTargetNames(ActionProvider.COMMAND_PROFILE_SINGLE, context, p);
445
        } finally {
446
            MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
447
        }
448
        assertNotNull("Must found some targets for COMMAND_PROFILE_SINGLE", targets);
449
        assertEquals("There must be one target for COMMAND_PROFILE_SINGLE", 1, targets.length);
450
        assertEquals("Unexpected target name", "profile-single", targets[0]);
451
        assertEquals("There must be one target parameter", 2, p.keySet().size());
452
        assertEquals("There must be be target parameter", "foo/Main.java", p.getProperty("javac.includes"));
453
        assertEquals("There must be be target parameter", "foo.Main", p.getProperty("run.class"));
454
        p = new Properties();
455
        context = Lookups.fixed(someSource2);
456
        MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.FALSE;
457
        AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
458
        try {
459
            targets = actionProvider.getTargetNames(ActionProvider.COMMAND_PROFILE_SINGLE, context, p);
460
        } finally {
461
            MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
462
            AppletSupport.unitTestingSupport_isApplet = null;
463
        }
464
        assertNotNull("Must found some targets for COMMAND_PROFILE_SINGLE", targets);
465
        assertEquals("There must be one target for COMMAND_PROFILE_SINGLE", 1, targets.length);
466
        assertEquals("Unexpected target name", "profile-applet", targets[0]);
467
        assertEquals("There must be one target parameter", 3, p.keySet().size());
468
        assertEquals("There must be be target parameter", "foo/Main.java", p.getProperty("javac.includes"));
469
        appletHtml = build.getFileObject("Main", "html");
470
        assertNotNull("Applet HTML page must be generated", appletHtml);
471
        appletUrl = URLMapper.findURL(appletHtml, URLMapper.EXTERNAL);
472
        assertEquals("There must be be target parameter", appletUrl.toExternalForm(), p.getProperty("applet.url"));
473
        p = new Properties();
474
        context = Lookups.fixed(someTest1);
475
        MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
476
        AppletSupport.unitTestingSupport_isApplet = Boolean.TRUE;
477
        try {
478
            targets = actionProvider.getTargetNames(ActionProvider.COMMAND_PROFILE_SINGLE, context, p);
479
        } finally {
480
            MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
481
            AppletSupport.unitTestingSupport_isApplet = null;
482
        }
483
        assertNotNull("Must found some targets for COMMAND_PROFILE_SINGLE", targets);
484
        assertEquals("There must be one target for COMMAND_PROFILE_SINGLE", 1, targets.length);
485
        assertEquals("Unexpected target name", "profile-test-with-main", targets[0]);
486
        assertEquals("There must be two target parameters", 2, p.keySet().size());
487
        assertEquals("There must be be target parameter", "foo.BarTest", p.getProperty("run.class"));
488
        assertEquals("There must be be target parameter", "foo/BarTest.java", p.getProperty("javac.includes"));
425
489
426
        // test COMMAND_RUN
490
        // test COMMAND_RUN
427
491
Lines 478-483 Link Here
478
        //See issue #61244: Main class setting not saved for J2SE Project during IDE session
542
        //See issue #61244: Main class setting not saved for J2SE Project during IDE session
479
        assertEquals("There must be one target parameter", 1, p.keySet().size());
543
        assertEquals("There must be one target parameter", 1, p.keySet().size());
480
        assertEquals("There must be be target parameter", "foo.Main", p.getProperty("debug.class"));
544
        assertEquals("There must be be target parameter", "foo.Main", p.getProperty("debug.class"));
545
        
546
        // test COMMAND_PROFILE
547
548
        p = new Properties();
549
        context = Lookup.EMPTY;
550
        MainClassChooser.unitTestingSupport_hasMainMethodResult = Boolean.TRUE;
551
        try {
552
            targets = actionProvider.getTargetNames(ActionProvider.COMMAND_PROFILE, context, p);
553
        } finally {
554
            MainClassChooser.unitTestingSupport_hasMainMethodResult = null;
555
        }
556
        assertNotNull("Must found some targets for COMMAND_PROFILE", targets);
557
        assertEquals("There must be one target for COMMAND_PROFILE", 1, targets.length);
558
        assertEquals("Unexpected target name", "profile", targets[0]);
559
        //The project is saved after the main.class property was added into the project's properties,
560
        //it is no more needed to pass it in the properties.
561
        //See issue #61244: Main class setting not saved for J2SE Project during IDE session
562
        assertEquals("There must be one target parameter", 1, p.keySet().size());
563
        assertEquals("There must be be target parameter", "foo.Main", p.getProperty("run.class"));
481
    }
564
    }
482
    
565
    
483
    public void testGetTargetNamesFromConfig() throws Exception {
566
    public void testGetTargetNamesFromConfig() throws Exception {
(-)a/java.project/src/org/netbeans/api/java/project/runner/JavaRunner.java (+6 lines)
Lines 108-113 Link Here
108
     */
108
     */
109
    public static final String QUICK_DEBUG = "debug";
109
    public static final String QUICK_DEBUG = "debug";
110
110
111
    public static final String QUICK_PROFILE = "profile";
112
    
111
    /**
113
    /**
112
     * <p>"Test" run the given test. Classfiles produced by the Java infrastructure will be
114
     * <p>"Test" run the given test. Classfiles produced by the Java infrastructure will be
113
     * executed.</p>
115
     * executed.</p>
Lines 134-139 Link Here
134
     */
136
     */
135
    public static final String QUICK_TEST_DEBUG = "junit-debug";
137
    public static final String QUICK_TEST_DEBUG = "junit-debug";
136
138
139
    public static final String QUICK_TEST_PROFILE = "junit-profile";
140
    
137
    /** <p>"Test" run the given applet. Classfiles produced by the Java infrastructure will be
141
    /** <p>"Test" run the given applet. Classfiles produced by the Java infrastructure will be
138
     * executed.</p>
142
     * executed.</p>
139
     * 
143
     * 
Lines 156-161 Link Here
156
     */
160
     */
157
    public static final String QUICK_DEBUG_APPLET = "debug-applet";
161
    public static final String QUICK_DEBUG_APPLET = "debug-applet";
158
    
162
    
163
    public static final String QUICK_PROFILE_APPLET = "profile-applet";
164
    
159
    /** Clean classfiles produced by the Java infrastructure.
165
    /** Clean classfiles produced by the Java infrastructure.
160
     * 
166
     * 
161
     * @since 1.22
167
     * @since 1.22
(-)a/java.source.ant/src/org/netbeans/modules/java/source/ant/resources/junit-debug-snippet.xml (-41 / +22 lines)
Lines 43-100 Link Here
43
Version 2 license, then the option applies only if the new code is
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
44
made subject to such option by the copyright holder.
45
-->
45
-->
46
<project name="{0} (debug-test)" default="debug-test" basedir=".">
46
<project name="{0} (profile-test)" default="profile-test" basedir=".">
47
    <target name="-profile-check" if="netbeans.home">
48
        <condition property="profiler.configured">
49
            <or>
50
                <contains string="${run.jvmargs.ide}" substring="-agentpath:" casesensitive="false"/>
51
                <contains string="${run.jvmargs.ide}" substring="-javaagent:" casesensitive="false"/>
52
            </or>
53
        </condition>
54
    </target>
55
    
47
    <target name="-check-run-test-single-method-supported" if="methodname">
56
    <target name="-check-run-test-single-method-supported" if="methodname">
48
        <available property="run.test.single.method.supported"
57
        <available property="run.test.single.method.supported"
49
                   resource="org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.class"/>
58
                   resource="org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.class"/>
50
        <fail unless="run.test.single.method.supported">Execution of a single test method is not supported by this version of Ant.</fail>
59
        <fail unless="run.test.single.method.supported">Execution of a single test method is not supported by this version of Ant.</fail>
51
    </target>
60
    </target>
52
    <target name="-init-debug-args">
61
    <target name="-prepare-execution">
53
        <property name="version-output" value="java version &quot;${ant.java.version}"/>
54
        <condition property="have-jdk-older-than-1.4">
55
            <or>
56
                <contains string="${version-output}" substring="java version &quot;1.0"/>
57
                <contains string="${version-output}" substring="java version &quot;1.1"/>
58
                <contains string="${version-output}" substring="java version &quot;1.2"/>
59
                <contains string="${version-output}" substring="java version &quot;1.3"/>
60
            </or>
61
        </condition>
62
        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
63
            <istrue value="${have-jdk-older-than-1.4}"/>
64
        </condition>
65
        <condition property="debug-transport-by-os" value="dt_shmem" else="dt_socket">
66
            <os family="windows"/>
67
        </condition>
68
        <condition property="debug-transport" value="${debug.transport}" else="${debug-transport-by-os}">
69
            <isset property="debug.transport"/>
70
        </condition>
71
    </target>
72
    <target name="-prepare-execution" depends="-init-debug-args">
73
        <property name="test.result.dir" location="${java.io.tmpdir}"/>
62
        <property name="test.result.dir" location="${java.io.tmpdir}"/>
74
        <property name="test.result.file"
63
        <property name="test.result.file"
75
                  location="${test.result.dir}/TEST-${classname}.xml"/>
64
                  location="${test.result.dir}/TEST-${classname}.xml"/>
76
        <property  name="tmp.dir" value="${basedir}"/>
65
        <property  name="tmp.dir" value="${basedir}"/>
77
        <macrodef name="junit-debug-template">
66
        <macrodef name="junit-template">
78
            <element name="test-spec" implicit="yes"/>
67
            <element name="test-spec" implicit="yes"/>
79
            <sequential>
68
            <sequential>
80
                <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
69
                <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
81
                <nbjpdastart addressproperty="jpda.address" name="${classname}" stopclassname="" transport="${debug-transport}" listeningcp="${classpath}">
82
                    <classpath>
83
                        <path path="${classpath-translated}"/>
84
                    </classpath>
85
                    <bootclasspath>
86
                        <path path="${platform.bootcp}"/>
87
                    </bootclasspath>
88
                </nbjpdastart>
89
                <property name="run.jvmargs" value="" />
70
                <property name="run.jvmargs" value="" />
90
                <property name="work.dir" value="${basedir}"/>
71
                <property name="work.dir" value="${basedir}"/>
72
73
                <startprofiler/>
91
                <junit showoutput="true" fork="true" dir="${work.dir}" jvm="${platform.java}" tempdir="${tmp.dir}">
74
                <junit showoutput="true" fork="true" dir="${work.dir}" jvm="${platform.java}" tempdir="${tmp.dir}">
92
                    <test-spec/>
75
                    <test-spec/>
93
                    <classpath path="${classpath-translated}" />
76
                    <classpath path="${classpath-translated}" />
94
                    <jvmarg line="${debug-args-line}"/>
95
                    <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
96
                    <jvmarg value="-ea"/>
77
                    <jvmarg value="-ea"/>
97
                    <jvmarg line="${run.jvmargs}"/>
78
                    <jvmarg line="${run.jvmargs}"/>
79
                    <jvmarg line="${run.jvmargs.ide}"/>
98
                    <formatter type="brief" usefile="false"/>
80
                    <formatter type="brief" usefile="false"/>
99
                    <formatter type="xml" />
81
                    <formatter type="xml" />
100
                    <syspropertyset>
82
                    <syspropertyset>
Lines 106-127 Link Here
106
        </macrodef>
88
        </macrodef>
107
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated"/>
89
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated"/>
108
    </target>
90
    </target>
109
    <target name="-debug-test-class" depends="-prepare-execution" unless="methodname">
91
    <target name="-test-class" depends="-prepare-execution" unless="methodname">
110
        <junit-debug-template>
92
        <junit-template>
111
            <test name="${classname}" todir="${test.result.dir}"/>
93
            <test name="${classname}" todir="${test.result.dir}"/>
112
        </junit-debug-template>
94
        </junit-template>
113
    </target>
95
    </target>
114
    <target name="-debug-test-method" depends="-check-run-test-single-method-supported,-prepare-execution" if="methodname">
96
    <target name="-test-method" depends="-check-run-test-single-method-supported,-prepare-execution" if="methodname">
115
        <junit-debug-template>
97
        <junit-template>
116
            <test name="${classname}" methods="${methodname}"
98
            <test name="${classname}" methods="${methodname}"
117
                  todir="${test.result.dir}"/>
99
                  todir="${test.result.dir}"/>
118
        </junit-debug-template>
100
        </junit-template>
119
    </target>
101
    </target>
120
    <target name="debug-test" depends="-debug-test-class,-debug-test-method">
102
    <target name="profile-test" depends="-profile-check,-test-class,-test-method" if="profiler.configured">
121
        <!-- This target is intended to be used in conjunction with the
103
        <!-- This target is intended to be used in conjunction with the
122
        org.apache.tools.ant.module.spi.AntLogger. Note, the next task
104
        org.apache.tools.ant.module.spi.AntLogger. Note, the next task
123
        deletes just created test report. -->
105
        deletes just created test report. -->
124
        <delete file="${test.result.file}" deleteonexit="true" />
106
        <delete file="${test.result.file}" deleteonexit="true" />
125
    </target>
107
    </target>
126
127
</project>
108
</project>
(-)a/java.source.ant/src/org/netbeans/modules/java/source/ant/resources/debug-applet-snippet.xml (-29 / +10 lines)
Lines 43-86 Link Here
43
Version 2 license, then the option applies only if the new code is
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
44
made subject to such option by the copyright holder.
45
-->
45
-->
46
<project name="{0} (debug)" default="debug" basedir=".">
46
<project name="{0} (profile-applet)" default="profile" basedir=".">
47
    <target name="-init-debug-args">
47
    <target name="-profile-check" if="netbeans.home">
48
        <property name="version-output" value="java version &quot;${ant.java.version}"/>
48
        <condition property="profiler.configured">
49
        <condition property="have-jdk-older-than-1.4">
50
            <or>
49
            <or>
51
                <contains string="${version-output}" substring="java version &quot;1.0"/>
50
                <contains string="${run.jvmargs.ide}" substring="-agentpath:" casesensitive="false"/>
52
                <contains string="${version-output}" substring="java version &quot;1.1"/>
51
                <contains string="${run.jvmargs.ide}" substring="-javaagent:" casesensitive="false"/>
53
                <contains string="${version-output}" substring="java version &quot;1.2"/>
54
                <contains string="${version-output}" substring="java version &quot;1.3"/>
55
            </or>
52
            </or>
56
        </condition>
53
        </condition>
57
        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
58
            <istrue value="${have-jdk-older-than-1.4}"/>
59
        </condition>
60
        <condition property="debug-transport-by-os" value="dt_shmem" else="dt_socket">
61
            <os family="windows"/>
62
        </condition>
63
        <condition property="debug-transport" value="${debug.transport}" else="${debug-transport-by-os}">
64
            <isset property="debug.transport"/>
65
        </condition>
66
    </target>
54
    </target>
67
55
    
68
    <target name="debug" depends="-init-debug-args">
56
    <target name="profile" depends="-profile-check" if="profiler.configured">
69
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
57
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
70
        <property name="run.jvmargs" value="" />
58
        <property name="run.jvmargs" value="" />
71
        <property name="work.dir" value="${basedir}"/>
59
        <property name="work.dir" value="${basedir}"/>
72
        <nbjpdastart addressproperty="jpda.address" name="${classname}" stopclassname="" transport="${debug-transport}" listeningcp="${classpath}">
60
73
            <classpath>
61
        <startprofiler/>
74
                <path path="${classpath-translated}"/>
75
            </classpath>
76
            <bootclasspath>
77
                <path path="${platform.bootcp}"/>
78
            </bootclasspath>
79
        </nbjpdastart>
80
        <java classpath="${classpath-translated}" classname="sun.applet.AppletViewer" dir="${work.dir}" jvm="${platform.java}" fork="true">
62
        <java classpath="${classpath-translated}" classname="sun.applet.AppletViewer" dir="${work.dir}" jvm="${platform.java}" fork="true">
81
            <jvmarg line="${debug-args-line}"/>
82
            <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
83
            <jvmarg line="${run.jvmargs}" />
63
            <jvmarg line="${run.jvmargs}" />
64
            <jvmarg line="${run.jvmargs.ide}" />
84
            <arg value="${applet.url}"/>
65
            <arg value="${applet.url}"/>
85
            <syspropertyset>
66
            <syspropertyset>
86
                <propertyref prefix="run-sys-prop."/>
67
                <propertyref prefix="run-sys-prop."/>
(-)a/java.source.ant/src/org/netbeans/modules/java/source/ant/resources/debug-snippet.xml (-30 / +10 lines)
Lines 43-90 Link Here
43
Version 2 license, then the option applies only if the new code is
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
44
made subject to such option by the copyright holder.
45
-->
45
-->
46
<project name="{0} (debug)" default="debug" basedir=".">
46
<project name="{0} (profile)" default="profile" basedir=".">
47
    <target name="-init-debug-args">
47
    <target name="-profile-check" if="netbeans.home">
48
        <property name="version-output" value="java version &quot;${ant.java.version}"/>
48
        <condition property="profiler.configured">
49
        <condition property="have-jdk-older-than-1.4">
50
            <or>
49
            <or>
51
                <contains string="${version-output}" substring="java version &quot;1.0"/>
50
                <contains string="${run.jvmargs.ide}" substring="-agentpath:" casesensitive="false"/>
52
                <contains string="${version-output}" substring="java version &quot;1.1"/>
51
                <contains string="${run.jvmargs.ide}" substring="-javaagent:" casesensitive="false"/>
53
                <contains string="${version-output}" substring="java version &quot;1.2"/>
54
                <contains string="${version-output}" substring="java version &quot;1.3"/>
55
            </or>
52
            </or>
56
        </condition>
53
        </condition>
57
        <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
58
            <istrue value="${have-jdk-older-than-1.4}"/>
59
        </condition>
60
        <condition property="debug-transport-by-os" value="dt_shmem" else="dt_socket">
61
            <os family="windows"/>
62
        </condition>
63
        <condition property="debug-transport" value="${debug.transport}" else="${debug-transport-by-os}">
64
            <isset property="debug.transport"/>
65
        </condition>
66
    </target>
54
    </target>
67
55
    <target name="profile" depends="-profile-check" if="profiler.configured">
68
    <target name="debug" depends="-init-debug-args">
69
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
56
        <translate-classpath classpath="${classpath}" targetProperty="classpath-translated" />
70
        <property name="run.jvmargs" value="" />
57
        <property name="run.jvmargs" value="" />
58
        <property name="run.jvmargs.ide" value="" />
71
        <property name="work.dir" value="${basedir}"/>
59
        <property name="work.dir" value="${basedir}"/>
72
        <property name="application.args" value="" />
60
        <property name="application.args" value="" />
73
        <property name="stopclassname" value="" />
61
74
        <nbjpdastart addressproperty="jpda.address" name="${classname}" transport="${debug-transport}" listeningcp="${classpath}" stopclassname="${stopclassname}">
62
        <startprofiler/>
75
            <classpath>
76
                <path path="${classpath-translated}"/>
77
            </classpath>
78
            <bootclasspath>
79
                <path path="${platform.bootcp}"/>
80
            </bootclasspath>
81
        </nbjpdastart>
82
        <java classpath="${classpath-translated}" classname="${classname}" dir="${work.dir}" jvm="${platform.java}" fork="true">
63
        <java classpath="${classpath-translated}" classname="${classname}" dir="${work.dir}" jvm="${platform.java}" fork="true">
83
            <jvmarg line="${debug-args-line}"/>
84
            <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
85
            <jvmarg value="-Dfile.encoding=${encoding}"/>
64
            <jvmarg value="-Dfile.encoding=${encoding}"/>
86
            <redirector inputencoding="${encoding}" outputencoding="${encoding}" errorencoding="${encoding}"/>
65
            <redirector inputencoding="${encoding}" outputencoding="${encoding}" errorencoding="${encoding}"/>
87
            <jvmarg line="${run.jvmargs}" />
66
            <jvmarg line="${run.jvmargs}" />
67
            <jvmarg line="${run.jvmargs.ide}"/>
88
            <arg line="${application.args}" />
68
            <arg line="${application.args}" />
89
            <syspropertyset>
69
            <syspropertyset>
90
                <propertyref prefix="run-sys-prop."/>
70
                <propertyref prefix="run-sys-prop."/>
(-)a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NetBeansStartupArgs.java (-1 / +1 lines)
Lines 70-76 Link Here
70
            mode = StartupExtender.StartMode.NORMAL;
70
            mode = StartupExtender.StartMode.NORMAL;
71
        } else if (ActionProvider.COMMAND_DEBUG.equals(actionName)) {
71
        } else if (ActionProvider.COMMAND_DEBUG.equals(actionName)) {
72
            mode = StartupExtender.StartMode.DEBUG;
72
            mode = StartupExtender.StartMode.DEBUG;
73
        } else if ("profile".equals(actionName)) {
73
        } else if (ActionProvider.COMMAND_PROFILE.equals(actionName)) {
74
            mode = StartupExtender.StartMode.PROFILE;
74
            mode = StartupExtender.StartMode.PROFILE;
75
        } else {
75
        } else {
76
            return true;
76
            return true;
(-)a/maven.profiler/nbproject/project.xml (+24 lines)
Lines 121-126 Link Here
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
124
                    <code-name-base>org.openide.execution</code-name-base>
125
                    <build-prerequisite/>
126
                    <compile-dependency/>
127
                    <run-dependency>
128
                        <specification-version>1.25</specification-version>
129
                    </run-dependency>
130
                </dependency>
131
                <dependency>
124
                    <code-name-base>org.openide.filesystems</code-name-base>
132
                    <code-name-base>org.openide.filesystems</code-name-base>
125
                    <build-prerequisite/>
133
                    <build-prerequisite/>
126
                    <compile-dependency/>
134
                    <compile-dependency/>
Lines 129-134 Link Here
129
                    </run-dependency>
137
                    </run-dependency>
130
                </dependency>
138
                </dependency>
131
                <dependency>
139
                <dependency>
140
                    <code-name-base>org.openide.loaders</code-name-base>
141
                    <build-prerequisite/>
142
                    <compile-dependency/>
143
                    <run-dependency>
144
                        <specification-version>7.33</specification-version>
145
                    </run-dependency>
146
                </dependency>
147
                <dependency>
148
                    <code-name-base>org.openide.nodes</code-name-base>
149
                    <build-prerequisite/>
150
                    <compile-dependency/>
151
                    <run-dependency>
152
                        <specification-version>7.27</specification-version>
153
                    </run-dependency>
154
                </dependency>
155
                <dependency>
132
                    <code-name-base>org.openide.util</code-name-base>
156
                    <code-name-base>org.openide.util</code-name-base>
133
                    <build-prerequisite/>
157
                    <build-prerequisite/>
134
                    <compile-dependency/>
158
                    <compile-dependency/>
(-)a/maven.profiler/src/org/netbeans/modules/maven/profiler/ActionMappings.xml (-20 / +14 lines)
Lines 56-64 Link Here
56
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
56
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
57
        </goals>
57
        </goals>
58
        <properties>
58
        <properties>
59
            <exec.args>${profiler.args} -classpath %classpath ${packageClassName}</exec.args>
59
            <exec.args>-classpath %classpath ${packageClassName}</exec.args>
60
            <exec.executable>${profiler.java}</exec.executable>
60
            <exec.executable>java</exec.executable>
61
            <profiler.action>profile</profiler.action>
62
        </properties>
61
        </properties>
63
    </action>
62
    </action>
64
63
Lines 88-95 Link Here
88
            <goal>nbm:run-ide</goal>
87
            <goal>nbm:run-ide</goal>
89
        </goals>
88
        </goals>
90
        <properties>
89
        <properties>
91
            <netbeans.run.params.ide>${profiler.args.prefixed} ${profiler.jdkhome.opt}</netbeans.run.params.ide>
90
            <netbeans.run.params.ide/>
92
            <profiler.action>profile</profiler.action>
93
        </properties>
91
        </properties>
94
    </action>
92
    </action>
95
    <action>
93
    <action>
Lines 102-131 Link Here
102
            <goal>nbm:run-platform</goal>
100
            <goal>nbm:run-platform</goal>
103
        </goals>
101
        </goals>
104
        <properties>
102
        <properties>
105
            <netbeans.run.params.ide>${profiler.args.prefixed} ${profiler.jdkhome.opt}</netbeans.run.params.ide>
103
            <netbeans.run.params.ide/>
106
            <profiler.action>profile</profiler.action>
107
        </properties>
104
        </properties>
108
    </action>
105
    </action>
109
106
110
    <action>
107
    <action>
111
        <actionName>profile-single</actionName>
108
        <actionName>profile.single</actionName>
112
        <packagings>
109
        <packagings>
113
            <packaging>jar</packaging>
110
            <packaging>*</packaging>
114
        </packagings>
111
        </packagings>
115
        <goals>
112
        <goals>
116
            <goal>process-classes</goal>
113
            <goal>process-classes</goal>
117
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
114
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
118
        </goals>
115
        </goals>
119
        <properties>
116
        <properties>
120
            <exec.args>${profiler.args} -classpath %classpath ${packageClassName}</exec.args>
117
            <exec.args>-classpath %classpath ${packageClassName}</exec.args>
121
            <exec.executable>${profiler.java}</exec.executable>
118
            <exec.executable>java</exec.executable>
122
            <exec.classpathScope>${classPathScope}</exec.classpathScope>
119
            <exec.classpathScope>${classPathScope}</exec.classpathScope>
123
            <profiler.action>profile-single</profiler.action>
124
        </properties>
120
        </properties>
125
    </action>
121
    </action>
126
122
127
    <action>
123
    <action>
128
        <actionName>profile-single.deploy</actionName>
124
        <actionName>profile.single.deploy</actionName>
129
        <packagings>
125
        <packagings>
130
            <packaging>war</packaging>
126
            <packaging>war</packaging>
131
        </packagings>
127
        </packagings>
Lines 140-146 Link Here
140
    </action>
136
    </action>
141
137
142
    <action>
138
    <action>
143
        <actionName>profile-tests</actionName>
139
        <actionName>profile.test.single</actionName>
144
        <packagings>
140
        <packagings>
145
            <packaging>*</packaging>
141
            <packaging>*</packaging>
146
        </packagings>
142
        </packagings>
Lines 149-161 Link Here
149
            <goal>surefire:test</goal>
145
            <goal>surefire:test</goal>
150
        </goals>
146
        </goals>
151
        <properties>
147
        <properties>
152
            <test>${className}</test>
148
            <test>${packageClassName}</test>
153
            <forkMode>once</forkMode>
149
            <forkMode>once</forkMode>
154
            <maven.surefire.debug>${profiler.args} -classpath %classpath</maven.surefire.debug>
150
            <maven.surefire.debug>${exec.args}</maven.surefire.debug>
155
            <!--<exec.executable>${profiler.java}</exec.executable>
151
            <!-- need to declare exec.args property to engage the StartupExtender infrastructure -->
156
            <exec.classpathScope>${classPathScope}</exec.classpathScope>
152
            <exec.args/>
157
            -->
158
            <profiler.action>profile-tests</profiler.action>
159
        </properties>
153
        </properties>
160
    </action>
154
    </action>
161
</actions>
155
</actions>
(-)a/maven.profiler/src/org/netbeans/modules/maven/profiler/MavenProjectProfilingSupportProvider.java (-21 / +21 lines)
Lines 77-83 Link Here
77
    };
77
    };
78
    
78
    
79
    
79
    
80
    public JavaPlatform getProjectJavaPlatform() {
80
    public JavaPlatform resolveProjectJavaPlatform() {
81
        return JavaPlatform.getDefaultPlatform();
81
        return JavaPlatform.getDefaultPlatform();
82
    }
82
    }
83
83
Lines 92-121 Link Here
92
    
92
    
93
    @Override
93
    @Override
94
    public boolean startProfilingSession(final FileObject profiledClassFile, final boolean isTest, final Properties properties) {
94
    public boolean startProfilingSession(final FileObject profiledClassFile, final boolean isTest, final Properties properties) {
95
        RequestProcessor.getDefault().post(new Runnable() {
95
//        RequestProcessor.getDefault().post(new Runnable() {
96
            public void run() { startMaven(getProject().getLookup().lookup(Project.class), profiledClassFile, isTest, properties); }
96
//            public void run() { startMaven(getProject().getLookup().lookup(Project.class), profiledClassFile, isTest, properties); }
97
        });
97
//        });
98
        
98
        
99
        return true;
99
        return true;
100
    }
100
    }
101
    
101
    
102
    private void startMaven(Project project, FileObject profiledClassFile, boolean isTest, Properties properties) {
102
//    private void startMaven(Project project, FileObject profiledClassFile, boolean isTest, Properties properties) {
103
        ProfilingSettings lastProfilingSettings = new ProfilingSettings();
103
//        ProfilingSettings lastProfilingSettings = new ProfilingSettings();
104
        SessionSettings lastSessionSettings = new SessionSettings();
104
//        SessionSettings lastSessionSettings = new SessionSettings();
105
        Properties lastSessionProperties = new Properties(properties);
105
//        Properties lastSessionProperties = new Properties(properties);
106
        
106
//        
107
        lastProfilingSettings.load(properties);
107
//        lastProfilingSettings.load(properties);
108
        lastSessionSettings.load(properties);
108
//        lastSessionSettings.load(properties);
109
        
109
//        
110
        RunCheckerImpl.configureProject(project, lastSessionProperties, lastProfilingSettings, lastSessionSettings);
110
//        RunCheckerImpl.configureProject(project, lastSessionProperties, lastProfilingSettings, lastSessionSettings);
111
111
//
112
        NetBeansProfiler.getDefaultNB().setProfiledProject(project, profiledClassFile);
112
//        NetBeansProfiler.getDefaultNB().setProfiledProject(project, profiledClassFile);
113
113
//
114
        String packaging = project.getLookup().lookup(NbMavenProject.class).getPackagingType();
114
//        String packaging = project.getLookup().lookup(NbMavenProject.class).getPackagingType();
115
        
115
//        
116
        if (profiledClassFile != null) ProjectUtilities.invokeAction(project, isTest ? "profile-tests": (packaging.equals("war") ? "profile-single.deploy" : "profile-single")); //NOI18N
116
//        if (profiledClassFile != null) ProjectUtilities.invokeAction(project, isTest ? "profile-tests": (packaging.equals("war") ? "profile-single.deploy" : "profile-single")); //NOI18N
117
        else ProjectUtilities.invokeAction(project, isTest ? "profile-tests" : "profile"); //NOI18N
117
//        else ProjectUtilities.invokeAction(project, isTest ? "profile-tests" : "profile"); //NOI18N
118
    }
118
//    }
119
    
119
    
120
    
120
    
121
    public MavenProjectProfilingSupportProvider(Project project) {
121
    public MavenProjectProfilingSupportProvider(Project project) {
(-)a/maven.profiler/src/org/netbeans/modules/maven/profiler/ProfilerActionsProvider.java (-5 / +6 lines)
Lines 48-53 Link Here
48
import org.netbeans.modules.maven.api.NbMavenProject;
48
import org.netbeans.modules.maven.api.NbMavenProject;
49
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider;
49
import org.netbeans.modules.maven.spi.actions.AbstractMavenActionsProvider;
50
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.Project;
51
import org.netbeans.spi.project.ActionProvider;
51
import org.openide.util.Lookup;
52
import org.openide.util.Lookup;
52
53
53
/**
54
/**
Lines 68-74 Link Here
68
69
69
    @Override
70
    @Override
70
    public boolean isActionEnable(String action, Project project, Lookup lookup) {
71
    public boolean isActionEnable(String action, Project project, Lookup lookup) {
71
        if (!(action.equals("profile") || action.startsWith("profile-single") || action.equals("profile-tests"))) {
72
        if (!(action.equals(ActionProvider.COMMAND_PROFILE) || action.startsWith(ActionProvider.COMMAND_PROFILE_SINGLE) || action.equals(ActionProvider.COMMAND_PROFILE_TEST_SINGLE))) {
72
            return false;
73
            return false;
73
        }
74
        }
74
        NbMavenProject mavenprj = project.getLookup().lookup(NbMavenProject.class);
75
        NbMavenProject mavenprj = project.getLookup().lookup(NbMavenProject.class);
Lines 81-89 Link Here
81
82
82
    @Override
83
    @Override
83
    protected InputStream getActionDefinitionStream() {
84
    protected InputStream getActionDefinitionStream() {
84
            String path = "/org/netbeans/modules/maven/profiler/ActionMappings.xml"; //NOI18N
85
        String path = "/org/netbeans/modules/maven/profiler/ActionMappings.xml"; //NOI18N
85
            InputStream in = getClass().getResourceAsStream(path);
86
        InputStream in = getClass().getResourceAsStream(path);
86
            assert in != null : "no instream for " + path; //NOI18N
87
        assert in != null : "no instream for " + path; //NOI18N
87
            return in;
88
        return in;
88
    }
89
    }
89
}
90
}
(-)a/maven.profiler/src/org/netbeans/modules/maven/profiler/RunCheckerImpl.java (-69 / +98 lines)
Lines 43-77 Link Here
43
package org.netbeans.modules.maven.profiler;
43
package org.netbeans.modules.maven.profiler;
44
44
45
import java.io.File;
45
import java.io.File;
46
import java.util.ArrayList;
46
import java.util.*;
47
import java.util.List;
48
import java.util.Map;
49
import java.util.Properties;
50
import java.util.WeakHashMap;
51
import java.util.logging.Level;
47
import java.util.logging.Level;
52
import java.util.logging.Logger;
48
import java.util.logging.Logger;
49
import org.netbeans.api.project.FileOwnerQuery;
53
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.Project;
54
import org.netbeans.lib.profiler.common.Profiler;
51
import org.netbeans.lib.profiler.common.Profiler;
55
import org.netbeans.lib.profiler.common.ProfilingSettings;
52
import org.netbeans.lib.profiler.common.ProfilingSettings;
56
import org.netbeans.lib.profiler.common.SessionSettings;
53
import org.netbeans.lib.profiler.common.SessionSettings;
57
import org.netbeans.modules.maven.api.execute.ExecutionContext;
54
import org.netbeans.modules.maven.api.execute.ExecutionContext;
58
import org.netbeans.modules.maven.api.execute.LateBoundPrerequisitesChecker;
55
import org.netbeans.modules.maven.api.execute.LateBoundPrerequisitesChecker;
56
import org.netbeans.modules.maven.api.execute.PrerequisitesChecker;
59
import org.netbeans.modules.maven.api.execute.RunConfig;
57
import org.netbeans.modules.maven.api.execute.RunConfig;
58
import org.netbeans.modules.maven.api.execute.RunUtils;
59
import org.netbeans.modules.profiler.NetBeansProfiler;
60
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher;
61
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher.Launcher;
62
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher.Session;
63
import org.netbeans.spi.project.ActionProvider;
60
import org.netbeans.spi.project.ProjectServiceProvider;
64
import org.netbeans.spi.project.ProjectServiceProvider;
65
import org.openide.filesystems.FileObject;
66
import org.openide.loaders.DataObject;
67
import org.openide.loaders.DataObjectNotFoundException;
68
import org.openide.util.Lookup;
61
import org.openide.util.RequestProcessor;
69
import org.openide.util.RequestProcessor;
62
import org.openide.util.Utilities;
70
import org.openide.util.Utilities;
71
import org.openide.util.lookup.Lookups;
63
72
64
/**
73
/**
65
 *
74
 *
66
 * @author mkleint
75
 * @author mkleint
67
 * @author Jiri Sedlacek
76
 * @author Jiri Sedlacek
68
 */
77
 */
69
@ProjectServiceProvider(service=LateBoundPrerequisitesChecker.class, projectType="org-netbeans-modules-maven")
78
@ProjectServiceProvider(service={LateBoundPrerequisitesChecker.class}, projectType="org-netbeans-modules-maven")
70
public class RunCheckerImpl implements LateBoundPrerequisitesChecker {
79
public class RunCheckerImpl implements LateBoundPrerequisitesChecker {
71
    
72
    private static final String ACTION_PROFILE = "profile"; // NOI18N
73
    private static final String ACTION_PROFILE_SINGLE = "profile-single"; // NOI18N
74
        private static final String ACTION_PROFILE_TESTS = "profile-tests"; // NOI18N
75
80
76
    private static final Logger LOG = Logger.getLogger(RunCheckerImpl.class.getName());
81
    private static final Logger LOG = Logger.getLogger(RunCheckerImpl.class.getName());
77
    
82
    
Lines 83-172 Link Here
83
    private static final String PROFILER_JDKHOME_OPT = "${profiler.jdkhome.opt}"; // NOI18N
88
    private static final String PROFILER_JDKHOME_OPT = "${profiler.jdkhome.opt}"; // NOI18N
84
    
89
    
85
    private final Project project;
90
    private final Project project;
86
    private static final Map<Project, Properties> properties = new WeakHashMap();
87
    private static final Map<Project, ProfilingSettings> profilingSettings = new WeakHashMap();
88
    private static final Map<Project, SessionSettings> sessionSettings = new WeakHashMap();
89
91
92
    @ProjectServiceProvider(service=ProfilerLauncher.LauncherFactory.class, projectType="org-netbeans-modules-maven")
93
    final public static class MavenLauncherFactory implements ProfilerLauncher.LauncherFactory {
94
        @Override
95
        public Launcher createLauncher(final Session session) {
96
            return new Launcher() {
97
98
                @Override
99
                public void launch(boolean rerun) {
100
                    if (rerun) {
101
                        RunConfig config = (RunConfig)session.getAttribute("mvn-run-checker.config");
102
                        if (config != null) {
103
                            RunUtils.executeMaven(config);
104
                        }
105
                    } else {
106
                        Project p = session.getProject();
107
                        if (p == null) {
108
                            FileObject f = session.getFile();
109
                            if (f != null) {
110
                                p = FileOwnerQuery.getOwner(f);
111
                            }
112
                        }
113
                        if (p != null) {
114
                            ActionProvider ap = p.getLookup().lookup(ActionProvider.class);
115
                            if (ap != null) {
116
                                ap.invokeAction(session.getCommand(), session.getContext());
117
                            }
118
                        }
119
                    }
120
                }
121
            };
122
        }
123
        
124
    }
90
    
125
    
91
    public RunCheckerImpl(Project prj) {
126
    public RunCheckerImpl(Project prj) {
92
        project = prj;
127
        project = prj;
93
    }
128
    }
94
    
129
    
95
    static void configureProject(Project project, Properties p, ProfilingSettings ps, SessionSettings ss) {
130
//    static void configureProject(Project project, Properties p, ProfilingSettings ps, SessionSettings ss) {
96
        properties.put(project, p);
131
//        properties.put(project, p);
97
        profilingSettings.put(project, ps);
132
//        profilingSettings.put(project, ps);
98
        sessionSettings.put(project, ss);
133
//        sessionSettings.put(project, ss);
99
    }
134
//    }
135
//    
136
//    private void configureProfiler(RunConfig config, Properties props) {
137
//        ProfilingSettings lastProfilingSettings = new ProfilingSettings();
138
//        SessionSettings lastSessionSettings = new SessionSettings();
139
//        
140
//        lastProfilingSettings.load(props);
141
//        lastSessionSettings.load(props);
142
//        
143
//        NetBeansProfiler.getDefaultNB().setProfiledProject(config.getProject(), config.getSelectedFileObject());
144
//    }
145
146
//    @Override
147
//    public boolean checkRunConfig(RunConfig config) {
148
//        if (ActionProvider.COMMAND_PROFILE.equals(config.getActionName()) ||
149
//               ActionProvider.COMMAND_PROFILE_TEST_SINGLE.equals(config.getActionName()) ||
150
//              (config.getActionName() != null && config.getActionName().startsWith(ActionProvider.COMMAND_PROFILE_SINGLE))) {
151
//            isFirstRun = true;
152
//        }
153
//        
154
//        return true;
155
//    }
100
    
156
    
101
    public boolean checkRunConfig(RunConfig config, ExecutionContext context) {
157
    @Override
158
    public boolean checkRunConfig(final RunConfig config, ExecutionContext context) {
102
        Map<? extends String,? extends String> configProperties = config.getProperties();
159
        Map<? extends String,? extends String> configProperties = config.getProperties();
160
        
161
        if (ActionProvider.COMMAND_PROFILE.equals(config.getActionName()) ||
162
               ActionProvider.COMMAND_PROFILE_TEST_SINGLE.equals(config.getActionName()) ||
163
              (config.getActionName() != null && config.getActionName().startsWith(ActionProvider.COMMAND_PROFILE_SINGLE))) {
164
            Map<String, String> props = new HashMap<String, String>();
165
            props.putAll(configProperties);
103
166
104
        if (   ACTION_PROFILE.equals(config.getActionName()) ||
167
            ProfilerLauncher.Session session = ProfilerLauncher.getLastSession();
105
               ACTION_PROFILE_TESTS.equals(config.getActionName()) ||
168
            
106
              (config.getActionName() != null && config.getActionName().startsWith(ACTION_PROFILE_SINGLE))) { // action "profile"
169
            if (session == null) {
107
            // Resolve profiling configuration
170
                return false;
108
            Properties sessionProperties = properties.get(project);
109
            if (sessionProperties == null) return false;
110
            // Resolve profiling session properties
111
            for (Object k : configProperties.keySet()) {
112
                String key = (String)k;
113
                
114
                String value = configProperties.get(key);
115
                if (value.contains(PROFILER_ARGS)) {
116
                    value = value.replace(PROFILER_ARGS, profilerArgs(sessionProperties, false));
117
                    config.setProperty(key, value.trim());
118
                }
119
                if (value.contains(PROFILER_ARGS_PREFIXED)) {
120
                    value = value.replace(PROFILER_ARGS_PREFIXED, profilerArgs(sessionProperties, true));
121
                    config.setProperty(key, value.trim());
122
                }
123
                if (value.contains(PROFILER_JAVA)) {
124
                    String profilerJava = sessionProperties.getProperty("profiler.info.jvm"); // NOI18N
125
                    value = value.replace(PROFILER_JAVA,
126
                            (profilerJava != null && new File(profilerJava).isFile()) ? profilerJava : "java"); // NOI18N
127
                    config.setProperty(key, value.trim());
128
                }
129
                if (value.contains(PROFILER_JDKHOME_OPT)) {
130
                    String opt = "";
131
                    String profilerJava = sessionProperties.getProperty("profiler.info.jvm"); // NOI18N
132
                    if (profilerJava != null) {
133
                        File binJava = new File(profilerJava);
134
                        if (binJava.isFile() && binJava.getName().matches("java([.]exe)?") && binJava.getParentFile().getName().equals("bin")) {
135
                            String jdkhome = binJava.getParentFile().getParent();
136
                            opt = Utilities.escapeParameters(new String[] {"--jdkhome", jdkhome});
137
                            LOG.log(Level.FINE, "from {0} escaped {1}", new Object[] {jdkhome, opt});
138
                        }
139
                    }
140
                    value = value.replace(PROFILER_JDKHOME_OPT, opt);
141
                    config.setProperty(key, value.trim());
142
                }
143
            }
171
            }
172
                       
173
            Map<String, String> sProps = session.getProperties();
174
            if (sProps == null) return false;
144
            
175
            
176
            props.putAll(sProps);
177
            
178
            session.setAttribute("mvn-run-checker.config", config);
179
                        
180
            final ProfilerLauncher.Session s = session;
145
            // Attach profiler engine (in separate thread) to profiled process
181
            // Attach profiler engine (in separate thread) to profiled process
146
            RequestProcessor.getDefault().post(new Runnable() {
182
            RequestProcessor.getDefault().post(new Runnable() {
147
                public void run() {
183
                public void run() {
148
                    ProfilingSettings ps = profilingSettings.get(project);
184
                    Profiler.getDefault().connectToStartedApp(s.getProfilingSettings(), s.getSessionSettings());
149
                    SessionSettings ss = sessionSettings.get(project);
150
                    Profiler.getDefault().connectToStartedApp(ps, ss);
151
                }
185
                }
152
            });
186
            });
153
            
154
//        } else if (ACTION_PROFILE_SINGLE.equals(actionName)) { // action "profile-single"
155
//            // profile-single not supported yet, shouldn't get here
156
//        } else if (ACTION_PROFILE_TESTS.equals(actionName)) {
157
//            // profile-tests not supported yet, shouldn't get here // action "profile-tests"
158
        }
187
        }
159
        
188
        
160
        return true;
189
        return true;
161
    }
190
    }
162
191
163
    private String profilerArgs(Properties sessionProperties, boolean prefixed) {
192
    private String profilerArgs(Map<String, String> sessionProperties, boolean prefixed) {
164
        List<String> args = new ArrayList<String>();
193
        List<String> args = new ArrayList<String>();
165
        String jvmargs = sessionProperties.getProperty("profiler.info.jvmargs");
194
        String jvmargs = sessionProperties.get("profiler.info.jvmargs");
166
        for (String arg : Utilities.parseParameters(jvmargs)) {
195
        for (String arg : Utilities.parseParameters(jvmargs)) {
167
            args.add(prefixed ? "-J" + arg : arg);
196
            args.add(prefixed ? "-J" + arg : arg);
168
        }
197
        }
169
        String agentarg = sessionProperties.getProperty("profiler.info.jvmargs.agent");
198
        String agentarg = sessionProperties.get("agent.jvmargs");
170
        if (Utilities.isWindows()) {
199
        if (Utilities.isWindows()) {
171
            agentarg = agentarg.replace('\\', '/'); // XXX is this still necessary given quoting?
200
            agentarg = agentarg.replace('\\', '/'); // XXX is this still necessary given quoting?
172
        }
201
        }
(-)a/maven/src/org/netbeans/modules/maven/ActionProviderImpl.java (-3 / +13 lines)
Lines 128-134 Link Here
128
        COMMAND_DEBUG_SINGLE,
128
        COMMAND_DEBUG_SINGLE,
129
        COMMAND_DEBUG_TEST_SINGLE,
129
        COMMAND_DEBUG_TEST_SINGLE,
130
        "debug.fix", //NOI18N
130
        "debug.fix", //NOI18N
131
131
        COMMAND_PROFILE,
132
        COMMAND_PROFILE_SINGLE,
133
        COMMAND_PROFILE_TEST_SINGLE,
134
        
132
        //operations
135
        //operations
133
        COMMAND_DELETE,
136
        COMMAND_DELETE,
134
        COMMAND_RENAME,
137
        COMMAND_RENAME,
Lines 181-187 Link Here
181
184
182
    @Messages("run_single_method_disabled=Surefire 2.8+ with JUnit 4 needed to run a single test method without Compile on Save.")
185
    @Messages("run_single_method_disabled=Surefire 2.8+ with JUnit 4 needed to run a single test method without Compile on Save.")
183
    @Override public void invokeAction(final String action, final Lookup lookup) {
186
    @Override public void invokeAction(final String action, final Lookup lookup) {
184
        if (action.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || action.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)) {
187
        if (action.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || 
188
            action.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)) {
185
            if (!runSingleMethodEnabled()) {
189
            if (!runSingleMethodEnabled()) {
186
                StatusDisplayer.getDefault().setStatusText(run_single_method_disabled());
190
                StatusDisplayer.getDefault().setStatusText(run_single_method_disabled());
187
                return;
191
                return;
Lines 251-256 Link Here
251
    @Messages({
255
    @Messages({
252
        "# {0} - artifactId", "TXT_Run=Run {0}",
256
        "# {0} - artifactId", "TXT_Run=Run {0}",
253
        "# {0} - artifactId", "TXT_Debug=Debug {0}",
257
        "# {0} - artifactId", "TXT_Debug=Debug {0}",
258
        "# {0} - artifactId", "TXT_Profile=Profile {0}",
254
        "# {0} - artifactId", "TXT_Test=Test {0}",
259
        "# {0} - artifactId", "TXT_Test=Test {0}",
255
        "# {0} - artifactId", "TXT_Build=Build {0}"
260
        "# {0} - artifactId", "TXT_Build=Build {0}"
256
    })
261
    })
Lines 267-278 Link Here
267
            title = TXT_Run(prj.getMavenProject().getArtifactId());
272
            title = TXT_Run(prj.getMavenProject().getArtifactId());
268
        } else if (ActionProvider.COMMAND_DEBUG.equals(action)) {
273
        } else if (ActionProvider.COMMAND_DEBUG.equals(action)) {
269
            title = TXT_Debug(prj.getMavenProject().getArtifactId());
274
            title = TXT_Debug(prj.getMavenProject().getArtifactId());
275
        } else if (ActionProvider.COMMAND_PROFILE.equals(action)) {
276
            title = TXT_Profile(prj.getMavenProject().getArtifactId());
270
        } else if (ActionProvider.COMMAND_TEST.equals(action)) {
277
        } else if (ActionProvider.COMMAND_TEST.equals(action)) {
271
            title = TXT_Test(prj.getMavenProject().getArtifactId());
278
            title = TXT_Test(prj.getMavenProject().getArtifactId());
272
        } else if (action.startsWith(ActionProvider.COMMAND_RUN_SINGLE)) {
279
        } else if (action.startsWith(ActionProvider.COMMAND_RUN_SINGLE)) {
273
            title = TXT_Run(dobjName);
280
            title = TXT_Run(dobjName);
274
        } else if (action.startsWith(ActionProvider.COMMAND_DEBUG_SINGLE) || ActionProvider.COMMAND_DEBUG_TEST_SINGLE.equals(action)) {
281
        } else if (action.startsWith(ActionProvider.COMMAND_DEBUG_SINGLE) || ActionProvider.COMMAND_DEBUG_TEST_SINGLE.equals(action)) {
275
            title = TXT_Debug(dobjName);
282
            title = TXT_Debug(dobjName);
283
        } else if (action.startsWith(ActionProvider.COMMAND_PROFILE_SINGLE) || ActionProvider.COMMAND_PROFILE_TEST_SINGLE.equals(action)) {
284
            title = TXT_Profile(dobjName);
276
        } else if (ActionProvider.COMMAND_TEST_SINGLE.equals(action)) {
285
        } else if (ActionProvider.COMMAND_TEST_SINGLE.equals(action)) {
277
            title = TXT_Test(dobjName);
286
            title = TXT_Test(dobjName);
278
        } else {
287
        } else {
Lines 289-295 Link Here
289
                COMMAND_MOVE.equals(action)) {
298
                COMMAND_MOVE.equals(action)) {
290
            return true;
299
            return true;
291
        }
300
        }
292
        if (action.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || action.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)) {
301
        if (action.equals(SingleMethod.COMMAND_RUN_SINGLE_METHOD) || 
302
            action.equals(SingleMethod.COMMAND_DEBUG_SINGLE_METHOD)) {
293
            return true;
303
            return true;
294
        }
304
        }
295
        //TODO if order is important, use the lookupmerger
305
        //TODO if order is important, use the lookupmerger
(-)a/maven/src/org/netbeans/modules/maven/layer.xml (-1 / +1 lines)
Lines 122-128 Link Here
122
                    <attr name="position" intvalue="1000"/>
122
                    <attr name="position" intvalue="1000"/>
123
                </file>
123
                </file>
124
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
124
                <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
125
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.instance"/>
125
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectPopup.instance"/>
126
                    <attr name="position" intvalue="1100"/>
126
                    <attr name="position" intvalue="1100"/>
127
                </file>
127
                </file>
128
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
128
                <file name="org-netbeans-modules-project-ui-TestProject.shadow">
(-)a/maven/src/org/netbeans/modules/maven/runjar/RunJarStartupArgs.java (-1 / +3 lines)
Lines 71-78 Link Here
71
            mode = StartupExtender.StartMode.NORMAL;
71
            mode = StartupExtender.StartMode.NORMAL;
72
        } else if (ActionProvider.COMMAND_DEBUG.equals(actionName) || DEBUG_MAIN.equals(actionName)) {
72
        } else if (ActionProvider.COMMAND_DEBUG.equals(actionName) || DEBUG_MAIN.equals(actionName)) {
73
            mode = StartupExtender.StartMode.DEBUG;
73
            mode = StartupExtender.StartMode.DEBUG;
74
        } else if ("profile".equals(actionName)) {
74
        } else if (ActionProvider.COMMAND_PROFILE.equals(actionName) || ActionProvider.COMMAND_PROFILE_SINGLE.equals(actionName)) {
75
            mode = StartupExtender.StartMode.PROFILE;
75
            mode = StartupExtender.StartMode.PROFILE;
76
        } else if (ActionProvider.COMMAND_PROFILE_TEST_SINGLE.equals(actionName)) {
77
            mode = StartupExtender.StartMode.TEST_PROFILE;
76
        } else {
78
        } else {
77
            // XXX could also set argLine for COMMAND_TEST and relatives (StartMode.TEST_*); need not be specific to TYPE_JAR
79
            // XXX could also set argLine for COMMAND_TEST and relatives (StartMode.TEST_*); need not be specific to TYPE_JAR
78
            return true;
80
            return true;
(-)a/nbbuild/build.xml (-6 / +16 lines)
Lines 914-921 Link Here
914
    <property name="debug.server" value="n"/>
914
    <property name="debug.server" value="n"/>
915
    <antcall target="tryme"/>
915
    <antcall target="tryme"/>
916
  </target>
916
  </target>
917
    
917
918
  <target name="tryme-profile" depends="-jdk-presetdef-nbprofiledirect" description="Start IDE in debugger. May only be called from within IDE.">
918
  <target name="-profile-check" if="netbeans.home">
919
      <condition property="profiler.configured">
920
          <or>
921
              <contains string="${run.args.ide}" substring="-agentpath:" casesensitive="false"/>
922
              <contains string="${run.args.ide}" substring="-javaagent:" casesensitive="false"/>
923
          </or>
924
      </condition>
925
  </target>
926
  
927
  <target name="-tryme-profile-pre72" depends="-jdk-presetdef-nbprofiledirect" if="profiler.info.jvmargs.agent" description="Start IDE in profiler (pre72 compatibility mode). May only be called from within IDE.">
919
    <property name="profiler.roots.path" value="profiler.roots.all" />
928
    <property name="profiler.roots.path" value="profiler.roots.all" />
920
    <fileset id="profiler.roots.all" dir="${netbeans.dest.dir}">
929
    <fileset id="profiler.roots.all" dir="${netbeans.dest.dir}">
921
        <include name="**/*.jar"/>
930
        <include name="**/*.jar"/>
Lines 934-943 Link Here
934
          <fileset refid="${profiler.roots.path}" />
943
          <fileset refid="${profiler.roots.path}" />
935
      </rootspath>
944
      </rootspath>
936
    </nbprofiledirect>
945
    </nbprofiledirect>
937
    
946
  </target>
938
    <antcall target="tryme">
947
  
939
        <param name="tryme.debug.args" value="${profiler.jvmargs}"/>
948
  <target name="tryme-profile" depends="-profile-check,-tryme-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent" description="Start IDE in profiler. May only be called from within IDE.">
940
    </antcall>
949
    <startprofiler/>
950
    <antcall target="tryme"/>
941
  </target>
951
  </target>
942
  
952
  
943
  <target name="tryme" depends="-load-build-properties,tryme-setup-debug-args,-jdk-init"
953
  <target name="tryme" depends="-load-build-properties,tryme-setup-debug-args,-jdk-init"
(-)a/nbbuild/templates/common.xml (-1 / +31 lines)
Lines 692-697 Link Here
692
            <attribute name="test.type"/>
692
            <attribute name="test.type"/>
693
            <sequential>
693
            <sequential>
694
                <fail unless="test.includes">Must set test.includes</fail>
694
                <fail unless="test.includes">Must set test.includes</fail>
695
                <property name="run.jvmargs.ide" value=""/> 
695
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
696
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
696
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}">
697
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}">
697
                    <batchtest todir="${build.test.@{test.type}.results.dir}">
698
                    <batchtest todir="${build.test.@{test.type}.results.dir}">
Lines 701-706 Link Here
701
                    <syspropertyset refid="test.@{test.type}.properties"/>
702
                    <syspropertyset refid="test.@{test.type}.properties"/>
702
                    <jvmarg line="${test.run.args}"/>
703
                    <jvmarg line="${test.run.args}"/>
703
                    <jvmarg line="${test.bootclasspath.prepend.args}"/>
704
                    <jvmarg line="${test.bootclasspath.prepend.args}"/>
705
                    <jvmarg line="${run.args.ide}"/>
706
                    <jvmarg line="${run.jvmargs.ide}"/>
704
                    <formatter type="brief" usefile="false"/>
707
                    <formatter type="brief" usefile="false"/>
705
                    <formatter type="xml"/>
708
                    <formatter type="xml"/>
706
                </junit>
709
                </junit>
Lines 708-713 Link Here
708
            </sequential>
711
            </sequential>
709
        </macrodef>
712
        </macrodef>
710
        <property name="test.type" value="unit"/>
713
        <property name="test.type" value="unit"/>
714
        <property name="run.args.ide" value=""/>
715
        
711
        <test-single test.type="${test.type}"/>
716
        <test-single test.type="${test.type}"/>
712
    </target>
717
    </target>
713
718
Lines 776-781 Link Here
776
            <sequential>
781
            <sequential>
777
                <fail unless="test.class">Must set test.class</fail>
782
                <fail unless="test.class">Must set test.class</fail>
778
                <fail unless="test.methods">Must set test.methods</fail>
783
                <fail unless="test.methods">Must set test.methods</fail>
784
                <property name="run.jvmargs.ide" value=""/>
779
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
785
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
780
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}">
786
                <junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed" filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}">
781
                    <test name="${test.class}" methods="${test.methods}" todir="${build.test.@{test.type}.results.dir}"/>
787
                    <test name="${test.class}" methods="${test.methods}" todir="${build.test.@{test.type}.results.dir}"/>
Lines 783-788 Link Here
783
                    <syspropertyset refid="test.@{test.type}.properties"/>
789
                    <syspropertyset refid="test.@{test.type}.properties"/>
784
                    <jvmarg line="${test.run.args}"/>
790
                    <jvmarg line="${test.run.args}"/>
785
                    <jvmarg line="${test.bootclasspath.prepend.args}"/>
791
                    <jvmarg line="${test.bootclasspath.prepend.args}"/>
792
                    <jvmarg line="${run.jvmargs.ide}"/>
786
                    <formatter type="brief" usefile="false"/>
793
                    <formatter type="brief" usefile="false"/>
787
                    <formatter type="xml"/>
794
                    <formatter type="xml"/>
788
                </junit>
795
                </junit>
Lines 799-814 Link Here
799
            <element name="customize" optional="true"/>
806
            <element name="customize" optional="true"/>
800
            <sequential>
807
            <sequential>
801
                <fail unless="main.class">Must set main.class.</fail>
808
                <fail unless="main.class">Must set main.class.</fail>
809
                <property name="run.jvmargs.ide" value=""/>
802
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
810
                <mkdir dir="${build.test.@{test.type}.results.dir}"/>
803
                <java classname="${main.class}" dir="${build.test.@{test.type}.results.dir}" fork="true">
811
                <java classname="${main.class}" dir="${build.test.@{test.type}.results.dir}" fork="true">
804
                    <classpath refid="test.@{test.type}.run.cp"/>
812
                    <classpath refid="test.@{test.type}.run.cp"/>
805
                    <syspropertyset refid="test.@{test.type}.properties"/>
813
                    <syspropertyset refid="test.@{test.type}.properties"/>
806
                    <jvmarg line="${test.run.args}"/>
814
                    <jvmarg line="${test.run.args}"/>
815
                    <jvmarg line="${run.args.ide}"/>
816
                    <jvmarg line="${run.jvmargs.ide"/>
807
                    <customize/>
817
                    <customize/>
808
                </java>
818
                </java>
809
            </sequential>
819
            </sequential>
810
        </macrodef>
820
        </macrodef>
811
        <property name="test.type" value="unit"/> <!-- compatibility -->
821
        <property name="test.type" value="unit"/> <!-- compatibility -->
822
        <property name="run.args.ide" value=""/> <!-- default -->
812
        <tjava test.type="${test.type}"/>
823
        <tjava test.type="${test.type}"/>
813
    </target>
824
    </target>
814
825
Lines 875-881 Link Here
875
        <debug-fix-test-nb test.type="${test.type}"/>
886
        <debug-fix-test-nb test.type="${test.type}"/>
876
    </target>
887
    </target>
877
888
878
    <target name="profile-test-single-nb" depends="init,test-init,test-build,-jdk-presetdef-nbprofiledirect">
889
    <target name="-profile-check" if="netbeans.home">
890
        <condition property="profiler.configured">
891
            <or>
892
                <contains string="${run.args.ide}" substring="-agentpath:" casesensitive="false"/>
893
                <contains string="${run.args.ide}" substring="-javaagent:" casesensitive="false"/>
894
            </or>
895
        </condition>
896
    </target>
897
898
    <target name="-profile-test-single-nb-pre72" depends="init,test-init,test-build,-jdk-presetdef-nbprofiledirect" if="profiler.info.jvmargs.agent">
879
        <macrodef name="profile-test-single-nb">
899
        <macrodef name="profile-test-single-nb">
880
            <attribute name="test.type"/>
900
            <attribute name="test.type"/>
881
            <sequential>
901
            <sequential>
Lines 905-910 Link Here
905
        <profile-test-single-nb test.type="${test.type}"/>
925
        <profile-test-single-nb test.type="${test.type}"/>
906
    </target>
926
    </target>
907
927
928
    <target name="profile-test-single-nb" depends="-profile-check,init,test-init,test-build,-profile-test-single-nb-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent">        
929
        <startprofiler/>
930
        <antcall target="test-single"/>
931
    </target>
932
    
933
    <target name="profile-test-main-nb" depends="-profile-check,init,test-init,test-build" if="profiler.configured" unless="profiler.info.jvmargs.agent">
934
        <startprofiler/>
935
        <antcall target="run-test-main"/>
936
    </target>
937
908
    <target name="-javadoc-init" depends="init">
938
    <target name="-javadoc-init" depends="init">
909
        <!-- #71884: default Javadoc title and header -->
939
        <!-- #71884: default Javadoc title and header -->
910
        <property file="${manifest.mf}" prefix="mf."/>
940
        <property file="${manifest.mf}" prefix="mf."/>
(-)a/profiler.api/src/org/netbeans/modules/profiler/api/project/ProjectProfilingSupport.java (-1 / +2 lines)
Lines 41-46 Link Here
41
 */
41
 */
42
package org.netbeans.modules.profiler.api.project;
42
package org.netbeans.modules.profiler.api.project;
43
43
44
import java.util.Map;
44
import java.util.Properties;
45
import java.util.Properties;
45
import org.netbeans.lib.profiler.common.SessionSettings;
46
import org.netbeans.lib.profiler.common.SessionSettings;
46
import org.netbeans.modules.profiler.api.JavaPlatform;
47
import org.netbeans.modules.profiler.api.JavaPlatform;
Lines 122-128 Link Here
122
     * @param props properties
123
     * @param props properties
123
     * @param profiledClassFile profiled file or null for profiling the entire project
124
     * @param profiledClassFile profiled file or null for profiling the entire project
124
     */
125
     */
125
    public void configurePropertiesForProfiling(Properties props, FileObject profiledClassFile) {
126
    public void configurePropertiesForProfiling(Map props, FileObject profiledClassFile) {
126
        provider.configurePropertiesForProfiling(props, profiledClassFile);
127
        provider.configurePropertiesForProfiling(props, profiledClassFile);
127
    }
128
    }
128
    
129
    
(-)a/profiler.api/src/org/netbeans/modules/profiler/spi/project/ProjectProfilingSupportProvider.java (-2 / +3 lines)
Lines 41-46 Link Here
41
 */
41
 */
42
package org.netbeans.modules.profiler.spi.project;
42
package org.netbeans.modules.profiler.spi.project;
43
43
44
import java.util.Map;
44
import java.util.Properties;
45
import java.util.Properties;
45
import org.netbeans.lib.profiler.common.SessionSettings;
46
import org.netbeans.lib.profiler.common.SessionSettings;
46
import org.netbeans.modules.profiler.api.JavaPlatform;
47
import org.netbeans.modules.profiler.api.JavaPlatform;
Lines 103-109 Link Here
103
     * @param props properties
104
     * @param props properties
104
     * @param profiledClassFile profiled file or null for profiling the entire project
105
     * @param profiledClassFile profiled file or null for profiling the entire project
105
     */
106
     */
106
    public abstract void configurePropertiesForProfiling(Properties props, FileObject profiledClassFile);
107
    public abstract void configurePropertiesForProfiling(Map<String, String> props, FileObject profiledClassFile);
107
    
108
    
108
    /**
109
    /**
109
     * Configures project-specific session settings.
110
     * Configures project-specific session settings.
Lines 175-181 Link Here
175
        }
176
        }
176
177
177
        @Override
178
        @Override
178
        public void configurePropertiesForProfiling(Properties props, FileObject profiledClassFile) {
179
        public void configurePropertiesForProfiling(Map<String, String> props, FileObject profiledClassFile) {
179
        }
180
        }
180
181
181
        @Override
182
        @Override
(-)a/profiler.freeform/nbproject/project.xml (+17 lines)
Lines 122-127 Link Here
122
                    </run-dependency>
122
                    </run-dependency>
123
                </dependency>
123
                </dependency>
124
                <dependency>
124
                <dependency>
125
                    <code-name-base>org.netbeans.modules.project.ant</code-name-base>
126
                    <build-prerequisite/>
127
                    <compile-dependency/>
128
                    <run-dependency>
129
                        <release-version>1</release-version>
130
                        <specification-version>1.46</specification-version>
131
                    </run-dependency>
132
                </dependency>
133
                <dependency>
125
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
134
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
126
                    <build-prerequisite/>
135
                    <build-prerequisite/>
127
                    <compile-dependency/>
136
                    <compile-dependency/>
Lines 154-159 Link Here
154
                        <specification-version>8.0</specification-version>
163
                        <specification-version>8.0</specification-version>
155
                    </run-dependency>
164
                    </run-dependency>
156
                </dependency>
165
                </dependency>
166
                <dependency>
167
                    <code-name-base>org.openide.util.lookup</code-name-base>
168
                    <build-prerequisite/>
169
                    <compile-dependency/>
170
                    <run-dependency>
171
                        <specification-version>8.12</specification-version>
172
                    </run-dependency>
173
                </dependency>
157
            </module-dependencies>
174
            </module-dependencies>
158
            <public-packages/>
175
            <public-packages/>
159
        </data>
176
        </data>
(-)a/profiler.freeform/src/org/netbeans/modules/profiler/freeform/FreeFormProjectProfilingSupportProvider.java (-6 / +33 lines)
Lines 42-58 Link Here
42
 */
42
 */
43
package org.netbeans.modules.profiler.freeform;
43
package org.netbeans.modules.profiler.freeform;
44
44
45
import java.util.Map;
45
import org.netbeans.api.project.Project;
46
import org.netbeans.api.project.Project;
46
import org.netbeans.api.project.ProjectUtils;
47
import org.netbeans.api.project.ProjectUtils;
47
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileUtil;
49
import org.openide.filesystems.FileUtil;
49
import org.w3c.dom.Element;
50
import org.w3c.dom.Element;
50
import java.util.Properties;
51
import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
52
import org.netbeans.modules.profiler.api.JavaPlatform;
51
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
53
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
52
import org.netbeans.modules.profiler.nbimpl.project.JavaProjectProfilingSupportProvider;
54
import org.netbeans.modules.profiler.nbimpl.project.JavaProjectProfilingSupportProvider;
53
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
55
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
54
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
56
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
55
import org.netbeans.spi.project.ProjectServiceProvider;
57
import org.netbeans.spi.project.ProjectServiceProvider;
58
import org.netbeans.spi.project.support.ant.EditableProperties;
56
59
57
/**
60
/**
58
 * A class providing basic support for profiling free-form projects.
61
 * A class providing basic support for profiling free-form projects.
Lines 62-67 Link Here
62
@ProjectServiceProvider(service=org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider.class, 
65
@ProjectServiceProvider(service=org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider.class, 
63
                        projectTypes={@ProjectType(id="org-netbeans-modules-ant-freeform", position=1210)}) // NOI18N
66
                        projectTypes={@ProjectType(id="org-netbeans-modules-ant-freeform", position=1210)}) // NOI18N
64
public final class FreeFormProjectProfilingSupportProvider extends JavaProjectProfilingSupportProvider {
67
public final class FreeFormProjectProfilingSupportProvider extends JavaProjectProfilingSupportProvider {
68
    private static final String NBJDK_PROPERTIES = "nbproject/nbjdk.properties"; // NOI18N
69
    private static final String NBJDK_ACTIVE = "nbjdk.active"; // NOI18N
65
70
66
    @Override
71
    @Override
67
    public boolean checkProjectIsModifiedForProfiler() {
72
    public boolean checkProjectIsModifiedForProfiler() {
Lines 85-91 Link Here
85
    }
90
    }
86
91
87
    @Override
92
    @Override
88
    public void configurePropertiesForProfiling(final Properties props, final FileObject profiledClassFile) {
93
    public void configurePropertiesForProfiling(final Map<String, String> props, final FileObject profiledClassFile) {
89
        if (profiledClassFile != null) { // In case the class to profile is explicitely selected (profile-single)
94
        if (profiledClassFile != null) { // In case the class to profile is explicitely selected (profile-single)
90
            // 1. specify profiled class name
95
            // 1. specify profiled class name
91
96
Lines 93-111 Link Here
93
            JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
98
            JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
94
            if (src != null) {
99
            if (src != null) {
95
                final String profiledClass = src.getTopLevelClass().getQualifiedName();
100
                final String profiledClass = src.getTopLevelClass().getQualifiedName();
96
                props.setProperty("profile.class", profiledClass); //NOI18N
101
                props.put("profile.class", profiledClass); //NOI18N
97
102
98
                // 2. include it in javac.includes so that the compile-single picks it up
103
                // 2. include it in javac.includes so that the compile-single picks it up
99
                final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(ProjectUtilities.getSourceRoots(getProject()),
104
                final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(ProjectUtilities.getSourceRoots(getProject()),
100
                        profiledClassFile), profiledClassFile);
105
                        profiledClassFile), profiledClassFile);
101
                props.setProperty("javac.includes", clazz); //NOI18N
106
                props.put("javac.includes", clazz); //NOI18N
102
            }
107
            }
103
        }
108
        }
104
    }
109
    }
105
    
110
111
    @Override
112
    public JavaPlatform resolveProjectJavaPlatform() {
113
        ProjectAccessor acc = getProject().getLookup().lookup(ProjectAccessor.class);
114
        EditableProperties ep = acc.getHelper().getProperties(NBJDK_PROPERTIES);
115
        String platformName = ep.getProperty(NBJDK_ACTIVE);
116
117
        return getPlatformByName(platformName);
118
    }
119
120
    @Override
121
    public boolean isProfilingSupported() {
122
        boolean supported = super.isProfilingSupported();
123
        if (!supported) return false;
124
        
125
        final String WEB_MODULE_PROVIDER_TYPE = "org.netbeans.modules.web.freeform.WebModules";
126
        
127
        for(Object x : getProject().getLookup().lookupAll(Object.class)) {
128
            if (WEB_MODULE_PROVIDER_TYPE.equals(x.getClass().getName())) {
129
                return false; // web freeforms are not supported
130
            }
131
        }
132
        return true;
133
    }
106
    
134
    
107
    public FreeFormProjectProfilingSupportProvider(Project project) {
135
    public FreeFormProjectProfilingSupportProvider(Project project) {
108
        super(project);
136
        super(project);
109
    }
137
    }
110
111
}
138
}
(-)a/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/J2EEProjectProfilingSupportProvider.java (-24 / +25 lines)
Lines 76-81 Link Here
76
import org.netbeans.modules.profiler.api.JavaPlatform;
76
import org.netbeans.modules.profiler.api.JavaPlatform;
77
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
77
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
78
import org.netbeans.modules.profiler.api.ProfilerDialogs;
78
import org.netbeans.modules.profiler.api.ProfilerDialogs;
79
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher;
79
import org.netbeans.modules.profiler.nbimpl.project.JavaProjectProfilingSupportProvider;
80
import org.netbeans.modules.profiler.nbimpl.project.JavaProjectProfilingSupportProvider;
80
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
81
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
81
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
82
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
Lines 198-204 Link Here
198
    // --- ProjectTypeProfiler implementation ------------------------------------------------------------------------------
199
    // --- ProjectTypeProfiler implementation ------------------------------------------------------------------------------
199
200
200
    @Override
201
    @Override
201
    public JavaPlatform getProjectJavaPlatform() {
202
    public JavaPlatform resolveProjectJavaPlatform() {
202
        String serverInstanceID = getServerInstanceID(getProject());
203
        String serverInstanceID = getServerInstanceID(getProject());
203
204
204
        if (serverInstanceID == null) {
205
        if (serverInstanceID == null) {
Lines 265-306 Link Here
265
    }
266
    }
266
267
267
    @Override
268
    @Override
268
    public void configurePropertiesForProfiling(final Properties props, final FileObject profiledClassFile) {
269
    public void configurePropertiesForProfiling(final Map<String, String> props, final FileObject profiledClassFile) {
269
        Project project = getProject();
270
        Project project = getProject();
270
        initAntPlatform(project, props);
271
        initAntPlatform(project, props);
271
        // set forceRestart
272
        // set forceRestart
272
        props.setProperty("profiler.j2ee.serverForceRestart", "true"); // NOI18N
273
        props.put("profiler.j2ee.serverForceRestart", "true"); // NOI18N
273
                                                                       // set timeout
274
                                                                       // set timeout
274
275
275
        props.setProperty("profiler.j2ee.serverStartupTimeout", "300000"); // NOI18N
276
        props.put("profiler.j2ee.serverStartupTimeout", "300000"); // NOI18N
276
                                                                           // set agent id
277
                                                                           // set agent id
277
278
278
        props.setProperty("profiler.j2ee.agentID", "-Dnbprofiler.agentid=" + new Integer(generateAgentID()).toString()); // NOI18N // sets lastAgentID
279
        props.put("profiler.j2ee.agentID", "-Dnbprofiler.agentid=" + new Integer(generateAgentID()).toString()); // NOI18N // sets lastAgentID
279
                                                                                                                         // redirect profiler.info.jvmargs to profiler.info.jvmargs.extra
280
                                                                                                                         // redirect profiler.info.jvmargs to profiler.info.jvmargs.extra
280
                                                                                                                         // NOTE: disabled as a workaround for Issue 102323, needs to be fixed in order to restore the OOME detection functionality!
281
                                                                                                                         // NOTE: disabled as a workaround for Issue 102323, needs to be fixed in order to restore the OOME detection functionality!
281
282
282
        String jvmArgs = props.getProperty("profiler.info.jvmargs"); // NOI18N
283
        String jvmArgs = props.get("profiler.info.jvmargs"); // NOI18N
283
284
284
        if ((jvmArgs != null) && (jvmArgs.trim().length() > 0)) {
285
        if ((jvmArgs != null) && (jvmArgs.trim().length() > 0)) {
285
            props.setProperty("profiler.info.jvmargs.extra", jvmArgs);
286
            props.put("profiler.info.jvmargs.extra", jvmArgs);
286
        }
287
        }
287
288
288
        // fix agent startup arguments
289
        // fix agent startup arguments
289
        JavaPlatform javaPlatform = getJavaPlatformFromAntName(project, props);
290
        JavaPlatform javaPlatform = getJavaPlatformFromAntName(project, props);
290
        props.setProperty("profiler.info.javaPlatform", javaPlatform.getPlatformId()); // set the used platform ant property
291
        props.put("profiler.java.platform", javaPlatform.getPlatformId()); // set the used platform ant property
291
292
292
        String javaVersion = javaPlatform.getPlatformJDKVersion();
293
        String javaVersion = javaPlatform.getPlatformJDKVersion();
293
        String localPlatform = IntegrationUtils.getLocalPlatform(javaPlatform.getPlatformArchitecture());
294
        String localPlatform = IntegrationUtils.getLocalPlatform(javaPlatform.getPlatformArchitecture());
294
295
295
        if (javaVersion.equals(CommonConstants.JDK_15_STRING)) {
296
        if (javaVersion.equals(CommonConstants.JDK_15_STRING)) {
296
            // JDK 1.5 used
297
            // JDK 1.5 used
297
            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
298
            props.put("profiler.info.jvmargs.agent", // NOI18N
298
                              IntegrationUtils.getProfilerAgentCommandLineArgs(localPlatform, IntegrationUtils.PLATFORM_JAVA_50,
299
                              IntegrationUtils.getProfilerAgentCommandLineArgs(localPlatform, IntegrationUtils.PLATFORM_JAVA_50,
299
                                                                               false,
300
                                                                               false,
300
                                                                               ProfilerIDESettings.getInstance().getPortNo()));
301
                                                                               ProfilerIDESettings.getInstance().getPortNo()));
301
        } else {
302
        } else {
302
            // JDK 1.6 or later used
303
            // JDK 1.6 or later used
303
            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
304
            props.put("profiler.info.jvmargs.agent", // NOI18N
304
                              IntegrationUtils.getProfilerAgentCommandLineArgs(localPlatform, IntegrationUtils.PLATFORM_JAVA_60,
305
                              IntegrationUtils.getProfilerAgentCommandLineArgs(localPlatform, IntegrationUtils.PLATFORM_JAVA_60,
305
                                                                               false,
306
                                                                               false,
306
                                                                               ProfilerIDESettings.getInstance().getPortNo()));
307
                                                                               ProfilerIDESettings.getInstance().getPortNo()));
Lines 310-316 Link Here
310
311
311
        String loadGenPath = LoadGenPanel.hasInstance() ? LoadGenPanel.instance().getSelectedScript() : null;
312
        String loadGenPath = LoadGenPanel.hasInstance() ? LoadGenPanel.instance().getSelectedScript() : null;
312
        if (loadGenPath != null) {
313
        if (loadGenPath != null) {
313
            props.setProperty("profiler.loadgen.path", loadGenPath); // TODO factor out "profiler.loadgen.path" to a constant
314
            props.put("profiler.loadgen.path", loadGenPath); // TODO factor out "profiler.loadgen.path" to a constant
314
        }
315
        }
315
316
316
        if (profiledClassFile == null) {
317
        if (profiledClassFile == null) {
Lines 359-370 Link Here
359
        JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
360
        JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
360
        if (src != null) {
361
        if (src != null) {
361
            String profiledClass = src.getTopLevelClass().getQualifiedName();
362
            String profiledClass = src.getTopLevelClass().getQualifiedName();
362
            props.setProperty("profile.class", profiledClass); //NOI18N
363
            props.put("profile.class", profiledClass); //NOI18N
363
            // include it in javac.includes so that the compile-single picks it up
364
            // include it in javac.includes so that the compile-single picks it up
364
            final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(
365
            final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(
365
                    ProjectUtilities.getSourceRoots(project),profiledClassFile), 
366
                    ProjectUtilities.getSourceRoots(project),profiledClassFile), 
366
                    profiledClassFile);
367
                    profiledClassFile);
367
            props.setProperty("javac.includes", clazz); //NOI18N
368
            props.put("javac.includes", clazz); //NOI18N
368
        }
369
        }
369
    }
370
    }
370
371
Lines 422-427 Link Here
422
                                                            FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath()) : ""); // NOI18N
423
                                                            FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath()) : ""); // NOI18N
423
        ss.setJVMArgs(""); // NOI18N
424
        ss.setJVMArgs(""); // NOI18N
424
        ss.setWorkingDir(""); // NOI18N
425
        ss.setWorkingDir(""); // NOI18N
426
        
427
        super.setupProjectSessionSettings(ss);
425
    }
428
    }
426
429
427
    @Override
430
    @Override
Lines 453-460 Link Here
453
        return Deployment.getDefault().getJ2eePlatform(serverInstanceID);
456
        return Deployment.getDefault().getJ2eePlatform(serverInstanceID);
454
    }
457
    }
455
458
456
    private static JavaPlatform getJavaPlatformFromAntName(Project project, Properties props) {
459
    private static JavaPlatform getJavaPlatformFromAntName(Project project, Map<String, String> props) {
457
        String javaPlatformAntName = props.getProperty("profiler.info.javaPlatform"); // NOI18N
460
        String javaPlatformAntName = props.get("profiler.info.javaPlatform"); // NOI18N
458
461
459
        if (javaPlatformAntName.equals("default_platform")) {
462
        if (javaPlatformAntName.equals("default_platform")) {
460
            return JavaPlatform.getDefaultPlatform();
463
            return JavaPlatform.getDefaultPlatform();
Lines 468-489 Link Here
468
        return (int) (Math.random() * (float) Integer.MAX_VALUE);
471
        return (int) (Math.random() * (float) Integer.MAX_VALUE);
469
    }
472
    }
470
473
471
    private static void initAntPlatform(Project project, Properties props) {
474
    private void initAntPlatform(Project project, Map<String, String> props) {
472
        String javaPlatformAntName = props.getProperty("profiler.info.javaPlatform"); // NOI18N
475
        String javaPlatformAntName = props.get("profiler.info.javaPlatform"); // NOI18N
473
476
474
        if (javaPlatformAntName == null) {
477
        if (javaPlatformAntName == null) {
475
            JavaPlatform platform = null;
478
            JavaPlatform platform = getProjectJavaPlatform();
476
            J2eePlatform j2eepf = getJ2eePlatform(project); // try to get the J2EE Platform
477
            String platformId;
479
            String platformId;
478
            
480
            
479
            if (j2eepf == null) {
481
            if (platform == null) {
480
                platformId = JavaPlatform.getDefaultPlatform().getPlatformId(); // no J2EE Platform sepcified; use the IDE default JVM platform
482
                platformId = JavaPlatform.getDefaultPlatform().getPlatformId(); // no Platform sepcified; use the IDE default JVM platform
481
            } else {
483
            } else {
482
                Map<String,String> jpprops = j2eepf.getJavaPlatform().getProperties(); // use the J2EE Platform specified JVM platform
484
                platformId = platform.getPlatformId();
483
                platformId = jpprops.get("platform.ant.name");
484
            }
485
            }
485
486
486
            props.setProperty("profiler.info.javaPlatform", platformId); // set the used platform ant property
487
            props.put("profiler.info.javaPlatform", platformId); // set the used platform ant property
487
        }
488
        }
488
    }
489
    }
489
490
(-)a/profiler.j2ee/src/org/netbeans/modules/profiler/j2ee/impl/ProfilerArgsProvider.java (-8 / +10 lines)
Lines 45-50 Link Here
45
import java.util.Collections;
45
import java.util.Collections;
46
import java.util.List;
46
import java.util.List;
47
import org.netbeans.api.extexecution.startup.StartupExtender.StartMode;
47
import org.netbeans.api.extexecution.startup.StartupExtender.StartMode;
48
import org.netbeans.api.project.Project;
48
import org.netbeans.api.server.ServerInstance;
49
import org.netbeans.api.server.ServerInstance;
49
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
50
import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
50
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
51
import org.netbeans.modules.j2ee.deployment.profiler.spi.Profiler;
Lines 57-75 Link Here
57
 */
58
 */
58
@StartupExtenderImplementation.Registration(position=100, displayName="#DESC_Profiler",
59
@StartupExtenderImplementation.Registration(position=100, displayName="#DESC_Profiler",
59
        startMode=StartMode.PROFILE)
60
        startMode=StartMode.PROFILE)
60
public class ProfilerArgsProvider implements StartupExtenderImplementation {
61
public class ServerProfilerArgsProvider implements StartupExtenderImplementation {
61
62
62
    @Override
63
    @Override
63
    public List<String> getArguments(Lookup context, StartMode mode) {
64
    public List<String> getArguments(Lookup context, StartMode mode) {
64
        Profiler p = Lookup.getDefault().lookup(Profiler.class);
65
        if (context.lookup(Project.class) == null) { // project related execution is handled elsewhere
65
        ServerInstance server = context.lookup(ServerInstance.class);
66
            Profiler p = Lookup.getDefault().lookup(Profiler.class);
66
        if (server != null) {
67
            ServerInstance server = context.lookup(ServerInstance.class);
67
            InstanceProperties ip = server.getLookup().lookup(InstanceProperties.class);
68
            if (server != null) {
68
            if (ip != null) {
69
                InstanceProperties ip = server.getLookup().lookup(InstanceProperties.class);
69
                return Arrays.asList(p.getSettings(ip.getProperty("url"), false).getJvmArgs()); //NOI18N
70
                if (ip != null) {
71
                    return Arrays.asList(p.getSettings(ip.getProperty("url"), false).getJvmArgs()); //NOI18N
72
                }
70
            }
73
            }
71
        }
74
        }
72
73
        return Collections.EMPTY_LIST;
75
        return Collections.EMPTY_LIST;
74
    }
76
    }
75
77
(-)a/profiler.j2se/src/org/netbeans/modules/profiler/j2se/J2SEProjectProfilingSupportProvider.java (-26 / +19 lines)
Lines 44-63 Link Here
44
package org.netbeans.modules.profiler.j2se;
44
package org.netbeans.modules.profiler.j2se;
45
45
46
import org.netbeans.api.project.Project;
46
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.lib.profiler.common.SessionSettings;
47
import org.netbeans.lib.profiler.common.SessionSettings;
49
import org.netbeans.modules.profiler.projectsupport.utilities.AppletSupport;
48
import org.netbeans.modules.profiler.projectsupport.utilities.AppletSupport;
50
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
49
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
51
import org.netbeans.spi.project.support.ant.*;
50
import org.netbeans.spi.project.support.ant.*;
52
import org.openide.ErrorManager;
53
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
52
import org.openide.filesystems.FileUtil;
55
import org.openide.modules.InstalledFileLocator;
56
import java.io.*;
53
import java.io.*;
57
import java.net.URL;
54
import java.net.URL;
58
import java.util.Map;
55
import java.util.Map;
59
import java.util.Properties;
56
import java.util.Properties;
57
import java.util.logging.Level;
58
import java.util.logging.Logger;
60
import javax.swing.event.ChangeListener;
59
import javax.swing.event.ChangeListener;
60
import org.netbeans.api.project.ProjectManager;
61
import org.netbeans.modules.profiler.api.JavaPlatform;
61
import org.netbeans.modules.profiler.api.JavaPlatform;
62
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
62
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
63
import org.netbeans.modules.profiler.api.java.ProfilerTypeUtils;
63
import org.netbeans.modules.profiler.api.java.ProfilerTypeUtils;
Lines 65-70 Link Here
65
import org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider;
65
import org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider;
66
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
66
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
67
import org.netbeans.spi.project.ProjectServiceProvider;
67
import org.netbeans.spi.project.ProjectServiceProvider;
68
import org.openide.modules.InstalledFileLocator;
68
69
69
70
70
/**
71
/**
Lines 74-80 Link Here
74
@ProjectServiceProvider(service=ProjectProfilingSupportProvider.class, 
75
@ProjectServiceProvider(service=ProjectProfilingSupportProvider.class, 
75
                        projectTypes={@ProjectType(id="org-netbeans-modules-java-j2seproject",position=550)}) // NOI18N
76
                        projectTypes={@ProjectType(id="org-netbeans-modules-java-j2seproject",position=550)}) // NOI18N
76
public class J2SEProjectProfilingSupportProvider extends JavaProjectProfilingSupportProvider {
77
public class J2SEProjectProfilingSupportProvider extends JavaProjectProfilingSupportProvider {
77
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
78
    final private static Logger LOG = Logger.getLogger(J2SEProjectProfilingSupportProvider.class.getName());
78
79
79
    private static class MyPropertyProvider implements PropertyProvider {
80
    private static class MyPropertyProvider implements PropertyProvider {
80
        //~ Instance fields ------------------------------------------------------------------------------------------------------
81
        //~ Instance fields ------------------------------------------------------------------------------------------------------
Lines 100-111 Link Here
100
        }
101
        }
101
    }
102
    }
102
103
103
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------
104
105
    // -----
106
    // I18N String constants                                                                                                                   // -----
107
    public static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.profiler.j2se"); // NOI18N
108
109
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
104
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
110
    private String mainClassSetManually = null; // used for case when the main class is not set in project and user is prompted for it
105
    private String mainClassSetManually = null; // used for case when the main class is not set in project and user is prompted for it
111
106
Lines 120-126 Link Here
120
    }
115
    }
121
116
122
    @Override
117
    @Override
123
    public JavaPlatform getProjectJavaPlatform() {
118
    public JavaPlatform resolveProjectJavaPlatform() {
124
        PropertyEvaluator props = getProjectProperties(getProject());
119
        PropertyEvaluator props = getProjectProperties(getProject());
125
        String platformName = props.getProperty("platform.active"); // NOI18N
120
        String platformName = props.getProperty("platform.active"); // NOI18N
126
121
Lines 128-137 Link Here
128
            return null; // not provided for some reason
123
            return null; // not provided for some reason
129
        }
124
        }
130
125
131
        if (platformName.equals("default_platform")) { // NOI18N
132
            return JavaPlatform.getDefaultPlatform(); 
133
        }
134
135
        return JavaPlatform.getJavaPlatformById(platformName);
126
        return JavaPlatform.getJavaPlatformById(platformName);
136
    }
127
    }
137
128
Lines 167-173 Link Here
167
    }
158
    }
168
159
169
    @Override
160
    @Override
170
    public void configurePropertiesForProfiling(final Properties props, final FileObject profiledClassFile) {
161
    public void configurePropertiesForProfiling(final Map<String, String> props, final FileObject profiledClassFile) {
171
        if (profiledClassFile == null) {
162
        if (profiledClassFile == null) {
172
            if (mainClassSetManually != null) {
163
            if (mainClassSetManually != null) {
173
                props.put("main.class", mainClassSetManually); // NOI18N
164
                props.put("main.class", mainClassSetManually); // NOI18N
Lines 182-188 Link Here
182
            if (src != null) {
173
            if (src != null) {
183
                Project project = getProject();
174
                Project project = getProject();
184
                if (src.isApplet()) {
175
                if (src.isApplet()) {
185
                    String jvmargs = props.getProperty("run.jvmargs"); // NOI18N
176
                    String jvmargs = props.get("run.jvmargs"); // NOI18N
186
177
187
                    URL url = null;
178
                    URL url = null;
188
179
Lines 198-208 Link Here
198
                        AppletSupport.generateSecurityPolicy(project.getProjectDirectory(), buildFolder);
189
                        AppletSupport.generateSecurityPolicy(project.getProjectDirectory(), buildFolder);
199
190
200
                        if ((jvmargs == null) || (jvmargs.length() == 0)) {
191
                        if ((jvmargs == null) || (jvmargs.length() == 0)) {
201
                            props.setProperty("run.jvmargs",
192
                            props.put("run.jvmargs",
202
                                              "-Djava.security.policy=" + FileUtil.toFile(buildFolder).getPath() + File.separator
193
                                              "-Djava.security.policy=" + FileUtil.toFile(buildFolder).getPath() + File.separator
203
                                              + "applet.policy"); //NOI18N
194
                                              + "applet.policy"); //NOI18N
204
                        } else {
195
                        } else {
205
                            props.setProperty("run.jvmargs",
196
                            props.put("run.jvmargs",
206
                                              jvmargs + " -Djava.security.policy=" + FileUtil.toFile(buildFolder).getPath()
197
                                              jvmargs + " -Djava.security.policy=" + FileUtil.toFile(buildFolder).getPath()
207
                                              + File.separator + "applet.policy"); //NOI18N
198
                                              + File.separator + "applet.policy"); //NOI18N
208
                        }
199
                        }
Lines 218-233 Link Here
218
                        return; // TODO: fail?
209
                        return; // TODO: fail?
219
                    }
210
                    }
220
211
221
                    props.setProperty("applet.url", url.toString()); // NOI18N
212
                    props.put("applet.url", url.toString()); // NOI18N
222
                } else {
213
                } else {
223
                    final String profiledClass = src.getTopLevelClass().getQualifiedName();
214
                    final String profiledClass = src.getTopLevelClass().getQualifiedName();
224
                    props.setProperty("profile.class", profiledClass); //NOI18N
215
                    props.put("profile.class", profiledClass); //NOI18N
225
                }
216
                }
226
217
227
                // 2. include it in javac.includes so that the compile-single picks it up
218
                // 2. include it in javac.includes so that the compile-single picks it up
228
                final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(ProjectUtilities.getSourceRoots(project),
219
                final String clazz = FileUtil.getRelativePath(ProjectUtilities.getRootOf(ProjectUtilities.getSourceRoots(project),
229
                                                                                         profiledClassFile), profiledClassFile);
220
                                                                                         profiledClassFile), profiledClassFile);
230
                props.setProperty("javac.includes", clazz); //NOI18N
221
                props.put("javac.includes", clazz); //NOI18N
231
            }
222
            }
232
        }
223
        }
233
    }
224
    }
Lines 252-257 Link Here
252
243
253
        String jvmArgs = pp.getProperty("run.jvmargs"); // NOI18N
244
        String jvmArgs = pp.getProperty("run.jvmargs"); // NOI18N
254
        ss.setJVMArgs((jvmArgs != null) ? jvmArgs : ""); // NOI18N
245
        ss.setJVMArgs((jvmArgs != null) ? jvmArgs : ""); // NOI18N
246
        
247
        super.setupProjectSessionSettings(ss);
255
    }
248
    }
256
249
257
    @Override
250
    @Override
Lines 294-300 Link Here
294
                                is.close();
287
                                is.close();
295
                            }
288
                            }
296
                        } catch (IOException e) {
289
                        } catch (IOException e) {
297
                            err.notify(ErrorManager.INFORMATIONAL, e);
290
                            LOG.log(Level.INFO, null, e);
298
                        }
291
                        }
299
                    }
292
                    }
300
293
Lines 308-314 Link Here
308
                                is.close();
301
                                is.close();
309
                            }
302
                            }
310
                        } catch (IOException e) {
303
                        } catch (IOException e) {
311
                            err.notify(ErrorManager.INFORMATIONAL, e);
304
                            LOG.log(Level.INFO, null, e);
312
                        }
305
                        }
313
                    }
306
                    }
314
307
Lines 322-328 Link Here
322
                                is.close();
315
                                is.close();
323
                            }
316
                            }
324
                        } catch (IOException e) {
317
                        } catch (IOException e) {
325
                            err.notify(ErrorManager.INFORMATIONAL, e);
318
                            LOG.log(Level.INFO, null, e);
326
                        }
319
                        }
327
                    }
320
                    }
328
321
Lines 352-358 Link Here
352
                                is.close();
345
                                is.close();
353
                            }
346
                            }
354
                        } catch (IOException e) {
347
                        } catch (IOException e) {
355
                            err.notify(ErrorManager.INFORMATIONAL, e);
348
                            LOG.log(Level.INFO, null, e);
356
                        }
349
                        }
357
                    }
350
                    }
358
                }
351
                }
(-)a/profiler.nbimpl/antsrc/org/netbeans/modules/profiler/ant/NBProfileAttachTask.java (-159 lines)
Lines 1-159 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Microsystems, Inc. All Rights Reserved.
31
 *
32
 * If you wish your version of this file to be governed by only the CDDL
33
 * or only the GPL Version 2, indicate your decision by adding
34
 * "[Contributor] elects to include this software in this distribution
35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36
 * single choice of license, a recipient has the option to distribute
37
 * your version of this file under either the CDDL, the GPL Version 2 or
38
 * to extend the choice of license to its licensees as provided above.
39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
40
 * Version 2 license, then the option applies only if the new code is
41
 * made subject to such option by the copyright holder.
42
 */
43
44
package org.netbeans.modules.profiler.ant;
45
46
import org.apache.tools.ant.BuildException;
47
import org.apache.tools.ant.Project;
48
import org.apache.tools.ant.Task;
49
import org.apache.tools.ant.types.Path;
50
import org.netbeans.api.project.ProjectManager;
51
import org.netbeans.lib.profiler.common.AttachSettings;
52
import org.netbeans.lib.profiler.common.Profiler;
53
import org.netbeans.lib.profiler.common.ProfilingSettings;
54
import org.netbeans.modules.profiler.NetBeansProfiler;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileUtil;
57
import java.io.File;
58
import java.io.IOException;
59
import java.util.Hashtable;
60
import javax.swing.*;
61
62
63
/** Ant task to start the NetBeans profiler attach action.
64
 *
65
 * @author Tomas Hurka
66
 * @author Ian Formanek
67
 */
68
public final class NBProfileAttachTask extends Task {
69
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
70
71
    /** Explicit classpath of the profiled process. */
72
    private Path classpath = null;
73
    private String port = null;
74
    private boolean direct = true;
75
    private boolean directDefinedExplicitely = false;
76
77
    //~ Methods ------------------------------------------------------------------------------------------------------------------
78
79
    public void setDirect(final boolean aos) {
80
        this.direct = aos;
81
        directDefinedExplicitely = true;
82
    }
83
84
    public void setPort(final String port) {
85
        this.port = port;
86
    }
87
88
    // properties -----------------------------------------------------------------
89
90
    /** "classpath" subelements, only one is allowed
91
     * @param path the classpath
92
     */
93
    public void addClasspath(final Path path) {
94
        if (classpath != null) {
95
            throw new BuildException("Only one classpath subelement is supported"); //NOI18N
96
        }
97
98
        classpath = path;
99
    }
100
101
    // main methods ---------------------------------------------------------------
102
    public void execute() throws BuildException {
103
        Project antProject = getProject();
104
        final Hashtable props = antProject.getProperties();
105
        final ProfilingSettings ps = new ProfilingSettings();
106
107
        // 1. process parameters passed via Properties
108
        ps.load(props);
109
110
        final AttachSettings as = new AttachSettings();
111
        as.load(antProject.getProperties());
112
113
        // 2. Process those passed as attributes/elements from the buildl script
114
        if (directDefinedExplicitely) {
115
            as.setDirect(Boolean.valueOf(direct).booleanValue());
116
        }
117
118
        if (port != null) {
119
            try {
120
                final int portNo = Integer.parseInt(port);
121
                as.setPort(portNo);
122
            } catch (NumberFormatException e) {
123
            } // ignore, will not be used
124
        }
125
126
        // 3. log used properties in verbose level
127
        antProject.log("Attaching to Profiled Application", Project.MSG_VERBOSE); //NOI18N
128
        antProject.log("  classpath: " + classpath, Project.MSG_VERBOSE); //NOI18N
129
        antProject.log("  attach direct: " + as.isDirect(), Project.MSG_VERBOSE); //NOI18N
130
        antProject.log("  remote attach: " + as.isRemote(), Project.MSG_VERBOSE); //NOI18N
131
        antProject.log("  remote host: " + as.getHost(), Project.MSG_VERBOSE); //NOI18N
132
        antProject.log("  profiler port: " + as.getPort(), Project.MSG_VERBOSE); //NOI18N
133
134
        // 4. log profiling and session settings in debug level
135
        antProject.log("  profiling settings: " + ps.debug(), Project.MSG_DEBUG); //NOI18N
136
        antProject.log("  attach settings: " + as.debug(), Project.MSG_DEBUG); //NOI18N
137
138
        // 5. determine project being profiled
139
        org.netbeans.api.project.Project profiledProject = null;
140
141
        String projectDir = (String) props.get("profiler.info.project.dir"); //NOI18N
142
143
        if (projectDir != null) {
144
            FileObject projectFO = FileUtil.toFileObject(FileUtil.normalizeFile(new File(projectDir)));
145
146
            if (projectFO != null) {
147
                try {
148
                    profiledProject = ProjectManager.getDefault().findProject(projectFO);
149
                } catch (IOException e) {
150
                    antProject.log("Could not determine project: " + e.getMessage(), Project.MSG_WARN); //NOI18N
151
                }
152
            }
153
        }
154
155
        // 6. invoke profiling with constructed profiling and attach settings
156
        ((NetBeansProfiler) Profiler.getDefault()).setProfiledProject(profiledProject, null);
157
        Profiler.getDefault().attachToApp(ps, as);
158
    }
159
}
(-)a/profiler.nbimpl/antsrc/org/netbeans/modules/profiler/ant/NBProfileDirectTask.java (-543 lines)
Lines 1-543 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Microsystems, Inc. All Rights Reserved.
31
 *
32
 * If you wish your version of this file to be governed by only the CDDL
33
 * or only the GPL Version 2, indicate your decision by adding
34
 * "[Contributor] elects to include this software in this distribution
35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36
 * single choice of license, a recipient has the option to distribute
37
 * your version of this file under either the CDDL, the GPL Version 2 or
38
 * to extend the choice of license to its licensees as provided above.
39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
40
 * Version 2 license, then the option applies only if the new code is
41
 * made subject to such option by the copyright holder.
42
 */
43
44
package org.netbeans.modules.profiler.ant;
45
46
import org.apache.tools.ant.BuildException;
47
import org.apache.tools.ant.Project;
48
import org.apache.tools.ant.Task;
49
import org.apache.tools.ant.types.EnumeratedAttribute;
50
import org.apache.tools.ant.types.Path;
51
import org.netbeans.api.project.ProjectManager;
52
import org.netbeans.lib.profiler.client.ClientUtils;
53
import org.netbeans.lib.profiler.common.Profiler;
54
import org.netbeans.lib.profiler.common.ProfilingSettings;
55
import org.netbeans.lib.profiler.common.SessionSettings;
56
import org.netbeans.lib.profiler.global.CalibrationDataFileIO;
57
import org.netbeans.modules.profiler.NetBeansProfiler;
58
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
59
import org.netbeans.modules.profiler.ProfilerModule;
60
import org.netbeans.modules.profiler.actions.JavaPlatformSelector;
61
import org.netbeans.modules.profiler.actions.ProfilingSupport;
62
import org.netbeans.modules.profiler.utils.IDEUtils;
63
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.util.NbBundle;
66
import java.io.File;
67
import java.io.IOException;
68
import java.util.ArrayList;
69
import java.util.Enumeration;
70
import java.util.Hashtable;
71
import java.util.jar.JarEntry;
72
import java.util.jar.JarFile;
73
import org.netbeans.modules.profiler.api.JavaPlatform;
74
import org.netbeans.modules.profiler.api.ProfilerDialogs;
75
import org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities;
76
77
78
/**
79
 * Ant task to start the NetBeans profiler profile action.
80
 * <p/>
81
 * Will put the profiler into listening mode, placing the port number into the "profiler.port" property.
82
 * The target app then should be started through the profiler agent passing it this port number.
83
 *
84
 * @author Tomas Hurka
85
 * @author Ian Formanek
86
 */
87
public final class NBProfileDirectTask extends Task {
88
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
89
90
    /**
91
     * Enumerated attribute with the values "asis", "add" and "remove".
92
     */
93
    public static class YesNoAuto extends EnumeratedAttribute {
94
        //~ Methods --------------------------------------------------------------------------------------------------------------
95
96
        public String[] getValues() {
97
            return new String[] { "yes", "true", "no", "false", "auto" }; //NOI18N
98
        }
99
    }
100
101
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------
102
103
    // -----
104
    // I18N String constants
105
    private static final String CALIBRATION_FAILED_MESSAGE = NbBundle.getMessage(ProfilerModule.class,
106
                                                                                 "ProfilerModule_CalibrationFailedMessage"); //NOI18N
107
                                                                                                                             // -----
108
    private static final int INTERACTIVE_AUTO = 0;
109
    private static final int INTERACTIVE_YES = 1;
110
    private static final int INTERACTIVE_NO = 2;
111
    private static final String DEFAULT_AGENT_JVMARGS_PROPERTY = "profiler.info.jvmargs.agent"; // NOI18N
112
    private static final String DEFAULT_JVM_PROPERTY = "profiler.info.jvm"; // NOI18N
113
    private static final String EXTRA_JVM_ARGS = "profiler.info.jvmargs"; // NOI18N
114
    private static final String EXTRA_RUN_ARGS = "run.args.extra"; // NOI18N
115
116
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
117
118
    /**
119
     * Explicit classpath of the profiled process.
120
     */
121
    private Path classpath = null;
122
    private Path rootsPath = null;
123
    private String jvmArgsPrefix = ""; // NOI18N
124
    private String jvmArgsProperty = DEFAULT_AGENT_JVMARGS_PROPERTY;
125
    private String jvmProperty = DEFAULT_JVM_PROPERTY;
126
    private String mainClass = null;
127
    private int interactive = INTERACTIVE_AUTO;
128
129
    //~ Methods ------------------------------------------------------------------------------------------------------------------
130
131
    public void setInteractive(YesNoAuto arg) {
132
        String value = arg.getValue();
133
134
        if (value.equals("auto")) { //NOI18N
135
            interactive = INTERACTIVE_AUTO;
136
        } else if (value.equals("yes") || value.equals("true")) { // NOI18N
137
            interactive = INTERACTIVE_YES;
138
        } else if (value.equals("no") || value.equals("false")) { // NOI18N
139
            interactive = INTERACTIVE_NO;
140
        }
141
    }
142
143
    public void setJvmArgsPrefix(String value) {
144
        jvmArgsPrefix = value;
145
    }
146
147
    public void setJvmArgsProperty(String value) {
148
        jvmArgsProperty = value;
149
    }
150
151
    public void setJvmProperty(String value) {
152
        jvmProperty = value;
153
    }
154
155
    // -- Properties -------------------------------------------------------------------------------------------------------
156
    public void setMainClass(String mainClass) {
157
        this.mainClass = mainClass;
158
    }
159
160
    /**
161
     * "classpath" subelements, only one is allowed
162
     *
163
     * @param path the classpath
164
     */
165
    public void addClasspath(final Path path) {
166
        if (classpath != null) {
167
            throw new BuildException("Only one classpath subelement is supported"); //NOI18N
168
        }
169
170
        classpath = path;
171
    }
172
173
    /**
174
     * "classpath" subelements, only one is allowed
175
     *
176
     * @param path the classpath
177
     */
178
    public void addRootspath(final Path path) {
179
        if (rootsPath != null) {
180
            throw new BuildException("Only one classpath subelement is supported"); //NOI18N
181
        }
182
183
        rootsPath = path;
184
    }
185
186
    // -- Main methods -----------------------------------------------------------------------------------------------------
187
    public void execute() throws BuildException {
188
        // Settings are created this way:
189
        //   1. project context (stored as properties)
190
        //   2. profiling settings (configuration)
191
        //         - possibly override some of the settings from 1. if ps.getOverrideGlobalSettings() is set
192
        //   3. explicitely override anything and everything in the build script
193
        Project antProject = getProject();
194
        final Hashtable props = antProject.getProperties();
195
        ProfilingSettings ps = new ProfilingSettings();
196
        final SessionSettings ss = new SessionSettings();
197
        String projectDir = (String) props.get("profiler.info.project.dir"); //NOI18N
198
        String singleFile = (String) props.get("profiler.info.single.file"); //NOI18N
199
200
        boolean initializedInteractively = false;
201
202
        if ((props.get(DEFAULT_AGENT_JVMARGS_PROPERTY) == null) || (interactive == INTERACTIVE_YES)) {
203
            if (interactive != INTERACTIVE_NO) {
204
                projectDir = initializeInteractively(ps, ss);
205
                initializedInteractively = true;
206
            }
207
        }
208
209
        if (!initializedInteractively) {
210
            if (props.get(DEFAULT_AGENT_JVMARGS_PROPERTY) == null) {
211
                throw new BuildException("Missing context for nbprofiledirect task.\n" //NOI18N
212
                                         + "Please set the \"interactive\" attribute to \"true\" or set the required properties." //NOI18N
213
                                         );
214
            }
215
216
            if (!DEFAULT_AGENT_JVMARGS_PROPERTY.equals(jvmArgsProperty) || !"".equals(jvmArgsPrefix)) { //NOI18N
217
218
                String args = " " + (String) props.get(EXTRA_JVM_ARGS); // get the extra JVM args
219
                                                                        // reformat the string to the form suitable for starting the NB platform
220
221
                args = args.replaceAll("\\s+(\\-)", " -J$1"); // NOI18N
222
223
                String origArgs = antProject.getProperty(EXTRA_RUN_ARGS);
224
                origArgs = (origArgs != null) ? (" " + origArgs + " ") : ""; // NOI18N
225
226
                antProject.setProperty("run.args.extra", origArgs + args); // merge the profiler extra JVM args with the platform extra JVM args
227
228
                String usedAgentJvmArgs = jvmArgsPrefix + props.get(DEFAULT_AGENT_JVMARGS_PROPERTY);
229
                antProject.setProperty(jvmArgsProperty, usedAgentJvmArgs);
230
                antProject.log("Profiler agent JVM arguments: " + usedAgentJvmArgs, Project.MSG_VERBOSE); //NOI18N
231
                antProject.log("Profiler agent JVM arguments stored in property " + jvmArgsProperty, Project.MSG_INFO); //NOI18N
232
                antProject.log("Extra JVM arguments: " + antProject.getProperty("run.args.extra")); // NOI18N
233
            }
234
235
            // 2. process parameters passed via Properties
236
            ps.load(props);
237
            try {
238
                ss.load(props);
239
            } catch (IllegalArgumentException e) {
240
                ProfilerDialogs.displayWarning(e.getLocalizedMessage());
241
            }
242
243
            // get correct working directory available only at runtime (not from ProjectTypeProfiler!)
244
            String projectWorkDir = (String) props.get("work.dir"); // NOI18N
245
            ss.setWorkingDir(((projectWorkDir != null) && !"".equals(projectWorkDir.trim())) ? projectWorkDir
246
                                                                                             : System.getProperty("user.dir")); // NOI18N
247
        }
248
249
        // Correctly setup working directory
250
        String profilerInfoDir = (String) props.get("profiler.info.dir"); // NOI18N
251
252
        if (!initializedInteractively || (profilerInfoDir == null /* means that WD wasn't set in interactive setup */)
253
                || !"".equals(profilerInfoDir.trim())) { // NOI18N
254
255
            String workingDirectory = ss.getWorkingDir();
256
257
            if (ps.getOverrideGlobalSettings()) {
258
                String overridenWorkingDirectory = ps.getWorkingDir();
259
260
                if ((overridenWorkingDirectory != null) && !"".equals(overridenWorkingDirectory.trim())) {
261
                    workingDirectory = overridenWorkingDirectory; // NOI18N
262
                }
263
            }
264
265
            antProject.setProperty("profiler.info.dir", workingDirectory); // NOI18N
266
        }
267
268
        if (classpath != null) {
269
            ss.setMainClassPath(classpath.toString());
270
        }
271
272
        if (ps.getProfilingType() == ProfilingSettings.PROFILE_CPU_ENTIRE) {
273
            antProject.log("Roots path: " + rootsPath, Project.MSG_VERBOSE); //NOI18N
274
275
            if (rootsPath != null) {
276
                String[] paths = rootsPath.list();
277
                ArrayList al = new ArrayList();
278
279
                for (int i = 0; i < paths.length; i++) {
280
                    addPackagesList(al, paths[i]);
281
                }
282
283
                ClientUtils.SourceCodeSelection[] ret = new ClientUtils.SourceCodeSelection[al.size()];
284
285
                for (int i = 0; i < al.size(); i++) {
286
                    if ("".equals(al.get(i))) { //NOI18N
287
                        ret[i] = new ClientUtils.SourceCodeSelection("", "", ""); //NOI18N
288
                    } else {
289
                        ret[i] = new ClientUtils.SourceCodeSelection(((String) al.get(i)) + ".", "", ""); //NOI18N
290
                    }
291
                }
292
293
                ps.setInstrumentationRootMethods(ret);
294
            }
295
        }
296
297
        // 3. log used properties in verbose level
298
        antProject.log("Starting Profiled Application", Project.MSG_VERBOSE); //NOI18N
299
        antProject.log("  mainClass: " + ss.getMainClass(), Project.MSG_VERBOSE); //NOI18N
300
        antProject.log("  classpath: " + ss.getMainClassPath(), Project.MSG_VERBOSE); //NOI18N
301
        antProject.log("  arguments: " + ss.getMainArgs(), Project.MSG_VERBOSE); //NOI18N
302
303
        if (ps.getOverrideGlobalSettings()) {
304
            antProject.log("  jvm arguments: " + ps.getJVMArgs(), Project.MSG_VERBOSE); //NOI18N
305
        } else {
306
            antProject.log("  jvm arguments: " + ss.getJVMArgs(), Project.MSG_VERBOSE); //NOI18N
307
        }
308
309
        if (ps.getOverrideGlobalSettings()) {
310
            antProject.log("  working dir: " + ps.getWorkingDir(), Project.MSG_VERBOSE); //NOI18N
311
        } else {
312
            antProject.log("  working dir: " + ss.getWorkingDir(), Project.MSG_VERBOSE); //NOI18N
313
        }
314
315
        // 4. log profiling and session settings in debug level
316
        antProject.log("  profiling settings: " + ps.debug(), Project.MSG_DEBUG); //NOI18N
317
        antProject.log("  session settings: " + ss.debug(), Project.MSG_DEBUG); //NOI18N
318
319
        // 5. determine project being profiled
320
        org.netbeans.api.project.Project profiledProject = null;
321
        FileObject singleFO = null;
322
323
        if (projectDir != null) {
324
            String errorMessage = null;
325
            FileObject projectFO = FileUtil.toFileObject(FileUtil.normalizeFile(new File(projectDir)));
326
327
            if (projectFO != null) {
328
                try {
329
                    profiledProject = ProjectManager.getDefault().findProject(projectFO);
330
                } catch (IOException e) {
331
                    errorMessage = "IOException: " + e.getMessage(); //NOI18N
332
                }
333
            } else {
334
                errorMessage = "Could not find project directory: " + projectDir; //NOI18N
335
            }
336
337
            if (errorMessage != null) {
338
                antProject.log("Could not determine project: " + errorMessage, Project.MSG_INFO); //NOI18N
339
                antProject.log("Using global (no project) attach context", Project.MSG_INFO); //NOI18N
340
            }
341
342
            if (singleFile != null) {
343
                singleFO = FileUtil.toFileObject(FileUtil.normalizeFile(new File(singleFile)));
344
            }
345
        } else {
346
            antProject.log("You can use property profiler.info.project.dir to specify project that is being profiled.", //NOI18N
347
                             Project.MSG_VERBOSE);
348
        }
349
350
        final org.netbeans.api.project.Project projectToUse = profiledProject;
351
352
        if (!CalibrationDataFileIO.validateCalibrationInput(ss.getJavaVersionString(), ss.getJavaExecutable())
353
                || !Profiler.getDefault()
354
                                .runCalibration(true, ss.getJavaExecutable(), ss.getJavaVersionString(),
355
                                                    ss.getSystemArchitecture())) {
356
            ProfilerDialogs.displayError(CALIBRATION_FAILED_MESSAGE);
357
            throw new BuildException(CALIBRATION_FAILED_MESSAGE); // failed, cannot proceed
358
        }
359
360
        // 6. invoke profiling with constructed profiling and session settings
361
        final ProfilingSettings ps1 = ps;
362
        final FileObject singleFO1 = singleFO;
363
364
        NetBeansProfiler.getDefaultNB().setProfiledProject(projectToUse, singleFO1);
365
        Profiler.getDefault().connectToStartedApp(ps1, ss);
366
    }
367
368
    private void addPackagesForArchive(ArrayList list, String s, File f) {
369
        Project antProject = getProject();
370
        
371
        antProject.log("Add root packages for archive: " + f.getName(), Project.MSG_VERBOSE); //NOI18N
372
        try {
373
            JarFile jf = new JarFile(f);
374
375
            for (Enumeration e = jf.entries(); e.hasMoreElements();) {
376
                JarEntry je = (JarEntry) e.nextElement();
377
                antProject.log("Checking jar entry: " + je.getName(), Project.MSG_VERBOSE); //NOI18N
378
379
                if (!je.isDirectory() && je.getName().endsWith(".class")) { //NOI18N
380
381
                    String name = je.getName();
382
                    int idx = name.lastIndexOf('/'); //NOI18N
383
                    String packageName = (idx == -1) ? name : name.substring(0, idx);
384
                    packageName = packageName.replace('/', '.'); //NOI18N
385
386
                    if (!list.contains(packageName)) {
387
                        antProject.log("Adding package: " + packageName, Project.MSG_VERBOSE); //NOI18N
388
                        list.add(packageName);
389
                    }
390
                }
391
            }
392
        } catch (IOException e) {
393
            antProject.log("Failed to scan packages for archive: " + f.getName()); //NOI18N
394
        }
395
    }
396
397
    private void addPackagesForDirectory(ArrayList packages, String prefix, File f) {
398
        if (!f.isDirectory()) { // not a folder
399
400
            return;
401
        }
402
403
        getProject().log("Add root packages for directory: " + f.getName(), Project.MSG_VERBOSE); //NOI18N
404
405
        File[] children = f.listFiles();
406
407
        // 1. check if there are java sdources in this folder and if so, add to the list of packages
408
        if (!packages.contains(prefix)) { // already in there, skip this
409
410
            for (int i = 0; i < children.length; i++) {
411
                File child = children[i];
412
413
                if (child.getName().endsWith(".class")) { //NOI18N
414
                    getProject().log("Addding package: " + prefix, Project.MSG_VERBOSE); //NOI18N
415
                    packages.add(prefix);
416
417
                    break;
418
                }
419
            }
420
        }
421
422
        // 2. recurse into subfolders
423
        for (int i = 0; i < children.length; i++) {
424
            File child = children[i];
425
426
            if (child.isDirectory()) {
427
                if ("".equals(prefix)) { //NOI18N
428
                    addPackagesForDirectory(packages, child.getName(), child);
429
                } else {
430
                    addPackagesForDirectory(packages, prefix + "." + child.getName(), child); //NOI18N
431
                }
432
            }
433
        }
434
    }
435
436
    private void addPackagesList(ArrayList list, String path)
437
                          throws BuildException {
438
        File f = new File(path);
439
440
        if (!f.exists()) {
441
            getProject().log("Cannot find: " + path); //NOI18N
442
443
            return;
444
        }
445
446
        if (f.isDirectory()) {
447
            addPackagesForDirectory(list, "", f); //NOI18N
448
        } else if (f.getName().endsWith(".jar")) { //NOI18N
449
            addPackagesForArchive(list, "", f); //NOI18N
450
        }
451
    }
452
453
    private String initializeInteractively(ProfilingSettings ps, SessionSettings ss)
454
                                    throws BuildException {
455
        String projectDir = null;
456
        Project antProject = getProject();
457
        antProject.log("Entering interactive mode of nbprofiledirect task...", Project.MSG_VERBOSE); //NOI18N
458
459
        org.netbeans.api.project.Project p = ProjectUtilities.getProjectForBuildScript(getLocation().getFileName());
460
461
        if (p != null) {
462
            antProject.log("Using project: " + ProjectUtilities.getProjectName(p), Project.MSG_INFO); //NOI18N
463
            projectDir = FileUtil.toFile(p.getProjectDirectory()).getAbsolutePath();
464
        }
465
466
        ss.setPortNo(ProfilerIDESettings.getInstance().getPortNo());
467
468
        if (mainClass != null) {
469
            ss.setMainClass(mainClass);
470
        }
471
472
        JavaPlatform platform = JavaPlatform.getJavaPlatformById(ProfilerIDESettings.getInstance().getJavaPlatformForProfiling());
473
474
        if (platform == null) {
475
            platform = JavaPlatformSelector.getDefault().selectPlatformToUse();
476
477
            if (platform == null) {
478
                throw new BuildException("Cancelled..."); //NOI18N
479
            }
480
        }
481
482
        String javaFile = platform.getPlatformJavaFile();
483
484
        if (javaFile == null) {
485
            throw new BuildException("Cannot determine Java executable for platform: " + platform.getDisplayName()); //NOI18N
486
        }
487
488
        String javaVersion = platform.getPlatformJDKVersion();
489
490
        if (javaVersion == null) {
491
            throw new BuildException("Cannot determine Java version for the selected Java platform"); //NOI18N
492
        }
493
494
        ss.setJavaExecutable(javaFile);
495
        ss.setJavaVersionString(javaVersion);
496
        ss.setSystemArchitecture(platform.getPlatformArchitecture());
497
498
        ps = ProfilingSupport.getDefault().selectTaskForProfiling(p, ss, null, false);
499
500
        if (ps == null) {
501
            throw new BuildException("Cancelled by the user"); //NOI18N
502
        }
503
504
        String usedJavaExecutable = null;
505
        String usedJvmArgs = null;
506
        String usedWorkDir = null;
507
508
        if (ps.getOverrideGlobalSettings()) {
509
            antProject.log("Global settings are overridden by the profiling configuration", Project.MSG_VERBOSE); //NOI18N
510
511
            if (ps.getJavaPlatformName() != null) {
512
                usedJavaExecutable = Profiler.getDefault().getPlatformJavaFile(ps.getJavaPlatformName());
513
            }
514
515
            usedJvmArgs = ps.getJVMArgs();
516
            usedWorkDir = ps.getWorkingDir();
517
518
            if (usedJavaExecutable != null) {
519
                antProject.log("Overridden Java Executable: " + usedJavaExecutable //NOI18N
520
                                 + ", stored in property: " + jvmProperty, Project.MSG_VERBOSE //NOI18N
521
                );
522
                antProject.setProperty(jvmProperty, usedJavaExecutable);
523
            }
524
525
            if (usedJvmArgs != null) {
526
                antProject.log("Overridden Working Directory: " + usedWorkDir, Project.MSG_VERBOSE); //NOI18N
527
                antProject.setProperty("profiler.info.jvmargs", usedJvmArgs); // NOI18N
528
            }
529
530
            if (usedWorkDir != null) {
531
                antProject.setProperty("profiler.info.dir", usedWorkDir); // NOI18N
532
            }
533
        }
534
535
        String usedAgentJvmArgs = jvmArgsPrefix
536
                                  + IDEUtils.getAntProfilerStartArgument15(ss.getPortNo(), ss.getSystemArchitecture());
537
        antProject.setProperty(jvmArgsProperty, usedAgentJvmArgs); // NOI18N
538
        antProject.log("Profiler agent JVM arguments: " + usedAgentJvmArgs, Project.MSG_VERBOSE); //NOI18N
539
        antProject.log("Profiler agent JVM arguments stored in property " + jvmArgsProperty, Project.MSG_INFO); //NOI18N
540
541
        return projectDir;
542
    }
543
}
(-)a/profiler.nbimpl/antsrc/org/netbeans/modules/profiler/nbimpl/StartProfilerTask.java (+96 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.profiler.nbimpl;
43
44
import java.io.File;
45
import java.util.Map;
46
import org.apache.tools.ant.BuildException;
47
import org.apache.tools.ant.Task;
48
import org.netbeans.api.project.FileOwnerQuery;
49
import org.netbeans.api.project.Project;
50
import org.netbeans.lib.profiler.common.Profiler;
51
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher;
52
import org.openide.filesystems.FileUtil;
53
54
/**
55
 *
56
 * @author Jaroslav Bachorik
57
 */
58
public class StartProfilerTask extends Task {
59
    private String freeformStr = "";
60
    private boolean isFreeForm = false;
61
    
62
    @Override
63
    public void execute() throws BuildException {
64
        ProfilerLauncher.Session s = ProfilerLauncher.getLastSession();
65
        if (s == null && isFreeForm) {
66
            File baseDir = getProject().getBaseDir();
67
            if (baseDir != null) {
68
                Project p = FileOwnerQuery.getOwner(FileUtil.toFileObject(baseDir));
69
                if (p != null) {
70
                    s = ProfilerLauncher.Session.createSession(p);
71
                }
72
            }
73
            
74
        }
75
        if (s != null) {
76
            Map<String, String> props = s.getProperties();
77
            if (props != null) {
78
                for(Map.Entry<String, String> e : props.entrySet()) {
79
                    getProject().setProperty(e.getKey(), e.getValue());
80
                }
81
                NetBeansProfiler.getDefaultNB().setupDispatcher(s.getProfilingSettings());
82
                Profiler.getDefault().connectToStartedApp(s.getProfilingSettings(), s.getSessionSettings());
83
                getProject().setProperty("profiler.configured", "true"); // NOI18N
84
            }
85
        }
86
    }
87
    
88
    public void setFreeform(String val) {
89
        freeformStr = val;
90
        isFreeForm = Boolean.parseBoolean(val);
91
    }
92
    
93
    public String getFreeform() {
94
        return freeformStr;
95
    }
96
}
(-)a/profiler.nbimpl/antsrc/org/netbeans/modules/profiler/nbimpl/antlib.xml (-4 / +3 lines)
Lines 2-8 Link Here
2
<!--
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
Copyright 2010 Oracle and/or its affiliates. All rights reserved.
6
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
8
Other names may be trademarks of their respective owners.
Lines 29-35 Link Here
29
Contributor(s):
29
Contributor(s):
30
30
31
The Original Software is NetBeans. The Initial Developer of the Original
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
32
Software is Sun Microsystems, Inc. Portions Copyright 2008 Sun
33
Microsystems, Inc. All Rights Reserved.
33
Microsystems, Inc. All Rights Reserved.
34
34
35
If you wish your version of this file to be governed by only the CDDL
35
If you wish your version of this file to be governed by only the CDDL
Lines 44-49 Link Here
44
made subject to such option by the copyright holder.
44
made subject to such option by the copyright holder.
45
-->
45
-->
46
<antlib>
46
<antlib>
47
  <taskdef name="nbprofileattach" classname="org.netbeans.modules.profiler.ant.NBProfileAttachTask"/>
47
    <taskdef name="startprofiler" classname="org.netbeans.modules.profiler.nbimpl.StartProfilerTask"/>
48
  <taskdef name="nbprofiledirect" classname="org.netbeans.modules.profiler.ant.NBProfileDirectTask"/>
49
</antlib>
48
</antlib>
(-)a/profiler.nbimpl/manifest.mf (-1 / +1 lines)
Lines 3-7 Link Here
3
OpenIDE-Module: org.netbeans.modules.profiler.nbimpl/1
3
OpenIDE-Module: org.netbeans.modules.profiler.nbimpl/1
4
OpenIDE-Module-Layer: org/netbeans/modules/profiler/nbimpl/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/profiler/nbimpl/layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/profiler/nbimpl/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/profiler/nbimpl/Bundle.properties
6
OpenIDE-Module-Provides: org.netbeans.lib.profiler.common.Profiler
6
OpenIDE-Module-Provides: org.netbeans.lib.profiler.common.Profiler,org.netbeans.api.profiler
7
OpenIDE-Module-Specification-Version: 1.2
7
OpenIDE-Module-Specification-Version: 1.2
(-)a/profiler.nbimpl/nbproject/project.xml (+28 lines)
Lines 59-64 Link Here
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>1</release-version>
67
                        <specification-version>1.13</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
62
                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
71
                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
63
                    <build-prerequisite/>
72
                    <build-prerequisite/>
64
                    <compile-dependency/>
73
                    <compile-dependency/>
Lines 68-73 Link Here
68
                    </run-dependency>
77
                    </run-dependency>
69
                </dependency>
78
                </dependency>
70
                <dependency>
79
                <dependency>
80
                    <code-name-base>org.netbeans.api.progress</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <release-version>1</release-version>
85
                        <specification-version>1.27</specification-version>
86
                    </run-dependency>
87
                </dependency>
88
                <dependency>
71
                    <code-name-base>org.netbeans.lib.profiler</code-name-base>
89
                    <code-name-base>org.netbeans.lib.profiler</code-name-base>
72
                    <build-prerequisite/>
90
                    <build-prerequisite/>
73
                    <compile-dependency/>
91
                    <compile-dependency/>
Lines 130-135 Link Here
130
                    </run-dependency>
148
                    </run-dependency>
131
                </dependency>
149
                </dependency>
132
                <dependency>
150
                <dependency>
151
                    <code-name-base>org.netbeans.modules.extexecution</code-name-base>
152
                    <build-prerequisite/>
153
                    <compile-dependency/>
154
                    <run-dependency>
155
                        <release-version>2</release-version>
156
                        <specification-version>1.30</specification-version>
157
                    </run-dependency>
158
                </dependency>
159
                <dependency>
133
                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
160
                    <code-name-base>org.netbeans.modules.java.platform</code-name-base>
134
                    <build-prerequisite/>
161
                    <build-prerequisite/>
135
                    <compile-dependency/>
162
                    <compile-dependency/>
Lines 426-431 Link Here
426
                <friend>org.netbeans.modules.profiler.j2ee</friend>
453
                <friend>org.netbeans.modules.profiler.j2ee</friend>
427
                <friend>org.netbeans.modules.profiler.j2se</friend>
454
                <friend>org.netbeans.modules.profiler.j2se</friend>
428
                <friend>org.netbeans.modules.profiler.nbmodule</friend>
455
                <friend>org.netbeans.modules.profiler.nbmodule</friend>
456
                <package>org.netbeans.modules.profiler.nbimpl.actions</package>
429
                <package>org.netbeans.modules.profiler.nbimpl.javac</package>
457
                <package>org.netbeans.modules.profiler.nbimpl.javac</package>
430
                <package>org.netbeans.modules.profiler.nbimpl.project</package>
458
                <package>org.netbeans.modules.profiler.nbimpl.project</package>
431
            </friend-packages>
459
            </friend-packages>
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/NetBeansProfiler.java (-5 / +14 lines)
Lines 50-55 Link Here
50
import org.netbeans.lib.profiler.common.ProfilingSettings;
50
import org.netbeans.lib.profiler.common.ProfilingSettings;
51
import org.netbeans.modules.profiler.HeapDumpWatch;
51
import org.netbeans.modules.profiler.HeapDumpWatch;
52
import org.netbeans.modules.profiler.ProfilerModule;
52
import org.netbeans.modules.profiler.ProfilerModule;
53
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher;
53
import org.netbeans.modules.profiler.spi.LoadGenPlugin;
54
import org.netbeans.modules.profiler.spi.LoadGenPlugin;
54
import org.openide.execution.ExecutorTask;
55
import org.openide.execution.ExecutorTask;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
Lines 72-77 Link Here
72
73
73
        doRunTarget(buildScriptFO, target, props);
74
        doRunTarget(buildScriptFO, target, props);
74
    }
75
    }
76
    
77
    public void notifyRunTarget(FileObject buildXml, String target) {
78
        getActionSupport().setAll(buildXml, target, null);
79
    }
80
    
81
    public void storeProfilingProperties(Properties props) {
82
        getActionSupport().setProperties(props);
83
    }
75
84
76
    /**
85
    /**
77
     * Runs an target in Ant script with properties context.
86
     * Runs an target in Ant script with properties context.
Lines 114-132 Link Here
114
    @Override
123
    @Override
115
    public boolean rerunAvailable() {
124
    public boolean rerunAvailable() {
116
        int state = getProfilingState();
125
        int state = getProfilingState();
117
        return (state == Profiler.PROFILING_INACTIVE || state == Profiler.PROFILING_STOPPED) ? getActionSupport().isActionAvailable() : false;
126
        return (state == Profiler.PROFILING_INACTIVE || state == Profiler.PROFILING_STOPPED) ? ProfilerLauncher.canRelaunch() : false;
118
    }
127
    }
119
128
120
    @Override
129
    @Override
121
    public boolean modifyAvailable() {
130
    public boolean modifyAvailable() {
122
        return getProfilingMode()==MODE_ATTACH || getActionSupport().isActionAvailable();
131
        return getProfilingState() == Profiler.PROFILING_RUNNING;
123
    }
132
    }
124
133
125
    @Override
134
    @Override
126
    public void rerunLastProfiling() {
135
    public void rerunLastProfiling() {
127
        String target = getActionSupport().getTarget();
136
        ProfilerLauncher.Session s = ProfilerLauncher.getLastSession();
128
        if (target!=null) {
137
        if (s != null) {
129
            doRunTarget(getActionSupport().getScript(), target, getActionSupport().getProperties());
138
            s.run();
130
        }
139
        }
131
    }
140
    }
132
141
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/ProfilerControlPanel2Support.java (+6 lines)
Lines 82-87 Link Here
82
        this.properties = properties;
82
        this.properties = properties;
83
        registerListener();
83
        registerListener();
84
    }
84
    }
85
    
86
    void setProperties(Properties p) {
87
        if (this.script != null) {
88
            this.properties = p;
89
        }
90
    }
85
91
86
    FileObject getScript() {
92
    FileObject getScript() {
87
        return script;
93
        return script;
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/AntActions.java (-751 / +122 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
7
 * Other names may be trademarks of their respective owners.
Lines 24-34 Link Here
24
 * your own identifying information:
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
26
 *
27
 * Contributor(s):
28
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Microsystems, Inc. All Rights Reserved.
31
 *
32
 * If you wish your version of this file to be governed by only the CDDL
27
 * If you wish your version of this file to be governed by only the CDDL
33
 * or only the GPL Version 2, indicate your decision by adding
28
 * or only the GPL Version 2, indicate your decision by adding
34
 * "[Contributor] elects to include this software in this distribution
29
 * "[Contributor] elects to include this software in this distribution
Lines 39-810 Link Here
39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
40
 * Version 2 license, then the option applies only if the new code is
35
 * Version 2 license, then the option applies only if the new code is
41
 * made subject to such option by the copyright holder.
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
42
 */
41
 */
43
44
package org.netbeans.modules.profiler.nbimpl.actions;
42
package org.netbeans.modules.profiler.nbimpl.actions;
45
43
44
import javax.swing.Action;
46
import org.netbeans.api.project.Project;
45
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.ProjectUtils;
48
import org.netbeans.api.project.ui.OpenProjects;
49
import org.netbeans.lib.profiler.ProfilerLogger;
46
import org.netbeans.lib.profiler.ProfilerLogger;
50
import org.netbeans.lib.profiler.common.Profiler;
51
import org.netbeans.lib.profiler.common.ProfilingSettings;
52
import org.netbeans.lib.profiler.common.SessionSettings;
53
import org.netbeans.lib.profiler.global.CommonConstants;
54
import org.netbeans.lib.profiler.utils.MiscUtils;
55
import org.netbeans.modules.profiler.NetBeansProfiler;
47
import org.netbeans.modules.profiler.NetBeansProfiler;
56
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
48
57
import org.netbeans.modules.profiler.utils.IDEUtils;
49
import org.netbeans.modules.profiler.api.icons.Icons;
50
import org.netbeans.modules.profiler.api.icons.ProfilerIcons;
51
import org.netbeans.modules.profiler.api.project.ProjectProfilingSupport;
52
import org.netbeans.spi.project.ActionProvider;
53
import org.netbeans.spi.project.ui.support.FileSensitiveActions;
58
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions;
54
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions;
59
import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
55
import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
60
import org.openide.ErrorManager;
56
import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
61
import org.openide.filesystems.FileObject;
57
import org.openide.awt.ActionID;
62
import org.openide.filesystems.FileUtil;
58
import org.openide.awt.ActionReference;
63
import org.openide.util.Lookup;
59
import org.openide.awt.ActionReferences;
60
import org.openide.awt.ActionRegistration;
64
import org.openide.util.NbBundle;
61
import org.openide.util.NbBundle;
65
import org.openide.util.RequestProcessor;
62
import org.openide.util.NbBundle.Messages;
66
import java.io.IOException;
67
import java.text.MessageFormat;
68
import java.util.Properties;
69
import javax.swing.Action;
70
import org.netbeans.api.java.source.ui.ScanDialog;
71
import org.netbeans.lib.profiler.common.CommonUtils;
72
import org.netbeans.lib.profiler.global.Platform;
73
import org.netbeans.modules.profiler.HeapDumpWatch;
74
import org.netbeans.modules.profiler.actions.JavaPlatformSelector;
75
import org.netbeans.modules.profiler.actions.ProfilingSupport;
76
import org.netbeans.modules.profiler.api.icons.Icons;
77
import org.netbeans.modules.profiler.api.JavaPlatform;
78
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
79
import org.netbeans.modules.profiler.api.ProfilerDialogs;
80
import org.netbeans.modules.profiler.api.icons.ProfilerIcons;
81
import org.netbeans.modules.profiler.api.project.ProjectStorage;
82
import org.netbeans.modules.profiler.api.project.AntProjectSupport;
83
import org.netbeans.modules.profiler.api.project.ProjectProfilingSupport;
84
import org.netbeans.modules.profiler.projectsupport.utilities.ProjectUtilities;
85
86
63
87
/**
64
/**
88
 * 4.0 Ant-style actions
89
 *
65
 *
90
 * @author Tomas Hurka
66
 * @author Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
91
 * @author Ian Formanek
92
 */
67
 */
93
@NbBundle.Messages({
68
public class AntActions {
94
    "AntActions_FileTestNotFoundMsg=Test for the file does not exist.",
69
    @ActionID(category="Profile", id="org.netbeans.modules.profiler.actions.ProfileMainProject")
95
    "AntActions_FailedDetermineJavaPlatformMsg=Failed to determine version of Java platform: {0}",
70
    @ActionRegistration(displayName="Profile Main Project", lazy=false)
96
    "AntActions_FailedDetermineProjectBuildScriptMsg=Cannot determine build script for project {0}",
71
    @ActionReferences({
97
    "AntActions_IncorrectJavaSpecVersionDialogCaption=Warning",
72
        @ActionReference(path="Menu/Profile", position=100),
98
    "AntActions_IncorrectJavaSpecVersionDialogMsg=The specification version of project Java Platform is greater than specification version of the\nplatform that will be used for profiling. You may experience problems unless you set the compiler\nparameter to generate bytecode compatible with the platform that will be used.\n\nDo you want to continue with the current settings?",
73
        @ActionReference(path="Shortcuts", name="A-F2")
99
    "AntActions_UnsupportedProjectTypeMsg=Profiling this project type is not supported.",
74
    })
100
    "AntActions_InvalidJavaplatformMsg=Failed to determine overridden platform: {0}",
75
    public static Action profileMainProjectAction() {
101
    "AntActions_InvalidPlatformProjectMsg=The Java platform defined for the project is invalid. Right-click the project\nand choose a different platform using Properties | Libraries | Java Platform.\n\nInvalid platform: {0}",
76
        final Action delegate = MainProjectSensitiveActions.mainProjectSensitiveAction(
102
    "AntActions_InvalidPlatformProfilerMsg=The Java platform defined for profiling is invalid. Choose a different platform\nin Tools | Options | Miscellaneous | Profiler | Profiler Java Platform.\n\nInvalid platform: {0}",
77
                new ProjectSensitivePerformer(ActionProvider.COMMAND_PROFILE), 
103
    "AntActions_LazyEnablementFailure=<html><b>Unable to start profiling.</b><br><br>Please, make sure the project type is supported</p><p>and/or the selected file can be executed.",
78
                NbBundle.getMessage(AntActions.class, "LBL_ProfileMainProjectAction"), // NOI18N
104
    "AntActions_LazyEnablementProgressMessage=Validating profiler action"
79
                Icons.getIcon(ProfilerIcons.PROFILE)
105
})
80
        );
106
public final class AntActions {
81
        delegate.putValue(Action.SHORT_DESCRIPTION, NbBundle.getMessage(AntActions.class, "HINT_ProfileMainProjectAction")); // NOI18N
107
    private static final String LINUX_THREAD_TIMER_KEY = "-XX:+UseLinuxPosixThreadCPUClocks"; // NOI18N
82
        
108
    //~ Constructors -------------------------------------------------------------------------------------------------------------
83
        return delegate;
109
110
    /** Default constructor to avoid creating instances */
111
    private AntActions() {
112
    }
84
    }
113
85
    
114
    //~ Methods ------------------------------------------------------------------------------------------------------------------
86
    @ActionID(category="Profile", id="org.netbeans.modules.profiler.actions.ProfileProjectPopup")
115
87
    @ActionRegistration(displayName="Profile", lazy=false, asynchronous=true)
116
    /**
88
    @ActionReferences({
117
     * @return An Action to invoke profiling of the main project in the IDE
89
        @ActionReference(path="Projects/org-netbeans-modules-java-j2seproject/Actions", position=1000),
118
     */
90
        @ActionReference(path="Projects/org-netbeans-modules-apisupport-project/Actions", position=900),
119
    public static Action profileMainProject() {
91
        @ActionReference(path="Projects/org-netbeans-modules-apisupport-project-suite/Actions", position=1000),
120
        final Action a = MainProjectSensitiveActions.mainProjectSensitiveAction(new ProjectActionPerformer() {
92
        @ActionReference(path="Projects/org-netbeans-modules-web-project/Actions", position=1000)
121
                public boolean enable(final Project project) {
93
    })
122
                    // Check if the Profiler is initialized correctly
94
    public static Action profileProjectPopup() {
123
                    if (!NetBeansProfiler.isInitialized()) {
95
        Action delegate = ProjectSensitiveActions.projectSensitiveAction(
124
                        return false;
96
                new ProjectSensitivePerformer(ActionProvider.COMMAND_PROFILE), 
125
                    }
97
                NbBundle.getMessage(AntActions.class, "LBL_ProfileProject"), // NOI18N
126
98
                null
127
                    // No projects opened => disable action
99
        );
128
                    if (OpenProjects.getDefault().getOpenProjects().length == 0) {
100
        
129
                        return false;
101
        return delegate;
130
                    }
102
    }
131
103
    
132
                    // No main project set => enable action (see Issue 116619)
104
    @ActionID(category="Project", id="org.netbeans.modules.apisupport.project.suite.ProfileOsgi")
133
                    if (project == null) {
105
    @ActionRegistration(displayName="#SUITE_ACTION_profile_osgi", asynchronous=true)
134
                        return true;
106
    @ActionReference(path="Projects/org-netbeans-modules-apisupport-project-suite-osgi/Actions", position=500)
135
                    }
107
    @NbBundle.Messages("SUITE_ACTION_profile_osgi=Profile in Felix")
136
108
    public static Action profileOsgi() {
137
                    // Check if project type is supported, eventually return null
109
        Action delegate = ProjectSensitiveActions.projectSensitiveAction(
138
                    return org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities.isProjectTypeSupported(project);
110
                new ProjectSensitivePerformer("profile-osgi"), 
111
                Bundle.SUITE_ACTION_profile_osgi(), 
112
                null
113
        );
114
        
115
        return delegate;
116
    }
117
    
118
    @Messages("LBL_ProfileFile=Profile File")
119
    @ActionID(category="Profile", id="org.netbeans.modules.profiler.actions.ProfileSingle")
120
    @ActionRegistration(displayName="#LBL_ProfileFile", lazy=false)
121
    @ActionReferences({
122
        @ActionReference(path="Loaders/text/x-java/Actions", position=1200),
123
        @ActionReference(path="Loaders/text/x-jsp/Actions", position=800),
124
        @ActionReference(path="Menu/Profile", position=110)
125
    })
126
    public static Action profileSingle() {
127
        Action delegate = FileSensitiveActions.fileSensitiveAction(
128
                new FileSensitivePerformer(ActionProvider.COMMAND_PROFILE_SINGLE),  
129
                Bundle.LBL_ProfileFile(),
130
                null);
131
        
132
        return delegate;
133
    }
134
        
135
    @Messages("LBL_ProfileTest=Profile Test File")
136
    @ActionID(category = "Profile", id = "org.netbeans.modules.profiler.actions.ProfileTest")
137
    @ActionRegistration(displayName = "#LBL_ProfileTest", lazy=false)
138
    @ActionReferences(value = {
139
        @ActionReference(path = "Loaders/text/x-java/Actions", position = 1280),
140
        @ActionReference(path = "Menu/Profile", position = 120)})
141
    public static Action profileTest() {
142
        return FileSensitiveActions.fileSensitiveAction(
143
                new FileSensitivePerformer(ActionProvider.COMMAND_PROFILE_TEST_SINGLE), 
144
                Bundle.LBL_ProfileTest(),
145
                null);
146
    }
147
    
148
    @ActionID(id = "org.netbeans.modules.profiler.nbimpl.actions.UnintegrateProfilerAction", category = "Profile")
149
    @ActionRegistration(displayName = "#LBL_UnintegrateProfilerAction", lazy=false)
150
    @ActionReference(path = "Menu/Profile/Advanced", position = 500)
151
    public static Action unintegrateProfiler() {
152
        final Action a = ProjectSensitiveActions.projectSensitiveAction(new ProjectActionPerformer() {
153
            @Override
154
            public boolean enable(Project project) {
155
                if (!NetBeansProfiler.isInitialized()) {
156
                    return false;
139
                }
157
                }
140
158
141
                public void perform(final Project project) {
159
                if (project == null) {
142
                    if (org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities.isProjectTypeSupported(project)) {
160
                    return false;
143
                        doProfileProject(project, null, NbBundle.getMessage(AntActions.class, "LBL_ProfileProject"));
144
                    } else {
145
                        ProfilerDialogs.displayError(Bundle.AntActions_UnsupportedProjectTypeMsg());
146
                    }
147
                }
148
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileMainProjectAction"), // NOI18N
149
                                                                                null);
150
        a.putValue(Action.SHORT_DESCRIPTION, NbBundle.getMessage(AntActions.class, "HINT_ProfileMainProjectAction" // NOI18N
151
        ));
152
        a.putValue("iconBase", Icons.getResource(ProfilerIcons.PROFILE));
153
        a.putValue(Action.SMALL_ICON, Icons.getIcon(ProfilerIcons.PROFILE));
154
155
        return a;
156
    }
157
158
    /**
159
     * @return An Action to invoke profiling of a selected project in the IDE
160
     */
161
    public static Action profileProject() {
162
        final Action a = ProjectSensitiveAction.projectSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
163
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
164
                    if (!NetBeansProfiler.isInitialized()) {
165
                        return false;
166
                    }
167
168
                    if (project == null) {
169
                        return false;
170
                    }
171
172
                    return org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities.isProjectTypeSupported(project);
173
                }
161
                }
174
162
175
                public void perform(final Project project, final Lookup context) {
163
                ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
176
                    doProfileProject(project, null, NbBundle.getMessage(AntActions.class, "LBL_ProfileProject"));
164
                return support.supportsUnintegrate();
165
            }
166
167
            @Override
168
            public void perform(Project project) {
169
                ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
170
                try {
171
                    support.unintegrateProfiler();
172
                } catch (Exception e) {
173
                    ProfilerLogger.log(e);
177
                }
174
                }
178
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileProjectAction40_General"), // NOI18N
175
            }
179
                                                                       NbBundle.getMessage(AntActions.class,
176
        }, NbBundle.getMessage(AntActions.class, "LBL_UnintegrateProfilerAction"), null); // NOI18N
180
                                                                                           "LBL_ProfileProjectAction40"), // NOI18N
181
                                                                       null);
182
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
177
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
183
178
184
        return a;
179
        return a;
185
    }
180
    }
186
187
    /**
188
     * @return An Action to invoke profiling of a selected project in the IDE, does not have project name in display name
189
     */
190
    public static Action profileProjectPopup() {
191
        final Action a = ProjectSensitiveAction.projectSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
192
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
193
                    if (!NetBeansProfiler.isInitialized()) {
194
                        return false;
195
                    }
196
197
                    if (project == null) {
198
                        return false;
199
                    }
200
201
                    return org.netbeans.modules.profiler.nbimpl.project.ProjectUtilities.isProjectTypeSupported(project);
202
                }
203
204
                public void perform(final Project project, final Lookup context) {
205
                    doProfileProject(project, null, NbBundle.getMessage(AntActions.class, "LBL_ProfileProject"));
206
                }
207
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileProjectActionPopup"), // NOI18N
208
                                                                       NbBundle.getMessage(AntActions.class,
209
                                                                                           "LBL_ProfileProjectActionPopup"), // NOI18N
210
                                                                       null);
211
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
212
213
        return a;
214
    }
215
216
    /**
217
     * @return An Action to invoke profiling of a single class in the IDE
218
     */
219
    public static Action profileSingle() {
220
        final Action a = FileSensitiveAction.fileSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
221
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
222
                    if (!NetBeansProfiler.isInitialized()) {
223
                        return false;
224
                    }
225
226
                    if (project == null) {
227
                        return false;
228
                    }
229
230
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
231
232
                    if (fos.length != 1) {
233
                        return false;
234
                    }
235
236
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
237
//                    if (!lightweightOnly) {
238
//                        if (!ptp.isFileObjectSupported(project, fos[0])) {
239
//                            return ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
240
//                        }
241
//                    } else {
242
//                        return ptp.isProfilingSupported(project) || ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
243
//                    }
244
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
245
                    if (!lightweightOnly) {
246
                        if (!support.isFileObjectSupported(fos[0])) {
247
                            return ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
248
                        }
249
                    } else {
250
                        return support.isProfilingSupported() || ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
251
                    }
252
                    
253
                    return true;
254
                }
255
256
                public void perform(final Project project, final Lookup context) {
257
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
258
259
                    if (fos.length != 1) {
260
                        throw new IllegalStateException();
261
                    }
262
263
                    doProfileProject(project, JavaProfilerSource.createFrom(fos[0]), NbBundle.getMessage(AntActions.class, "LBL_ProfileFile"));
264
                }
265
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileSingleAction40_General"), // NOI18N
266
                                                                 NbBundle.getMessage(AntActions.class, "LBL_ProfileSingleAction40"), // NOI18N
267
                                                                 null);
268
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
269
270
        return a;
271
    }
272
273
    /**
274
     * @return An Action to invoke profiling of a single class in the IDE. Does not have file name in its display name
275
     */
276
    public static Action profileSinglePopup() {
277
        final Action a = FileSensitiveAction.fileSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
278
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
279
                    if (!NetBeansProfiler.isInitialized()) {
280
                        return false;
281
                    }
282
283
                    if (project == null) {
284
                        return false;
285
                    }
286
287
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
288
289
                    if (fos.length != 1) {
290
                        return false;
291
                    }
292
293
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
294
//                    if (!lightweightOnly) {
295
//                        if (!ptp.isFileObjectSupported(project, fos[0])) {
296
//                            return ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
297
//                        }
298
//                    } else {
299
//                        return ptp.isProfilingSupported(project) || ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
300
//                    }
301
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
302
                    if (!lightweightOnly) {
303
                        if (!support.isFileObjectSupported( fos[0])) {
304
                            return ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
305
                        }
306
                    } else {
307
                        return support.isProfilingSupported() || ProjectUtilities.hasAction(project, "profile-single"); //NOI18N
308
                    }
309
310
                    return true;
311
                }
312
313
                public void perform(final Project project, final Lookup context) {
314
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
315
316
                    if (fos.length != 1) {
317
                        throw new IllegalStateException();
318
                    }
319
320
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
321
//                    if (!ptp.isFileObjectSupported(project, fos[0]) && !ProjectUtilities.hasAction(project, "profile-single")) { //NOI18N
322
//                        throw new IllegalStateException();
323
//                    }
324
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
325
                    if (!support.isFileObjectSupported( fos[0]) && !ProjectUtilities.hasAction(project, "profile-single")) { //NOI18N
326
                        throw new IllegalStateException();
327
                    }
328
329
                    doProfileProject(project, JavaProfilerSource.createFrom(fos[0]) ,NbBundle.getMessage(AntActions.class, "LBL_ProfileFile"));
330
                }
331
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileSingleActionPopup"), // NOI18N
332
                                                                 NbBundle.getMessage(AntActions.class,
333
                                                                                     "LBL_ProfileSingleActionPopup"), // NOI18N
334
                                                                 null);
335
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
336
337
        return a;
338
    }
339
340
    /**
341
     * @return An Action to invoke profiling of a single class in the IDE
342
     */
343
    public static Action profileTest() {
344
        final Action a = FileSensitiveAction.fileSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
345
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
346
                    if (!NetBeansProfiler.isInitialized()) {
347
                        return false;
348
                    }
349
350
                    if (project == null) {
351
                        return false;
352
                    }
353
354
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
355
356
                    if (fos.length != 1) {
357
                        return false;
358
                    }
359
360
                    final FileObject fo = ProjectUtilities.findTestForFile(fos[0]);
361
362
                    if (fo == null) {
363
                        return false; // not a test and test for it does not exist
364
                    }
365
366
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
367
//                    if (!lightweightOnly) {
368
//                        return (ptp.isFileObjectSupported(project, fo));
369
//                    } else {
370
//                        return ptp.isProfilingSupported(project);
371
//                    }
372
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
373
                    if (!lightweightOnly) {
374
                        return (support.isFileObjectSupported(fo));
375
                    } else {
376
                        return support.isProfilingSupported();
377
                    }
378
                }
379
380
                public void perform(final Project project, final Lookup context) {
381
                    final FileObject[] fos = ProjectSensitiveAction.ActionsUtil.getFilesFromLookup(context, project);
382
383
                    if (fos.length != 1) {
384
                        throw new IllegalStateException();
385
                    }
386
387
                    final FileObject fo = ProjectUtilities.findTestForFile(fos[0]);
388
389
                    if (fo == null) {
390
                        throw new IllegalStateException(Bundle.AntActions_FileTestNotFoundMsg());
391
                    }
392
393
                    if (!ProjectProfilingSupport.get(project).isFileObjectSupported(fo)) {
394
                        throw new IllegalStateException();
395
                    }
396
397
                    doProfileProject(project, JavaProfilerSource.createFrom(fo), NbBundle.getMessage(AntActions.class, "LBL_ProfileTest"));
398
                }
399
            }, NbBundle.getMessage(AntActions.class, "LBL_ProfileTestAction_General"), // NI18N
400
                                                                 NbBundle.getMessage(AntActions.class, "LBL_ProfileTestAction"), // NOI18N
401
                                                                 null);
402
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
403
404
        return a;
405
    }
406
407
    public static Action unintegrateProfiler() {
408
        final Action a = ProjectSensitiveAction.projectSensitiveAction(new ProjectSensitiveAction.ProfilerProjectActionPerformer() {
409
                public boolean enable(final Project project, final Lookup context, final boolean lightweightOnly) {
410
                    if (!NetBeansProfiler.isInitialized()) {
411
                        return false;
412
                    }
413
414
                    if (project == null) {
415
                        return false;
416
                    }
417
418
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
419
//
420
//                    return ptp.supportsUnintegrate(project);
421
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
422
                    return support.supportsUnintegrate();
423
                }
424
425
                public void perform(final Project project, final Lookup context) {
426
//                    final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
427
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
428
                    try {
429
                        support.unintegrateProfiler();
430
                    } catch (Exception e) {
431
                        ProfilerLogger.log(e);
432
                    }
433
                }
434
            }, NbBundle.getMessage(AntActions.class, "LBL_UnintegrateProfilerAction"), // NOI18N
435
                                                                       NbBundle.getMessage(AntActions.class,
436
                                                                                           "LBL_UnintegrateProfilerAction"), // NOI18N
437
                                                                       null);
438
        a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
439
440
        return a;
441
    }
442
443
    private static String getHeapDumpPath(ProfilerIDESettings gps, Project project) {
444
        int oomeDetectionMode = gps.getOOMDetectionMode();
445
446
        switch (oomeDetectionMode) {
447
            case ProfilerIDESettings.OOME_DETECTION_TEMPDIR:
448
                return System.getProperty("java.io.tmpdir"); // NOI18N
449
            case ProfilerIDESettings.OOME_DETECTION_PROJECTDIR:
450
451
                try {
452
                    return FileUtil.toFile(ProjectStorage.getSettingsFolder(project, true)).getAbsolutePath();
453
                } catch (IOException e) {
454
                    ErrorManager.getDefault().annotate(e, "Cannot resolve project settings directory:\n" + e.getMessage());
455
                    ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
456
457
                    return null;
458
                }
459
            case ProfilerIDESettings.OOME_DETECTION_CUSTOMDIR:
460
                return gps.getCustomHeapdumpPath();
461
        }
462
463
        return null;
464
    }
465
466
    private static void activateLinuxPosixThreadTime(ProfilingSettings ps, Properties props, Project project) {
467
        if (ps.getThreadCPUTimerOn()) {
468
            props.setProperty("profiler.info.jvmargs", LINUX_THREAD_TIMER_KEY + " " + props.getProperty("profiler.info.jvmargs")); // NOI18N
469
            ProfilerLogger.log("Profiler.UseLinuxPosixThreadCPUClocks: Enabled"); // NOI18N
470
        }
471
    }
472
473
    private static void activateOOMProtection(ProfilerIDESettings gps, Properties props, Project project) {
474
        if (gps.isOOMDetectionEnabled()) {
475
            String oldArgs = props.getProperty("profiler.info.jvmargs");
476
            oldArgs = (oldArgs != null) ? oldArgs : "";
477
478
            StringBuilder oomArgsBuffer = new StringBuilder(oldArgs);
479
            String heapDumpPath = getHeapDumpPath(gps, project);
480
481
            if ((heapDumpPath != null) && (heapDumpPath.length() > 0)) {
482
                // used for filesystem listener
483
                props.setProperty(HeapDumpWatch.OOME_PROTECTION_ENABLED_KEY, "yes");
484
                props.setProperty(HeapDumpWatch.OOME_PROTECTION_DUMPPATH_KEY, heapDumpPath);
485
486
                // used as an argument for starting java process
487
                if (heapDumpPath.contains(" ")) {
488
                    heapDumpPath = "\"" + heapDumpPath + "\"";
489
                }
490
491
                oomArgsBuffer.append(" -XX:+HeapDumpOnOutOfMemoryError"); // NOI18N
492
                oomArgsBuffer.append(" -XX:HeapDumpPath=").append(heapDumpPath).append(" "); // NOI18N
493
494
                ProfilerLogger.log("Profiler.OutOfMemoryDetection: Enabled"); // NOI18N
495
            }
496
497
            props.setProperty("profiler.info.jvmargs", oomArgsBuffer.toString()); // NOI18N
498
        }
499
    }
500
501
    // -- Private implementation -----------------------------------------------------------------------------------------
502
503
    /**
504
     * Performs profiling of the selected project using either the supplied class (in case of profile single) or the
505
     * project's main class.
506
     *
507
     * @param project           The project to profile
508
     * @param profiledClassFile In case profiledClass is not null, this is the FileObject representing the specified class
509
     */
510
    private static void doProfileProject(final Project project, final JavaProfilerSource profiledClassFile, final String actionName) {
511
        final boolean isTest = profiledClassFile != null ? profiledClassFile.isTest() : false;
512
        final FileObject fo = profiledClassFile != null ? profiledClassFile.getFile() : null;
513
        
514
        if (ProfilingSupport.getDefault().isProfilingActionInvoked()) {
515
            return;
516
        }
517
518
        ProfilingSupport.getDefault().setProfilingActionInvoked(true);
519
520
        final Runnable actionPerform = new Runnable() {
521
            public void run() {
522
                try {
523
                    // 1. if there is profiling in progress, ask the user and possibly cancel
524
                    if (ProfilingSupport.getDefault().checkProfilingInProgress()) {
525
                        return;
526
                    }
527
528
//                        final ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
529
                    ProjectProfilingSupport support = ProjectProfilingSupport.get(project);
530
                    if (!support.isProfilingSupported()) {
531
                        // Branch A: not supported project with profile action in the action provider
532
533
                        // as of now, the profile-tests will neve be used
534
                        ProjectUtilities.invokeAction(project, isTest ? "profile-tests" : "profile"); //NOI18N
535
                    } else {
536
                        // Branch B: project profiling directly supported via ProjectTypeProfiler
537
                        // 2. check if the project has been modified for profiling
538
                        if (!support.checkProjectIsModifiedForProfiler()) {
539
                            return; // something failed - has already been reported to the user
540
                        }
541
542
                        // 3. determine Java platform to use
543
                        final JavaPlatform platform = initPlatform(project, support);
544
545
                        if (platform == null) {
546
                            return; // user already notified
547
                        }
548
549
                        // 3. check if the project is properly setup to be profiled (e.g. main class has a main method)
550
                        // FIXME - probably it would be better to pass around JavaProfilerSource instead of FileObject
551
                        if (!support.checkProjectCanBeProfiled(fo)) {
552
                            return;
553
                        }
554
555
                        // 5. get session settings from the project context
556
                        final ProfilerIDESettings gps = ProfilerIDESettings.getInstance();
557
558
                        final String javaFile = platform.getPlatformJavaFile();
559
560
                        if (javaFile == null) {
561
                            if (ProfilerIDESettings.getInstance().getJavaPlatformForProfiling() == null) {
562
                                // used platform defined for project
563
                                ProfilerDialogs.displayError(Bundle.AntActions_InvalidPlatformProjectMsg(platform.getDisplayName()));
564
                            } else {
565
                                // used platform defined in Options / Profiler
566
                                ProfilerDialogs.displayError(Bundle.AntActions_InvalidPlatformProfilerMsg(platform.getDisplayName()));
567
                            }
568
                            return;
569
                        }
570
571
                        final String javaVersion = platform.getPlatformJDKVersion();
572
573
                        if (javaVersion == null) {
574
                            ProfilerDialogs.displayError(Bundle.AntActions_FailedDetermineJavaPlatformMsg(platform.getDisplayName()));
575
576
                            return;
577
                        }
578
579
                        final SessionSettings ss = new SessionSettings();
580
                        ss.setJavaExecutable(javaFile);
581
                        ss.setJavaVersionString(javaVersion);
582
                        ss.setSystemArchitecture(platform.getPlatformArchitecture());
583
                        ss.setPortNo(gps.getPortNo());
584
                        support.setupProjectSessionSettings(ss);
585
586
                        boolean settingsAccepted = false;
587
                        ProfilingSettings pSettings = null;
588
589
                        while (!settingsAccepted) {
590
                            // 6. show SelectTaskPanel and let the user choose the profiling type
591
                            pSettings = ProfilingSupport.getDefault()
592
                                                        .selectTaskForProfiling(project, ss, fo,
593
                                                                                support.supportsSettingsOverride());
594
595
                            if (pSettings == null) {
596
                                return; // cancelled
597
                            }
598
599
                            // Here was a check for enormous profiling overhead when profiling Web Projects.
600
                            // Generally, this is the right place to give ProjectTypeProfiler a chance to
601
                            // accept/reject current profiling settings before starting new profiling session.
602
                            settingsAccepted = true;
603
                        }
604
605
                        final ProfilingSettings profilingSettings = pSettings;
606
                        final Properties props = new Properties();
607
608
                        // 7. store things into properties to be passed to Ant
609
                        profilingSettings.store(props); // Profiling settings
610
                        ss.store(props); // Session settings
611
612
                        // Auxiliary internal profiler information:
613
                        String projectDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
614
                        props.setProperty("profiler.info.project.dir", projectDir); // NOI18N // TODO: create constant
615
616
                        if (fo != null) {
617
                            String singleFile = FileUtil.toFile(fo).getAbsolutePath();
618
                            props.setProperty("profiler.info.single.file", singleFile); // NOI18N // TODO: create constant
619
                        }
620
621
                        String usedJavaExecutable = ss.getJavaExecutable();
622
                        String usedJvmArgs = ss.getJVMArgs();
623
624
                        if (profilingSettings.getOverrideGlobalSettings()) {
625
                            String javaPlatformName = profilingSettings.getJavaPlatformName();
626
                            JavaPlatform jp;
627
628
                            if (javaPlatformName != null) {
629
                                usedJavaExecutable = Profiler.getDefault().getPlatformJavaFile(javaPlatformName);
630
                                jp = JavaPlatform.getJavaPlatformById(javaPlatformName);
631
632
                                if (jp == null) {
633
                                    // selected platform does not exist, use 
634
                                    String text = Bundle.AntActions_InvalidJavaplatformMsg(javaPlatformName);
635
                                    ProfilerDialogs.displayWarning(text);
636
                                    jp = platform;
637
                                }
638
                            } else { 
639
                                // javaPlatformName == null -> do not override java platform, use platform from global settings
640
                                jp = platform;
641
                            }
642
                            // added to support nbstartprofiledserver
643
                            props.setProperty("profiler.info.javaPlatform",
644
                                              jp.getPlatformId());
645
                            usedJvmArgs = profilingSettings.getJVMArgs();
646
                        } else {
647
                            // added to support nbstartprofiledserver
648
                            props.setProperty("profiler.info.javaPlatform",
649
                                              platform.getPlatformId());
650
                        }
651
652
                        props.setProperty("profiler.info.jvm", usedJavaExecutable); // NOI18N
653
                        props.setProperty("profiler.info.jvmargs", usedJvmArgs); // NOI18N
654
655
                        if (javaVersion.equals(CommonConstants.JDK_15_STRING)) {
656
                            // JDK 1.5 used
657
                            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
658
                                              IDEUtils.getAntProfilerStartArgument15(ss.getPortNo(),
659
                                                                                     ss.getSystemArchitecture())
660
                            );
661
662
                            if (platform.getPlatformJDKMinor() >= 7) {
663
                                activateOOMProtection(gps, props, project);
664
                            } else {
665
                                ProfilerLogger.log("Profiler.OutOfMemoryDetection: Disabled. Not supported JVM. Use at least 1.4.2_12 or 1.5.0_07"); // NOI18N
666
                            }
667
                        } else if (javaVersion.equals(CommonConstants.JDK_16_STRING)) {
668
                            // JDK 1.6 used
669
                            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
670
                                              IDEUtils.getAntProfilerStartArgument16(ss.getPortNo(),
671
                                                                                     ss.getSystemArchitecture())
672
                            );
673
                            activateOOMProtection(gps, props, project);
674
                        } else if (javaVersion.equals(CommonConstants.JDK_17_STRING)) {
675
                            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
676
                                              IDEUtils.getAntProfilerStartArgument17(ss.getPortNo(),
677
                                                                                     ss.getSystemArchitecture())
678
                            );
679
                            activateOOMProtection(gps, props, project);
680
                        } else if (javaVersion.equals(CommonConstants.JDK_18_STRING)) {
681
                            props.setProperty("profiler.info.jvmargs.agent", // NOI18N
682
                                              IDEUtils.getAntProfilerStartArgument18(ss.getPortNo(),
683
                                                                                     ss.getSystemArchitecture())
684
                            );
685
                            activateOOMProtection(gps, props, project);
686
                        } else {
687
                            throw new IllegalArgumentException("Unsupported JDK " + javaVersion); // NOI18N
688
                        }
689
690
                        if (Platform.isLinux() && javaVersion.equals(CommonConstants.JDK_16_STRING)) {
691
                            activateLinuxPosixThreadTime(pSettings, props, project);
692
                        }
693
694
                        if (!support.startProfilingSession(fo, isTest, props)) { // Used for Maven - ProjectTypeProfiler itself controls starting profiling session
695
696
                            // 8. determine the build script and target to run
697
                            AntProjectSupport antSupport = AntProjectSupport.get(project);
698
                            final FileObject buildScriptFO = antSupport.getProjectBuildScript();
699
700
                            if (buildScriptFO == null) {
701
                                ProfilerDialogs.displayError(Bundle.AntActions_FailedDetermineProjectBuildScriptMsg(ProjectUtils.getInformation(project).getName()));
702
703
                                return;
704
                            }
705
706
                            // determine which type fo target shoudl be called, and request its name
707
                            int type;
708
709
                            if (isTest) {
710
                                type = (fo == null) ? AntProjectSupport.TARGET_PROFILE_TEST
711
                                                                   : AntProjectSupport.TARGET_PROFILE_TEST_SINGLE;
712
                            } else {
713
                                type = (fo == null) ? AntProjectSupport.TARGET_PROFILE
714
                                                                   : AntProjectSupport.TARGET_PROFILE_SINGLE;
715
                            }
716
717
                            final String profileTarget = antSupport.getProfilerTargetName(buildScriptFO, type, fo);
718
719
                            if (profileTarget == null) {
720
                                return; // already notified the user or user's choice
721
                            }
722
723
                            // 9. final ability of the ProjectTypeProfiler to influence the properties passed to Ant
724
                            support.configurePropertiesForProfiling(props, fo);
725
726
                            // 10. Run the target
727
                            ((org.netbeans.modules.profiler.nbimpl.NetBeansProfiler)Profiler.getDefault()).runTarget(buildScriptFO, profileTarget, props);
728
729
                        }
730
731
732
                    }
733
                } finally {
734
                    ProfilingSupport.getDefault().setProfilingActionInvoked(false);
735
                }
736
            }
737
        };
738
        
739
        CommonUtils.runInEventDispatchThread(new Runnable() {
740
            @Override
741
            public void run() {
742
                if (ScanDialog.runWhenScanFinished(new Runnable() {
743
                    @Override
744
                    public void run() {
745
                        RequestProcessor.getDefault().post(actionPerform);
746
                    }
747
                }, actionName)) {
748
                    ProfilingSupport.getDefault().setProfilingActionInvoked(false);
749
                }
750
            }
751
        });
752
    }
753
754
    private static JavaPlatform initPlatform(Project project, ProjectProfilingSupport pps) {
755
        // 1. check if we have a Java platform to use for profiling
756
        final ProfilerIDESettings gps = ProfilerIDESettings.getInstance();
757
        JavaPlatform platform = JavaPlatform.getJavaPlatformById(gps.getJavaPlatformForProfiling());
758
        JavaPlatform projectPlatform = pps.getProjectJavaPlatform();
759
760
        if (platform == null) { // should use the one defined in project
761
            platform = projectPlatform;
762
763
            if ((platform == null) || !MiscUtils.isSupportedJVM(platform.getSystemProperties())) {
764
                platform = JavaPlatformSelector.getDefault().selectPlatformToUse();
765
766
                if (platform == null) {
767
                    return null;
768
                }
769
            }
770
        }
771
772
        if (projectPlatform != null) { // check that the project platform is not newer than platform to use
773
774
            while (true) {
775
                if (projectPlatform.getVersion().compareTo(platform.getVersion()) > 0) {
776
                    Boolean ret = ProfilerDialogs.displayCancellableConfirmation(
777
                            Bundle.AntActions_IncorrectJavaSpecVersionDialogMsg(),
778
                            Bundle.AntActions_IncorrectJavaSpecVersionDialogCaption());
779
780
                    if (Boolean.TRUE.equals(ret)) {
781
                        break;
782
                    } else if (Boolean.FALSE.equals(ret)) {
783
                        platform = JavaPlatformSelector.getDefault().selectPlatformToUse();
784
785
                        if (platform == null) {
786
                            return null; // cancelled by the user
787
                        }
788
                    } else { // cancelled
789
790
                        return null;
791
                    }
792
                } else {
793
                    break; // version comparison OK.
794
                }
795
            }
796
        }
797
798
        return platform;
799
    }
800
    
801
//    private static boolean isProjectTypeSupported(final Project project) {
802
//        ProjectTypeProfiler ptp = org.netbeans.modules.profiler.utils.ProjectUtilities.getProjectTypeProfiler(project);
803
//
804
//        if (ptp.isProfilingSupported(project)) {
805
//            return true;
806
//        }
807
//
808
//        return ProjectUtilities.hasAction(project, "profile"); //NOI18N
809
//    }
810
}
181
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/Bundle.properties (-3 / +1 lines)
Lines 67-72 Link Here
67
LBL_ProfileProjectActionPopup=Profile
67
LBL_ProfileProjectActionPopup=Profile
68
LBL_UnintegrateProfilerAction=&Unintegrate Profiler from {0,choice,0#Project|1#\"{1}\"|1<Projects}
68
LBL_UnintegrateProfilerAction=&Unintegrate Profiler from {0,choice,0#Project|1#\"{1}\"|1<Projects}
69
69
70
LBL_ProfileProject=Profile Project
70
LBL_ProfileProject=Profile
71
LBL_ProfileFile=Profile File
72
LBL_ProfileTest=Profile Test
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/FileSensitiveAction.java (-101 lines)
Lines 1-101 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Microsystems, Inc. All Rights Reserved.
31
 *
32
 * If you wish your version of this file to be governed by only the CDDL
33
 * or only the GPL Version 2, indicate your decision by adding
34
 * "[Contributor] elects to include this software in this distribution
35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36
 * single choice of license, a recipient has the option to distribute
37
 * your version of this file under either the CDDL, the GPL Version 2 or
38
 * to extend the choice of license to its licensees as provided above.
39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
40
 * Version 2 license, then the option applies only if the new code is
41
 * made subject to such option by the copyright holder.
42
 */
43
44
package org.netbeans.modules.profiler.nbimpl.actions;
45
46
import org.netbeans.api.project.Project;
47
import org.openide.filesystems.FileObject;
48
import org.openide.util.Lookup;
49
import javax.swing.Action;
50
import javax.swing.Icon;
51
52
53
/**
54
 * Action sensitive to current project
55
 *
56
 * @author Ian Formanek
57
 */
58
public final class FileSensitiveAction extends ProjectSensitiveAction {
59
    //~ Constructors -------------------------------------------------------------------------------------------------------------
60
61
    /**
62
     * Constructor for global actions. E.g. actions in main menu which
63
     * listen to the global context.
64
     */
65
    private FileSensitiveAction(final ProfilerProjectActionPerformer performer, final String name, final String namePattern,
66
                                final Icon icon, final Lookup lookup) {
67
        super(performer, name, namePattern, icon, lookup);
68
    }
69
70
    //~ Methods ------------------------------------------------------------------------------------------------------------------
71
72
    public static FileSensitiveAction fileSensitiveAction(final ProfilerProjectActionPerformer performer, final String name,
73
                                                          final String namePattern, final Icon icon) {
74
        return new FileSensitiveAction(performer, name, namePattern, icon, null);
75
    }
76
77
    @Override
78
    public Action createContextAwareInstance(final Lookup actionContext) {
79
        return new FileSensitiveAction(getPerformer(), getName(), getNamePattern(), (Icon) getValue(SMALL_ICON), actionContext);
80
    }
81
82
    @Override
83
    protected void doRefresh(final Lookup context) {
84
        final Project[] projects = ActionsUtil.getProjectsFromLookup(context, null);
85
86
        if (projects.length != 1) {
87
            setDisplayName(ActionsUtil.formatName(getNamePattern(), 0, "")); //NOI18N
88
            setEnabled(false);
89
        } else {
90
            final FileObject[] files = ActionsUtil.getFilesFromLookup(context, projects[0]);
91
92
            if ((files != null) && (files.length == 1)) {
93
                setEnabled(getPerformer().enable(projects[0], context, true));
94
            } else {
95
                setEnabled(false);
96
            }
97
98
            setDisplayName(ActionsUtil.formatName(getNamePattern(), files.length, (files.length > 0) ? files[0].getNameExt() : "")); // NOI18N
99
        }
100
    }
101
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/FileSensitivePerformer.java (+115 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.profiler.nbimpl.actions;
43
44
import org.netbeans.api.project.FileOwnerQuery;
45
import org.netbeans.api.project.Project;
46
import org.netbeans.modules.profiler.api.project.ProjectProfilingSupport;
47
import org.netbeans.spi.project.ActionProvider;
48
import org.netbeans.spi.project.ui.support.FileActionPerformer;
49
import org.openide.filesystems.FileObject;
50
import org.openide.loaders.DataObject;
51
import org.openide.loaders.DataObjectNotFoundException;
52
import org.openide.util.Lookup;
53
import org.openide.util.lookup.Lookups;
54
55
/**
56
 *
57
 * @author Jaroslav Bachorik
58
 */
59
public class FileSensitivePerformer implements FileActionPerformer {
60
61
    final private String command;
62
63
    public FileSensitivePerformer(String command) {
64
        this.command = command;
65
    }
66
67
    @Override
68
    public boolean enable(FileObject file) {
69
        if (file == null) {
70
            return false;
71
        }
72
73
        Project p = FileOwnerQuery.getOwner(file);
74
75
        if (p == null) {
76
            return false;
77
        }
78
79
        ActionProvider ap = p.getLookup().lookup(ActionProvider.class);
80
        try {
81
            if (ap != null && ap.isActionEnabled(command, getContext(file))) {
82
                ProjectProfilingSupport ppp = ProjectProfilingSupport.get(p);
83
                if (ppp == null) {
84
                    return false;
85
                }
86
                
87
                return ppp.isProfilingSupported();
88
            }
89
        } catch (IllegalArgumentException e) {
90
            // command not supported
91
        }
92
        return false;
93
    }
94
95
    @Override
96
    public void perform(FileObject file) {
97
        Project p = FileOwnerQuery.getOwner(file);
98
        ActionProvider ap = p.getLookup().lookup(ActionProvider.class);
99
        if (ap != null) {
100
            ProfilerLauncher.Session s = ProfilerLauncher.newSession(command, getContext(file));
101
            if (s != null) {
102
                s.run();
103
            }
104
        }
105
    }
106
107
    private Lookup getContext(FileObject file) {
108
        Project p = FileOwnerQuery.getOwner(file);
109
        try {
110
            return Lookups.fixed(file, p, DataObject.find(file));
111
        } catch (DataObjectNotFoundException e) {
112
        }
113
        return Lookups.fixed(file, p);
114
    }
115
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/ProfilerLauncher.java (+472 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.profiler.nbimpl.actions;
43
44
import java.io.IOException;
45
import java.util.HashMap;
46
import java.util.Map;
47
import java.util.logging.Level;
48
import java.util.logging.Logger;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.api.project.FileOwnerQuery;
51
import org.netbeans.api.project.Project;
52
import org.netbeans.lib.profiler.ProfilerLogger;
53
import org.netbeans.lib.profiler.common.ProfilingSettings;
54
import org.netbeans.lib.profiler.common.SessionSettings;
55
import org.netbeans.lib.profiler.global.CommonConstants;
56
import org.netbeans.lib.profiler.global.Platform;
57
import org.netbeans.modules.profiler.HeapDumpWatch;
58
import org.netbeans.modules.profiler.actions.ProfilingSupport;
59
import org.netbeans.modules.profiler.api.JavaPlatform;
60
import org.netbeans.modules.profiler.api.ProfilerDialogs;
61
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
62
import org.netbeans.modules.profiler.api.project.ProjectProfilingSupport;
63
import org.netbeans.modules.profiler.api.project.ProjectStorage;
64
import org.netbeans.modules.profiler.nbimpl.NetBeansProfiler;
65
import org.netbeans.modules.profiler.utils.IDEUtils;
66
import org.netbeans.spi.project.ActionProvider;
67
import org.netbeans.spi.project.LookupProvider.Registration.ProjectType;
68
import org.netbeans.spi.project.ProjectServiceProvider;
69
import org.openide.filesystems.FileObject;
70
import org.openide.filesystems.FileUtil;
71
import org.openide.util.Lookup;
72
import org.openide.util.NbBundle;
73
74
/**
75
 *
76
 * @author Jaroslav Bachorik
77
 */
78
public class ProfilerLauncher {
79
    final private static Logger LOG = Logger.getLogger(ProfilerLauncher.class.getName());
80
    
81
    final private static String AGENT_ARGS = "agent.jvmargs"; // NOI18N
82
    final private static String LINUX_THREAD_TIMER_KEY = "-XX:+UseLinuxPosixThreadCPUClocks"; // NOI18N
83
84
    final public static class Session  {
85
        private SessionSettings ss;
86
        private ProfilingSettings ps;
87
        private Map<String, String> props;
88
        private Launcher launcher;
89
        private Project project;
90
        private FileObject fo;
91
        private JavaPlatform platform;
92
        private String command;
93
        private Lookup context;
94
        final private Map<String, Object> customProps = new HashMap<String, Object>();
95
        
96
        private boolean configured = false;
97
        private boolean rerun;
98
99
        public static Session createSession(String command, Lookup context) {
100
            Session s = new Session(command, context);
101
            config(s);
102
            lastSession = s;
103
            
104
            return s;
105
        }
106
        
107
        public static Session createSession(Project p) {
108
            Session s = new Session(p);
109
            config(s);
110
            return s;
111
        }
112
        
113
        private Session(Project p) {
114
            this.props = new HashMap<String, String>();
115
            this.launcher = null;
116
            this.project = p;
117
        }
118
        
119
        private Session(String command, Lookup context) {
120
            assert command != null;
121
            assert context != null;
122
            
123
            this.project = context.lookup(Project.class);
124
            this.fo = context.lookup(FileObject.class);
125
            this.command = command;
126
            this.props = new HashMap<String, String>();
127
            this.context = context;
128
            
129
            initLauncher();
130
        }
131
132
        public ProfilingSettings getProfilingSettings() {
133
            return ps;
134
        }
135
        
136
        public SessionSettings getSessionSettings() {
137
            return ss;
138
        }
139
        
140
        public void setSessionSettings(SessionSettings ss) {
141
            this.ss = ss;
142
            this.ss.store(props);
143
        }
144
        
145
        public Map<String, String> getProperties() {
146
            if (!configured) {
147
                if (configure()) {
148
                    return props;
149
                } else {
150
                    return null;
151
                }
152
            }
153
            return props;
154
        }
155
        
156
        public Project getProject() {
157
            return project;
158
        }
159
        
160
        public JavaPlatform getPlatform() {
161
            return platform;
162
        }
163
        
164
        public Lookup getContext() {
165
            return context;
166
        }
167
        
168
        public FileObject getFile() {
169
            return fo;
170
        }
171
        
172
        public String getCommand() {
173
            return command;
174
        }
175
        
176
        public Object getAttribute(String name) {
177
            return customProps.get(name);
178
        }
179
        
180
        public void setAttribute(String name, Object value) {
181
            customProps.put(name, value);
182
        }
183
        
184
        public boolean hasAttribute(String name) {
185
            return customProps.containsKey(name);
186
        }
187
        
188
        public boolean isConfigured() {
189
            return configured;
190
        }
191
        
192
        public boolean configure() {
193
            final ProjectProfilingSupport pSupport = ProjectProfilingSupport.get(project);
194
195
            NetBeansProfiler.getDefaultNB().setProfiledProject(project, fo);
196
197
            // ** display select task panel
198
            ProfilingSettings ps = ProfilingSupport.getDefault().selectTaskForProfiling(project, ss, fo, true);;
199
            if (ps != null) {
200
                this.ps = ps;
201
                this.ps.store(props);
202
                
203
                setupAgentEnv(platform, ss, ProfilerIDESettings.getInstance(), ps, project, props);
204
                pSupport.configurePropertiesForProfiling(props, fo);
205
206
                rerun = false;
207
                configured = true;
208
            }
209
            return configured;
210
        }
211
        
212
        public void run() {
213
            if (launcher != null) {
214
                launcher.launch(rerun);
215
                rerun = true;
216
            } else {
217
                // LOG
218
            }
219
        }
220
        
221
        private void initLauncher() {
222
            Project p = null;
223
            if (project != null) {
224
                p = project;
225
                
226
            } else if (fo != null) {
227
                p = FileOwnerQuery.getOwner(fo);
228
            }
229
            
230
            if (p != null) {
231
                LauncherFactory f = p.getLookup().lookup(LauncherFactory.class);
232
                if (f != null) {
233
                    launcher = f.createLauncher(this);
234
                }
235
            }
236
        }
237
    }
238
    
239
    public interface Launcher {
240
        void launch(boolean rerun);
241
    }
242
    
243
    public interface LauncherFactory {
244
        Launcher createLauncher(Session session);
245
    }
246
    
247
    @ProjectServiceProvider(service=LauncherFactory.class, projectTypes={
248
        @ProjectType(id="org-netbeans-modules-java-j2seproject"), 
249
        @ProjectType(id="org-netbeans-modules-ant-freeform"),
250
        @ProjectType(id="org-netbeans-modules-apisupport-project"),
251
        @ProjectType(id="org-netbeans-modules-apisupport-project-suite"),
252
        @ProjectType(id="org-netbeans-modules-j2ee-earproject"),
253
        @ProjectType(id="org-netbeans-modules-j2ee-ejbjarproject"),
254
        @ProjectType(id="org-netbeans-modules-web-project")
255
    })
256
    final public static class AntLauncherFactory implements LauncherFactory {
257
        final private Project prj;
258
        public AntLauncherFactory(Project prj) {
259
            this.prj = prj;
260
        }
261
262
        @Override
263
        public Launcher createLauncher(Session session) {
264
            ActionProvider ap = prj.getLookup().lookup(ActionProvider.class);
265
            if (ap != null) {
266
                return new AntLauncher(ap, session.command, session.context);
267
            }
268
            
269
            return null;
270
        }
271
    }
272
    
273
    final private static class AntLauncher implements Launcher {
274
        private ActionProvider ap;
275
        private String command;
276
        private Lookup context;
277
278
        public AntLauncher(ActionProvider ap, String command, Lookup context) {
279
            this.ap = ap;
280
            this.command = command;
281
            this.context = context;
282
        }
283
284
        @Override
285
        public void launch(boolean rerun) {
286
            ap.invokeAction(
287
                command, 
288
                context
289
            );
290
        }
291
    }
292
    
293
    private static Session lastSession;
294
    
295
    public static Session newSession(@NonNull final String command, @NonNull final Lookup context) {
296
        return Session.createSession(command, context);                
297
    }
298
    
299
    public static Session getLastSession() {
300
        return lastSession;
301
    }
302
    
303
    public static void clearLastSession() {
304
        lastSession = null;
305
    }
306
    
307
    public static boolean canRelaunch() {
308
        return lastSession != null;
309
    }
310
    
311
    @NbBundle.Messages({
312
        "InvalidPlatformProjectMsg=The Java platform defined for the project is invalid. Right-click the project\nand choose a different platform using Properties | Libraries | Java Platform.\n\nInvalid platform: {0}",
313
        "InvalidPlatformProfilerMsg=The Java platform defined for profiling is invalid. Choose a different platform\nin Tools | Options | Miscellaneous | Profiler | Profiler Java Platform.\n\nInvalid platform: {0}",
314
        "FailedDetermineJavaPlatformMsg=Failed to determine version of Java platform: {0}"
315
    })
316
    private static void config(Session session) {
317
        Project project = null;
318
        if (session.project == null) {
319
            if (session.fo != null) {
320
                project = FileOwnerQuery.getOwner(session.fo);
321
            }
322
        } else {
323
            project = session.project;
324
        }
325
        if (project == null) return; // sanity check; we need project here
326
        
327
        if (ProfilingSupport.getDefault().checkProfilingInProgress()) {
328
            return;
329
        }
330
        
331
        final ProjectProfilingSupport pSupport = ProjectProfilingSupport.get(project);
332
        if (pSupport == null) {
333
            return;
334
        }
335
        
336
        final SessionSettings ss = new SessionSettings();
337
        // *** session settings setup
338
        pSupport.setupProjectSessionSettings(ss);
339
        ProfilerIDESettings gps = ProfilerIDESettings.getInstance();
340
341
        ss.setPortNo(gps.getPortNo());
342
        // ***
343
344
        // *** java platform recheck
345
        JavaPlatform platform = pSupport.getProjectJavaPlatform();
346
        final String javaFile = platform.getPlatformJavaFile();
347
348
        if (javaFile == null) {
349
            if (ProfilerIDESettings.getInstance().getJavaPlatformForProfiling() == null) {
350
                // used platform defined for project
351
                ProfilerDialogs.displayError(Bundle.InvalidPlatformProjectMsg(platform.getDisplayName()));
352
            } else {
353
                // used platform defined in Options / Profiler
354
                ProfilerDialogs.displayError(Bundle.InvalidPlatformProfilerMsg(platform.getDisplayName()));
355
            }
356
            return;
357
        }
358
359
        final String javaVersion = platform.getPlatformJDKVersion();
360
361
        if (javaVersion == null) {
362
            ProfilerDialogs.displayError(Bundle.FailedDetermineJavaPlatformMsg(platform.getDisplayName()));
363
364
            return;
365
        }
366
        
367
        session.ss = ss;
368
        session.platform = platform;
369
    }
370
    
371
    private static void setupAgentEnv(JavaPlatform platform, SessionSettings ss, ProfilerIDESettings gps, ProfilingSettings pSettings, Project project, Map<String, String> props) {
372
        String javaVersion = platform.getPlatformJDKVersion();
373
        if (javaVersion.equals(CommonConstants.JDK_15_STRING)) {
374
            // JDK 1.5 used
375
            props.put(
376
                AGENT_ARGS, 
377
                IDEUtils.getAntProfilerStartArgument15(ss.getPortNo(), ss.getSystemArchitecture())
378
            );
379
380
            if (platform.getPlatformJDKMinor() >= 7) {
381
                activateOOMProtection(gps, props, project);
382
            } else {
383
                ProfilerLogger.log("Profiler.OutOfMemoryDetection: Disabled. Not supported JVM. Use at least 1.4.2_12 or 1.5.0_07"); // NOI18N
384
            }
385
        } else if (javaVersion.equals(CommonConstants.JDK_16_STRING)) {
386
            // JDK 1.6 used
387
            props.put(
388
                AGENT_ARGS,
389
                IDEUtils.getAntProfilerStartArgument16(ss.getPortNo(), ss.getSystemArchitecture())
390
            );
391
            activateOOMProtection(gps, props, project);
392
        } else if (javaVersion.equals(CommonConstants.JDK_17_STRING)) {
393
            props.put(
394
                AGENT_ARGS,
395
                IDEUtils.getAntProfilerStartArgument17(ss.getPortNo(), ss.getSystemArchitecture())
396
            );
397
            activateOOMProtection(gps, props, project);
398
        } else if (javaVersion.equals(CommonConstants.JDK_18_STRING)) {
399
            props.put(
400
                AGENT_ARGS,
401
                IDEUtils.getAntProfilerStartArgument18(ss.getPortNo(), ss.getSystemArchitecture())
402
            );
403
            activateOOMProtection(gps, props, project);
404
        } else {
405
            throw new IllegalArgumentException("Unsupported JDK " + javaVersion); // NOI18N
406
        }
407
408
        if (Platform.isLinux() && javaVersion.equals(CommonConstants.JDK_16_STRING)) {
409
            activateLinuxPosixThreadTime(pSettings, props);
410
        }
411
        
412
        props.put("profiler.java.platform", ss.getJavaExecutable());
413
        props.put("profiler.info.project.dir", project.getProjectDirectory().getPath());
414
    }
415
    
416
    private static void activateLinuxPosixThreadTime(ProfilingSettings ps, Map<String, String> props) {
417
        if (ps.getThreadCPUTimerOn()) {
418
            props.put("profiler.info.jvmargs", LINUX_THREAD_TIMER_KEY + " " + props.get("profiler.info.jvmargs")); // NOI18N
419
            ProfilerLogger.log("Profiler.UseLinuxPosixThreadCPUClocks: Enabled"); // NOI18N
420
        }
421
    }
422
423
    private static void activateOOMProtection(ProfilerIDESettings gps, Map<String, String> props, Project project) {
424
        if (gps.isOOMDetectionEnabled()) {
425
            String oldArgs = props.get("profiler.info.jvmargs");
426
            oldArgs = (oldArgs != null) ? oldArgs : "";
427
428
            StringBuilder oomArgsBuffer = new StringBuilder(oldArgs);
429
            String heapDumpPath = getHeapDumpPath(gps, project);
430
431
            if ((heapDumpPath != null) && (heapDumpPath.length() > 0)) {
432
                // used for filesystem listener
433
                props.put(HeapDumpWatch.OOME_PROTECTION_ENABLED_KEY, "yes");
434
                props.put(HeapDumpWatch.OOME_PROTECTION_DUMPPATH_KEY, heapDumpPath);
435
436
                // used as an argument for starting java process
437
                if (heapDumpPath.contains(" ")) {
438
                    heapDumpPath = "\"" + heapDumpPath + "\"";
439
                }
440
441
                oomArgsBuffer.append(" -XX:+HeapDumpOnOutOfMemoryError"); // NOI18N
442
                oomArgsBuffer.append(" -XX:HeapDumpPath=").append(heapDumpPath).append(" "); // NOI18N
443
444
                ProfilerLogger.log("Profiler.OutOfMemoryDetection: Enabled"); // NOI18N
445
            }
446
447
            props.put("profiler.info.jvmargs", oomArgsBuffer.toString()); // NOI18N
448
        }
449
    }
450
    
451
    private static String getHeapDumpPath(ProfilerIDESettings gps, Project project) {
452
        int oomeDetectionMode = gps.getOOMDetectionMode();
453
454
        switch (oomeDetectionMode) {
455
            case ProfilerIDESettings.OOME_DETECTION_TEMPDIR:
456
                return System.getProperty("java.io.tmpdir"); // NOI18N
457
            case ProfilerIDESettings.OOME_DETECTION_PROJECTDIR:
458
459
                try {
460
                    return FileUtil.toFile(ProjectStorage.getSettingsFolder(project, true)).getAbsolutePath();
461
                } catch (IOException e) {
462
                    LOG.log(Level.WARNING, "Cannot resolve project settings directory:\n" + e.getMessage(), e);
463
                    
464
                    return null;
465
                }
466
            case ProfilerIDESettings.OOME_DETECTION_CUSTOMDIR:
467
                return gps.getCustomHeapdumpPath();
468
        }
469
470
        return null;
471
    }
472
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/ProfilerToolbarDropdownAction.java (-1 / +1 lines)
Lines 72-78 Link Here
72
    //~ Constructors -------------------------------------------------------------------------------------------------------------
72
    //~ Constructors -------------------------------------------------------------------------------------------------------------
73
73
74
    public ProfilerToolbarDropdownAction() {
74
    public ProfilerToolbarDropdownAction() {
75
        defaultAction = AntActions.profileMainProject();
75
        defaultAction = AntActions.profileMainProjectAction();
76
    }
76
    }
77
77
78
    //~ Methods ------------------------------------------------------------------------------------------------------------------
78
    //~ Methods ------------------------------------------------------------------------------------------------------------------
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/ProjectSensitiveAction.java (-436 lines)
Lines 1-436 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 * The Original Software is NetBeans. The Initial Developer of the Original
29
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30
 * Microsystems, Inc. All Rights Reserved.
31
 *
32
 * If you wish your version of this file to be governed by only the CDDL
33
 * or only the GPL Version 2, indicate your decision by adding
34
 * "[Contributor] elects to include this software in this distribution
35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36
 * single choice of license, a recipient has the option to distribute
37
 * your version of this file under either the CDDL, the GPL Version 2 or
38
 * to extend the choice of license to its licensees as provided above.
39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
40
 * Version 2 license, then the option applies only if the new code is
41
 * made subject to such option by the copyright holder.
42
 */
43
44
package org.netbeans.modules.profiler.nbimpl.actions;
45
46
import org.netbeans.api.project.FileOwnerQuery;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.ProjectUtils;
49
import org.netbeans.modules.profiler.ui.NBSwingWorker;
50
import org.netbeans.modules.profiler.ui.ProfilerProgressDisplayer;
51
import org.netbeans.modules.profiler.utilities.OutputParameter;
52
import org.netbeans.spi.project.ActionProvider;
53
import org.openide.filesystems.FileObject;
54
import org.openide.loaders.DataObject;
55
import org.openide.util.*;
56
import java.awt.event.ActionEvent;
57
import java.text.MessageFormat;
58
import java.util.Arrays;
59
import java.util.Collection;
60
import java.util.HashSet;
61
import java.util.Iterator;
62
import java.util.List;
63
import java.util.Set;
64
import javax.swing.AbstractAction;
65
import javax.swing.Action;
66
import javax.swing.Icon;
67
import org.netbeans.modules.profiler.api.ProfilerDialogs;
68
import org.netbeans.lib.profiler.common.CommonUtils;
69
import org.netbeans.modules.profiler.api.ProgressDisplayer;
70
71
72
/**
73
 * Action sensitive to current project
74
 *
75
 * @author Ian Formanek
76
 */
77
public class ProjectSensitiveAction extends AbstractAction implements ContextAwareAction, LookupListener {
78
    //~ Inner Interfaces ---------------------------------------------------------------------------------------------------------
79
80
    public interface ProfilerProjectActionPerformer {
81
        //~ Methods --------------------------------------------------------------------------------------------------------------
82
83
        /**
84
         * Called when the context of the action changes and the action should
85
         * be enabled or disabled within the new context, according to the newly
86
         * selected project.
87
         *
88
         * @param project the currently selected project, or null if no project is selected
89
         * @return true to enable the action, false to disable it
90
         */
91
        public boolean enable(Project project, Lookup context, boolean lightweightOnly);
92
93
        /**
94
         * Called when the user invokes the action.
95
         *
96
         * @param project the project this action was invoked for (XXX can this be null or not?)
97
         * @throws IllegalStateException when trying to perform the action in an illegal context
98
         */
99
        public void perform(Project project, Lookup context);
100
    }
101
102
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
103
104
    public static final class ActionsUtil {
105
        //~ Methods --------------------------------------------------------------------------------------------------------------
106
107
        /**
108
         * In given lookup will find all FileObjects owned by given project
109
         * with given command supported.
110
         */
111
        public static FileObject[] getFilesFromLookup(final Lookup lookup, final Project project) {
112
            final HashSet result = new HashSet();
113
            final Collection dataObjects = lookup.lookup(new Lookup.Template(DataObject.class)).allInstances();
114
115
            for (Iterator it = dataObjects.iterator(); it.hasNext();) {
116
                final DataObject dObj = (DataObject) it.next();
117
                final FileObject fObj = dObj.getPrimaryFile();
118
                final Project p = FileOwnerQuery.getOwner(fObj);
119
120
                if ((p != null) && p.equals(project)) {
121
                    result.add(fObj);
122
                }
123
            }
124
125
            final FileObject[] fos = new FileObject[result.size()];
126
            result.toArray(fos);
127
128
            return fos;
129
        }
130
131
        /**
132
         * Finds all projects in given lookup. If the command is not null it will check
133
         * whether given command is enabled on all projects. If and only if all projects
134
         * have the command supported it will return array including the project. If there
135
         * is one project with the command disabled it will return empty array.
136
         */
137
        public static Project[] getProjectsFromLookup(final Lookup lookup, final String command) {
138
            final Set result = new HashSet();
139
140
            // First find out whether there is a project directly in the Lookup
141
            final Collection projects = lookup.lookup(new Lookup.Template(Project.class)).allInstances();
142
143
            for (Iterator it = projects.iterator(); it.hasNext();) {
144
                final Project p = (Project) it.next();
145
                result.add(p);
146
            }
147
148
            // Now try to guess the project from dataobjects
149
            final Collection dataObjects = lookup.lookup(new Lookup.Template(DataObject.class)).allInstances();
150
151
            for (Iterator it = dataObjects.iterator(); it.hasNext();) {
152
                final DataObject dObj = (DataObject) it.next();
153
                final FileObject fObj = dObj.getPrimaryFile();
154
                final Project p = FileOwnerQuery.getOwner(fObj);
155
156
                if (p != null) {
157
                    result.add(p);
158
                }
159
            }
160
161
            final Project[] projectsArray = new Project[result.size()];
162
            result.toArray(projectsArray);
163
164
            if (command != null) {
165
                // All projects have to have the command enabled
166
                for (int i = 0; i < projectsArray.length; i++) {
167
                    if (!commandSupported(projectsArray[i], command, lookup)) {
168
                        return new Project[0];
169
                    }
170
                }
171
            }
172
173
            return projectsArray;
174
        }
175
176
        /**
177
         * Tests whether given command is available on the project and whether
178
         * the action as to be enabled in current Context
179
         *
180
         * @param project Project to test
181
         * @param command Command for test
182
         * @param context Lookup representing current context or null if context
183
         *                does not matter.
184
         */
185
        public static boolean commandSupported(final Project project, final String command, final Lookup context) {
186
            //We have to look whether the command is supported by the project
187
            final ActionProvider ap = (ActionProvider) project.getLookup().lookup(ActionProvider.class);
188
189
            if (ap != null) {
190
                final List commands = Arrays.asList(ap.getSupportedActions());
191
192
                if (commands.contains(command)) {
193
                    if ((context == null) || ap.isActionEnabled(command, context)) {
194
                        return true;
195
                    }
196
                }
197
            }
198
199
            return false;
200
        }
201
202
        /**
203
         * Good for formating names of actions with some two parameter pattern
204
         * {0} nuber of objects (e.g. Projects or files ) and {1} name of one
205
         * or first object (e.g. Project or file) or null if the number is == 0
206
         */
207
        public static String formatName(final String namePattern, final int numberOfObjects, final String firstObjectName) {
208
            return MessageFormat.format(namePattern,
209
                                        new Object[] {
210
                                            Integer.valueOf(numberOfObjects), (firstObjectName == null) ? "" : firstObjectName, //NOI18N
211
                                        });
212
        }
213
214
        public static String formatProjectSensitiveName(final String namePattern, final Project[] projects) {
215
            // Set the action's name
216
            if ((projects == null) || (projects.length == 0)) {
217
                // No project selected
218
                return ActionsUtil.formatName(namePattern, 0, null);
219
            } else {
220
                // Some project selected
221
                return ActionsUtil.formatName(namePattern, projects.length,
222
                                              ProjectUtils.getInformation(projects[0]).getDisplayName());
223
            }
224
        }
225
    }
226
227
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
228
229
    protected volatile boolean actionEnabled = false;
230
    private final Lookup lookup;
231
    private final Object initLock = new Object();
232
    private final Object refreshRequestLock = new Object();
233
    private final ProfilerProjectActionPerformer performer;
234
    private final String namePattern;
235
    private final Lookup.Result[] results;
236
    private final Class[] watch;
237
238
    // @GuarderBy initLock
239
    private volatile boolean isCalculated = false;
240
241
    // @GuardedBy refreshRequestLock
242
    private int refreshRequested = 0;
243
244
    //~ Constructors -------------------------------------------------------------------------------------------------------------
245
246
    /**
247
     * Constructor for global actions. E.g. actions in main menu which
248
     * listen to the global context.
249
     */
250
    ProjectSensitiveAction(final ProfilerProjectActionPerformer performer, final String name, final String namePattern,
251
                           final Icon icon, Lookup lookup) {
252
        super(name);
253
254
        if (icon != null) {
255
            putValue(SMALL_ICON, icon);
256
        }
257
258
        if (lookup == null) {
259
            lookup = Utilities.actionsGlobalContext();
260
        }
261
262
        this.lookup = lookup;
263
        this.watch = new Class[] { Project.class, DataObject.class };
264
        this.results = new Lookup.Result[watch.length];
265
266
        // Needs to listen on changes in results
267
        for (int i = 0; i < watch.length; i++) {
268
            final Lookup.Result result = lookup.lookup(new Lookup.Template(watch[i]));
269
            // #147348 - Action instance is probobly only weakly held; we must add the strong reference to lookup listener
270
//            resultListeners[i] = (LookupListener) WeakListeners.create(LookupListener.class, this, result);
271
//            result.addLookupListener(resultListeners[i]);
272
            result.addLookupListener(this);
273
            // MUST hold on the reference to the result; otherwise it will vanish in a puff of smoke
274
            results[i] = result;
275
        }
276
277
        this.performer = performer;
278
        this.namePattern = namePattern;
279
280
        init();
281
    }
282
283
    //~ Methods ------------------------------------------------------------------------------------------------------------------
284
285
    /**
286
     * Needs to override isEnabled in order to force refresh
287
     */
288
    public final boolean isEnabled() {
289
        init(); // the action must be initialized
290
291
        return super.isEnabled();
292
    }
293
294
    public final void actionPerformed(final ActionEvent e) {
295
        actionPerformed(lookup);
296
    }
297
298
    public static ProjectSensitiveAction projectSensitiveAction(final ProfilerProjectActionPerformer performer,
299
                                                                final String name, final String namePattern, final Icon icon) {
300
        return new ProjectSensitiveAction(performer, name, namePattern, icon, null);
301
    }
302
303
    // Implementation of ContextAwareAction ------------------------------------
304
    public Action createContextAwareInstance(final Lookup actionContext) {
305
        return new ProjectSensitiveAction(getPerformer(), getName(), getNamePattern(), (Icon) getValue(SMALL_ICON), actionContext);
306
    }
307
308
    // Implementation of LookupListener ----------------------------------------
309
    public final void resultChanged(final LookupEvent e) {
310
        isCalculated = false;
311
    }
312
313
    protected final void setDisplayName(final String name) {
314
        putValue(NAME, name);
315
    }
316
317
    protected final String getName() {
318
        return (String) getValue(NAME);
319
    }
320
321
    protected final String getNamePattern() {
322
        return namePattern;
323
    }
324
325
    protected final ProfilerProjectActionPerformer getPerformer() {
326
        return performer;
327
    }
328
329
    protected void actionPerformed(final Lookup context) {
330
        final Project[] projects = ActionsUtil.getProjectsFromLookup(context, null);
331
332
        if (projects.length == 1) {
333
            if (performer != null) {
334
                new NBSwingWorker(false) {
335
                        private boolean isEnabled = false;
336
                        private final OutputParameter<Boolean> isCancelled = new OutputParameter<Boolean>(Boolean.FALSE);
337
                        private final OutputParameter<ProgressDisplayer> progress = new OutputParameter<ProgressDisplayer>(null);
338
339
                        protected void doInBackground() {
340
                            isEnabled = performer.enable(projects[0], context, false);
341
                        }
342
343
                        protected void done() {
344
                            if (progress.isSet()) {
345
                                progress.getValue().close();
346
                            }
347
348
                            if (isEnabled && !isCancelled.getValue()) {
349
                                performer.perform(projects[0], context);
350
                            } else if (!isCancelled.getValue()) {
351
                                ProfilerDialogs.displayInfo(NbBundle.getMessage(ProjectSensitiveAction.class, "AntActions_LazyEnablementFailure")); // NOI18N
352
                            }
353
                        }
354
355
                        protected void nonResponding() {
356
                            progress.setValue(ProfilerProgressDisplayer.getDefault().showProgress(
357
                                    java.util.ResourceBundle.getBundle("org/netbeans/modules/profiler/actions/Bundle") // NOI18N
358
                                        .getString("AntActions_LazyEnablementProgressMessage"), // NOI18N
359
                                    new ProgressDisplayer.ProgressController() {
360
                                    public boolean cancel() {
361
                                        if (progress.isSet()) {
362
                                            progress.getValue().close();
363
                                        }
364
365
                                        progress.setValue(null);
366
                                        isCancelled.setValue(true);
367
368
                                        return true;
369
                                    }
370
                                }));
371
                        }
372
                    }.execute();
373
            }
374
        }
375
    }
376
377
    protected void doRefresh(final Lookup context) {
378
        final Project[] projects = ActionsUtil.getProjectsFromLookup(context, null);
379
380
        setDisplayName(ActionsUtil.formatProjectSensitiveName(getNamePattern(), projects));
381
382
        if ((projects != null) && (projects.length == 1)) { // must be selected single project
383
            setEnabled(getPerformer().enable(projects[0], context, true));
384
        } else {
385
            setEnabled(false);
386
        }
387
    }
388
389
    /**
390
     * Initializes the action
391
     */
392
    private void init() {
393
        if (isCalculated) {
394
            return;
395
        }
396
397
        synchronized (initLock) {
398
            if (isCalculated) {
399
                return;
400
            }
401
402
            refresh(ProjectSensitiveAction.this.lookup);
403
            isCalculated = true;
404
        }
405
    }
406
407
    private void refresh(final Lookup context) {
408
        synchronized (refreshRequestLock) {
409
            if (refreshRequested++ > 0) {
410
                return;
411
            }
412
413
            CommonUtils.runInEventDispatchThread(new Runnable() {
414
                    public void run() {
415
                        int oldReqCount = -1;
416
                        int currentReqCount = -1;
417
418
                        synchronized (refreshRequestLock) {
419
                            oldReqCount = refreshRequested;
420
                        }
421
422
                        doRefresh(lookup);
423
424
                        synchronized (refreshRequestLock) {
425
                            currentReqCount = refreshRequested;
426
                            refreshRequested = 0;
427
                        }
428
429
                        if (oldReqCount != currentReqCount) {
430
                            refresh(context);
431
                        }
432
                    }
433
                });
434
        }
435
    }
436
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/actions/ProjectSensitivePerformer.java (+97 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.profiler.nbimpl.actions;
43
44
import org.netbeans.api.project.Project;
45
import org.netbeans.lib.profiler.common.Profiler;
46
import org.netbeans.modules.profiler.api.project.ProjectProfilingSupport;
47
import org.netbeans.modules.profiler.nbimpl.NetBeansProfiler;
48
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher.Session;
49
import org.netbeans.spi.project.ActionProvider;
50
import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
51
import org.openide.util.Lookup;
52
import org.openide.util.lookup.Lookups;
53
import org.openide.util.lookup.ProxyLookup;
54
55
/**
56
 *
57
 * @author Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
58
 */
59
public class ProjectSensitivePerformer implements ProjectActionPerformer {
60
    final private String command;
61
    
62
    public ProjectSensitivePerformer(String command) {
63
        this.command = command;
64
    }
65
    
66
    @Override
67
    public boolean enable(Project project) {
68
        if (project == null) return false;
69
70
        ActionProvider ap = project.getLookup().lookup(ActionProvider.class);
71
        try {
72
            if (ap != null && ap.isActionEnabled(command, project.getLookup())) {
73
                ProjectProfilingSupport ppp = ProjectProfilingSupport.get(project);
74
                if (ppp == null) {
75
                    return false;
76
                }
77
                return ppp.isProfilingSupported();
78
            }
79
        } catch (IllegalArgumentException e) {
80
            // no provider responds to the command
81
        }
82
        return false;
83
    }
84
85
    @Override
86
    public void perform(final Project project) {
87
        final ActionProvider ap = project.getLookup().lookup(ActionProvider.class);
88
        if (ap != null) {
89
            Lookup ctx = new ProxyLookup(project.getLookup(), Lookups.fixed(project));
90
            
91
            Session s = ProfilerLauncher.newSession(command, ctx);
92
            if (s != null) {
93
                s.run();
94
            }
95
        }
96
    }
97
}
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/layer.xml (-106 lines)
Lines 57-134 Link Here
57
            </folder>
57
            </folder>
58
        </folder>
58
        </folder>
59
    </folder>
59
    </folder>
60
    
61
    <folder name="Projects">
62
        <folder name="Profiler_Actions_temporary">
63
            <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.shadow">
64
                <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.instance"/>
65
            </file>
66
        </folder>
67
    </folder>
68
69
    <folder name="Loaders">
70
        <folder name="text">
71
            <folder name="x-java">
72
                <folder name="Actions">
73
                    <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.shadow">
74
                        <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.instance"/>
75
                        <attr name="position" intvalue="1200"/>
76
                    </file>
77
                </folder>
78
            </folder>
79
            <folder name="x-jsp">
80
                <folder name="Actions">
81
                    <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.shadow">
82
                        <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.instance"/>
83
                        <attr name="position" intvalue="800"/>
84
                    </file>
85
                </folder>
86
            </folder>
87
            <folder name="x-fx">
88
                <folder name="Actions">
89
                    <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.shadow">
90
                        <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.instance"/>
91
                        <attr name="position" intvalue="660"/>
92
                    </file>
93
                </folder>
94
            </folder>
95
        </folder>
96
    </folder>
97
98
    <folder name="Menu">
99
        <folder name="Profile">
100
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileMainProjectAction.shadow">
101
                <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileMainProjectAction.instance"/>
102
                <attr name="position" intvalue="100"/>
103
            </file>
104
            <folder name="ProfileOther">
105
                <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.profiler.nbimpl.actions.Bundle"/>
106
                <attr name="position" intvalue="300"/>
107
                <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileProjectAction.shadow">
108
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileProjectAction.instance"/>
109
                    <attr name="position" intvalue="100"/>
110
                </file>
111
                <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleAction.shadow">
112
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleAction.instance"/>
113
                    <attr name="position" intvalue="200"/>
114
                </file>
115
                <attr boolvalue="true" name="org-netbeans-modules-profiler-nbimpl-actions-ProfileProjectAction.instance"/>
116
                <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileTestAction.shadow">
117
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileTestAction.instance"/>
118
                    <attr name="position" intvalue="300"/>
119
                </file>
120
            </folder>
121
            <folder name="Advanced">
122
                <file name="org-netbeans-modules-profiler-nbimpl-actions-UnintegrateProfilerAction.shadow">
123
                    <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.unintegrateProfiler"/>
124
                    <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-UnintegrateProfilerAction.instance"/>
125
                    <attr name="position" intvalue="500"/>
126
                </file>
127
            </folder>
128
129
            <attr boolvalue="true" name="org-netbeans-modules-profiler-nbimpl-actions-ProfileMainProjectAction.instance"/>
130
        </folder>
131
    </folder>
132
60
133
    <folder name="Toolbars">
61
    <folder name="Toolbars">
134
        <folder name="Build">
62
        <folder name="Build">
Lines 138-175 Link Here
138
            </file>
66
            </file>
139
        </folder>
67
        </folder>
140
    </folder>
68
    </folder>
141
142
    <folder name="Shortcuts">
143
        <file name="A-F2.shadow">
144
            <attr name="originalFile" stringvalue="Actions/Profile/org-netbeans-modules-profiler-nbimpl-actions-ProfileMainProjectAction.instance"/>
145
        </file>
146
    </folder>
147
148
    <folder name="Actions">
149
        <folder name="Profile">
150
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleAction.instance">
151
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileSingle"/>
152
            </file>
153
            <!-- XXX impl is nearly the same, really just different label... should probably share an Action instance -->
154
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileSingleActionPopup.instance">
155
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileSinglePopup"/>
156
            </file>
157
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileTestAction.instance">
158
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileTest"/>
159
            </file>
160
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileProjectAction.instance">
161
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileProject"/>
162
            </file>
163
            <file name="org-netbeans-modules-profiler-nbimpl-actions-ProfileMainProjectAction.instance">
164
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileMainProject"/>
165
            </file>
166
            <file name="org-netbeans-modules-profiler-actions-ProfileProjectActionPopup.instance">
167
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.profileProjectPopup"/>
168
            </file>
169
            <file name="org-netbeans-modules-profiler-nbimpl-actions-UnintegrateProfilerAction.instance">
170
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.profiler.nbimpl.actions.AntActions.unintegrateProfiler"/>
171
            </file>
172
        </folder>
173
    </folder>
174
175
</filesystem>
69
</filesystem>
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/project/JavaProjectProfilingSupportProvider.java (-2 / +82 lines)
Lines 42-50 Link Here
42
package org.netbeans.modules.profiler.nbimpl.project;
42
package org.netbeans.modules.profiler.nbimpl.project;
43
43
44
import org.netbeans.api.project.Project;
44
import org.netbeans.api.project.Project;
45
import org.netbeans.lib.profiler.common.SessionSettings;
46
import org.netbeans.lib.profiler.utils.MiscUtils;
47
import org.netbeans.modules.profiler.actions.JavaPlatformSelector;
48
import org.netbeans.modules.profiler.api.JavaPlatform;
49
import org.netbeans.modules.profiler.api.ProfilerDialogs;
50
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
45
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
51
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
46
import org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider;
52
import org.netbeans.modules.profiler.spi.project.ProjectProfilingSupportProvider;
47
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
54
import org.openide.util.NbBundle;
48
55
49
/**
56
/**
50
 *
57
 *
Lines 53-59 Link Here
53
public abstract class JavaProjectProfilingSupportProvider extends ProjectProfilingSupportProvider.Basic {
60
public abstract class JavaProjectProfilingSupportProvider extends ProjectProfilingSupportProvider.Basic {
54
    
61
    
55
    private final Project project;
62
    private final Project project;
56
    
63
    private JavaPlatform projectJavaPlatform = null;
57
    
64
    
58
    @Override
65
    @Override
59
    public boolean isProfilingSupported() {
66
    public boolean isProfilingSupported() {
Lines 74-80 Link Here
74
    
81
    
75
    @Override
82
    @Override
76
    public boolean checkProjectCanBeProfiled(FileObject profiledClassFile) {
83
    public boolean checkProjectCanBeProfiled(FileObject profiledClassFile) {
77
        return true;
84
        return getProjectJavaPlatform() != null;
85
    }
86
87
    @Override
88
    public void setupProjectSessionSettings(SessionSettings ss) {
89
        JavaPlatform platform = getProjectJavaPlatform();
90
        
91
        ss.setSystemArchitecture(platform.getPlatformArchitecture());
92
        ss.setJavaVersionString(platform.getPlatformJDKVersion());
93
        ss.setJavaExecutable(platform.getPlatformJavaFile());
94
    }
95
96
    @Override
97
    @NbBundle.Messages({
98
        "IncorrectJavaSpecVersionDialogCaption=Warning",
99
        "IncorrectJavaSpecVersionDialogMsg=The specification version of project Java Platform is greater than specification version of the\nplatform that will be used for profiling. You may experience problems unless you set the compiler\nparameter to generate bytecode compatible with the platform that will be used.\n\nDo you want to continue with the current settings?"
100
    })
101
    final synchronized public JavaPlatform getProjectJavaPlatform() {
102
        if (projectJavaPlatform == null) {
103
            // 1. check if we have a Java platform to use for profiling
104
            final ProfilerIDESettings gps = ProfilerIDESettings.getInstance();
105
            JavaPlatform platform = JavaPlatform.getJavaPlatformById(gps.getJavaPlatformForProfiling());
106
            projectJavaPlatform = resolveProjectJavaPlatform();
107
108
            if (platform == null) { // should use the one defined in project
109
                platform = projectJavaPlatform;
110
111
                if ((platform == null) || !MiscUtils.isSupportedJVM(platform.getSystemProperties())) {
112
                    platform = JavaPlatformSelector.getDefault().selectPlatformToUse();
113
114
                    if (platform == null) {
115
                        return null;
116
                    }
117
                    projectJavaPlatform = platform;
118
                }
119
            }
120
121
            if (projectJavaPlatform != null) { // check that the project platform is not newer than platform to use
122
123
                while (true) {
124
                    if (projectJavaPlatform.getVersion().compareTo(platform.getVersion()) > 0) {
125
                        Boolean ret = ProfilerDialogs.displayCancellableConfirmation(
126
                                Bundle.IncorrectJavaSpecVersionDialogMsg(),
127
                                Bundle.IncorrectJavaSpecVersionDialogCaption());
128
129
                        if (Boolean.TRUE.equals(ret)) {
130
                            break;
131
                        } else if (Boolean.FALSE.equals(ret)) {
132
                            platform = JavaPlatformSelector.getDefault().selectPlatformToUse();
133
134
                            if (platform == null) {
135
                                return null; // cancelled by the user
136
                            }
137
                        } else { // cancelled
138
139
                            return null;
140
                        }
141
                    } else {
142
                        break; // version comparison OK.
143
                    }
144
                }
145
            }
146
        }
147
        return projectJavaPlatform;
148
    }
149
    
150
    abstract protected JavaPlatform resolveProjectJavaPlatform();
151
    
152
    protected final JavaPlatform getPlatformByName(String platformName) {
153
        if (platformName == null || platformName.equals("default_platform")) { // NOI18N
154
            return JavaPlatform.getDefaultPlatform(); 
155
        }
156
157
        return JavaPlatform.getJavaPlatformById(platformName);
78
    }
158
    }
79
    
159
    
80
    protected final Project getProject() {
160
    protected final Project getProject() {
(-)a/profiler.nbimpl/src/org/netbeans/modules/profiler/nbimpl/providers/DefaultProfilerArgsProvider.java (+92 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.profiler.nbimpl.providers;
43
44
import java.util.*;
45
import org.netbeans.api.extexecution.startup.StartupExtender;
46
import org.netbeans.api.extexecution.startup.StartupExtender.StartMode;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.modules.profiler.nbimpl.actions.ProfilerLauncher;
49
import org.netbeans.spi.extexecution.startup.StartupExtenderImplementation;
50
import org.openide.util.Lookup;
51
import org.openide.util.NbBundle;
52
53
/**
54
 *
55
 * @author Jaroslav Bachorik
56
 */
57
@NbBundle.Messages({
58
    "DESC_NBProfiler=NetBeans Profiler"
59
})
60
@StartupExtenderImplementation.Registration(displayName="#DESC_NBProfiler", position=1000, startMode={
61
    StartupExtender.StartMode.PROFILE,
62
    StartupExtender.StartMode.TEST_PROFILE
63
})
64
public class DefaultProfilerArgsProvider implements StartupExtenderImplementation {
65
    @Override
66
    public List<String> getArguments(Lookup context, StartMode mode) {
67
        Project p = context.lookup(Project.class);
68
        if (p != null) {
69
            ProfilerLauncher.Session s = ProfilerLauncher.getLastSession();
70
            if (s != null) {
71
                Map<String, String> m = ProfilerLauncher.getLastSession().getProperties();
72
                if (m != null) {
73
                    String agentArgs = m.get("agent.jvmargs");
74
                    String jvmargs = m.get("profiler.info.jvmargs");
75
                    jvmargs = jvmargs.replace(" -", "^");
76
                    StringTokenizer st = new StringTokenizer(jvmargs, "^");
77
                    
78
                    List<String> args = new ArrayList<String>();
79
                    args.add(agentArgs);
80
                    while (st.hasMoreTokens()) {
81
                        String arg = st.nextToken();
82
                        if (!arg.isEmpty()) {
83
                            args.add((arg.startsWith("-") ? "" : "-") + arg);
84
                        }
85
                    }
86
                    return args;
87
                }
88
            }
89
        }
90
        return Collections.EMPTY_LIST;
91
    }
92
}
(-)a/profiler.nbmodule/src/org/netbeans/modules/profiler/nbmodule/NbModuleProjectProfilingSupportProvider.java (-8 / +20 lines)
Lines 52-63 Link Here
52
import org.openide.util.Utilities;
52
import org.openide.util.Utilities;
53
import org.w3c.dom.Element;
53
import org.w3c.dom.Element;
54
import java.util.List;
54
import java.util.List;
55
import java.util.Properties;
55
import java.util.Map;
56
import java.util.Set;
56
import java.util.Set;
57
import org.netbeans.api.java.platform.JavaPlatformManager;
57
import org.netbeans.api.java.platform.JavaPlatformManager;
58
import org.netbeans.api.java.platform.Specification;
58
import org.netbeans.api.java.platform.Specification;
59
import org.netbeans.api.project.ProjectUtils;
59
import org.netbeans.api.project.ProjectUtils;
60
import org.netbeans.lib.profiler.common.Profiler;
60
import org.netbeans.lib.profiler.common.Profiler;
61
import org.netbeans.lib.profiler.common.SessionSettings;
61
import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
62
import org.netbeans.lib.profiler.common.integration.IntegrationUtils;
62
import org.netbeans.modules.profiler.api.JavaPlatform;
63
import org.netbeans.modules.profiler.api.JavaPlatform;
63
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
64
import org.netbeans.modules.profiler.api.java.JavaProfilerSource;
Lines 102-108 Link Here
102
    }
103
    }
103
104
104
    @Override
105
    @Override
105
    public JavaPlatform getProjectJavaPlatform() {
106
    public JavaPlatform resolveProjectJavaPlatform() {
106
        return getProjectJavaPlatform(getProject());
107
        return getProjectJavaPlatform(getProject());
107
    }
108
    }
108
    
109
    
Lines 173-204 Link Here
173
    }
174
    }
174
175
175
    @Override
176
    @Override
176
    public void configurePropertiesForProfiling(final Properties props, final FileObject profiledClassFile) {
177
    public void configurePropertiesForProfiling(final Map<String, String> props, final FileObject profiledClassFile) {
177
        // FIXME
178
        // FIXME
178
        JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
179
        JavaProfilerSource src = JavaProfilerSource.createFrom(profiledClassFile);
179
        if (src != null) {
180
        if (src != null) {
180
            final String profiledClass = src.getTopLevelClass().getQualifiedName();
181
            final String profiledClass = src.getTopLevelClass().getQualifiedName();
181
            props.setProperty("profile.class", profiledClass); //NOI18N
182
            props.put("profile.class", profiledClass); //NOI18N
182
            // Set for all cases (incl. Profile Project, Profile File) but should only
183
            // Set for all cases (incl. Profile Project, Profile File) but should only
183
            // be taken into account when profiling single test
184
            // be taken into account when profiling single test
184
            props.setProperty("test.type", getTestType(profiledClassFile)); //NOI18N
185
            props.put("test.type", getTestType(profiledClassFile)); //NOI18N
185
        }
186
        }
186
        
187
        
187
        String agentArg = props.getProperty("profiler.info.jvmargs.agent"); //NOI18N
188
        String agentArg = props.get("agent.jvmargs"); //NOI18N
188
        if (agentArg.indexOf(' ') != -1) { //NOI18N
189
        if (agentArg.indexOf(' ') != -1) { //NOI18N
189
            if (Utilities.isUnix()) {
190
            if (Utilities.isUnix()) {
190
                // Profiler is installed in directory with space on Unix (Linux, Solaris, Mac OS X)
191
                // Profiler is installed in directory with space on Unix (Linux, Solaris, Mac OS X)
191
                // create temporary link in /tmp directory and use it instead of directory with space
192
                // create temporary link in /tmp directory and use it instead of directory with space
192
                String libsDir = Profiler.getDefault().getLibsDir();
193
                String libsDir = Profiler.getDefault().getLibsDir();
193
                props.setProperty("profiler.info.jvmargs.agent", IntegrationUtils.fixLibsDirPath(libsDir, agentArg)); //NOI18N
194
                props.put("agent.jvmargs", IntegrationUtils.fixLibsDirPath(libsDir, agentArg)); //NOI18N
194
            } else if (Utilities.isWindows() && isNbSourceModule(getProject())) {
195
            } else if (Utilities.isWindows() && isNbSourceModule(getProject())) {
195
                // Profiler is installed in directory with space on Windows
196
                // Profiler is installed in directory with space on Windows
196
                // surround the whole -agentpath argument with quotes for NB source module
197
                // surround the whole -agentpath argument with quotes for NB source module
197
                agentArg = "\"" + agentArg + "\""; //NOI18N
198
                agentArg = "\"" + agentArg + "\""; //NOI18N
198
                props.setProperty("profiler.info.jvmargs.agent", agentArg); //NOI18N
199
                props.put("agent.jvmargs", agentArg); //NOI18N
199
            }
200
            }
200
        }
201
        }
201
    }
202
    }
203
204
    @Override
205
    public void setupProjectSessionSettings(SessionSettings ss) {
206
        JavaPlatform platform = getProjectJavaPlatform();
207
        
208
        ss.setSystemArchitecture(platform.getPlatformArchitecture());
209
        ss.setJavaVersionString(platform.getPlatformJDKVersion());
210
        ss.setJavaExecutable(platform.getPlatformJavaFile());
211
    }
212
    
213
    
202
    
214
    
203
    /**
215
    /**
204
     * Returns true if the provided Project is a NB source module, false otherwise.
216
     * Returns true if the provided Project is a NB source module, false otherwise.
(-)a/profiler.stp/src/org/netbeans/modules/profiler/stp/SelectProfilingTask.java (-21 / +34 lines)
Lines 78-83 Link Here
78
import javax.swing.SwingConstants;
78
import javax.swing.SwingConstants;
79
import javax.swing.SwingUtilities;
79
import javax.swing.SwingUtilities;
80
import javax.swing.event.ChangeListener;
80
import javax.swing.event.ChangeListener;
81
import org.netbeans.api.progress.ProgressUtils;
81
import org.netbeans.lib.profiler.common.CommonUtils;
82
import org.netbeans.lib.profiler.common.CommonUtils;
82
import org.netbeans.lib.profiler.ui.UIUtils;
83
import org.netbeans.lib.profiler.ui.UIUtils;
83
import org.netbeans.modules.profiler.api.ProfilerDialogs;
84
import org.netbeans.modules.profiler.api.ProfilerDialogs;
Lines 258-269 Link Here
258
        initClosedProjectHook();
259
        initClosedProjectHook();
259
        initComponents();
260
        initComponents();
260
        initTasks();
261
        initTasks();
261
        SwingUtilities.invokeLater(new Runnable() {
262
        Runnable r = new Runnable() {
262
                public void run() {
263
            public void run() {
263
                    initTaskChooserSize();
264
                initTaskChooserSize();
264
                    initPreferredSize();
265
                initPreferredSize();
265
                }
266
            }
266
            });
267
        };
268
        if (SwingUtilities.isEventDispatchThread()) {
269
            r.run();
270
        } else {
271
            SwingUtilities.invokeLater(r);
272
        }
267
    }
273
    }
268
    
274
    
269
    private static void initColors() {
275
    private static void initColors() {
Lines 383-420 Link Here
383
    }
389
    }
384
390
385
    // --- Public interface ------------------------------------------------------
391
    // --- Public interface ------------------------------------------------------
386
    public static Configuration selectProfileProjectTask(Lookup.Provider project, FileObject profiledFile, boolean enableOverride) {
392
    public static Configuration selectProfileProjectTask(final Lookup.Provider project, final FileObject profiledFile, final boolean enableOverride) {
387
        // Running this code in EDT would cause deadlock
393
        // Running this code in EDT would cause deadlock
388
        assert !SwingUtilities.isEventDispatchThread();
394
//        assert !SwingUtilities.isEventDispatchThread();
389
        
395
        
390
        final SelectProfilingTask spt = getDefault();
396
        final SelectProfilingTask[] spt = new SelectProfilingTask[1];
391
        spt.setSubmitButton(spt.runButton);
392
        spt.setupProfileProject(project, profiledFile, enableOverride);
393
394
        String targetName = Utils.getProjectName(project) + ((profiledFile == null) ? "" : (": " + profiledFile.getNameExt())); // NOI18N
395
        spt.dd = new DialogDescriptor(spt, Bundle.SelectProfilingTask_ProfileDialogCaption(targetName), true,
396
                                      new Object[] { spt.runButton, spt.cancelButton }, spt.runButton, 0, null, null);
397
397
398
        final CountDownLatch latch = new CountDownLatch(1);
398
        final CountDownLatch latch = new CountDownLatch(1);
399
399
400
        SwingUtilities.invokeLater(new Runnable() {
400
        Runnable r = new Runnable() {
401
401
402
            public void run() {
402
            public void run() {
403
                Dialog d = DialogDisplayer.getDefault().createDialog(spt.dd);
403
                spt[0] = getDefault();
404
                spt[0].setSubmitButton(spt[0].runButton);
405
                spt[0].setupProfileProject(project, profiledFile, enableOverride);
406
407
                String targetName = Utils.getProjectName(project) + ((profiledFile == null) ? "" : (": " + profiledFile.getNameExt())); // NOI18N
408
                spt[0].dd = new DialogDescriptor(spt, Bundle.SelectProfilingTask_ProfileDialogCaption(targetName), true,
409
                                            new Object[] { spt[0].runButton, spt[0].cancelButton }, spt[0].runButton, 0, null, null);
410
                Dialog d = DialogDisplayer.getDefault().createDialog(spt[0].dd);
404
                d.getAccessibleContext().setAccessibleDescription(d.getTitle());
411
                d.getAccessibleContext().setAccessibleDescription(d.getTitle());
405
                d.pack();
412
                d.pack();
406
                d.setVisible(true);
413
                d.setVisible(true);
407
                latch.countDown();
414
                latch.countDown();
408
            }
415
            }
409
        });
416
        };
417
418
        if (SwingUtilities.isEventDispatchThread()) {
419
            r.run();
420
        } else {
421
            SwingUtilities.invokeLater(r);
422
        }
410
423
411
        try {
424
        try {
412
            latch.await();
425
            latch.await();
413
426
414
            Configuration result = null;
427
            Configuration result = null;
415
428
416
            if (spt.dd.getValue() == spt.runButton) {
429
            if (spt[0].dd.getValue() == spt[0].runButton) {
417
                ProfilingSettings settings = spt.createFinalSettings();
430
                ProfilingSettings settings = spt[0].createFinalSettings();
418
                if (settings.getOverrideGlobalSettings()) {
431
                if (settings.getOverrideGlobalSettings()) {
419
                    String workDir = settings.getWorkingDir().trim();
432
                    String workDir = settings.getWorkingDir().trim();
420
                    if (workDir.length() != 0 && !new java.io.File(workDir).exists()) {
433
                    if (workDir.length() != 0 && !new java.io.File(workDir).exists()) {
Lines 427-433 Link Here
427
                
440
                
428
            }
441
            }
429
            
442
            
430
            spt.cleanup(result != null);
443
            spt[0].cleanup(result != null);
431
            
444
            
432
            return result;
445
            return result;
433
        } catch (InterruptedException e) {
446
        } catch (InterruptedException e) {
(-)a/profiler/nbproject/project.xml (+1 lines)
Lines 289-294 Link Here
289
                <friend>org.netbeans.modules.profiler.freeform</friend>
289
                <friend>org.netbeans.modules.profiler.freeform</friend>
290
                <friend>org.netbeans.modules.profiler.heapwalker</friend>
290
                <friend>org.netbeans.modules.profiler.heapwalker</friend>
291
                <friend>org.netbeans.modules.profiler.j2ee</friend>
291
                <friend>org.netbeans.modules.profiler.j2ee</friend>
292
                <friend>org.netbeans.modules.profiler.j2se</friend>
292
                <friend>org.netbeans.modules.profiler.nbimpl</friend>
293
                <friend>org.netbeans.modules.profiler.nbimpl</friend>
293
                <friend>org.netbeans.modules.profiler.ppoints</friend>
294
                <friend>org.netbeans.modules.profiler.ppoints</friend>
294
                <friend>org.netbeans.modules.profiler.snaptracer</friend>
295
                <friend>org.netbeans.modules.profiler.snaptracer</friend>
(-)a/profiler/src/org/netbeans/modules/profiler/NetBeansProfiler.java (-2 / +5 lines)
Lines 1663-1669 Link Here
1663
        controlPanel2.requestActive();
1663
        controlPanel2.requestActive();
1664
    }
1664
    }
1665
1665
1666
    private void setupDispatcher(ProfilingSettings profilingSettings) {
1666
    public void setupDispatcher(ProfilingSettings profilingSettings) {
1667
        lastProfilingSettings = profilingSettings;
1667
        synchronized (setupLock) {
1668
        synchronized (setupLock) {
1668
            final Lookup.Provider project = getProfiledProject();
1669
            final Lookup.Provider project = getProfiledProject();
1669
1670
Lines 1752-1758 Link Here
1752
                    }
1753
                    }
1753
                }
1754
                }
1754
            }
1755
            }
1755
1756
            
1756
            ProfilingPointsProcessor ppp = getProfilingPointsManager();
1757
            ProfilingPointsProcessor ppp = getProfilingPointsManager();
1757
            if (ppp != null) ppp.init(getProfiledProject());
1758
            if (ppp != null) ppp.init(getProfiledProject());
1758
1759
Lines 1763-1768 Link Here
1763
    // Used for killing an agent which could cause a collision on port
1764
    // Used for killing an agent which could cause a collision on port
1764
    // Returns true if TERMINATE_TARGET_JVM was invoked on agent (not necessarily killed!), false if the agent is already profiling (port is used)
1765
    // Returns true if TERMINATE_TARGET_JVM was invoked on agent (not necessarily killed!), false if the agent is already profiling (port is used)
1765
    private boolean shutdownAgent(String host, int port) {
1766
    private boolean shutdownAgent(String host, int port) {
1767
        if (port == -1) return false; // invalid port
1768
        
1766
        Socket clientSocket = null;
1769
        Socket clientSocket = null;
1767
        ObjectOutputStream socketOut = null;
1770
        ObjectOutputStream socketOut = null;
1768
        ObjectInputStream socketIn = null;
1771
        ObjectInputStream socketIn = null;
(-)a/profiler/src/org/netbeans/modules/profiler/actions/JavaPlatformSelector.java (+1 lines)
Lines 51-56 Link Here
51
import javax.swing.*;
51
import javax.swing.*;
52
import javax.swing.event.ListSelectionEvent;
52
import javax.swing.event.ListSelectionEvent;
53
import javax.swing.event.ListSelectionListener;
53
import javax.swing.event.ListSelectionListener;
54
import org.netbeans.modules.profiler.api.JavaPlatform;
54
import org.netbeans.modules.profiler.api.ProfilerDialogs;
55
import org.netbeans.modules.profiler.api.ProfilerDialogs;
55
import org.openide.DialogDisplayer;
56
import org.openide.DialogDisplayer;
56
57
(-)a/profiler/src/org/netbeans/modules/profiler/actions/ProfilingSupport.java (-2 / +2 lines)
Lines 44-50 Link Here
44
package org.netbeans.modules.profiler.actions;
44
package org.netbeans.modules.profiler.actions;
45
45
46
import org.netbeans.lib.profiler.ProfilerLogger;
46
import org.netbeans.lib.profiler.ProfilerLogger;
47
import org.netbeans.lib.profiler.TargetAppRunner;
48
import org.netbeans.lib.profiler.common.*;
47
import org.netbeans.lib.profiler.common.*;
49
import org.netbeans.modules.profiler.NetBeansProfiler;
48
import org.netbeans.modules.profiler.NetBeansProfiler;
50
import org.netbeans.modules.profiler.ui.panels.PIDSelectPanel;
49
import org.netbeans.modules.profiler.ui.panels.PIDSelectPanel;
Lines 52-58 Link Here
52
import org.openide.util.NbBundle;
51
import org.openide.util.NbBundle;
53
import org.openide.util.RequestProcessor;
52
import org.openide.util.RequestProcessor;
54
import java.io.IOException;
53
import java.io.IOException;
55
import java.text.MessageFormat;
54
import org.netbeans.lib.profiler.TargetAppRunner;
56
import org.netbeans.modules.profiler.api.ProfilerDialogs;
55
import org.netbeans.modules.profiler.api.ProfilerDialogs;
57
import org.netbeans.modules.profiler.api.project.ProjectStorage;
56
import org.netbeans.modules.profiler.api.project.ProjectStorage;
58
import org.netbeans.modules.profiler.api.TaskConfigurator;
57
import org.netbeans.modules.profiler.api.TaskConfigurator;
Lines 76-81 Link Here
76
    "ProfilingSupport_FailedLoadSettingsMsg=Failed to load attach settings: {0}"
75
    "ProfilingSupport_FailedLoadSettingsMsg=Failed to load attach settings: {0}"
77
})
76
})
78
public final class ProfilingSupport {
77
public final class ProfilingSupport {
78
    public static final String RERUN_PROP = "profiler.rerun";
79
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
79
    //~ Inner Classes ------------------------------------------------------------------------------------------------------------
80
80
81
    public static class AttachSTPData {
81
    public static class AttachSTPData {
(-)a/profiler/src/org/netbeans/modules/profiler/actions/ResetResultsAction.java (-1 / +1 lines)
Lines 119-125 Link Here
119
    @ActionRegistration(displayName="#LBL_ResetResultsAction", lazy=false)
119
    @ActionRegistration(displayName="#LBL_ResetResultsAction", lazy=false)
120
    @ActionReferences({
120
    @ActionReferences({
121
        @ActionReference(path="Menu/Profile", position=900),
121
        @ActionReference(path="Menu/Profile", position=900),
122
        @ActionReference(path = "Shortcuts", name = "AS-F2")
122
        @ActionReference(path = "Shortcuts", name = "CA-F2")
123
    })
123
    })
124
    public static ResetResultsAction getInstance() {
124
    public static ResetResultsAction getInstance() {
125
        return Singleton.INSTANCE;
125
        return Singleton.INSTANCE;
(-)a/projectapi/apichanges.xml (-1 / +18 lines)
Lines 107-113 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
110
        <change id="Profiler.Actions">
111
            <api name="general"/>
112
            <summary>Profiler actions are an integral part of the project infrastructure - just like the debugger actions</summary>
113
            <version major="1" minor="43"/>
114
            <date day="23" month="3" year="2011"/>
115
            <author login="yardus"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                <p>
119
                    In order to be able to fully integrate the profiler with the project infrastructure
120
                    it is necessary to add three new constants to 
121
                    <code>ActionProvider</code> SPI for profiling a project, profiling a single file and
122
                    profiling a test for single file. 
123
                </p>
124
            </description>
125
            <class package="org.netbeans.spi.project" name="ActionProvider"/>
126
            <issue number="203519"/>
127
        </change>
111
        <change id="SourceGroup.contains.IAE">
128
        <change id="SourceGroup.contains.IAE">
112
            <api name="general"/>
129
            <api name="general"/>
113
            <summary><code>SourceGroup.contains</code> no longer throws <code>IllegalArgumentException</code></summary>
130
            <summary><code>SourceGroup.contains</code> no longer throws <code>IllegalArgumentException</code></summary>
(-)a/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
4
OpenIDE-Module-Specification-Version: 1.42
4
OpenIDE-Module-Specification-Version: 1.43
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
7
7
(-)a/projectapi/src/org/netbeans/spi/project/ActionProvider.java (+18 lines)
Lines 130-135 Link Here
130
    String COMMAND_DEBUG_STEP_INTO = "debug.stepinto"; // NOI18N
130
    String COMMAND_DEBUG_STEP_INTO = "debug.stepinto"; // NOI18N
131
    
131
    
132
    /**
132
    /**
133
     * Standard command for running the project in profiler
134
     * @since 1.43
135
     */
136
    String COMMAND_PROFILE = "profile"; // NOI18N
137
    
138
    /**
139
     * Standard command for running single file in profiler
140
     * @since 1.43
141
    */
142
    String COMMAND_PROFILE_SINGLE = "profile.single"; // NOI18N
143
    
144
    /** 
145
     * Standard command for running one test in profiler
146
     * @since 1.43
147
    */
148
    String COMMAND_PROFILE_TEST_SINGLE = "profile.test.single"; // NOI18N
149
    
150
    /**
133
     * Standard command for deleting the project.
151
     * Standard command for deleting the project.
134
     *
152
     *
135
     * @since 1.6
153
     * @since 1.6
(-)a/projectapi/src/org/netbeans/spi/project/SingleMethod.java (-1 / +1 lines)
Lines 110-116 Link Here
110
     * @since 1.19
110
     * @since 1.19
111
     */
111
     */
112
    public static final String COMMAND_DEBUG_SINGLE_METHOD = "debug.single.method";
112
    public static final String COMMAND_DEBUG_SINGLE_METHOD = "debug.single.method";
113
113
    
114
    @Override
114
    @Override
115
    public boolean equals(Object obj) {
115
    public boolean equals(Object obj) {
116
        if ((obj == null) || (obj.getClass() != SingleMethod.class)) {
116
        if ((obj == null) || (obj.getClass() != SingleMethod.class)) {
(-)a/web.project/src/org/netbeans/modules/web/project/WebActionProvider.java (-10 / +36 lines)
Lines 142-152 Link Here
142
        COMMAND_RUN_SINGLE,
142
        COMMAND_RUN_SINGLE,
143
        COMMAND_DEBUG,
143
        COMMAND_DEBUG,
144
        COMMAND_DEBUG_SINGLE,
144
        COMMAND_DEBUG_SINGLE,
145
        COMMAND_PROFILE,
146
        COMMAND_PROFILE_SINGLE,
145
        WebProjectConstants.COMMAND_REDEPLOY,
147
        WebProjectConstants.COMMAND_REDEPLOY,
146
        JavaProjectConstants.COMMAND_JAVADOC,
148
        JavaProjectConstants.COMMAND_JAVADOC,
147
        COMMAND_TEST,
149
        COMMAND_TEST,
148
        COMMAND_TEST_SINGLE,
150
        COMMAND_TEST_SINGLE,
149
        COMMAND_DEBUG_TEST_SINGLE,
151
        COMMAND_DEBUG_TEST_SINGLE,
152
        COMMAND_PROFILE_TEST_SINGLE,
150
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
153
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
151
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
154
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
152
        JavaProjectConstants.COMMAND_DEBUG_FIX,
155
        JavaProjectConstants.COMMAND_DEBUG_FIX,
Lines 163-174 Link Here
163
        COMMAND_COMPILE_SINGLE,
166
        COMMAND_COMPILE_SINGLE,
164
        COMMAND_RUN_SINGLE,
167
        COMMAND_RUN_SINGLE,
165
        COMMAND_DEBUG_SINGLE,
168
        COMMAND_DEBUG_SINGLE,
169
        COMMAND_PROFILE_SINGLE,
166
        JavaProjectConstants.COMMAND_JAVADOC,
170
        JavaProjectConstants.COMMAND_JAVADOC,
167
        COMMAND_TEST,
171
        COMMAND_TEST,
168
        COMMAND_TEST_SINGLE,
172
        COMMAND_TEST_SINGLE,
169
        COMMAND_DEBUG_TEST_SINGLE,
173
        COMMAND_DEBUG_TEST_SINGLE,
174
        COMMAND_PROFILE_TEST_SINGLE,
170
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
175
        SingleMethod.COMMAND_RUN_SINGLE_METHOD,
171
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD,
176
        SingleMethod.COMMAND_DEBUG_SINGLE_METHOD
172
    };
177
    };
173
178
174
    /**Set of commands which are affected by background scanning*/
179
    /**Set of commands which are affected by background scanning*/
Lines 201-214 Link Here
201
        commands.put(COMMAND_DEBUG, new String[]{"debug"}); // NOI18N
206
        commands.put(COMMAND_DEBUG, new String[]{"debug"}); // NOI18N
202
        // the target name is debug, except for Java files with main method, where it is debug-single-main
207
        // the target name is debug, except for Java files with main method, where it is debug-single-main
203
        commands.put(COMMAND_DEBUG_SINGLE, new String[]{"debug-single-main"}); // NOI18N
208
        commands.put(COMMAND_DEBUG_SINGLE, new String[]{"debug-single-main"}); // NOI18N
209
        commands.put(COMMAND_PROFILE, new String[]{"profile"}); // NOI18N
210
        commands.put(COMMAND_PROFILE_SINGLE, new String[]{"profile-single-main"}); // NOI18N
204
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[]{"javadoc"}); // NOI18N
211
        commands.put(JavaProjectConstants.COMMAND_JAVADOC, new String[]{"javadoc"}); // NOI18N
205
        commands.put(COMMAND_TEST, new String[]{"test"}); // NOI18N
212
        commands.put(COMMAND_TEST, new String[]{"test"}); // NOI18N
206
        commands.put(COMMAND_TEST_SINGLE, new String[]{"test-single"}); // NOI18N
213
        commands.put(COMMAND_TEST_SINGLE, new String[]{"test-single"}); // NOI18N
207
        commands.put(COMMAND_DEBUG_TEST_SINGLE, new String[]{"debug-test"}); // NOI18N
214
        commands.put(COMMAND_DEBUG_TEST_SINGLE, new String[]{"debug-test"}); // NOI18N
215
        commands.put(COMMAND_PROFILE_TEST_SINGLE, new String[]{"profile-test"}); // NOI18N
208
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[]{"debug-fix"}); // NOI18N
216
        commands.put(JavaProjectConstants.COMMAND_DEBUG_FIX, new String[]{"debug-fix"}); // NOI18N
209
        commands.put(COMMAND_VERIFY, new String[]{"verify"}); // NOI18N
217
        commands.put(COMMAND_VERIFY, new String[]{"verify"}); // NOI18N
210
        this.bkgScanSensitiveActions = new HashSet<String>(Arrays.asList(
218
        this.bkgScanSensitiveActions = new HashSet<String>(Arrays.asList(
211
            COMMAND_RUN_SINGLE
219
            COMMAND_RUN_SINGLE,
220
            COMMAND_PROFILE_SINGLE
212
        ));
221
        ));
213
222
214
        this.needJavaModelActions = new HashSet<String>(Arrays.asList(
223
        this.needJavaModelActions = new HashSet<String>(Arrays.asList(
Lines 254-262 Link Here
254
263
255
    @Override
264
    @Override
256
    protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) {
265
    protected void updateJavaRunnerClasspath(String command, Map<String, Object> execProperties) {
257
        if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) ||
266
        if (COMMAND_TEST_SINGLE.equals(command) || COMMAND_DEBUG_TEST_SINGLE.equals(command) || COMMAND_PROFILE_TEST_SINGLE.equals(command) ||
258
            SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) ||
267
            SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(command) || SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(command) ||
259
            COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command)) {
268
            COMMAND_RUN_SINGLE.equals(command) || COMMAND_DEBUG_SINGLE.equals(command) || COMMAND_PROFILE_SINGLE.equals(command)) {
260
            FileObject fo = (FileObject)execProperties.get(JavaRunner.PROP_EXECUTE_FILE);
269
            FileObject fo = (FileObject)execProperties.get(JavaRunner.PROP_EXECUTE_FILE);
261
            ClassPath cp = getCallback().findClassPath(fo, ClassPath.EXECUTE);
270
            ClassPath cp = getCallback().findClassPath(fo, ClassPath.EXECUTE);
262
            ClassPath cp2 = ClassPathFactory.createClassPath(
271
            ClassPath cp2 = ClassPathFactory.createClassPath(
Lines 287-293 Link Here
287
296
288
    @Override
297
    @Override
289
    protected boolean handleJavaClass(Properties p, FileObject javaFile, String command, List<String> targetNames) {
298
    protected boolean handleJavaClass(Properties p, FileObject javaFile, String command, List<String> targetNames) {
290
        return runServlet(p, javaFile, "LBL_RunAction", false, targetNames);
299
        return runServlet(p, javaFile, "LBL_RunAction", COMMAND_DEBUG_SINGLE.equals(command), COMMAND_PROFILE_SINGLE.equals(command), targetNames);
291
    }
300
    }
292
301
293
    @Override
302
    @Override
Lines 295-301 Link Here
295
        if (command.equals(COMMAND_RUN_SINGLE) ||command.equals(COMMAND_RUN) ||
304
        if (command.equals(COMMAND_RUN_SINGLE) ||command.equals(COMMAND_RUN) ||
296
            command.equals(WebProjectConstants.COMMAND_REDEPLOY) ||command.equals(COMMAND_DEBUG) ||
305
            command.equals(WebProjectConstants.COMMAND_REDEPLOY) ||command.equals(COMMAND_DEBUG) ||
297
            command.equals(COMMAND_DEBUG_SINGLE) || command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX) ||
306
            command.equals(COMMAND_DEBUG_SINGLE) || command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX) ||
298
            command.equals( COMMAND_TEST_SINGLE) || command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
307
            command.equals(COMMAND_PROFILE) || command.equals(COMMAND_PROFILE_SINGLE) ||
308
            command.equals( COMMAND_TEST_SINGLE) || command.equals(COMMAND_DEBUG_TEST_SINGLE) || command.equals(COMMAND_PROFILE_TEST_SINGLE)) {
299
            setDirectoryDeploymentProperty(p);
309
            setDirectoryDeploymentProperty(p);
300
        }
310
        }
301
311
Lines 308-314 Link Here
308
        if (isDebugged()) {
318
        if (isDebugged()) {
309
            p.setProperty("is.debugged", "true");
319
            p.setProperty("is.debugged", "true");
310
        }
320
        }
311
        if (command.equals(COMMAND_RUN_SINGLE) || command.equals(COMMAND_DEBUG_SINGLE)) {
321
        if (command.equals(COMMAND_RUN_SINGLE) || command.equals(COMMAND_DEBUG_SINGLE) || command.equals(COMMAND_PROFILE_SINGLE)) {
312
            String res[] = super.getTargetNames(command, context, p, doJavaChecks);
322
            String res[] = super.getTargetNames(command, context, p, doJavaChecks);
313
            if (res != null) {
323
            if (res != null) {
314
                return res;
324
                return res;
Lines 323-328 Link Here
323
                if (!keepDebugging) {
333
                if (!keepDebugging) {
324
                    return null;
334
                    return null;
325
                }
335
                }
336
            } else if (command.equals(COMMAND_PROFILE_SINGLE)) {
337
                targetNames = new String[]{"profile"};
326
            } else {
338
            } else {
327
                targetNames = new String[]{"run"};
339
                targetNames = new String[]{"run"};
328
            }
340
            }
Lines 372-377 Link Here
372
                return null;
384
                return null;
373
            }
385
            }
374
            return commands.get(command);
386
            return commands.get(command);
387
        } else if (command.equals(COMMAND_PROFILE)) {
388
            if (!isSelectedServer()) {
389
                return null;
390
            }
391
            initWebServiceProperties(p);
375
        } else if (command.equals(COMMAND_DEBUG)) {
392
        } else if (command.equals(COMMAND_DEBUG)) {
376
            if (!isSelectedServer()) {
393
            if (!isSelectedServer()) {
377
                return null;
394
                return null;
Lines 486-493 Link Here
486
503
487
    // Fix for IZ#170419 - Invoking Run took 29110 ms.
504
    // Fix for IZ#170419 - Invoking Run took 29110 ms.
488
    private boolean runServlet( Properties p, FileObject javaFile, String
505
    private boolean runServlet( Properties p, FileObject javaFile, String
489
            actionName , boolean debug, List<String> targetNames) 
506
            actionName , boolean debug, boolean profile, List<String> targetNames) 
490
    {
507
    {
508
        assert !(debug && profile);
509
        
491
        // run servlet
510
        // run servlet
492
        // PENDING - what about servlets with main method? servlet should take
511
        // PENDING - what about servlets with main method? servlet should take
493
        // precedence
512
        // precedence
Lines 576-582 Link Here
576
            return runEmptyMapping(javaFile);
595
            return runEmptyMapping(javaFile);
577
        }
596
        }
578
        p.setProperty(BaseActionProvider.PROPERTY_RUN_SINGLE_ON_SERVER, "yes");
597
        p.setProperty(BaseActionProvider.PROPERTY_RUN_SINGLE_ON_SERVER, "yes");
579
        targetNames.add("run"); // NOI18N
598
        if (profile) {
599
            targetNames.add("profile"); // NOI18N
600
        } else if (debug) {
601
            targetNames.add("debug"); // NOI18N
602
        } else {
603
            targetNames.add("run"); // NOI18N
604
        }
580
        return true;
605
        return true;
581
    }
606
    }
582
607
Lines 784-790 Link Here
784
        }
809
        }
785
        if (command.equals(COMMAND_COMPILE_SINGLE) ||
810
        if (command.equals(COMMAND_COMPILE_SINGLE) ||
786
            command.equals(COMMAND_DEBUG_SINGLE) ||
811
            command.equals(COMMAND_DEBUG_SINGLE) ||
787
            command.equals(COMMAND_RUN_SINGLE)) {
812
            command.equals(COMMAND_RUN_SINGLE) ||
813
            command.equals(COMMAND_PROFILE_SINGLE)) {
788
            if (findJsps(context) != null || findHtml(context) != null ) {
814
            if (findJsps(context) != null || findHtml(context) != null ) {
789
                return true;
815
                return true;
790
            } else {
816
            } else {
(-)a/web.project/src/org/netbeans/modules/web/project/resources/build-impl.xsl (-43 / +85 lines)
Lines 719-724 Link Here
719
                            <jvmarg line="${{endorsed.classpath.cmd.line.arg}}"/>
719
                            <jvmarg line="${{endorsed.classpath.cmd.line.arg}}"/>
720
                            <jvmarg value="-ea"/>
720
                            <jvmarg value="-ea"/>
721
                            <jvmarg line="${{runmain.jvmargs}}"/>
721
                            <jvmarg line="${{runmain.jvmargs}}"/>
722
                            <jvmarg line="${{run.jvmargs.ide}}"/>
722
                        </junit>
723
                        </junit>
723
                    </sequential>
724
                    </sequential>
724
                </macrodef>
725
                </macrodef>
Lines 940-961 Link Here
940
                <property name="ap.cmd.line.internal" value=""/>
941
                <property name="ap.cmd.line.internal" value=""/>
941
            </target>
942
            </target>
942
943
943
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check"/>
944
            <xsl:comment>
945
                pre NB7.2 profiling section; consider it deprecated
946
            </xsl:comment>
947
            <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-check">
948
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
949
            </target>
944
950
945
            <target name="-profile-pre-init">
951
            <target name="-profile-pre-init">
946
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
952
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
947
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
953
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
954
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
948
            </target>
955
            </target>
949
956
950
            <target name="-profile-post-init">
957
            <target name="-profile-post-init">
951
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
958
                <xsl:comment> Empty placeholder for easier customization. </xsl:comment>
952
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
959
                <xsl:comment> You can override this target in the ../build.xml file. </xsl:comment>
960
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
953
            </target>
961
            </target>
954
            <target name="-profile-init-check">
962
            <target name="-profile-init-check">
955
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
963
                <xsl:attribute name="depends">-profile-pre-init, init, -profile-post-init</xsl:attribute>
964
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
956
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
965
                <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
957
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
966
                <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
958
            </target>
967
            </target>
968
            <xsl:comment>
969
                end of pre NB7.2 profiling section
970
            </xsl:comment>
959
971
960
            <target name="init">
972
            <target name="init">
961
                <xsl:attribute name="depends">-pre-init,-init-private<xsl:if test="/p:project/p:configuration/libs:libraries/libs:definitions">,-init-libraries</xsl:if>,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-java,-init-macrodef-nbjpda,-init-macrodef-nbjsdebug,-init-macrodef-debug,-init-taskdefs,-init-ap-cmdline</xsl:attribute>
973
                <xsl:attribute name="depends">-pre-init,-init-private<xsl:if test="/p:project/p:configuration/libs:libraries/libs:definitions">,-init-libraries</xsl:if>,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-java,-init-macrodef-nbjpda,-init-macrodef-nbjsdebug,-init-macrodef-debug,-init-taskdefs,-init-ap-cmdline</xsl:attribute>
Lines 1712-1719 Link Here
1712
            =================
1724
            =================
1713
            </xsl:comment>
1725
            </xsl:comment>
1714
1726
1715
            <target name="profile">
1727
            <xsl:comment>
1728
                pre NB7.2 profiling section; consider it deprecated
1729
            </xsl:comment>
1730
            <target name="-profile-pre72">
1716
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1731
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1732
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
1717
                <condition>
1733
                <condition>
1718
                    <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
1734
                    <xsl:attribute name="property">profiler.startserver.target</xsl:attribute>
1719
                    <xsl:attribute name="value">start-profiled-server-extraargs</xsl:attribute>
1735
                    <xsl:attribute name="value">start-profiled-server-extraargs</xsl:attribute>
Lines 1729-1739 Link Here
1729
                    <xsl:attribute name="target">run</xsl:attribute>
1745
                    <xsl:attribute name="target">run</xsl:attribute>
1730
                </antcall>
1746
                </antcall>
1731
                <antcall>
1747
                <antcall>
1732
                    <xsl:attribute name="target">start-loadgen</xsl:attribute>
1748
                    <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
1733
                </antcall>
1749
                </antcall>
1734
            </target>
1750
            </target>
1735
1751
1736
            <target name="start-profiled-server">
1752
            <target name="start-profiled-server" if="profiler.info.jvmargs.agent">
1737
                <nbstartprofiledserver>
1753
                <nbstartprofiledserver>
1738
                    <xsl:attribute name="forceRestart">${profiler.j2ee.serverForceRestart}</xsl:attribute>
1754
                    <xsl:attribute name="forceRestart">${profiler.j2ee.serverForceRestart}</xsl:attribute>
1739
                    <xsl:attribute name="startupTimeout">${profiler.j2ee.serverStartupTimeout}</xsl:attribute>
1755
                    <xsl:attribute name="startupTimeout">${profiler.j2ee.serverStartupTimeout}</xsl:attribute>
Lines 1747-1753 Link Here
1747
                </nbstartprofiledserver>
1763
                </nbstartprofiledserver>
1748
            </target>
1764
            </target>
1749
1765
1750
            <target name="start-profiled-server-extraargs">
1766
            <target name="start-profiled-server-extraargs" if="profiler.info.jvmargs.agent">
1751
                <nbstartprofiledserver>
1767
                <nbstartprofiledserver>
1752
                    <xsl:attribute name="forceRestart">${profiler.j2ee.serverForceRestart}</xsl:attribute>
1768
                    <xsl:attribute name="forceRestart">${profiler.j2ee.serverForceRestart}</xsl:attribute>
1753
                    <xsl:attribute name="startupTimeout">${profiler.j2ee.serverStartupTimeout}</xsl:attribute>
1769
                    <xsl:attribute name="startupTimeout">${profiler.j2ee.serverStartupTimeout}</xsl:attribute>
Lines 1763-1773 Link Here
1763
                    </jvmarg>
1779
                    </jvmarg>
1764
                </nbstartprofiledserver>
1780
                </nbstartprofiledserver>
1765
            </target>
1781
            </target>
1782
            
1783
            <target name="-profile-test-single-pre72">
1784
                <xsl:attribute name="if">profiler.info.jvmargs.agent</xsl:attribute>
1785
                <fail unless="netbeans.home">This target only works when run from inside the NetBeans IDE.</fail>
1786
                <xsl:attribute name="depends">profile-init,compile-test-single</xsl:attribute>
1787
                <nbprofiledirect>
1788
                    <classpath>
1789
                        <path path="${{run.test.classpath}}"/>
1790
                        <path path="${{j2ee.platform.classpath}}"/>
1791
                    </classpath>
1792
                </nbprofiledirect>
1766
1793
1767
            <target name="start-loadgen" if="profiler.loadgen.path">
1794
                <junit showoutput="true" fork="true" dir="${{profiler.info.dir}}"  jvm="${{profiler.info.jvm}}" failureproperty="tests.failed" errorproperty="tests.failed">
1768
                    <loadgenstart>
1795
                    <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
1769
                        <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
1796
                    <jvmarg value="${{profiler.info.jvmargs.agent}}" />
1770
                    </loadgenstart>
1797
                    <jvmarg line="${{profiler.info.jvmargs}}"/>
1798
                    <test name="${{profile.class}}"/>
1799
                    <classpath>
1800
                        <path path="${{run.test.classpath}}"/>
1801
                        <path path="${{j2ee.platform.classpath}}"/>
1802
                    </classpath>
1803
                    <syspropertyset>
1804
                        <propertyref prefix="test-sys-prop."/>
1805
                        <mapper type="glob" from="test-sys-prop.*" to="*"/>
1806
                    </syspropertyset>
1807
                    <formatter type="brief" usefile="false"/>
1808
                    <formatter type="xml"/>
1809
                </junit>
1810
            </target>
1811
1812
            <target name="-profile-check" if="netbeans.home">
1813
                <condition property="profiler.configured">
1814
                    <or>
1815
                        <contains string="${{run.jvmargs.ide}}" substring="-agentpath:" casesensitive="false"/>
1816
                        <contains string="${{run.jvmargs.ide}}" substring="-javaagent:" casesensitive="false"/>
1817
                    </or>
1818
                </condition>
1819
            </target>
1820
1821
            <target name="profile" depends="-profile-check,init,-init-cos,compile,compile-jsps,-do-compile-single-jsp,-pre-dist,-do-tmp-dist-with-manifest,-do-tmp-dist-without-manifest,-profile-pre72" if="profiler.configured" unless="profiler.info.jvmargs.agent">
1822
                <xsl:attribute name="description">Profile a J2EE project in the IDE.</xsl:attribute>
1823
                
1824
                <startprofiler/>
1825
                <nbstartserver profilemode="true"/>
1826
                
1827
                <nbdeploy profilemode="true" clientUrlPart="${{client.urlPart}}" forceRedeploy="true" />
1828
                <antcall>
1829
                    <xsl:attribute name="target">debug-display-browser</xsl:attribute>
1830
                </antcall>
1831
                <antcall>
1832
                    <xsl:attribute name="target">-profile-start-loadgen</xsl:attribute>
1833
                </antcall>
1834
            </target>
1835
            
1836
            <target name="profile-test-single" depends="-profile-test-single-pre72"/>
1837
            
1838
            <target name="profile-test" depends="-profile-check" if="profiler.configured" unless="profiler.info.jvmargs.agent">
1839
                <startprofiler/>
1840
                <antcall target="test-single"/>
1841
            </target>
1842
1843
            <target name="-profile-start-loadgen" if="profiler.loadgen.path">
1844
                <loadgenstart>
1845
                    <xsl:attribute name="path">${profiler.loadgen.path}</xsl:attribute>
1846
                </loadgenstart>
1771
            </target>
1847
            </target>
1772
1848
1773
            <xsl:comment>
1849
            <xsl:comment>
Lines 2051-2090 Link Here
2051
                <xsl:attribute name="if">netbeans.home</xsl:attribute>
2127
                <xsl:attribute name="if">netbeans.home</xsl:attribute>
2052
                <xsl:attribute name="depends">init,-pre-debug-fix,-do-debug-fix-test</xsl:attribute>
2128
                <xsl:attribute name="depends">init,-pre-debug-fix,-do-debug-fix-test</xsl:attribute>
2053
            </target>
2129
            </target>
2054
            
2055
        <xsl:comment>
2056
        =========================
2057
        TESTS PROFILING  SECTION
2058
        =========================
2059
        </xsl:comment>
2060
2061
          <target name="profile-test-single">
2062
              <xsl:attribute name="if">netbeans.home</xsl:attribute>
2063
              <xsl:attribute name="depends">profile-init,compile-test-single</xsl:attribute>
2064
              <nbprofiledirect>
2065
                  <classpath>
2066
                      <path path="${{run.test.classpath}}"/>
2067
                      <path path="${{j2ee.platform.classpath}}"/>
2068
                  </classpath>
2069
              </nbprofiledirect>
2070
2071
              <junit showoutput="true" fork="true" dir="${{profiler.info.dir}}"  jvm="${{profiler.info.jvm}}" failureproperty="tests.failed" errorproperty="tests.failed">
2072
                  <env key="${{profiler.info.pathvar}}" path="${{profiler.info.agentpath}}:${{profiler.current.path}}"/>
2073
                  <jvmarg value="${{profiler.info.jvmargs.agent}}" />
2074
                  <jvmarg line="${{profiler.info.jvmargs}}"/>
2075
                  <test name="${{profile.class}}"/>
2076
                  <classpath>
2077
                      <path path="${{run.test.classpath}}"/>
2078
                      <path path="${{j2ee.platform.classpath}}"/>
2079
                  </classpath>
2080
                  <syspropertyset>
2081
                      <propertyref prefix="test-sys-prop."/>
2082
                      <mapper type="glob" from="test-sys-prop.*" to="*"/>
2083
                  </syspropertyset>
2084
                  <formatter type="brief" usefile="false"/>
2085
                  <formatter type="xml"/>
2086
              </junit>
2087
          </target>
2088
2130
2089
            <xsl:comment>
2131
            <xsl:comment>
2090
                
2132
                
(-)a/web.project/src/org/netbeans/modules/web/project/ui/resources/layer.xml (-4 lines)
Lines 234-243 Link Here
234
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
234
                    <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-DebugProjectAction.instance"/>
235
                    <attr name="position" intvalue="900"/>
235
                    <attr name="position" intvalue="900"/>
236
                </file>
236
                </file>
237
                <file name="Profiler_Actions_temporary.shadow">
238
                    <attr name="originalFile" stringvalue="Projects/Profiler_Actions_temporary"/>
239
                    <attr name="position" intvalue="1000"/>
240
                </file>
241
                <file name="Rest_Actions_holder.shadow">
237
                <file name="Rest_Actions_holder.shadow">
242
                    <attr name="originalFile" stringvalue="Projects/Rest_Actions_holder"/>
238
                    <attr name="originalFile" stringvalue="Projects/Rest_Actions_holder"/>
243
                    <attr name="position" intvalue="1050"/>
239
                    <attr name="position" intvalue="1050"/>

Return to bug 203519