org.apache.tools.ant.types.ZipFileSet Java Examples

The following examples show how to use org.apache.tools.ant.types.ZipFileSet. 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: ObfuscatorTask.java    From yGuard with MIT License 6 votes vote down vote up
Collection createEntries(Collection srcJars) throws IOException{
    Collection entries = new ArrayList(20);
    for (Iterator it = srcJars.iterator(); it.hasNext();)
    {
      File file = (File) it.next();
      ZipFileSet zipFile = new ZipFileSet();
      zipFile.setProject(getProject());
      zipFile.setSrc(file);
      for (Iterator it2 = patches.iterator(); it2.hasNext();){
          ClassSection cs = (ClassSection) it2.next();
          if (cs.getName() == null){
            cs.addEntries(entries, zipFile);
          } else {
            cs.addEntries(entries, cs.getName());
          }
      }
    }
    return entries;
}
 
Example #2
Source File: AntJarProcessor.java    From bazel with Apache License 2.0 6 votes vote down vote up
protected void zipFile(
    InputStream is,
    ZipOutputStream zOut,
    String vPath,
    long lastModified,
    File fromArchive,
    int mode)
    throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  IoUtil.pipe(is, baos, buf);
  struct.data = baos.toByteArray();
  struct.name = vPath;
  struct.time = lastModified;
  if (proc.process(struct)) {
    if (mode == 0) {
      mode = ZipFileSet.DEFAULT_FILE_MODE;
    }
    if (!filesOnly) {
      addParentDirs(struct.name, zOut);
    }
    super.zipFile(
        new ByteArrayInputStream(struct.data), zOut, struct.name, struct.time, fromArchive, mode);
  }
}
 
Example #3
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 6 votes vote down vote up
protected void zipFile(InputStream is, ZipOutputStream zOut, String vPath,
                                 long lastModified, File fromArchive, int mode) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IoUtil.pipe(is, baos, buf);
    struct.data = baos.toByteArray();
    struct.name = vPath;
    struct.time = lastModified;
    if (proc.process(struct)) {
        if (mode == 0)
            mode = ZipFileSet.DEFAULT_FILE_MODE;
        if (!filesOnly) {
          addParentDirs(struct.name, zOut);
        }
        super.zipFile(new ByteArrayInputStream(struct.data),
                      zOut, struct.name, struct.time, fromArchive, mode);
    }
}
 
Example #4
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 6 votes vote down vote up
protected void zipFile(
    InputStream is,
    ZipOutputStream zOut,
    String vPath,
    long lastModified,
    File fromArchive,
    int mode)
    throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  IoUtil.pipe(is, baos, buf);
  struct.data = baos.toByteArray();
  struct.name = vPath;
  struct.time = lastModified;
  if (proc.process(struct)) {
    if (mode == 0) {
      mode = ZipFileSet.DEFAULT_FILE_MODE;
    }
    if (!filesOnly) {
      addParentDirs(struct.name, zOut);
    }
    super.zipFile(
        new ByteArrayInputStream(struct.data), zOut, struct.name, struct.time, fromArchive, mode);
  }
}
 
Example #5
Source File: MakeJNLP.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void processIndirectFiles(Writer fileWriter, String dashcnb) throws IOException, BuildException {
    if (indirectFiles == null) {
        return;
    }
    DirectoryScanner scan = indirectFiles.getDirectoryScanner(getProject());
    Map<String,File> entries = new LinkedHashMap<>();
    for (String f : scan.getIncludedFiles()) {
        entries.put(f.replace(File.separatorChar, '/'), new File(scan.getBasedir(), f));
    }
    if (entries.isEmpty()) {
        return;
    }
    File ext = new File(new File(targetFile, dashcnb), "extra-files.jar");
    Zip jartask = (Zip) getProject().createTask("jar");
    jartask.setDestFile(ext);
    for (Map.Entry<String,File> entry : entries.entrySet()) {
        ZipFileSet zfs = new ZipFileSet();
        zfs.setFile(entry.getValue());
        zfs.setFullpath("META-INF/files/" + entry.getKey());
        jartask.addZipfileset(zfs);
    }
    jartask.execute();
    fileWriter.write(constructJarHref(ext, dashcnb));
    signOrCopy(ext, null);
}
 
Example #6
Source File: AntJarProcessor.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}
 
Example #7
Source File: ClassSection.java    From yGuard with MIT License 5 votes vote down vote up
public void addEntries( Collection entries, ZipFileSet zf ) throws IOException {
  if ( classesSet && patternSets.size() < 1 ) {
    PatternSet ps = new PatternSet();
    ps.setProject( zf.getProject() );
    ps.setIncludes( "**.*" );
    patternSets.add( ps );
  }
  super.addEntries( entries, zf );
}
 
Example #8
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}
 
Example #9
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addConfiguredLib(ZipFileSet fileset)
{
  // TODO: handle refid
  if (fileset.getSrc(getProject()) == null) {
    addFileset(fileset);
    libs.add(fileset);
  } else {
    addClasses(fileset);
  }
}
 
