KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > ModuleActions


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Properties JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.regex.Pattern JavaDoc;
32 import javax.swing.AbstractAction JavaDoc;
33 import javax.swing.Action JavaDoc;
34 import javax.swing.JSeparator JavaDoc;
35 import org.apache.tools.ant.module.api.support.ActionUtils;
36 import org.netbeans.api.java.project.JavaProjectConstants;
37 import org.netbeans.api.project.ProjectManager;
38 import org.netbeans.modules.apisupport.project.NbModuleProject;
39 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
40 import org.netbeans.modules.apisupport.project.Util;
41 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
42 import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl;
43 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteProperties;
44 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils;
45 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
46 import org.netbeans.spi.project.ActionProvider;
47 import org.netbeans.spi.project.support.ant.AntProjectHelper;
48 import org.netbeans.spi.project.support.ant.EditableProperties;
49 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
50 import org.netbeans.spi.project.ui.support.CommonProjectActions;
51 import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
52 import org.netbeans.spi.project.ui.support.ProjectSensitiveActions;
53 import org.openide.DialogDisplayer;
54 import org.openide.ErrorManager;
55 import org.openide.NotifyDescriptor;
56 import org.openide.actions.FindAction;
57 import org.openide.actions.ToolsAction;
58 import org.openide.filesystems.FileObject;
59 import org.openide.filesystems.FileUtil;
60 import org.openide.filesystems.Repository;
61 import org.openide.loaders.DataFolder;
62 import org.openide.loaders.FolderLookup;
63 import org.openide.util.Lookup;
64 import org.openide.util.Mutex;
65 import org.openide.util.NbBundle;
66 import org.openide.util.actions.SystemAction;
67
68 public final class ModuleActions implements ActionProvider {
69     
70     static Action JavaDoc[] getProjectActions(NbModuleProject project) {
71         List JavaDoc<Action JavaDoc> actions = new ArrayList JavaDoc<Action JavaDoc>();
72         actions.add(CommonProjectActions.newFileAction());
73         actions.add(null);
74         actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, NbBundle.getMessage(ModuleActions.class, "ACTION_build"), null));
75         actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, NbBundle.getMessage(ModuleActions.class, "ACTION_rebuild"), null));
76         actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, NbBundle.getMessage(ModuleActions.class, "ACTION_clean"), null));
77         actions.add(null);
78         boolean isNetBeansOrg = Util.getModuleType(project) == NbModuleProvider.NETBEANS_ORG;
79         if (isNetBeansOrg) {
80             String JavaDoc path = project.getPathWithinNetBeansOrg();
81             actions.add(createMasterAction(project, new String JavaDoc[] {"init", "all-" + path}, NbBundle.getMessage(ModuleActions.class, "ACTION_build_with_deps")));
82             actions.add(createMasterAction(project, new String JavaDoc[] {"init", "all-" + path, "tryme"}, NbBundle.getMessage(ModuleActions.class, "ACTION_build_with_deps_tryme")));
83         } else {
84             actions.add(createSimpleAction(project, new String JavaDoc[] {"run"}, NbBundle.getMessage(ModuleActions.class, "ACTION_run")));
85         }
86         actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_DEBUG, NbBundle.getMessage(ModuleActions.class, "ACTION_debug"), null));
87         actions.add(null);
88         if (project.supportsUnitTests()) {
89             actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_TEST, NbBundle.getMessage(ModuleActions.class, "ACTION_test"), null));
90             actions.add(null);
91         }
92         actions.add(ProjectSensitiveActions.projectCommandAction(JavaProjectConstants.COMMAND_JAVADOC, NbBundle.getMessage(ModuleActions.class, "ACTION_javadoc"), null));
93         actions.add(createArchAction(project));
94         actions.add(null);
95         if (isNetBeansOrg) {
96             actions.add(createCheckBundleAction(project, NbBundle.getMessage(ModuleActions.class, "ACTION_unused_bundle_keys")));
97             actions.add(null);
98         }
99         actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_RUN, NbBundle.getMessage(ModuleActions.class, "ACTION_reload"), null));
100         actions.add(createReloadInIDEAction(project, new String JavaDoc[] {"reload-in-ide"}, NbBundle.getMessage(ModuleActions.class, "ACTION_reload_in_ide")));
101         actions.add(createSimpleAction(project, new String JavaDoc[] {"nbm"}, NbBundle.getMessage(ModuleActions.class, "ACTION_nbm")));
102         actions.add(null);
103         actions.add(CommonProjectActions.setAsMainProjectAction());
104         actions.add(CommonProjectActions.openSubprojectsAction());
105         actions.add(CommonProjectActions.closeProjectAction());
106         actions.add(null);
107         actions.add(SystemAction.get(FindAction.class));
108         actions.add(null);
109         actions.add(CommonProjectActions.renameProjectAction());
110         actions.add(CommonProjectActions.moveProjectAction());
111         actions.add(CommonProjectActions.copyProjectAction());
112         actions.add(CommonProjectActions.deleteProjectAction());
113         
114         // Honor #57874 contract:
115
FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("Projects/Actions"); // NOI18N
116
if (fo != null && fo.isFolder()) {
117             actions.add(null);
118             for (Object JavaDoc next : new FolderLookup(DataFolder.findFolder(fo)).getLookup().lookupAll(Object JavaDoc.class)) {
119                 if (next instanceof Action JavaDoc) {
120                     actions.add((Action JavaDoc) next);
121                 } else if (next instanceof JSeparator JavaDoc) {
122                     actions.add(null);
123                 }
124             }
125         }
126         
127         actions.add(null);
128         actions.add(SystemAction.get(ToolsAction.class));
129         actions.add(null);
130         actions.add(CommonProjectActions.customizeProjectAction());
131         return actions.toArray(new Action JavaDoc[actions.size()]);
132     }
133     
134     private final NbModuleProject project;
135     private final Map JavaDoc<String JavaDoc,String JavaDoc[]> globalCommands = new HashMap JavaDoc<String JavaDoc,String JavaDoc[]>();
136     private final String JavaDoc[] supportedActions;
137     
138     public ModuleActions(NbModuleProject project) {
139         this.project = project;
140         Set JavaDoc<String JavaDoc> supportedActionsSet = new HashSet JavaDoc<String JavaDoc>();
141         globalCommands.put(ActionProvider.COMMAND_BUILD, new String JavaDoc[] {"netbeans"}); // NOI18N
142
globalCommands.put(ActionProvider.COMMAND_CLEAN, new String JavaDoc[] {"clean"}); // NOI18N
143
globalCommands.put(ActionProvider.COMMAND_REBUILD, new String JavaDoc[] {"clean", "netbeans"}); // NOI18N
144
globalCommands.put(ActionProvider.COMMAND_DEBUG, new String JavaDoc[] {"debug"}); // NOI18N
145
globalCommands.put(ActionProvider.COMMAND_RUN, new String JavaDoc[] {"reload"}); // NOI18N
146
globalCommands.put("profile", new String JavaDoc[] {"profile"}); // NOI18N
147
globalCommands.put(JavaProjectConstants.COMMAND_JAVADOC, new String JavaDoc[] {"javadoc-nb"}); // NOI18N
148
if (project.supportsUnitTests()) {
149             globalCommands.put(ActionProvider.COMMAND_TEST, new String JavaDoc[] {"test"}); // NOI18N
150
}
151         supportedActionsSet.addAll(globalCommands.keySet());
152         supportedActionsSet.add(ActionProvider.COMMAND_COMPILE_SINGLE);
153         supportedActionsSet.add(JavaProjectConstants.COMMAND_DEBUG_FIX); // #47012
154
if (project.supportsUnitTests()) {
155             supportedActionsSet.add(ActionProvider.COMMAND_TEST_SINGLE);
156             supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_TEST_SINGLE);
157             supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
158             supportedActionsSet.add(ActionProvider.COMMAND_DEBUG_SINGLE);
159         }
160         if (project.getFunctionalTestSourceDirectory() != null) {
161             supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
162         }
163         if (project.getPerformanceTestSourceDirectory() != null) {
164             supportedActionsSet.add(ActionProvider.COMMAND_RUN_SINGLE);
165         }
166         supportedActionsSet.add(ActionProvider.COMMAND_RENAME);
167         supportedActionsSet.add(ActionProvider.COMMAND_MOVE);
168         supportedActionsSet.add(ActionProvider.COMMAND_COPY);
169         supportedActionsSet.add(ActionProvider.COMMAND_DELETE);
170         supportedActions = supportedActionsSet.toArray(new String JavaDoc[supportedActionsSet.size()]);
171     }
172     
173     public String JavaDoc[] getSupportedActions() {
174         return supportedActions;
175     }
176     
177     private static FileObject findBuildXml(NbModuleProject project) {
178         return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
179     }
180     
181     private static FileObject findTestBuildXml(NbModuleProject project) {
182         return project.getProjectDirectory().getFileObject("test/build.xml"); // NOI18N
183
}
184     
185     private static FileObject findMasterBuildXml(NbModuleProject project) {
186         return project.getNbrootFileObject("nbbuild/build.xml"); // NOI18N
187
}
188     
189     public boolean isActionEnabled(String JavaDoc command, Lookup context) {
190         if (ActionProvider.COMMAND_DELETE.equals(command) ||
191                 ActionProvider.COMMAND_RENAME.equals(command) ||
192                 ActionProvider.COMMAND_MOVE.equals(command) ||
193                 ActionProvider.COMMAND_COPY.equals(command)) {
194             return true;
195         } else if (command.equals(COMMAND_COMPILE_SINGLE)) {
196             return findBuildXml(project) != null &&
197                     (findSources(context) != null || findTestSources(context, false) != null);
198         } else if (command.equals(COMMAND_TEST_SINGLE)) {
199             return findBuildXml(project) != null && findTestSourcesForSources(context) != null;
200         } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
201             FileObject[] files = findTestSourcesForSources(context);
202             return findBuildXml(project) != null && files != null && files.length == 1;
203         } else if (command.equals(COMMAND_RUN_SINGLE)) {
204             FileObject[] files = findFunctionalTestSources(context);
205             if (files != null && files.length == 1 && findTestBuildXml(project) != null) {
206                 return true;
207             }
208             files = findPerformanceTestSources(context);
209             if (files != null && files.length == 1 && findTestBuildXml(project) != null) {
210                 return true;
211             }
212             files = findTestSources(context, false);
213             return files != null;
214         } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
215             FileObject[] files = findTestSources(context, false);
216             return files != null && files.length == 1;
217         } else if (command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
218             FileObject[] files = findSources(context);
219             if (files != null && files.length == 1 && findBuildXml(project) != null) {
220                 return true;
221             }
222             files = findTestSources(context, false);
223             return files != null && files.length == 1 && findBuildXml(project) != null;
224         } else {
225             // other actions are global
226
return findBuildXml(project) != null;
227         }
228     }
229     
230     private static final Pattern JavaDoc SRCDIRJAVA = Pattern.compile("\\.java$"); // NOI18N
231
private static final String JavaDoc SUBST = "Test.java"; // NOI18N
232

