1 19 20 package org.netbeans.modules.ruby.api.project.rake; 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 RakeArtifact { 52 53 private final Properties PROPS = new Properties (); 54 55 58 protected RakeArtifact() {} 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 URI artifactLocations[] = getArtifactLocations(); 191 List <FileObject> l = new ArrayList <FileObject>(); 192 for (int i=0; i<artifactLocations.length; i++) { 193 FileObject fo = getArtifactFile(artifactLocations[i]); 194 if (fo != null) { 195 l.add(fo); 196 } 197 } 198 return l.toArray(new FileObject[l.size()]); 199 } 200 201 208 public final FileObject getScriptFile() { 209 FileObject fo = FileUtil.toFileObject(getScriptLocation()); 210 assert fo == null || FileUtil.toFile(fo) != null : fo; 211 return fo; 212 } 213 214 220 public Project getProject() { 221 return FileOwnerQuery.getOwner(getScriptLocation().toURI()); 222 } 223 224 232 public Properties getProperties() { 233 return PROPS; 234 } 235 236 } 237 | Popular Tags |