1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.netbeans.api.java.platform.JavaPlatform; 27 import org.netbeans.api.java.platform.JavaPlatformManager; 28 import org.netbeans.api.java.platform.Specification; 29 import org.netbeans.api.java.source.ClasspathInfo; 30 import org.netbeans.api.java.source.SourceUtils; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.modules.j2ee.clientproject.ui.customizer.MainClassChooser; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 36 40 public class AppClientProjectUtil { 41 42 private AppClientProjectUtil () {} 43 44 53 public static Object getEvaluatedProperty(Project p, String value) { 54 if (value == null) { 55 return null; 56 } 57 AppClientProject j2seprj = (AppClientProject) p.getLookup().lookup(AppClientProject.class); 58 if (j2seprj != null) { 59 return j2seprj.evaluator().evaluate(value); 60 } else { 61 return null; 62 } 63 } 64 65 70 public static boolean hasMainMethod(FileObject fo) { 71 if (MainClassChooser.unitTestingSupport_hasMainMethodResult != null) { 73 return MainClassChooser.unitTestingSupport_hasMainMethodResult.booleanValue (); 74 } 75 if (fo == null) { 76 return false; 78 } 79 return !SourceUtils.getMainClasses(fo).isEmpty(); 80 } 81 82 public static boolean isMainClass (final String className, ClassPath bootPath, ClassPath compilePath, ClassPath sourcePath) { 83 ClasspathInfo cpInfo = ClasspathInfo.create(bootPath, compilePath, sourcePath); 84 return SourceUtils.isMainClass(className, cpInfo); 85 } 86 87 97 public static URL getRootURL (File root, String offset) throws MalformedURLException { 98 URL url = root.toURI().toURL(); 99 if (FileUtil.isArchiveFile(url)) { 100 url = FileUtil.getArchiveRoot(url); 101 } else if (!root.exists()) { 102 url = new URL (url.toExternalForm() + "/"); } 104 if (offset != null) { 105 assert offset.endsWith("/"); url = new URL (url.toExternalForm() + offset); } 108 return url; 109 } 110 111 112 120 public static JavaPlatform getActivePlatform (final String activePlatformId) { 121 final JavaPlatformManager pm = JavaPlatformManager.getDefault(); 122 if (activePlatformId == null) { 123 return pm.getDefaultPlatform(); 124 } 125 else { 126 JavaPlatform[] installedPlatforms = pm.getPlatforms(null, new Specification ("j2se",null)); for (int i=0; i<installedPlatforms.length; i++) { 128 String antName = (String ) installedPlatforms[i].getProperties().get("platform.ant.name"); if (antName != null && antName.equals(activePlatformId)) { 130 return installedPlatforms[i]; 131 } 132 } 133 return null; 134 } 135 } 136 } 137 | Popular Tags |