org.apache.tools.ant.types.Resource Java Examples
The following examples show how to use
org.apache.tools.ant.types.Resource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AntWorkspaceResolver.java From ant-ivy with Apache License 2.0 | 6 votes |
private synchronized Map<ModuleDescriptor, File> getModuleDescriptors() { if (md2IvyFile == null) { md2IvyFile = new HashMap<>(); for (ResourceCollection resources : allResources) { for (Resource resource : resources) { File ivyFile = ((FileResource) resource).getFile(); try { ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance() .parseDescriptor(getParserSettings(), ivyFile.toURI().toURL(), isValidate()); md2IvyFile.put(md, ivyFile); Message.debug("Add " + md.getModuleRevisionId().getModuleId()); } catch (Exception ex) { if (haltOnError) { throw new BuildException("impossible to parse ivy file " + ivyFile + " exception=" + ex, ex); } else { Message.warn("impossible to parse ivy file " + ivyFile + " exception=" + ex.getMessage()); } } } } } return md2IvyFile; }
Example #2
Source File: XtendCompilerAntTask.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private void validateArgs() { if (getDestdir() == null) { throw new BuildException("Destination directory 'destdir' is required."); } Path srcDirs = getSrcdir(); if (srcDirs == null) { throw new BuildException("Sources directory 'srcdir' is required."); } Iterator<?> pathIter = srcDirs.iterator(); while (pathIter.hasNext()) { Object next = pathIter.next(); if (!(next instanceof Resource && ((Resource) next).isDirectory())) { throw new BuildException("Source directory must be a directory. Check 'srcdir' entry: " + next); } } }
Example #3
Source File: JarResourceSelector.java From PoseidonX with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public boolean isSelected(Resource r) { if (!(r instanceof ZipResource)) { return true; } ZipResource zip = (ZipResource)r; if (zip.getName().startsWith("META-INF")) { return false; } return true; }
Example #4
Source File: Bundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void analyzeJar(Resource res) throws BuildException { log("Analyze jar file " + res, Project.MSG_VERBOSE); try { final JarInputStream jarStream = new JarInputStream(res.getInputStream()); ZipEntry ze = jarStream.getNextEntry(); while (null != ze) { final String fileName = ze.getName(); if (fileName.endsWith(".class")) { log("Analyze jar class file " + fileName, Project.MSG_VERBOSE); asmAnalyser.analyseClass(jarStream, fileName); } ze = jarStream.getNextEntry(); } } catch (final Exception e) { e.printStackTrace(); throw new BuildException("Failed to analyze class-file " + res + ", exception=" + e, getLocation()); } }
Example #5
Source File: Bundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void analyzeClass(Resource res) throws BuildException { log("Analyze class file " + res, Project.MSG_VERBOSE); try { asmAnalyser.analyseClass(res.getInputStream(), res.toString()); } catch (final BuildException be) { throw be; } catch (final Exception e) { e.printStackTrace(); throw new BuildException("Failed to analyze class-file " + res + ", exception=" + e, getLocation()); } }
Example #6
Source File: MakeMasterJNLP.java From netbeans with Apache License 2.0 | 5 votes |
private void generateFiles() throws IOException, BuildException { for (Iterator<Resource> fileIt = files.iterator(); fileIt.hasNext();) { FileResource fr = (FileResource) fileIt.next(); File jar = fr.getFile(); if (!jar.canRead()) { throw new BuildException("Cannot read file: " + jar); } try (JarFile theJar = new JarFile(jar)) { String codenamebase = JarWithModuleAttributes.extractCodeName(theJar.getManifest().getMainAttributes()); if (codenamebase == null) { throw new BuildException("Not a NetBeans Module: " + jar); } if (codenamebase.equals("org.objectweb.asm.all") && jar.getParentFile().getName().equals("core") && jar.getParentFile().getParentFile().getName().startsWith("platform")) { continue; } { int slash = codenamebase.indexOf('/'); if (slash >= 0) { codenamebase = codenamebase.substring(0, slash); } } String dashcnb = codenamebase.replace('.', '-'); File n = new File(target, dashcnb + ".ref"); try (FileWriter w = new FileWriter(n)) { w.write(" <extension name='" + codenamebase + "' href='" + this.masterPrefix + dashcnb + ".jnlp' />\n"); } } } }
Example #7
Source File: TestProduct.java From IntelliJDeodorant with MIT License | 5 votes |
public Resource[][] grabResources(FileSet[] filesets, Project thisProject) { Resource[][] result = new Resource[filesets.length][]; for (int i = 0; i < filesets.length; i++) { boolean skipEmptyNames = true; if (filesets[i] instanceof ZipFileSet) { ZipFileSet zfs = (ZipFileSet) filesets[i]; skipEmptyNames = zfs.getPrefix(thisProject).equals("") && zfs.getFullpath(thisProject).equals(""); } DirectoryScanner rs = filesets[i].getDirectoryScanner(thisProject); if (rs instanceof ZipScanner) { ((ZipScanner) rs).setEncoding(encoding); } Vector<Resource> resources = new Vector<Resource>(); if (!doFilesonly) { String[] directories = rs.getIncludedDirectories(); for (int j = 0; j < directories.length; j++) { if (!"".equals(directories[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(directories[j])); } } } String[] files = rs.getIncludedFiles(); for (int j = 0; j < files.length; j++) { if (!"".equals(files[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(files[j])); } } result[i] = new Resource[resources.size()]; resources.copyInto(result[i]); } return result; }
Example #8
Source File: GazetteerLists.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * ResourceCollection interface: returns an iterator over the list * files. */ @SuppressWarnings("unchecked") @Override public Iterator<Resource> iterator() { load(); if(listNames.length == 0) { return Collections.EMPTY_LIST.iterator(); } else { return new FileResourceIterator(getProject(), definition.getParentFile(), listNames); } }
Example #9
Source File: LicenseCheckTask.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Process all JARs. */ private void processJars() { log("Starting scan.", verboseLevel); long start = System.currentTimeMillis(); @SuppressWarnings("unchecked") Iterator<Resource> iter = (Iterator<Resource>) jarResources.iterator(); int checked = 0; int errors = 0; while (iter.hasNext()) { final Resource r = iter.next(); if (!r.isExists()) { throw new BuildException("JAR resource does not exist: " + r.getName()); } if (!(r instanceof FileResource)) { throw new BuildException("Only filesystem resource are supported: " + r.getName() + ", was: " + r.getClass().getName()); } File jarFile = ((FileResource) r).getFile(); if (! checkJarFile(jarFile) ) { errors++; } checked++; } log(String.format(Locale.ROOT, "Scanned %d JAR file(s) for licenses (in %.2fs.), %d error(s).", checked, (System.currentTimeMillis() - start) / 1000.0, errors), errors > 0 ? Project.MSG_ERR : Project.MSG_INFO); }
Example #10
Source File: PropertiesSyntaxCheckTask.java From development with Apache License 2.0 | 5 votes |
@Override public void execute() throws BuildException { final Iterator<?> resourceIterator = compareTo.iterator(); while (resourceIterator.hasNext()) { final Resource resource = (Resource) resourceIterator.next(); checkSyntax(resource); } }
Example #11
Source File: Bundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Analyze a resource by checking its suffix and delegate to * {@link #analyzeClass(Resource)}, {@link #analyzeJar(Resource)}, etc. * * @param res * The resource to be analyzed. */ protected void analyze(Resource res) throws BuildException { if (res.getName().endsWith(".class")) { analyzeClass(res); } else if (res.getName().endsWith(".jar")) { analyzeJar(res); } else if (res.getName().endsWith("/packageinfo")) { analyzePackageinfo(res); } else { // Just ignore all other files } }
Example #12
Source File: PluginTask.java From netbeans with Apache License 2.0 | 5 votes |
private boolean initRequested() throws IOException { requestedPlugins = new HashSet<CordovaPlugin>(); Resource resource = getProject().getResource("nbproject/plugins.properties"); if (resource == null || !resource.isExists()) { return false; } Properties props = new Properties(); props.load(resource.getInputStream()); for (String name : props.stringPropertyNames()) { requestedPlugins.add(new CordovaPlugin(name, props.getProperty(name))); } return true; }
Example #13
Source File: Bundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void analyzePackageinfo(Resource res) throws BuildException { log("Analyze packageinfo file " + res, Project.MSG_VERBOSE); bpInfo.setPackageVersion(res); }
Example #14
Source File: BundleInfoTask.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Analyze a resource by checking its suffix and delegate to {@link * #analyzeClass(Resource)} or {@link * #analyzePackageinfo(Resource)}. * * @param res The resource to be analyzed. */ protected void analyze(Resource res) throws BuildException { if(res.getName().endsWith(".class")) { analyzeClass(res); } else if(res.getName().endsWith("packageinfo")) { analyzePackageinfo(res); } else { // Just ignore all other files } }
Example #15
Source File: BundleInfoTask.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void analyzeClass(Resource res) throws BuildException { log("Analyze class file " + res, Project.MSG_VERBOSE); try { asmAnalyser.analyseClass(res.getInputStream(), res.toString()); } catch (final Exception e) { e.printStackTrace(); throw new BuildException("Failed to analyze class-file " +res + ", exception=" + e, getLocation()); } }
Example #16
Source File: BundleInfoTask.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void analyzePackageinfo(Resource res) throws BuildException { log("Analyze packageinfo file " + res, Project.MSG_VERBOSE); final String pkgName = bpInfo.setPackageVersion(res); if (addPackageinfoPackages && pkgName != null) { bpInfo.addProvidedPackage(pkgName); } }
Example #17
Source File: BundleInfoTask.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean isSelected(final Resource r) { for (final String suffix : BundleInfoTask.ANALYZE_SUFFIXES) { if (r.getName().endsWith(suffix)) { return true; } } return false; }
Example #18
Source File: BundlePackagesInfo.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Try to assign a version to the Java that the given * <code>packageinfo</code>-file resides in. This code assumes that * the resource has been created in such a way that * <code>res.getName()</code> returns a relative path to the * <code>packageinfo</code>-file that starts in its package * root. I.e., the path is the Java package that the * <code>packageinfo</code>-file provides data for. * * @param res Resource encapsulating a <code>packageinfo</code>-file. * @return The package name or <code>null</code> if no valid version was * found. */ public String setPackageVersion(final Resource res) { // The relative path to packageinfo-file starting from the root of // its classpath. Allways using forward slash as separator char. final String pkgInfoPath = res.getName().replace(File.separatorChar, '/'); // 12 = "/packageinfo".lenght() final String pkgName = pkgInfoPath.substring(0, pkgInfoPath.length()-12); // Currently registered path for version providing packageinfo // file, if any. final String curPkgInfoPath = packageToInfofile.get(pkgName); if (null==curPkgInfoPath || !curPkgInfoPath.equals(pkgInfoPath)) { final Version newVersion = getVersion(res); if (null!=newVersion) { final Version curVersion = getProvidedPackageVersion(pkgName); if (null==curVersion) { packageToVersion.put(pkgName, newVersion); packageToInfofile.put(pkgName, pkgInfoPath); task.log("Package version for '" +pkgName +"' set to " +newVersion +" based on data from '" +pkgInfoPath +"'.", Project.MSG_VERBOSE); return pkgName; } else if (!newVersion.equals(curVersion)) { // May happen when the classes of a package are in two // different directories on the class path. throw new BuildException("Conflicting versions for '" +pkgName +"' previous '" +curVersion +"' from '" +curPkgInfoPath +"', new '" +newVersion +"' in '" +pkgInfoPath +"'."); } } } return null; }
Example #19
Source File: IvyResources.java From ant-ivy with Apache License 2.0 | 5 votes |
private Collection<Resource> resolveResources(String id) throws BuildException { prepareAndCheck(); try { List<Resource> resources = new ArrayList<>(); if (id != null) { getProject().addReference(id, this); } for (ArtifactDownloadReport adr : getArtifactReports()) { resources.add(new FileResource(adr.getLocalFile())); } return resources; } catch (Exception ex) { throw new BuildException("impossible to build ivy resources: " + ex, ex); } }
Example #20
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
public Resource[][] grabManifests(ResourceCollection[] rcs) { Resource[][] manifests = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { Resource[][] resources = null; if (rcs[i] instanceof FileSet) { resources = grabResources(new FileSet[] {(FileSet) rcs[i]}); } else { resources = grabNonFileSetResources(new ResourceCollection[] { rcs[i] }); } for (int j = 0; j < resources[0].length; j++) { String name = resources[0][j].getName().replace('\\', '/'); if (rcs[i] instanceof ArchiveFileSet) { ArchiveFileSet afs = (ArchiveFileSet) rcs[i]; if (!"".equals(afs.getFullpath(getProject()))) { name = afs.getFullpath(getProject()); } else if (!"".equals(afs.getPrefix(getProject()))) { String prefix = afs.getPrefix(getProject()); if (!prefix.endsWith("/") && !prefix.endsWith("\\")) { prefix += "/"; } name = prefix + name; } } if (name.equalsIgnoreCase(MANIFEST_NAME)) { manifests[i] = new Resource[] {resources[0][j]}; break; } } if (manifests[i] == null) { manifests[i] = new Resource[0]; } } return manifests; }
Example #21
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
public Resource[][] grabManifests(ResourceCollection[] rcs) { Resource[][] manifests = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { Resource[][] resources = null; if (rcs[i] instanceof FileSet) { resources = testProduct.grabResources(new FileSet[]{(FileSet) rcs[i]}, this.project); } else { resources = grabNonFileSetResources(new ResourceCollection[]{ rcs[i] }); } for (int j = 0; j < resources[0].length; j++) { String name = resources[0][j].getName().replace('\\', '/'); if (rcs[i] instanceof ArchiveFileSet) { ArchiveFileSet afs = (ArchiveFileSet) rcs[i]; if (!"".equals(afs.getFullpath(getProject()))) { name = afs.getFullpath(getProject()); } else if (!"".equals(afs.getPrefix(getProject()))) { String prefix = afs.getPrefix(getProject()); if (!prefix.endsWith("/") && !prefix.endsWith("\\")) { prefix += "/"; } name = prefix + name; } } if (name.equalsIgnoreCase(MANIFEST_NAME)) { manifests[i] = new Resource[]{resources[0][j]}; break; } } if (manifests[i] == null) { manifests[i] = new Resource[0]; } } return manifests; }
Example #22
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) { Resource[][] result = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { ArrayList<Resource> dirs = new ArrayList<Resource>(); ArrayList<Resource> files = new ArrayList<Resource>(); for (Resource r : rcs[i]) { if (r.isExists()) { if (r.isDirectory()) { dirs.add(r); } else { files.add(r); } } } // make sure directories are in alpha-order - this also // ensures parents come before their children Collections.sort(dirs, new Comparator<Resource>() { public int compare(Resource r1, Resource r2) { return r1.getName().compareTo(r2.getName()); } }); ArrayList<Resource> rs = new ArrayList<Resource>(dirs); rs.addAll(files); result[i] = rs.toArray(new Resource[rs.size()]); } return result; }
Example #23
Source File: TestProduct.java From IntelliJDeodorant with MIT License | 5 votes |
public Resource[][] grabResources(FileSet[] filesets, Project thisProject) { Resource[][] result = new Resource[filesets.length][]; for (int i = 0; i < filesets.length; i++) { boolean skipEmptyNames = true; if (filesets[i] instanceof ZipFileSet) { ZipFileSet zfs = (ZipFileSet) filesets[i]; skipEmptyNames = zfs.getPrefix(thisProject).equals("") && zfs.getFullpath(thisProject).equals(""); } DirectoryScanner rs = filesets[i].getDirectoryScanner(thisProject); if (rs instanceof ZipScanner) { ((ZipScanner) rs).setEncoding(encoding); } Vector<Resource> resources = new Vector<Resource>(); if (!doFilesonly) { String[] directories = rs.getIncludedDirectories(); for (int j = 0; j < directories.length; j++) { if (!"".equals(directories[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(directories[j])); } } } String[] files = rs.getIncludedFiles(); for (int j = 0; j < files.length; j++) { if (!"".equals(files[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(files[j])); } } result[i] = new Resource[resources.size()]; resources.copyInto(result[i]); } return result; }
Example #24
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
public Resource[][] grabManifests(ResourceCollection[] rcs) { Resource[][] manifests = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { Resource[][] resources = null; if (rcs[i] instanceof FileSet) { resources = testProduct.grabResources(new FileSet[]{(FileSet) rcs[i]}, this.project); } else { resources = grabNonFileSetResources(new ResourceCollection[]{ rcs[i] }); } for (int j = 0; j < resources[0].length; j++) { String name = resources[0][j].getName().replace('\\', '/'); if (rcs[i] instanceof ArchiveFileSet) { ArchiveFileSet afs = (ArchiveFileSet) rcs[i]; if (!"".equals(afs.getFullpath(getProject()))) { name = afs.getFullpath(getProject()); } else if (!"".equals(afs.getPrefix(getProject()))) { String prefix = afs.getPrefix(getProject()); if (!prefix.endsWith("/") && !prefix.endsWith("\\")) { prefix += "/"; } name = prefix + name; } } if (name.equalsIgnoreCase(MANIFEST_NAME)) { manifests[i] = new Resource[]{resources[0][j]}; break; } } if (manifests[i] == null) { manifests[i] = new Resource[0]; } } return manifests; }
Example #25
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) { Resource[][] result = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { ArrayList<Resource> dirs = new ArrayList<Resource>(); ArrayList<Resource> files = new ArrayList<Resource>(); for (Resource r : rcs[i]) { if (r.isExists()) { if (r.isDirectory()) { dirs.add(r); } else { files.add(r); } } } // make sure directories are in alpha-order - this also // ensures parents come before their children Collections.sort(dirs, new Comparator<Resource>() { public int compare(Resource r1, Resource r2) { return r1.getName().compareTo(r2.getName()); } }); ArrayList<Resource> rs = new ArrayList<Resource>(dirs); rs.addAll(files); result[i] = rs.toArray(new Resource[rs.size()]); } return result; }
Example #26
Source File: CreateDependencies.java From netbeans with Apache License 2.0 | 5 votes |
private Map<String,Map<String,String>> findBinary2LicenseHeaderMapping() throws IOException { DirSet sources = getProject().getReference(refid); Map<String,Map<String,String>> file2LicenseHeaders = new HashMap<>(); for (Resource r : sources) { processModule(r.getName(), file2LicenseHeaders); } return file2LicenseHeaders; }
Example #27
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
protected Resource[][] grabNonFileSetResources(ResourceCollection[] rcs) { Resource[][] result = new Resource[rcs.length][]; for (int i = 0; i < rcs.length; i++) { ArrayList<Resource> dirs = new ArrayList<Resource>(); ArrayList<Resource> files = new ArrayList<Resource>(); for (Resource r : rcs[i]) { if (r.isExists()) { if (r.isDirectory()) { dirs.add(r); } else { files.add(r); } } } // make sure directories are in alpha-order - this also // ensures parents come before their children Collections.sort(dirs, new Comparator<Resource>() { public int compare(Resource r1, Resource r2) { return r1.getName().compareTo(r2.getName()); } }); ArrayList<Resource> rs = new ArrayList<Resource>(dirs); rs.addAll(files); result[i] = rs.toArray(new Resource[rs.size()]); } return result; }
Example #28
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
protected Resource[][] grabResources(FileSet[] filesets) { Resource[][] result = new Resource[filesets.length][]; for (int i = 0; i < filesets.length; i++) { boolean skipEmptyNames = true; if (filesets[i] instanceof ZipFileSet) { ZipFileSet zfs = (ZipFileSet) filesets[i]; skipEmptyNames = zfs.getPrefix(getProject()).equals("") && zfs.getFullpath(getProject()).equals(""); } DirectoryScanner rs = filesets[i].getDirectoryScanner(getProject()); if (rs instanceof ZipScanner) { ((ZipScanner) rs).setEncoding(encoding); } Vector<Resource> resources = new Vector<Resource>(); if (!doFilesonly) { String[] directories = rs.getIncludedDirectories(); for (int j = 0; j < directories.length; j++) { if (!"".equals(directories[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(directories[j])); } } } String[] files = rs.getIncludedFiles(); for (int j = 0; j < files.length; j++) { if (!"".equals(files[j]) || !skipEmptyNames) { resources.addElement(rs.getResource(files[j])); } } result[i] = new Resource[resources.size()]; resources.copyInto(result[i]); } return result; }
Example #29
Source File: CosUpdated.java From netbeans with Apache License 2.0 | 5 votes |
public int compareTo(Resource another) { if (another instanceof CosResource) { return delegate.compareTo(((CosResource)another).delegate); } else { return toString().compareTo(String.valueOf(another)); } }
Example #30
Source File: PathFileSet.java From netbeans with Apache License 2.0 | 4 votes |
public Iterator<Resource> iterator() { initFiles(); return files.iterator(); }