1 19 20 package org.netbeans.modules.ruby.rubyproject; 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.List ; 27 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation; 28 import org.netbeans.api.project.Project; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 36 public class RubyProjectUtil { 37 private RubyProjectUtil () {} 38 39 47 public static Object getEvaluatedProperty(Project p, String value) { 48 if (value == null) { 49 return null; 50 } 51 RubyProject j2seprj = (RubyProject) p.getLookup().lookup(RubyProject.class); 52 if (j2seprj != null) { 53 return j2seprj.evaluator().evaluate(value); 54 } else { 55 return null; 56 } 57 } 58 59 64 public static boolean hasMainMethod(FileObject fo) { 65 67 88 return true; 89 } 90 91 96 public static List getMainClasses (FileObject[] roots) { 97 List result = new ArrayList (); 98 for (int i=0; i<roots.length; i++) { 99 getMainClasses(roots[i], result); 100 } 101 return result; 102 } 103 104 public static void getAllScripts(String prefix, FileObject sourcesRoot, List result) { 105 FileObject children[] = sourcesRoot.getChildren(); 106 if (!"".equals(prefix)) { 107 prefix += "/"; 108 } 110 for (int i = 0; i < children.length; i++) { 111 if (children[i].isData()) { 112 if (children[i].getMIMEType().equals(RubyInstallation.RUBY_MIME_TYPE)) { 113 result.add(prefix + children[i].getNameExt()); 114 } 115 } 116 if (children[i].isFolder()) { 117 getAllScripts(prefix + children[i].getNameExt(), children[i], result); 118 } 119 } 120 } 121 122 123 128 private static void getMainClasses (FileObject root, List addInto) { 129 getAllScripts("", root, addInto); 130 131 } 159 160 167 public static boolean isMainClass(String className, FileObject[] roots) { 168 171 if (roots == null) { 173 return false; 174 } 175 176 for (FileObject root : roots) { 177 if (root.getFileObject(className) != null) { 178 return true; 179 } 180 } 181 return false; 182 } 183 184 185 186 196 public static URL getRootURL (File root, String offset) throws MalformedURLException { 197 URL url = root.toURI().toURL(); 198 if (FileUtil.isArchiveFile(url)) { 199 url = FileUtil.getArchiveRoot(url); 200 } else if (!root.exists()) { 201 url = new URL (url.toExternalForm() + "/"); } 203 if (offset != null) { 204 assert offset.endsWith("/"); url = new URL (url.toExternalForm() + offset); } 207 return url; 208 } 209 } 210 | Popular Tags |