233     private FileObject[] findSources(Lookup context) {
234         FileObject srcDir = project.getSourceDirectory();
235         if (srcDir != null) {
236             FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N
237
//System.err.println("findSources: srcDir=" + srcDir + " files=" + (files != null ? java.util.Arrays.asList(files) : null) + " context=" + context);
238
return files;
239         } else {
240             return null;
241         }
242     }
243     
244     private FileObject[] findTestSources(Lookup context, boolean checkInSrcDir) {
245         FileObject testSrcDir = project.getTestSourceDirectory();
246         if (testSrcDir != null) {
247             FileObject[] files = ActionUtils.findSelectedFiles(context, testSrcDir, ".java", true); // NOI18N
248
if (files != null) {
249                 return files;
250             }
251         }
252         //System.err.println("fTS: testSrcDir=" + testSrcDir + " checkInSrcDir=" + checkInSrcDir + " context=" + context);
253
if (checkInSrcDir && testSrcDir != null) {
254             FileObject srcDir = project.getSourceDirectory();
255             //System.err.println(" srcDir=" + srcDir);
256
if (srcDir != null) {
257                 FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N
258
//System.err.println(" files=" + files);
259
if (files != null) {
260                     FileObject[] files2 = ActionUtils.regexpMapFiles(files, srcDir, SRCDIRJAVA, testSrcDir, SUBST, true);
261                     //System.err.println(" files2=" + files2);
262
if (files2 != null) {
263                         return files2;
264                     }
265                 }
266             }
267         }
268         return null;
269     }
270     
271     /** Find tests corresponding to selected sources.
272      */

