Lines 29-34
Link Here
|
29 |
import javax.swing.event.ChangeEvent; |
29 |
import javax.swing.event.ChangeEvent; |
30 |
import javax.swing.event.ChangeListener; |
30 |
import javax.swing.event.ChangeListener; |
31 |
import org.apache.tools.ant.module.api.support.ActionUtils; |
31 |
import org.apache.tools.ant.module.api.support.ActionUtils; |
|
|
32 |
import org.netbeans.api.java.classpath.ClassPath; |
32 |
import org.netbeans.api.java.project.JavaProjectConstants; |
33 |
import org.netbeans.api.java.project.JavaProjectConstants; |
33 |
import org.netbeans.api.project.Project; |
34 |
import org.netbeans.api.project.Project; |
34 |
import org.netbeans.modules.java.j2seproject.ui.customizer.MainClassChooser; |
35 |
import org.netbeans.modules.java.j2seproject.ui.customizer.MainClassChooser; |
Lines 42-52
Link Here
|
42 |
import org.openide.ErrorManager; |
43 |
import org.openide.ErrorManager; |
43 |
import org.openide.NotifyDescriptor; |
44 |
import org.openide.NotifyDescriptor; |
44 |
import org.openide.awt.MouseUtils; |
45 |
import org.openide.awt.MouseUtils; |
|
|
46 |
import org.openide.cookies.SourceCookie; |
45 |
import org.openide.filesystems.FileObject; |
47 |
import org.openide.filesystems.FileObject; |
46 |
import org.openide.filesystems.FileUtil; |
48 |
import org.openide.filesystems.FileUtil; |
47 |
import org.openide.loaders.DataObject; |
49 |
import org.openide.loaders.DataObject; |
48 |
import org.openide.loaders.DataObjectNotFoundException; |
50 |
import org.openide.loaders.DataObjectNotFoundException; |
49 |
import org.openide.nodes.Node; |
51 |
import org.openide.nodes.Node; |
|
|
52 |
import org.openide.src.ClassElement; |
53 |
import org.openide.src.SourceElement; |
50 |
import org.openide.util.Lookup; |
54 |
import org.openide.util.Lookup; |
51 |
import org.openide.util.NbBundle; |
55 |
import org.openide.util.NbBundle; |
52 |
import org.openide.util.lookup.Lookups; |
56 |
import org.openide.util.lookup.Lookups; |
Lines 392-400
Link Here
|
392 |
return false; |
396 |
return false; |
393 |
} |
397 |
} |
394 |
|
398 |
|
395 |
return J2SEProjectUtil.isMainClass (mainClass, sourcesRoot); |
399 |
if (J2SEProjectUtil.isMainClass (mainClass, sourcesRoot)) { |
|
|
400 |
return true; |
401 |
} |
402 |
|
403 |
// check also EXECUTE classpath |
404 |
|
405 |
// find mainclass FileObject |
406 |
ClassPath classPath = ClassPath.getClassPath (sourcesRoot, ClassPath.EXECUTE); |
407 |
mainClass = mainClass.replace('.','/');// NOI18N |
408 |
FileObject mainFO = classPath.findResource (mainClass + ".class"); // XXX // NOI18N |
409 |
|
410 |
return canBeRun (mainFO); |
411 |
} |
412 |
|
413 |
/** Checks if given file object contains the main method. |
414 |
* |
415 |
* @param classFO file object represents java |
416 |
* @return false if parameter is null or doesn't contain SourceCookie |
417 |
* or SourceCookie doesn't contain the main method |
418 |
*/ |
419 |
public static boolean canBeRun (FileObject classFO) { |
420 |
if (classFO == null) { |
421 |
return false; |
422 |
} |
423 |
try { |
424 |
DataObject classDO = DataObject.find (classFO); |
425 |
Object obj = classDO.getCookie (SourceCookie.class); |
426 |
if (obj == null || !(obj instanceof SourceCookie)) { |
427 |
return false; |
428 |
} |
429 |
SourceCookie cookie = (SourceCookie) obj; |
430 |
// check the main class |
431 |
SourceElement source = cookie.getSource (); |
432 |
ClassElement[] classes = source.getClasses(); |
433 |
boolean hasMain = false; |
434 |
for (int i = 0; i < classes.length; i++) { |
435 |
if (classes[i].hasMainMethod()) { |
436 |
return true; |
437 |
} |
438 |
} |
439 |
} catch (DataObjectNotFoundException ex) { |
440 |
// can ignore it, classFO could be wrongly set |
441 |
} |
442 |
return false; |
396 |
} |
443 |
} |
397 |
|
444 |
|
|
|
445 |
|
398 |
private boolean showMainClassWarning (String mainClass, String projectName, EditableProperties ep) { |
446 |
private boolean showMainClassWarning (String mainClass, String projectName, EditableProperties ep) { |
399 |
boolean canceled; |
447 |
boolean canceled; |
400 |
final JButton okButton = new JButton (NbBundle.getMessage (MainClassWarning.class, "LBL_MainClassWarning_ChooseMainClass_OK")); // NOI18N |
448 |
final JButton okButton = new JButton (NbBundle.getMessage (MainClassWarning.class, "LBL_MainClassWarning_ChooseMainClass_OK")); // NOI18N |