当前位置: 首页>>代码示例>>Java>>正文


Java FileResource.getFile方法代码示例

本文整理汇总了Java中org.apache.tools.ant.types.resources.FileResource.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileResource.getFile方法的具体用法?Java FileResource.getFile怎么用?Java FileResource.getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tools.ant.types.resources.FileResource的用法示例。


在下文中一共展示了FileResource.getFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateFiles

import org.apache.tools.ant.types.resources.FileResource; //导入方法依赖的package包/类
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");
            }
        }
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:MakeMasterJNLP.java

示例2: execute

import org.apache.tools.ant.types.resources.FileResource; //导入方法依赖的package包/类
@Override
public void execute() throws BuildException {
    try {
        if (checksumDir == null) {
            // initialize a temp directory if we don't have one
            checksumDir = File.createTempFile("wonderlandpkg", "files");
            checksumDir.delete();
            checksumDir.mkdir();
            checksumDir.deleteOnExit();
        } else {
            checksumDir.mkdirs();
        }

        Map<String, Map<String, String>> fileLists =
                new HashMap<String, Map<String, String>>();

        // go through each fileset and generate checksums if necessary
        for (ZipFileSet files : checksums) {
            String prefix = files.getPrefix(getProject());
            File fileSetDir = new File(checksumDir, prefix);
            fileSetDir.mkdir();

            // keep track of file names
            Map<String, String> fileChecksums = fileLists.get(prefix);
            if (fileChecksums == null) {
                fileChecksums = new LinkedHashMap<String, String>();
                fileLists.put(prefix, fileChecksums);
            }

            Iterator<FileResource> i = (Iterator<FileResource>) files.iterator();
            while (i.hasNext()) {
                FileResource fr = i.next();
                File f = fr.getFile();

                String writeName = fr.getName().replace(File.separatorChar, '-');
                writeName += ".checksum";
                File checksumFile = new File(fileSetDir, writeName);

                if (!checksumFile.exists() || outOfDate(checksumFile, f)) {
                    generateChecksum(fr, checksumFile);
                }

                String checksum = readChecksum(checksumFile);

                fileChecksums.put(fr.getName(), checksum);
            }
        }

        // write file lists
        for (Map.Entry<String, Map<String, String>> e : fileLists.entrySet()) {
            writeFileList(e.getKey(), e.getValue());
        }

        // add the checksums directory to the jar
        ZipFileSet zfs = new ZipFileSet();
        zfs.setDir(checksumDir);
        FilenameSelector fs = new FilenameSelector();
        fs.setName("**/files.list");
        zfs.add(fs);
        zfs.setPrefix("META-INF");
        addFileset(zfs);
    } catch (IOException ioe) {
        throw new BuildException(ioe);
    }

    super.execute();
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:68,代码来源:WonderlandPackageTask.java

示例3: execute

import org.apache.tools.ant.types.resources.FileResource; //导入方法依赖的package包/类
/** Main function called by the ant task */
@Override public void execute() throws BuildException {
	// Map of all used services
	final Map<String, List<String>> once = new HashMap<>();
	final Map<String, String> services = new HashMap<>();
	// Open output file (new JDK-8 style)
	try(	final FileOutputStream fos = new FileOutputStream(this.dest, false);
			final ZipOutputStream  zos = new ZipOutputStream (fos)) {
		for (final FileSet fileSet : this.filesets) {
			final DirectoryScanner ds = fileSet.getDirectoryScanner();
			final Iterator<?> iter = new FileResourceIterator(fileSet.getDir(), ds.getIncludedFiles());
			while (iter.hasNext()) {
				final FileResource resource = (FileResource) iter.next();
				final File file = resource.getFile();
				final String name = file.getName();
				if(name.endsWith(".jar") || name.endsWith(".zip") || name.endsWith(".war") || name.endsWith(".ear")) {
					addFromZip (zos, file, services, once);
				} else {
					addFromFile(zos, resource, services, once);
				}
			}
		}
		// After the "normal" files write the merged META-INF/Services
		for(final Map.Entry<String,String> service : services.entrySet()) {
			zos.putNextEntry(new ZipEntry(service.getKey()));
			zos.write(service.getValue().getBytes());
		}
		if(this.webFragment != null) {
			zos.putNextEntry(new ZipEntry(WEB_FRAGMENT));
			this.webFragment.store(zos);
			// zos.write(service.getValue().getBytes());
		}
		zos.putNextEntry(new ZipEntry("META-INF/resources/"));
		zos.putNextEntry(new ZipEntry("META-INF/resources/WEB-INF/"));
		zos.putNextEntry(new ZipEntry("META-INF/resources/WEB-INF/tlds"));
		// META-INF/resources/WEB-INF/jetty-env.xml
		// META-INF/web-fragment.xml
		// META-INF/resources/WEB-INF/jetty8-web.xml
	} catch(final Exception e) {
		throw new BuildException("Error writing "+this.dest.getAbsolutePath(), e);
	}
}
 
开发者ID:pescuma,项目名称:merge-jar-services,代码行数:43,代码来源:MergeServicesTask.java


注:本文中的org.apache.tools.ant.types.resources.FileResource.getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。