1 19 20 package org.netbeans.modules.java.j2seproject; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.List ; 28 import javax.lang.model.element.TypeElement; 29 import org.netbeans.api.java.classpath.ClassPath; 30 import org.netbeans.api.java.platform.JavaPlatform; 31 import org.netbeans.api.java.platform.JavaPlatformManager; 32 import org.netbeans.api.java.platform.Specification; 33 import org.netbeans.api.java.source.ClasspathInfo; 34 import org.netbeans.api.java.source.ElementHandle; 35 import org.netbeans.api.java.source.SourceUtils; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.modules.java.j2seproject.ui.customizer.MainClassChooser; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileUtil; 40 41 45 public class J2SEProjectUtil { 46 private J2SEProjectUtil () {} 47 48 56 public static Object getEvaluatedProperty(Project p, String value) { 57 if (value == null) { 58 return null; 59 } 60 J2SEProject j2seprj = (J2SEProject) p.getLookup().lookup(J2SEProject.class); 61 if (j2seprj != null) { 62 return j2seprj.evaluator().evaluate(value); 63 } else { 64 return null; 65 } 66 } 67 68 73 public static boolean hasMainMethod(FileObject fo) { 74 if (MainClassChooser.unitTestingSupport_hasMainMethodResult != null) { 76 return MainClassChooser.unitTestingSupport_hasMainMethodResult.booleanValue (); 77 } 78 if (fo == null) { 79 return false; 81 } 82 return !SourceUtils.getMainClasses(fo).isEmpty(); 83 } 84 85 86 public static boolean isMainClass (final String className, ClassPath bootPath, ClassPath compilePath, ClassPath sourcePath) { 87 ClasspathInfo cpInfo = ClasspathInfo.create(bootPath, compilePath, sourcePath); 88 return SourceUtils.isMainClass(className, cpInfo); 89 } 90 91 92 93 103 public static URL getRootURL (File root, String offset) throws MalformedURLException { 104 URL url = root.toURI().toURL(); 105 if (FileUtil.isArchiveFile(url)) { 106 url = FileUtil.getArchiveRoot(url); 107 } else if (!root.exists()) { 108 url = new URL (url.toExternalForm() + "/"); } 110 if (offset != null) { 111 assert offset.endsWith("/"); url = new URL (url.toExternalForm() + offset); } 114 return url; 115 } 116 117 118 126 public static JavaPlatform getActivePlatform (final String activePlatformId) { 127 final JavaPlatformManager pm = JavaPlatformManager.getDefault(); 128 if (activePlatformId == null) { 129 return pm.getDefaultPlatform(); 130 } 131 else { 132 JavaPlatform[] installedPlatforms = pm.getPlatforms(null, new Specification ("j2se",null)); for (int i=0; i<installedPlatforms.length; i++) { 134 String antName = (String ) installedPlatforms[i].getProperties().get("platform.ant.name"); if (antName != null && antName.equals(activePlatformId)) { 136 return installedPlatforms[i]; 137 } 138 } 139 return null; 140 } 141 } 142 } 143 | Popular Tags |