Source Code Cross Referenced for ModuleActions.java in  » IDE-Netbeans » api » org » netbeans » modules » apisupport » project » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » api » org.netbeans.modules.apisupport.project.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.apisupport.project.ui;
043:
044:        import java.awt.event.ActionEvent;
045:        import java.io.IOException;
046:        import java.util.ArrayList;
047:        import java.util.Collection;
048:        import java.util.HashMap;
049:        import java.util.HashSet;
050:        import java.util.List;
051:        import java.util.Map;
052:        import java.util.Properties;
053:        import java.util.Set;
054:        import java.util.regex.Pattern;
055:        import javax.swing.AbstractAction;
056:        import javax.swing.Action;
057:        import javax.swing.JSeparator;
058:        import org.apache.tools.ant.module.api.support.ActionUtils;
059:        import org.netbeans.api.java.project.JavaProjectConstants;
060:        import org.netbeans.api.project.ProjectManager;
061:        import org.netbeans.modules.apisupport.project.NbModuleProject;
062:        import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
063:        import org.netbeans.modules.apisupport.project.Util;
064:        import org.netbeans.modules.apisupport.project.suite.SuiteProject;
065:        import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl;
066:        import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
067:        import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
068:        import org.netbeans.modules.apisupport.project.universe.NbPlatform;
069:        import org.netbeans.spi.project.ActionProvider;
070:        import org.netbeans.spi.project.support.ant.AntProjectHelper;
071:        import org.netbeans.spi.project.support.ant.EditableProperties;
072:        import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
073:        import org.netbeans.spi.project.ui.support.CommonProjectActions;
074:        import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
075:        import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
076:        import org.openide.DialogDisplayer;
077:        import org.openide.ErrorManager;
078:        import org.openide.NotifyDescriptor;
079:        import org.openide.actions.FindAction;
080:        import org.openide.filesystems.FileObject;
081:        import org.openide.filesystems.FileUtil;
082:        import org.openide.util.Lookup;
083:        import org.openide.util.Mutex;
084:        import org.openide.util.NbBundle;
085:        import org.openide.util.actions.SystemAction;
086:        import org.openide.util.lookup.Lookups;
087:
088:        public final class ModuleActions implements  ActionProvider {
089:
090:            static Action[] getProjectActions(NbModuleProject project) {
091:                List<Action> actions = new ArrayList<Action>();
092:                actions.add(CommonProjectActions.newFileAction());
093:                actions.add(null);
094:                actions.add(ProjectSensitiveActions.projectCommandAction(
095:                        ActionProvider.COMMAND_BUILD, NbBundle.getMessage(
096:                                ModuleActions.class, "ACTION_build"), null));
097:                actions.add(ProjectSensitiveActions.projectCommandAction(
098:                        ActionProvider.COMMAND_REBUILD, NbBundle.getMessage(
099:                                ModuleActions.class, "ACTION_rebuild"), null));
100:                actions.add(ProjectSensitiveActions.projectCommandAction(
101:                        ActionProvider.COMMAND_CLEAN, NbBundle.getMessage(
102:                                ModuleActions.class, "ACTION_clean"), null));
103:                actions.add(null);
104:                boolean isNetBeansOrg = Util.getModuleType(project) == NbModuleProvider.NETBEANS_ORG;
105:                if (isNetBeansOrg) {
106:                    String path = project.getPathWithinNetBeansOrg();
107:                    actions.add(createMasterAction(project, new String[] {
108:                            "init", "all-" + path }, NbBundle.getMessage(
109:                            ModuleActions.class, "ACTION_build_with_deps")));
110:                    actions.add(createMasterAction(project, new String[] {
111:                            "init", "all-" + path, "tryme" }, NbBundle
112:                            .getMessage(ModuleActions.class,
113:                                    "ACTION_build_with_deps_tryme")));
114:                } else {
115:                    actions.add(createSimpleAction(project,
116:                            new String[] { "run" }, NbBundle.getMessage(
117:                                    ModuleActions.class, "ACTION_run")));
118:                }
119:                actions.add(ProjectSensitiveActions.projectCommandAction(
120:                        ActionProvider.COMMAND_DEBUG, NbBundle.getMessage(
121:                                ModuleActions.class, "ACTION_debug"), null));
122:                addFromLayers(actions, "Projects/Profiler_Actions_temporary"); //NOI18N
123:                if (project.supportsUnitTests()) {
124:                    actions.add(ProjectSensitiveActions.projectCommandAction(
125:                            ActionProvider.COMMAND_TEST, NbBundle.getMessage(
126:                                    ModuleActions.class, "ACTION_test"), null));
127:                }
128:                actions.add(null);
129:                if (isNetBeansOrg) {
130:                    actions.add(createCheckBundleAction(project, NbBundle
131:                            .getMessage(ModuleActions.class,
132:                                    "ACTION_unused_bundle_keys")));
133:                    actions.add(null);
134:                }
135:                actions.add(ProjectSensitiveActions.projectCommandAction(
136:                        ActionProvider.COMMAND_RUN, NbBundle.getMessage(
137:                                ModuleActions.class, "ACTION_reload"), null));
138:                actions.add(createReloadInIDEAction(project,
139:                        new String[] { "reload-in-ide" }, NbBundle.getMessage(
140:                                ModuleActions.class, "ACTION_reload_in_ide")));
141:                actions
142:                        .add(createSimpleAction(project,
143:                                new String[] { "nbm" }, NbBundle.getMessage(
144:                                        ModuleActions.class, "ACTION_nbm")));
145:                actions.add(null);
146:                actions.add(ProjectSensitiveActions.projectCommandAction(
147:                        JavaProjectConstants.COMMAND_JAVADOC, NbBundle
148:                                .getMessage(ModuleActions.class,
149:                                        "ACTION_javadoc"), null));
150:                actions.add(createArchAction(project));
151:                actions.add(null);
152:                actions.add(CommonProjectActions.setAsMainProjectAction());
153:                actions.add(CommonProjectActions.openSubprojectsAction());
154:                actions.add(CommonProjectActions.closeProjectAction());
155:                actions.add(null);
156:                actions.add(CommonProjectActions.renameProjectAction());
157:                actions.add(CommonProjectActions.moveProjectAction());
158:                actions.add(CommonProjectActions.copyProjectAction());
159:                actions.add(CommonProjectActions.deleteProjectAction());
160:
161:                actions.add(null);
162:                actions.add(SystemAction.get(FindAction.class));
163:                // Honor #57874 contract:
164:                Collection<? extends Object> res = Lookups.forPath(
165:                        "Projects/Actions").lookupAll(Object.class); // NOI18N
166:                if (!res.isEmpty()) {
167:                    actions.add(null);
168:                    for (Object next : res) {
169:                        if (next instanceof  Action) {
170:                            actions.add((Action) next);
171:                        } else if (next instanceof  JSeparator) {
172:                            actions.add(null);
173:                        }
174:                    }
175:                }
176:
177:                actions.add(null);
178:                actions.add(CommonProjectActions.customizeProjectAction());
179:                return actions.toArray(new Action[actions.size()]);
180:            }
181:
182:            private static void addFromLayers(List<Action> actions, String path) {
183:                Lookup look = Lookups.forPath(path);
184:                for (Object next : look.lookupAll(Object.class)) {
185:                    if (next instanceof  Action) {
186:                        actions.add((Action) next);
187:                    } else if (next instanceof  JSeparator) {
188:                        actions.add(null);
189:                    }
190:                }
191:            }
192:
193:            private final NbModuleProject project;
194:            private final Map<String, String[]> globalCommands = new HashMap<String, String[]>();
195:            private final String[] supportedActions;
196:
197:            public ModuleActions(NbModuleProject project) {
198:                this .project = project;
199:                Set<String> supportedActionsSet = new HashSet<String>();
200:                globalCommands.put(ActionProvider.COMMAND_BUILD,
201:                        new String[] { "netbeans" }); // NOI18N
202:                globalCommands.put(ActionProvider.COMMAND_CLEAN,
203:                        new String[] { "clean" }); // NOI18N
204:                globalCommands.put(ActionProvider.COMMAND_REBUILD,
205:                        new String[] { "clean", "netbeans" }); // NOI18N
206:                globalCommands.put(ActionProvider.COMMAND_DEBUG,
207:                        new String[] { "debug" }); // NOI18N
208:                globalCommands.put(ActionProvider.COMMAND_RUN,
209:                        new String[] { "reload" }); // NOI18N
210:                globalCommands.put("profile", new String[] { "profile" }); // NOI18N
211:                globalCommands.put(JavaProjectConstants.COMMAND_JAVADOC,
212:                        new String[] { "javadoc-nb" }); // NOI18N
213:                if (project.supportsUnitTests()) {
214:                    globalCommands.put(ActionProvider.COMMAND_TEST,
215:                            new String[] { "test" }); // NOI18N
216:                }
217:                supportedActionsSet.addAll(globalCommands.keySet());
218:                supportedActionsSet.add(ActionProvider.COMMAND_COMPILE_SINGLE);
219:                supportedActionsSet.add(JavaProjectConstants.COMMAND_DEBUG_FIX); // #47012
220:                if (project.supportsUnitTests()) {
221:                    supportedActionsSet.add(ActionProvider.COMMAND_TEST_SINGLE);
222:                    supportedActionsSet
223:                            .add(ActionProvider.COMMAND_DEBUG_TEST_SINGLE);
224:                    supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
225:                    supportedActionsSet
226:                            .add(ActionProvider.COMMAND_DEBUG_SINGLE);
227:                }
228:                if (project.getFunctionalTestSourceDirectory() != null) {
229:                    supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
230:                }
231:                if (project.getPerformanceTestSourceDirectory() != null) {
232:                    supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
233:                }
234:                supportedActionsSet.add(ActionProvider.COMMAND_RENAME);
235:                supportedActionsSet.add(ActionProvider.COMMAND_MOVE);
236:                supportedActionsSet.add(ActionProvider.COMMAND_COPY);
237:                supportedActionsSet.add(ActionProvider.COMMAND_DELETE);
238:                supportedActions = supportedActionsSet
239:                        .toArray(new String[supportedActionsSet.size()]);
240:            }
241:
242:            public String[] getSupportedActions() {
243:                return supportedActions;
244:            }
245:
246:            private static FileObject findBuildXml(NbModuleProject project) {
247:                return project.getProjectDirectory().getFileObject(
248:                        GeneratedFilesHelper.BUILD_XML_PATH);
249:            }
250:
251:            private static FileObject findTestBuildXml(NbModuleProject project) {
252:                return project.getProjectDirectory().getFileObject(
253:                        "test/build.xml"); // NOI18N
254:            }
255:
256:            private static FileObject findMasterBuildXml(NbModuleProject project) {
257:                return project.getNbrootFileObject("nbbuild/build.xml"); // NOI18N
258:            }
259:
260:            public boolean isActionEnabled(String command, Lookup context) {
261:                if (ActionProvider.COMMAND_DELETE.equals(command)
262:                        || ActionProvider.COMMAND_RENAME.equals(command)
263:                        || ActionProvider.COMMAND_MOVE.equals(command)
264:                        || ActionProvider.COMMAND_COPY.equals(command)) {
265:                    return true;
266:                } else if (command.equals(COMMAND_COMPILE_SINGLE)) {
267:                    return findBuildXml(project) != null
268:                            && (findSources(context) != null || findTestSources(
269:                                    context, false) != null);
270:                } else if (command.equals(COMMAND_TEST_SINGLE)) {
271:                    return findBuildXml(project) != null
272:                            && findTestSourcesForSources(context) != null;
273:                } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
274:                    FileObject[] files = findTestSourcesForSources(context);
275:                    return findBuildXml(project) != null && files != null
276:                            && files.length == 1;
277:                } else if (command.equals(COMMAND_RUN_SINGLE)) {
278:                    FileObject[] files = findFunctionalTestSources(context);
279:                    if (files != null && files.length == 1
280:                            && findTestBuildXml(project) != null) {
281:                        return true;
282:                    }
283:                    files = findPerformanceTestSources(context);
284:                    if (files != null && files.length == 1
285:                            && findTestBuildXml(project) != null) {
286:                        return true;
287:                    }
288:                    files = findTestSources(context, false);
289:                    return files != null;
290:                } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
291:                    FileObject[] files = findTestSources(context, false);
292:                    return files != null && files.length == 1;
293:                } else if (command
294:                        .equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
295:                    FileObject[] files = findSources(context);
296:                    if (files != null && files.length == 1
297:                            && findBuildXml(project) != null) {
298:                        return true;
299:                    }
300:                    files = findTestSources(context, false);
301:                    return files != null && files.length == 1
302:                            && findBuildXml(project) != null;
303:                } else {
304:                    // other actions are global
305:                    return findBuildXml(project) != null;
306:                }
307:            }
308:
309:            private static final Pattern SRCDIRJAVA = Pattern
310:                    .compile("\\.java$"); // NOI18N
311:            private static final String SUBST = "Test.java"; // NOI18N
312:
313:            private FileObject[] findSources(Lookup context) {
314:                FileObject srcDir = project.getSourceDirectory();
315:                if (srcDir != null) {
316:                    FileObject[] files = ActionUtils.findSelectedFiles(context,
317:                            srcDir, ".java", true); // NOI18N
318:                    //System.err.println("findSources: srcDir=" + srcDir + " files=" + (files != null ? java.util.Arrays.asList(files) : null) + " context=" + context);
319:                    return files;
320:                } else {
321:                    return null;
322:                }
323:            }
324:
325:            private FileObject[] findTestSources(Lookup context,
326:                    boolean checkInSrcDir) {
327:                FileObject testSrcDir = project.getTestSourceDirectory();
328:                if (testSrcDir != null) {
329:                    FileObject[] files = ActionUtils.findSelectedFiles(context,
330:                            testSrcDir, ".java", true); // NOI18N
331:                    if (files != null) {
332:                        return files;
333:                    }
334:                }
335:                //System.err.println("fTS: testSrcDir=" + testSrcDir + " checkInSrcDir=" + checkInSrcDir + " context=" + context);
336:                if (checkInSrcDir && testSrcDir != null) {
337:                    FileObject srcDir = project.getSourceDirectory();
338:                    //System.err.println("  srcDir=" + srcDir);
339:                    if (srcDir != null) {
340:                        FileObject[] files = ActionUtils.findSelectedFiles(
341:                                context, srcDir, ".java", true); // NOI18N
342:                        //System.err.println("  files=" + files);
343:                        if (files != null) {
344:                            FileObject[] files2 = ActionUtils.regexpMapFiles(
345:                                    files, srcDir, SRCDIRJAVA, testSrcDir,
346:                                    SUBST, true);
347:                            //System.err.println("  files2=" + files2);
348:                            if (files2 != null) {
349:                                return files2;
350:                            }
351:                        }
352:                    }
353:                }
354:                return null;
355:            }
356:
357:            /** Find tests corresponding to selected sources.
358:             */
359:            private FileObject[] findTestSourcesForSources(Lookup context) {
360:                FileObject[] sourceFiles = findSources(context);
361:                if (sourceFiles == null) {
362:                    return null;
363:                }
364:                FileObject testSrcDir = project.getTestSourceDirectory();
365:                FileObject srcDir = project.getSourceDirectory();
366:                return ActionUtils.regexpMapFiles(sourceFiles, srcDir,
367:                        SRCDIRJAVA, testSrcDir, SUBST, true);
368:            }
369:
370:            private FileObject[] findFunctionalTestSources(Lookup context) {
371:                FileObject srcDir = project.getFunctionalTestSourceDirectory();
372:                if (srcDir != null) {
373:                    FileObject[] files = ActionUtils.findSelectedFiles(context,
374:                            srcDir, ".java", true); // NOI18N
375:                    return files;
376:                } else {
377:                    return null;
378:                }
379:            }
380:
381:            private FileObject[] findPerformanceTestSources(Lookup context) {
382:                FileObject srcDir = project.getPerformanceTestSourceDirectory();
383:                if (srcDir != null) {
384:                    FileObject[] files = ActionUtils.findSelectedFiles(context,
385:                            srcDir, ".java", true); // NOI18N
386:                    return files;
387:                } else {
388:                    return null;
389:                }
390:            }
391:
392:            public void invokeAction(String command, Lookup context)
393:                    throws IllegalArgumentException {
394:                if (ActionProvider.COMMAND_DELETE.equals(command)) {
395:                    if (ModuleOperations.canRun(project, true)) {
396:                        DefaultProjectOperations
397:                                .performDefaultDeleteOperation(project);
398:                    }
399:                    return;
400:                } else if (ActionProvider.COMMAND_RENAME.equals(command)) {
401:                    if (ModuleOperations.canRun(project, true)) {
402:                        DefaultProjectOperations.performDefaultRenameOperation(
403:                                project, null);
404:                    }
405:                    return;
406:                } else if (ActionProvider.COMMAND_MOVE.equals(command)) {
407:                    if (ModuleOperations.canRun(project, true)) {
408:                        DefaultProjectOperations
409:                                .performDefaultMoveOperation(project);
410:                    }
411:                    return;
412:                } else if (ActionProvider.COMMAND_COPY.equals(command)) {
413:                    if (ModuleOperations.canRun(project, true)) {
414:                        DefaultProjectOperations
415:                                .performDefaultCopyOperation(project);
416:                    }
417:                    return;
418:                }
419:                if (!verifySufficientlyNewHarness(project)) {
420:                    return;
421:                }
422:                Properties p;
423:                String[] targetNames;
424:                FileObject buildScript = null;
425:                if (command.equals(COMMAND_COMPILE_SINGLE)) {
426:                    FileObject[] files = findSources(context);
427:                    p = new Properties();
428:                    if (files != null) {
429:                        p.setProperty("javac.includes", ActionUtils
430:                                .antIncludesList(files, project
431:                                        .getSourceDirectory())); // NOI18N
432:                        targetNames = new String[] { "compile-single" }; // NOI18N
433:                    } else {
434:                        files = findTestSources(context, false);
435:                        p.setProperty("javac.includes", ActionUtils
436:                                .antIncludesList(files, project
437:                                        .getTestSourceDirectory())); // NOI18N
438:                        targetNames = new String[] { "compile-test-single" }; // NOI18N
439:                    }
440:                } else if (command.equals(COMMAND_TEST_SINGLE)) {
441:                    p = new Properties();
442:                    FileObject[] files = findTestSourcesForSources(context);
443:                    targetNames = setupTestSingle(p, files);
444:                } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
445:                    p = new Properties();
446:                    FileObject[] files = findTestSourcesForSources(context);
447:                    targetNames = setupDebugTestSingle(p, files);
448:                } else if (command.equals(COMMAND_RUN_SINGLE)) {
449:                    FileObject[] files = findFunctionalTestSources(context);
450:                    if (files != null) {
451:                        String path = FileUtil.getRelativePath(project
452:                                .getFunctionalTestSourceDirectory(), files[0]);
453:                        p = new Properties();
454:                        p.setProperty("xtest.testtype", "qa-functional"); // NOI18N
455:                        p.setProperty("classname", path.substring(0,
456:                                path.length() - 5).replace('/', '.')); // NOI18N
457:                        targetNames = new String[] { "internal-execution" }; // NOI18N
458:                        buildScript = findTestBuildXml(project);
459:                    } else if ((files = findPerformanceTestSources(context)) != null) {
460:                        String path = FileUtil.getRelativePath(project
461:                                .getPerformanceTestSourceDirectory(), files[0]);
462:                        p = new Properties();
463:                        p.setProperty("xtest.testtype", "qa-performance"); // NOI18N
464:                        p.setProperty("classname", path.substring(0,
465:                                path.length() - 5).replace('/', '.')); // NOI18N
466:                        targetNames = new String[] { "internal-execution" }; // NOI18N
467:                        buildScript = findTestBuildXml(project);
468:                    } else {
469:                        files = findTestSources(context, false);
470:                        p = new Properties();
471:                        targetNames = setupTestSingle(p, files);
472:                    }
473:                } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
474:                    FileObject[] files = findTestSources(context, false);
475:                    p = new Properties();
476:                    targetNames = setupDebugTestSingle(p, files);
477:                } else if (command
478:                        .equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
479:                    FileObject[] files = findSources(context);
480:                    String path = null;
481:                    if (files != null) {
482:                        path = FileUtil.getRelativePath(project
483:                                .getSourceDirectory(), files[0]);
484:                        assert path != null;
485:                        assert path.endsWith(".java");
486:                        targetNames = new String[] { "debug-fix-nb" }; // NOI18N
487:                    } else {
488:                        files = findTestSources(context, false);
489:                        path = FileUtil.getRelativePath(project
490:                                .getTestSourceDirectory(), files[0]);
491:                        assert path != null;
492:                        assert path.endsWith(".java");
493:                        targetNames = new String[] { "debug-fix-test-nb" }; // NOI18N
494:                    }
495:                    String clazzSlash = path.substring(0, path.length() - 5);
496:                    p = new Properties();
497:                    p.setProperty("fix.class", clazzSlash); // NOI18N
498:                    buildScript = findBuildXml(project);
499:                } else if (command.equals(JavaProjectConstants.COMMAND_JAVADOC)
500:                        && !project.supportsJavadoc()) {
501:                    promptForPublicPackagesToDocument();
502:                    return;
503:                } else {
504:                    p = null;
505:                    targetNames = globalCommands.get(command);
506:                    if (targetNames == null) {
507:                        throw new IllegalArgumentException(command);
508:                    }
509:                }
510:                if (buildScript == null) {
511:                    buildScript = findBuildXml(project);
512:                }
513:                try {
514:                    ActionUtils.runTarget(buildScript, targetNames, p);
515:                } catch (IOException e) {
516:                    Util.err.notify(e);
517:                }
518:            }
519:
520:            private void promptForPublicPackagesToDocument() {
521:                // #61372: warn the user, rather than disabling the action.
522:                if (UIUtil.showAcceptCancelDialog(NbBundle.getMessage(
523:                        ModuleActions.class, "TITLE_javadoc_disabled"),
524:                        NbBundle.getMessage(ModuleActions.class,
525:                                "ERR_javadoc_disabled"), NbBundle.getMessage(
526:                                ModuleActions.class, "LBL_configure_pubpkg"),
527:                        null, NotifyDescriptor.WARNING_MESSAGE)) {
528:                    CustomizerProviderImpl cpi = project.getLookup().lookup(
529:                            CustomizerProviderImpl.class);
530:                    cpi
531:                            .showCustomizer(
532:                                    CustomizerProviderImpl.CATEGORY_VERSIONING,
533:                                    CustomizerProviderImpl.SUBCATEGORY_VERSIONING_PUBLIC_PACKAGES);
534:                }
535:            }
536:
537:            private static boolean verifySufficientlyNewHarness(
538:                    NbModuleProject project) {
539:                NbPlatform plaf = project.getPlatform(false);
540:                if (plaf != null
541:                        && plaf.getHarnessVersion() != NbPlatform.HARNESS_VERSION_UNKNOWN
542:                        && plaf.getHarnessVersion() < project
543:                                .getMinimumHarnessVersion()) {
544:                    promptForNewerHarness();
545:                    return false;
546:                } else {
547:                    return true;
548:                }
549:            }
550:
551:            static void promptForNewerHarness() {
552:                // #82388: warn the user that the harness version is too low.
553:                NotifyDescriptor d = new NotifyDescriptor.Message(
554:                        NbBundle.getMessage(ModuleActions.class,
555:                                "ERR_harness_too_old"),
556:                        NotifyDescriptor.ERROR_MESSAGE);
557:                d.setTitle(NbBundle.getMessage(ModuleActions.class,
558:                        "TITLE_harness_too_old"));
559:                DialogDisplayer.getDefault().notify(d);
560:            }
561:
562:            private String[] setupTestSingle(Properties p, FileObject[] files) {
563:                p.setProperty("test.includes", ActionUtils.antIncludesList(
564:                        files, project.getTestSourceDirectory())); // NOI18N
565:                return new String[] { "test-single" }; // NOI18N
566:            }
567:
568:            private String[] setupDebugTestSingle(Properties p,
569:                    FileObject[] files) {
570:                String path = FileUtil.getRelativePath(project
571:                        .getTestSourceDirectory(), files[0]);
572:                // Convert foo/FooTest.java -> foo.FooTest
573:                p.setProperty("test.class", path
574:                        .substring(0, path.length() - 5).replace('/', '.')); // NOI18N
575:                return new String[] { "debug-test-single-nb" }; // NOI18N
576:            }
577:
578:            private static Action createSimpleAction(
579:                    final NbModuleProject project, final String[] targetNames,
580:                    String displayName) {
581:                return new AbstractAction(displayName) {
582:                    public @Override
583:                    boolean isEnabled() {
584:                        return findBuildXml(project) != null;
585:                    }
586:
587:                    public void actionPerformed(ActionEvent ignore) {
588:                        if (!verifySufficientlyNewHarness(project)) {
589:                            return;
590:                        }
591:                        try {
592:                            ActionUtils.runTarget(findBuildXml(project),
593:                                    targetNames, null);
594:                        } catch (IOException e) {
595:                            Util.err.notify(e);
596:                        }
597:                    }
598:                };
599:            }
600:
601:            private static Action createMasterAction(
602:                    final NbModuleProject project, final String[] targetNames,
603:                    String displayName) {
604:                return new AbstractAction(displayName) {
605:                    public @Override
606:                    boolean isEnabled() {
607:                        return findMasterBuildXml(project) != null;
608:                    }
609:
610:                    public void actionPerformed(ActionEvent ignore) {
611:                        try {
612:                            ActionUtils.runTarget(findMasterBuildXml(project),
613:                                    targetNames, null);
614:                        } catch (IOException e) {
615:                            Util.err.notify(e);
616:                        }
617:                    }
618:                };
619:            }
620:
621:            private static Action createCheckBundleAction(
622:                    final NbModuleProject project, String displayName) {
623:                return new AbstractAction(displayName) {
624:                    public @Override
625:                    boolean isEnabled() {
626:                        return findMonitorXml() != null
627:                                && project.getPathWithinNetBeansOrg() != null;
628:                    }
629:
630:                    public void actionPerformed(ActionEvent ignore) {
631:                        Properties props = new Properties();
632:                        props
633:                                .put("modules", project
634:                                        .getPathWithinNetBeansOrg()); // NOI18N
635:                        props.put("fixedmodules", ""); // NOI18N
636:                        try {
637:                            ActionUtils.runTarget(findMonitorXml(),
638:                                    new String[] { "check-bundle-usage" },
639:                                    props); // NOI18N
640:                        } catch (IOException e) {
641:                            Util.err.notify(e);
642:                        }
643:                    }
644:
645:                    private FileObject findMonitorXml() {
646:                        return project
647:                                .getNbrootFileObject("nbbuild/monitor.xml"); // NOI18N
648:                    }
649:                };
650:            }
651:
652:            private static Action createReloadInIDEAction(
653:                    final NbModuleProject project, final String[] targetNames,
654:                    String displayName) {
655:                return new AbstractAction(displayName) {
656:                    public @Override
657:                    boolean isEnabled() {
658:                        if (findBuildXml(project) == null) {
659:                            return false;
660:                        }
661:                        NbModuleProvider.NbModuleType type = Util
662:                                .getModuleType(project);
663:                        if (type == NbModuleProvider.NETBEANS_ORG) {
664:                            return true;
665:                        } else if (type == NbModuleProvider.STANDALONE) {
666:                            NbPlatform p = project.getPlatform(false);
667:                            return p != null && p.isDefault();
668:                        } else {
669:                            assert type == NbModuleProvider.SUITE_COMPONENT : type;
670:                            try {
671:                                SuiteProject suite = SuiteUtils
672:                                        .findSuite(project);
673:                                if (suite == null) {
674:                                    return false;
675:                                }
676:                                NbPlatform p = suite.getPlatform(false);
677:                                if (/* #67148 */p == null || !p.isDefault()) {
678:                                    return false;
679:                                }
680:                                return SuiteProperties
681:                                        .getArrayProperty(
682:                                                suite.getEvaluator(),
683:                                                SuiteProperties.ENABLED_CLUSTERS_PROPERTY).length == 0
684:                                        && SuiteProperties
685:                                                .getArrayProperty(
686:                                                        suite.getEvaluator(),
687:                                                        SuiteProperties.DISABLED_CLUSTERS_PROPERTY).length == 0
688:                                        && SuiteProperties
689:                                                .getArrayProperty(
690:                                                        suite.getEvaluator(),
691:                                                        SuiteProperties.DISABLED_MODULES_PROPERTY).length == 0;
692:                            } catch (IOException e) {
693:                                Util.err.notify(ErrorManager.INFORMATIONAL, e);
694:                                return false;
695:                            }
696:                        }
697:                    }
698:
699:                    public void actionPerformed(ActionEvent ignore) {
700:                        if (!verifySufficientlyNewHarness(project)) {
701:                            return;
702:                        }
703:                        if (ModuleUISettings.getDefault()
704:                                .getConfirmReloadInIDE()) {
705:                            NotifyDescriptor d = new NotifyDescriptor.Confirmation(
706:                                    NbBundle.getMessage(ModuleActions.class,
707:                                            "LBL_reload_in_ide_confirm"),
708:                                    NbBundle.getMessage(ModuleActions.class,
709:                                            "LBL_reload_in_ide_confirm_title"),
710:                                    NotifyDescriptor.OK_CANCEL_OPTION);
711:                            if (DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
712:                                return;
713:                            }
714:                            ModuleUISettings.getDefault()
715:                                    .setConfirmReloadInIDE(false); // do not ask again
716:                        }
717:                        try {
718:                            ActionUtils.runTarget(findBuildXml(project),
719:                                    targetNames, null);
720:                        } catch (IOException e) {
721:                            Util.err.notify(e);
722:                        }
723:                    }
724:                };
725:            }
726:
727:            private static Action createArchAction(final NbModuleProject project) {
728:                return new AbstractAction(NbBundle.getMessage(
729:                        ModuleActions.class, "ACTION_arch")) {
730:                    public @Override
731:                    boolean isEnabled() {
732:                        return findBuildXml(project) != null;
733:                    }
734:
735:                    public void actionPerformed(ActionEvent ignore) {
736:                        if (!verifySufficientlyNewHarness(project)) {
737:                            return;
738:                        }
739:                        ProjectManager.mutex().writeAccess(
740:                                new Mutex.Action<Void>() {
741:                                    public Void run() {
742:                                        String prop = "javadoc.arch"; // NOI18N
743:                                        if (project.evaluator().getProperty(
744:                                                prop) == null) {
745:                                            // User has not yet configured an arch desc. Assume we should just do it for them.
746:                                            EditableProperties props = project
747:                                                    .getHelper()
748:                                                    .getProperties(
749:                                                            AntProjectHelper.PROJECT_PROPERTIES_PATH);
750:                                            props.setProperty(prop,
751:                                                    "${basedir}/arch.xml"); // NOI18N
752:                                            project
753:                                                    .getHelper()
754:                                                    .putProperties(
755:                                                            AntProjectHelper.PROJECT_PROPERTIES_PATH,
756:                                                            props);
757:                                            try {
758:                                                ProjectManager.getDefault()
759:                                                        .saveProject(project);
760:                                            } catch (IOException e) {
761:                                                Util.err.notify(e);
762:                                            }
763:                                        }
764:                                        return null;
765:                                    }
766:                                });
767:                        try {
768:                            ActionUtils.runTarget(findBuildXml(project),
769:                                    new String[] { "arch-nb" }, null); // NOI18N
770:                        } catch (IOException e) {
771:                            Util.err.notify(e);
772:                        }
773:                    }
774:                };
775:            }
776:
777:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.