1 19 20 package org.netbeans.modules.ruby.api.project.rake; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.modules.ruby.spi.project.rake.RakeArtifactProvider; 28 import org.netbeans.modules.ruby.spi.project.rake.RakeArtifactQueryImplementation; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.util.Lookup; 31 32 37 public class RakeArtifactQuery { 38 39 private RakeArtifactQuery() {} 40 41 48 public static RakeArtifact findArtifactFromFile(File file) { 49 if (!file.equals(FileUtil.normalizeFile(file))) { 50 throw new IllegalArgumentException ("Parameter file was not "+ "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file)); } 53 Iterator it = Lookup.getDefault().lookupAll(RakeArtifactQueryImplementation.class).iterator(); 54 while (it.hasNext()) { 55 RakeArtifactQueryImplementation aaqi = (RakeArtifactQueryImplementation)it.next(); 56 RakeArtifact artifact = aaqi.findArtifact(file); 57 if (artifact != null) { 58 return artifact; 59 } 60 } 61 return null; 62 } 63 64 72 public static RakeArtifact findArtifactByID(Project p, String id) { 73 RakeArtifactProvider prov = p.getLookup().lookup(RakeArtifactProvider.class); 74 if (prov == null) { 75 return null; 76 } 77 RakeArtifact[] artifacts = prov.getBuildArtifacts(); 78 for (int i = 0; i < artifacts.length; i++) { 79 if (artifacts[i].getID().equals(id)) { 80 return artifacts[i]; 81 } 82 } 83 return null; 84 } 85 86 94 public static RakeArtifact[] findArtifactsByType(Project p, String type) { 95 RakeArtifactProvider prov = p.getLookup().lookup(RakeArtifactProvider.class); 96 if (prov == null) { 97 return new RakeArtifact[0]; 98 } 99 RakeArtifact[] artifacts = prov.getBuildArtifacts(); 100 List <RakeArtifact> l = new ArrayList <RakeArtifact>(artifacts.length); 101 for (RakeArtifact aa : artifacts) { 102 if (aa.getType().equals(type)) { 103 l.add(aa); 104 } 105 } 106 return l.toArray(new RakeArtifact[l.size()]); 107 } 108 109 } 110 | Popular Tags |