273     private FileObject[] findTestSourcesForSources(Lookup context) {
274         FileObject[] sourceFiles = findSources(context);
275         if (sourceFiles == null) {
276             return null;
277         }
278         FileObject testSrcDir = project.getTestSourceDirectory();
279         FileObject srcDir = project.getSourceDirectory();
280         return ActionUtils.regexpMapFiles(sourceFiles, srcDir, SRCDIRJAVA, testSrcDir, SUBST, true);
281     }
282     
283     private FileObject[] findFunctionalTestSources(Lookup context) {
284         FileObject srcDir = project.getFunctionalTestSourceDirectory();
285         if (srcDir != null) {
286             FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N
287
return files;
288         } else {
289             return null;
290         }
291     }
292     
293     private FileObject[] findPerformanceTestSources(Lookup context) {
294         FileObject srcDir = project.getPerformanceTestSourceDirectory();
295         if (srcDir != null) {
296             FileObject[] files = ActionUtils.findSelectedFiles(context, srcDir, ".java", true); // NOI18N
297
return files;
298         } else {
299             return null;
300         }
301     }
302     
303     public void invokeAction(String JavaDoc command, Lookup context) throws IllegalArgumentException JavaDoc {
304         if (ActionProvider.COMMAND_DELETE.equals(command)) {
305             if (ModuleOperations.canRun(project, true)) {
306                 DefaultProjectOperations.performDefaultDeleteOperation(project);
307             }
308             return;
309         } else if (ActionProvider.COMMAND_RENAME.equals(command)) {
310             if (ModuleOperations.canRun(project, true)) {
311                 DefaultProjectOperations.performDefaultRenameOperation(project, null);
312             }
313             return;
314         } else if (ActionProvider.COMMAND_MOVE.equals(command)) {
315             if (ModuleOperations.canRun(project, true)) {
316                 DefaultProjectOperations.performDefaultMoveOperation(project);
317             }
318             return;
319         } else if (ActionProvider.COMMAND_COPY.equals(command)) {
320             if (ModuleOperations.canRun(project, true)) {
321                 DefaultProjectOperations.performDefaultCopyOperation(project);
322             }
323             return;
324         }
325         NbPlatform plaf = project.getPlatform(false);
326         if (plaf != null && plaf.getHarnessVersion() != NbPlatform.HARNESS_VERSION_UNKNOWN && plaf.getHarnessVersion() < project.getMinimumHarnessVersion()) {
327             promptForNewerHarness();
328             return;
329         }
330         Properties JavaDoc p;
331         String JavaDoc[] targetNames;
332         FileObject buildScript = null;
333         if (command.equals(COMMAND_COMPILE_SINGLE)) {
334             FileObject[] files = findSources(context);
335             p = new Properties JavaDoc();
336             if (files != null) {
337                 p.setProperty("javac.includes", ActionUtils.antIncludesList(files, project.getSourceDirectory())); // NOI18N
338
targetNames = new String JavaDoc[] {"compile-single"}; // NOI18N
339
} else {
340                 files = findTestSources(context, false);
341                 p.setProperty("javac.includes", ActionUtils.antIncludesList(files, project.getTestSourceDirectory())); // NOI18N
342
targetNames = new String JavaDoc[] {"compile-test-single"}; // NOI18N
343
}
344         } else if (command.equals(COMMAND_TEST_SINGLE)) {
345             p = new Properties JavaDoc();
346             FileObject[] files = findTestSourcesForSources(context);
347             targetNames = setupTestSingle(p, files);
348         } else if (command.equals(COMMAND_DEBUG_TEST_SINGLE)) {
349             p = new Properties JavaDoc();
350             FileObject[] files = findTestSourcesForSources(context);
351             targetNames = setupDebugTestSingle(p, files);
352         } else if (command.equals(COMMAND_RUN_SINGLE)) {
353             FileObject[] files = findFunctionalTestSources(context);
354             if (files != null) {
355                 String JavaDoc path = FileUtil.getRelativePath(project.getFunctionalTestSourceDirectory(), files[0]);
356                 p = new Properties JavaDoc();
357                 p.setProperty("xtest.testtype", "qa-functional"); // NOI18N
358
p.setProperty("classname", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N
359
targetNames = new String JavaDoc[] {"internal-execution"}; // NOI18N
360
buildScript = findTestBuildXml(project);
361             } else if ((files = findPerformanceTestSources(context)) != null) {
362                 String JavaDoc path = FileUtil.getRelativePath(project.getPerformanceTestSourceDirectory(), files[0]);
363                 p = new Properties JavaDoc();
364                 p.setProperty("xtest.testtype", "qa-performance"); // NOI18N
365
p.setProperty("classname", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N
366
targetNames = new String JavaDoc[] {"internal-execution"}; // NOI18N
367
buildScript = findTestBuildXml(project);
368             } else {
369                 files = findTestSources(context, false);
370                 p = new Properties JavaDoc();
371                 targetNames = setupTestSingle(p, files);
372             }
373         } else if (command.equals(COMMAND_DEBUG_SINGLE)) {
374             FileObject[] files = findTestSources(context, false);
375             p = new Properties JavaDoc();
376             targetNames = setupDebugTestSingle(p, files);
377         } else if (command.equals(JavaProjectConstants.COMMAND_DEBUG_FIX)) {
378             FileObject[] files = findSources(context);
379             String JavaDoc path = null;
380             if (files != null) {
381                 path = FileUtil.getRelativePath(project.getSourceDirectory(), files[0]);
382                 assert path != null;
383                 assert path.endsWith(".java");
384                 targetNames = new String JavaDoc[] {"debug-fix-nb"}; // NOI18N
385
} else {
386                 files = findTestSources(context, false);
387                 path = FileUtil.getRelativePath(project.getTestSourceDirectory(), files[0]);
388                 assert path != null;
389                 assert path.endsWith(".java");
390                 targetNames = new String JavaDoc[] {"debug-fix-test-nb"}; // NOI18N
391
}
392             String JavaDoc clazzSlash = path.substring(0, path.length() - 5);
393             p = new Properties JavaDoc();
394             p.setProperty("fix.class", clazzSlash); // NOI18N
395
buildScript = findBuildXml(project);
396         } else if (command.equals(JavaProjectConstants.COMMAND_JAVADOC) && !project.supportsJavadoc()) {
397             promptForPublicPackagesToDocument();
398             return;
399         } else {
400             p = null;
401             targetNames = globalCommands.get(command);
402             if (targetNames == null) {
403                 throw new IllegalArgumentException JavaDoc(command);
404             }
405         }
406         if (buildScript == null) {
407             buildScript = findBuildXml(project);
408         }
409         try {
410             ActionUtils.runTarget(buildScript, targetNames, p);
411         } catch (IOException JavaDoc e) {
412             Util.err.notify(e);
413         }
414     }
415     
416     private void promptForPublicPackagesToDocument() {
417         // #61372: warn the user, rather than disabling the action.
418
if (UIUtil.showAcceptCancelDialog(
419                 NbBundle.getMessage(ModuleActions.class, "TITLE_javadoc_disabled"),
420                 NbBundle.getMessage(ModuleActions.class, "ERR_javadoc_disabled"),
421                 NbBundle.getMessage(ModuleActions.class, "LBL_configure_pubpkg"),
422                 null,
423                 NotifyDescriptor.WARNING_MESSAGE)) {
424             CustomizerProviderImpl cpi = project.getLookup().lookup(CustomizerProviderImpl.class);
425             cpi.showCustomizer(CustomizerProviderImpl.CATEGORY_VERSIONING, CustomizerProviderImpl.SUBCATEGORY_VERSIONING_PUBLIC_PACKAGES);
426         }
427     }
428
429     static void promptForNewerHarness() {
430         // #82388: warn the user that the harness version is too low.
431
NotifyDescriptor d = new NotifyDescriptor.Message(NbBundle.getMessage(ModuleActions.class, "ERR_harness_too_old"), NotifyDescriptor.ERROR_MESSAGE);
432         d.setTitle(NbBundle.getMessage(ModuleActions.class, "TITLE_harness_too_old"));
433         DialogDisplayer.getDefault().notify(d);
434     }
435     
436     private String JavaDoc[] setupTestSingle(Properties JavaDoc p, FileObject[] files) {
437         p.setProperty("test.includes", ActionUtils.antIncludesList(files, project.getTestSourceDirectory())); // NOI18N
438
return new String JavaDoc[] {"test-single"}; // NOI18N
439
}
440     
441     private String JavaDoc[] setupDebugTestSingle(Properties JavaDoc p, FileObject[] files) {
442         String JavaDoc path = FileUtil.getRelativePath(project.getTestSourceDirectory(), files[0]);
443         // Convert foo/FooTest.java -> foo.FooTest
444
p.setProperty("test.class", path.substring(0, path.length() - 5).replace('/', '.')); // NOI18N
445
return new String JavaDoc[] {"debug-test-single-nb"}; // NOI18N
446
}
447     
448     private static Action JavaDoc createSimpleAction(final NbModuleProject project, final String JavaDoc[] targetNames, String JavaDoc displayName) {
449         return new AbstractAction JavaDoc(displayName) {
450             public boolean isEnabled() {
451                 return findBuildXml(project) != null;
452             }
453             public void actionPerformed(ActionEvent JavaDoc ignore) {
454                 try {
455                     ActionUtils.runTarget(findBuildXml(project), targetNames, null);
456                 } catch (IOException JavaDoc e) {
457                     Util.err.notify(e);
458                 }
459             }
460         };
461     }
462     
463     private static Action JavaDoc createMasterAction(final NbModuleProject project, final String JavaDoc[] targetNames, String JavaDoc displayName) {
464         return new AbstractAction JavaDoc(displayName) {
465             public boolean isEnabled() {
466                 return findMasterBuildXml(project) != null;
467             }
468             public void actionPerformed(ActionEvent JavaDoc ignore) {
469                 try {
470                     ActionUtils.runTarget(findMasterBuildXml(project), targetNames, null);
471                 } catch (IOException JavaDoc e) {
472                     Util.err.notify(e);
473                 }
474             }
475         };
476     }
477     
478     private static Action JavaDoc createCheckBundleAction(final NbModuleProject project, String JavaDoc displayName) {
479         return new AbstractAction JavaDoc(displayName) {
480             public boolean isEnabled() {
481                 return findMonitorXml() != null && project.getPathWithinNetBeansOrg() != null;
482             }
483             public void actionPerformed(ActionEvent JavaDoc ignore) {
484                 Properties JavaDoc props = new Properties JavaDoc();
485                 props.put("modules", project.getPathWithinNetBeansOrg()); // NOI18N
486
props.put("fixedmodules", ""); // NOI18N
487
try {
488                     ActionUtils.runTarget(findMonitorXml(), new String JavaDoc[] {"check-bundle-usage"}, props); // NOI18N
489
} catch (IOException JavaDoc e) {
490                     Util.err.notify(e);
491                 }
492             }
493             private FileObject findMonitorXml() {
494                 return project.getNbrootFileObject("nbbuild/monitor.xml"); // NOI18N
495
}
496         };
497     }
498     
499     private static Action JavaDoc createReloadInIDEAction(final NbModuleProject project, final String JavaDoc[] targetNames, String JavaDoc displayName) {
500         return new AbstractAction JavaDoc(displayName) {
501             public boolean isEnabled() {
502                 if (findBuildXml(project) == null) {
503                     return false;
504                 }
505                 NbModuleProvider.NbModuleType type = Util.getModuleType(project);
506                 if (type == NbModuleProvider.NETBEANS_ORG) {
507                     return true;
508                 } else if (type == NbModuleProvider.STANDALONE) {
509                     NbPlatform p = project.getPlatform(false);
510                     return p != null && p.isDefault();
511                 } else {
512                     assert type == NbModuleProvider.SUITE_COMPONENT : type;
513                     try {
514                         SuiteProject suite = SuiteUtils.findSuite(project);
515                         if (suite == null) {
516                             return false;
517                         }
518                         NbPlatform p = suite.getPlatform(false);
519                         if (/* #67148 */p == null || !p.isDefault()) {
520                             return false;
521                         }
522                         return SuiteProperties.getArrayProperty(suite.getEvaluator(), SuiteProperties.ENABLED_CLUSTERS_PROPERTY).length == 0 &&
523                                 SuiteProperties.getArrayProperty(suite.getEvaluator(), SuiteProperties.DISABLED_CLUSTERS_PROPERTY).length == 0 &&
524                                 SuiteProperties.getArrayProperty(suite.getEvaluator(), SuiteProperties.DISABLED_MODULES_PROPERTY).length == 0;
525                     } catch (IOException JavaDoc e) {
526                         Util.err.notify(ErrorManager.INFORMATIONAL, e);
527                         return false;
528                     }
529                 }
530             }
531             public void actionPerformed(ActionEvent JavaDoc ignore) {
532                 if (ModuleUISettings.getDefault().getConfirmReloadInIDE()) {
533                     NotifyDescriptor d = new NotifyDescriptor.Confirmation(
534                             NbBundle.getMessage(ModuleActions.class, "LBL_reload_in_ide_confirm"),
535                             NbBundle.getMessage(ModuleActions.class, "LBL_reload_in_ide_confirm_title"),
536                             NotifyDescriptor.OK_CANCEL_OPTION);
537                     if (DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
538                         return;
539                     }
540                     ModuleUISettings.getDefault().setConfirmReloadInIDE(false); // do not ask again
541
}
542                 try {
543                     ActionUtils.runTarget(findBuildXml(project), targetNames, null);
544                 } catch (IOException JavaDoc e) {
545                     Util.err.notify(e);
546                 }
547             }
548         };
549     }
550     
551     private static Action JavaDoc createArchAction(final NbModuleProject project) {
552         return new AbstractAction JavaDoc(NbBundle.getMessage(ModuleActions.class, "ACTION_arch")) {
553             public boolean isEnabled() {
554                 return findBuildXml(project) != null;
555             }
556             public void actionPerformed(ActionEvent JavaDoc ignore) {
557                 ProjectManager.mutex().writeAccess(new Mutex.Action<Void JavaDoc>() {
558                     public Void JavaDoc run() {
559                         String JavaDoc prop = "javadoc.arch"; // NOI18N
560
if (project.evaluator().getProperty(prop) == null) {
561                             // User has not yet configured an arch desc. Assume we should just do it for them.
562
EditableProperties props = project.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
563                             props.setProperty(prop, "${basedir}/arch.xml"); // NOI18N
564
project.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
565                             try {
566                                 ProjectManager.getDefault().saveProject(project);
567                             } catch (IOException JavaDoc e) {
568                                 Util.err.notify(e);
569                             }
570                         }
571                         return null;
572                     }
573                 });
574                 try {
575                     ActionUtils.runTarget(findBuildXml(project), new String JavaDoc[] {"arch-nb"}, null); // NOI18N
576
} catch (IOException JavaDoc e) {
577                     Util.err.notify(e);
578                 }
579             }
580         };
581     }
582     
583 }
584
Popular Tags