1 19 20 package org.netbeans.api.project.ant; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.spi.project.ant.AntArtifactProvider; 27 import org.netbeans.spi.project.ant.AntArtifactQueryImplementation; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.util.Lookup; 30 31 36 public class AntArtifactQuery { 37 38 private AntArtifactQuery() {} 39 40 47 public static AntArtifact findArtifactFromFile(File file) { 48 if (!file.equals(FileUtil.normalizeFile(file))) { 49 throw new IllegalArgumentException ("Parameter file was not "+ "normalized. Was "+file+" instead of "+FileUtil.normalizeFile(file)); } 52 for (AntArtifactQueryImplementation aaqi : Lookup.getDefault().lookupAll(AntArtifactQueryImplementation.class)) { 53 AntArtifact artifact = aaqi.findArtifact(file); 54 if (artifact != null) { 55 return artifact; 56 } 57 } 58 return null; 59 } 60 61 69 public static AntArtifact findArtifactByID(Project p, String id) { 70 AntArtifactProvider prov = p.getLookup().lookup(AntArtifactProvider.class); 71 if (prov == null) { 72 return null; 73 } 74 for (AntArtifact artifact : prov.getBuildArtifacts()) { 75 if (artifact.getID().equals(id)) { 76 return artifact; 77 } 78 } 79 return null; 80 } 81 82 90 public static AntArtifact[] findArtifactsByType(Project p, String type) { 91 AntArtifactProvider prov = p.getLookup().lookup(AntArtifactProvider.class); 92 if (prov == null) { 93 return new AntArtifact[0]; 94 } 95 AntArtifact[] artifacts = prov.getBuildArtifacts(); 96 List <AntArtifact> l = new ArrayList <AntArtifact>(artifacts.length); 97 for (AntArtifact aa : artifacts) { 98 if (aa.getType().equals(type)) { 99 l.add(aa); 100 } 101 } 102 return l.toArray(new AntArtifact[l.size()]); 103 } 104 105 } 106 | Popular Tags |