Example #10
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addZipGroups()
{
  for (int i = 0; i < zipgroups.size(); i++) {
    final FileSet fileset = zipgroups.get(i);
    final FileScanner fs = fileset.getDirectoryScanner(getProject());
    final String[] files = fs.getIncludedFiles();
    final File basedir = fs.getBasedir();
    for (final String file : files) {
      final ZipFileSet zipfileset = new ZipFileSet();
      zipfileset.setSrc(new File(basedir, file));
      srcFilesets.add(zipfileset);
    }
  }
}
 
Example #11
Source File: JarVersionCreator.java    From gs-xsd2bean with Apache License 2.0 5 votes vote down vote up
private void createVersionInfo(ZipOutputStream zOut) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, "UTF8"));

    CRC32 fullCrc = new CRC32();
    // header
    writer.print("name: ");
    writer.println(applicationName);
    writer.print("version: ");
    writer.println(this.version);

    fullCrc.update(applicationName.getBytes("UTF8"));
    fullCrc.update(version.getBytes("UTF8"));

    writeVersionInfo(writer, fullCrc);
    writer.println();
    writer.print(":crc: ");
    writer.println(Long.toHexString(fullCrc.getValue()));
    
    if (writer.checkError())
    {
        throw new IOException("Encountered an error writing jar version information");
    }
    writer.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    super.zipFile(bais, zOut, "META-INF/"+applicationName+".crcver", System.currentTimeMillis(), null, ZipFileSet.DEFAULT_FILE_MODE);
    bais.close();
}
 
Example #12
Source File: JarVersionCreator.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void createVersionInfo(ZipOutputStream zOut) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(baos, "UTF8"));

    CRC32 fullCrc = new CRC32();
    // header
    writer.print("name: ");
    writer.println(applicationName);
    writer.print("version: ");
    writer.println(this.version);

    fullCrc.update(applicationName.getBytes("UTF8"));
    fullCrc.update(version.getBytes("UTF8"));

    writeVersionInfo(writer, fullCrc);
    writer.println();
    writer.print(":crc: ");
    writer.println(Long.toHexString(fullCrc.getValue()));
    
    if (writer.checkError())
    {
        throw new IOException("Encountered an error writing jar version information");
    }
    writer.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    super.zipFile(bais, zOut, "META-INF/"+applicationName+".crcver", System.currentTimeMillis(), null, ZipFileSet.DEFAULT_FILE_MODE);
    bais.close();
}
 
Example #13
Source File: AntJarProcessor.java    From jarjar with Apache License 2.0 5 votes vote down vote up
private void addParentDirs(String file, ZipOutputStream zOut) throws IOException {
  int slash = file.lastIndexOf('/');
  if (slash >= 0) {
    String dir = file.substring(0, slash);
    if (dirs.add(dir)) {
      addParentDirs(dir, zOut);
      super.zipDir((File) null, zOut, dir + "/", ZipFileSet.DEFAULT_DIR_MODE, JAR_MARKER);
    }
  }
}
 
Example #14
Source File: Test.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
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 #15
Source File: TestProduct.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
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 #16
Source File: TestProduct.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
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 #17
Source File: ZipScannerTool.java    From yGuard with MIT License 5 votes vote down vote up
public static File zipFileSetGetSrc(ZipFileSet fs) {
  Method ant15 = null;
  Method ant16 = null;
  try {
    ant15 = fs.getClass().getMethod("getSrc", new Class[]{});
  } catch (NoSuchMethodException nsme){
    try{
      ant16 = fs.getClass().getMethod("getSrc", new Class[]{Project.class});
    } catch (NoSuchMethodException nsme2){
      throw new BuildException("Could not determine getSrc method of ZipFileSet class");
    }
  }
  try {
    if (ant16 != null){
      return (File) ant16.invoke(fs, new Object[]{fs.getProject()});
    } else {
      return (File) ant15.invoke(fs, (Object[])null);
    }
  } catch (IllegalAccessException iaex){
    throw new BuildException("Could not invoke getSrc method of ZipFileSet class", iaex);
  } catch (InvocationTargetException itex){
    if (itex.getTargetException() instanceof BuildException){
      throw (BuildException) itex.getTargetException();
    } else {
      throw new BuildException("Internal error: getSrc invocation failed! "+itex.getTargetException().getMessage());
    }
  }
}
 
Example #18
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();
    }
}
 
Example #19
Source File: MakeNBM.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ZipFileSet createMain () {
    return (main = new ZipFileSet());
}
 
Example #20
Source File: MakeNBM.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public ZipFileSet createExtraNBMFiles() {
    return (extraNBMFiles = new ZipFileSet());
}
 
Example #21
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void addClasses(ZipFileSet fileset)
{
  super.addZipfileset(fileset);
  srcFilesets.add(fileset);
  classes.add(fileset);
}
 
Example #22
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void addZipfileset(ZipFileSet fileset)
{
  super.addZipfileset(fileset);
}
 
Example #23
Source File: ZipScannerTool.java    From yGuard with MIT License 4 votes vote down vote up
public static Collection getMatchedCollection(ZipFileSet fs, DirectoryScanner scanner) throws IOException{
  return getMatchedCollection(fs,scanner,"");
}
 
Example #24
Source File: ZipScannerTool.java    From yGuard with MIT License 4 votes vote down vote up
public static String[] getMatches(ZipFileSet fs, DirectoryScanner scanner) throws IOException{
  Collection result = getMatchedCollection(fs, scanner);
  return (String[])(result.toArray(new String[result.size()]));
}