Java Code Examples for org.apache.tools.ant.taskdefs.Jar#setDestFile()

The following examples show how to use org.apache.tools.ant.taskdefs.Jar#setDestFile() . 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: JarPacker.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
private Jar createAntJarTask(String distFile)
{
    Project prj = new Project();
    
    Jar jar = new Jar();
    jar.setProject(prj);
    jar.setDestFile(new File(distFile));
    jar.setBasedir(sourceDir);
    return jar;
}
 
Example 2
Source File: TranslateClassPath.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private File[] translateEntry(final String path, boolean disableSources) throws BuildException {
    final File entryFile = new HackedFile(path);
    try {
        final URL entry = FileUtil.urlForArchiveOrDir(entryFile);
        final SourceForBinaryQuery.Result2 r = SourceForBinaryQuery.findSourceRoots2(entry);
        boolean appendEntry = false;

        if (!disableSources && r.preferSources() && r.getRoots().length > 0) {
            final List<File> translated = new ArrayList<File>();
            for (FileObject source : r.getRoots()) {
                final File sourceFile = FileUtil.toFile(source);
                if (sourceFile == null) {
                    log("Source URL: " + source.toURL().toExternalForm() + " cannot be translated to file, skipped", Project.MSG_WARN);
                    appendEntry = true;
                    continue;
                }

                final Boolean bamiResult = clean ? BuildArtifactMapperImpl.clean(Utilities.toURI(sourceFile).toURL())
                                           : BuildArtifactMapperImpl.ensureBuilt(Utilities.toURI(sourceFile).toURL(), getProject(), true, true);
                if (bamiResult == null) {
                    appendEntry = true;
                    continue;
                }
                if (!bamiResult) {
                    throw new UserCancel();
                }
                
                for (URL binary : BinaryForSourceQuery.findBinaryRoots(source.toURL()).getRoots()) {
                    final FileObject binaryFO = URLMapper.findFileObject(binary);
                    final File finaryFile = binaryFO != null ? FileUtil.toFile(binaryFO) : null;
                    if (finaryFile != null) {
                        if (moduleOriented && finaryFile.isDirectory() && "jar".equals(entry.getProtocol())) {
                            boolean hasModuleInfo = finaryFile.listFiles(new FilenameFilter() {
                                @Override
                                public boolean accept(File dir, String name) {
                                    return "module-info.class".equals(name);
                                }
                            }).length > 0;
                            if (!hasModuleInfo) {
                                File jarFile = new File(finaryFile.getParentFile(), entryFile.getName());
                                Jar jarTask = new Jar();
                                jarTask.setProject(getProject());
                                jarTask.setDestFile(jarFile);
                                jarTask.setBasedir(finaryFile);
                                jarTask.setExcludes(".netbeans*");
                                jarTask.execute();
                                translated.add(jarFile);
                                continue;
                            }
                        }
                        translated.add(finaryFile);
                    }
                }                    
            }
            
            if (appendEntry) {
                translated.add(entryFile);
            }
            return translated.toArray(new File[translated.size()]);
        } else {
            return new File[] {entryFile};
        }
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}
 
Example 3
Source File: Branding.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void packBrandingJar(File srcDir, File destJarBase, String locale) throws IOException {
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(srcDir);
    String localeToken = "";
    if(locale != null) {
        String [] includes = {"**/*_" + locale.toString() + ".*"};
        scanner.setIncludes(includes);
        localeToken = "_" + locale.toString();
    } else {
        String [] excludes = {"**/*_??_??.*", "**/*_??.*"};
        scanner.setExcludes(excludes);
    }
    scanner.addDefaultExcludes(); // #68929
    scanner.scan();
    String[] files = scanner.getIncludedFiles();
    if(files.length > 0) {
        Jar zip = (Jar) getProject().createTask("jar");
        String name = destJarBase.getName();
        String nameBase = name.substring(0, name.length() - ".jar".length());
        File destFolder = new File(destJarBase.getParentFile(), "locale");
        if (!destFolder.isDirectory() && !destFolder.mkdirs()) {
            throw new IOException("Could not create directory " + destFolder);
        }
        File destJar = new File(destFolder, nameBase + "_" + token + localeToken + ".jar");
        zip.setDestFile(destJar);
        zip.setCompress(true);
        for (int i = 0; i < files.length; i++) {
            ZipFileSet entry = new ZipFileSet();
            entry.setFile(new File(srcDir, files[i]));
            String basePath = files[i].replace(File.separatorChar, '/');
            int slash = basePath.lastIndexOf('/');
            int dot = basePath.lastIndexOf('.');
            String infix = "_" + token + localeToken;
            String brandedPath;
            if (dot == -1 || dot < slash) {
                brandedPath = basePath + infix;
            } else {
                brandedPath = basePath.substring(0, dot - localeToken.length()) + infix + basePath.substring(dot);
            }
            entry.setFullpath(brandedPath);
            zip.addZipfileset(entry);
        }
        zip.setLocation(getLocation());
        zip.init();
        zip.execute();
    }
}