1 19 20 package org.netbeans.api.project.ant; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URI ; 25 import java.net.URL ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 import java.util.HashSet ; 29 import java.util.List ; 30 import java.util.Properties ; 31 import java.util.Set ; 32 import org.netbeans.api.project.FileOwnerQuery; 33 import org.netbeans.api.project.Project; 34 import org.openide.ErrorManager; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 import org.openide.filesystems.URLMapper; 38 39 41 51 public abstract class AntArtifact { 52 53 private final Properties PROPS = new Properties (); 54 55 58 protected AntArtifact() {} 59 60 77 public abstract String getType(); 78 79 84 public abstract File getScriptLocation(); 85 86 91 public abstract String getTargetName(); 92 93 99 public abstract String getCleanTargetName(); 100 101 108 @Deprecated 109 public URI getArtifactLocation() { 110 return getArtifactLocations()[0]; 111 } 112 113 private static final Set <String > warnedClasses = Collections.synchronizedSet(new HashSet <String >()); 114 124 public URI [] getArtifactLocations() { 125 String name = getClass().getName(); 126 if (warnedClasses.add(name)) { 127 ErrorManager.getDefault().log(ErrorManager.WARNING, "Warning: " + name + ".getArtifactLocations() must be overridden"); 128 } 129 return new URI []{getArtifactLocation()}; 130 } 131 132 138 public String getID() { 139 return getTargetName(); 140 } 141 142 148 @Deprecated 149 public final FileObject getArtifactFile() { 150 FileObject fos[] = getArtifactFiles(); 151 if (fos.length > 0) { 152 return fos[0]; 153 } else { 154 return null; 155 } 156 } 157 158 private FileObject getArtifactFile(URI artifactLocation) { 159 assert !artifactLocation.isAbsolute() || 160 (!artifactLocation.isOpaque() && "file".equals(artifactLocation.getScheme())) : artifactLocation; 162 URL artifact; 163 try { 164 artifact = getScriptLocation().toURI().resolve(artifactLocation).normalize().toURL(); 166 } catch (MalformedURLException e) { 167 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 168 return null; 169 } 170 FileObject fo = URLMapper.findFileObject(artifact); 171 if (fo != null) { 172 assert FileUtil.toFile(fo) != null : fo; 173 return fo; 174 } else { 175 return null; 176 } 177 } 178 179 189 public final FileObject[] getArtifactFiles() { 190 List <FileObject> l = new ArrayList <FileObject>(); 191 for (URI artifactLocation : getArtifactLocations()) { 192 FileObject fo = getArtifactFile(artifactLocation); 193 if (fo != null) { 194 l.add(fo); 195 } 196 } 197 return l.toArray(new FileObject[l.size()]); 198 } 199 200 207 public final FileObject getScriptFile() { 208 FileObject fo = FileUtil.toFileObject(getScriptLocation()); 209 assert fo == null || FileUtil.toFile(fo) != null : fo; 210 return fo; 211 } 212 213 219 public Project getProject() { 220 return FileOwnerQuery.getOwner(getScriptLocation().toURI()); 221 } 222 223 231 public Properties getProperties() { 232 return PROPS; 233 } 234 235 } 236 | Popular Tags |