Package org.apache.tools.ant.types

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


      FileSet fileset = (FileSet) zipgroups.get(i);
      FileScanner fs = fileset.getDirectoryScanner(getProject());
      String[] files = fs.getIncludedFiles();
      File basedir = fs.getBasedir();
      for (int j = 0; j < files.length; j++) {
        ZipFileSet zipfileset = new ZipFileSet();
        zipfileset.setSrc(new File(basedir, files[j]));
        srcFilesets.add(zipfileset);
      }
    }
  }
View Full Code Here


      rootIncluded = true;
    }

    Iterator i = classes.iterator();
    while (i.hasNext()) {
      final ZipFileSet zipFileSet = (ZipFileSet) i.next();
      final String prefix = zipFileSet.getPrefix(getProject());
      if (prefix.length() > 0) {
        value.append(prefix);
        value.append(',');
      } else if (!rootIncluded) {
        value.append(".,");
        rootIncluded = true;
      }
    }

    i = libs.iterator();
    while (i.hasNext()) {
      final ZipFileSet fileset = (ZipFileSet) i.next();
      if (fileset.getSrc(getProject()) == null) {
        final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
        final String[] files = ds.getIncludedFiles();
        if (files.length != 0) {
          zipgroups.add(fileset);
          final String prefix = fixPrefix(fileset.getPrefix(getProject()));
          for (int j = 0; j < files.length; j++) {
            value.append(prefix.replace('\\', '/'));
            value.append(files[j].replace('\\', '/'));
            value.append(',');
          }
View Full Code Here

      if (src.isDirectory()) {
        fileSet = new FileSet();
        fileSet.setDir(src);
        fileSet.setProject(getProject());
      } else if (src.exists()) {
        fileSet = new ZipFileSet();
        ((ZipFileSet) fileSet).setSrc(src);
      } else {
        final StringBuffer msg = new StringBuffer();
        msg.append("The following entry in the Bundle-ClassPath")
          .append(" header doesn't exist in the bundle: ")
View Full Code Here

    Zip zip = new Zip();
    Project project = getProject();
    zip.setProject(project);
    zip.setTaskName(getTaskName() + " - zip");
    zip.setDestFile(outjar);
    ZipFileSet zipfileset = new ZipFileSet();
    zipfileset.setProject(project);
    zipfileset.setSrc(tmpOutjar);
    zipfileset.setIncludes("**/*.class");
    zip.addZipfileset(zipfileset);
    if (copyInjars) {
      String[] paths = injars.list();
      if (!LangUtil.isEmpty(paths)) {
        for (int i = 0; i < paths.length; i++) {
          File jarFile = new File(paths[i]);
          zipfileset = new ZipFileSet();
          zipfileset.setProject(project);
          zipfileset.setSrc(jarFile);
          zipfileset.setIncludes("**/*");
          zipfileset.setExcludes("**/*.class");
          zip.addZipfileset(zipfileset);
        }
      }
    }
    if ((null != sourceRootCopyFilter) && (null != sourceRoots)) {
View Full Code Here

            FileWriter writer = new FileWriter(moduleInfoFile);
            mi.encode(writer);
            writer.close();
        }
       
        ZipFileSet zfs = new ZipFileSet();
        zfs.setFile(moduleInfoFile);
        zfs.setFullpath(Module.MODULE_INFO);
       
        super.addFileset(zfs);
    }
View Full Code Here

            FileOutputStream fos = new FileOutputStream(moduleRequiresFile);
            mr.encode(fos);
            fos.close();
        }
       
        ZipFileSet zfs = new ZipFileSet();
        zfs.setFile(moduleRequiresFile);
        zfs.setFullpath(Module.MODULE_REQUIRES);
       
        super.addFileset(zfs);
    }
View Full Code Here

        }
       
        jar.setInternalDestFile(jarFile);
        jar.execute();
           
        ZipFileSet zfs = new ZipFileSet();
        zfs.setFile(jarFile);
        zfs.setFullpath(partName + "/" + jarname);
       
        super.addFileset(zfs);
    }
View Full Code Here

            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);
        }

View Full Code Here

            File basedir = scanner.getBasedir();
            for (int j = 0; j < files.length; j++) {

                log("Adding file " + files[j] + " to fileset",
                    Project.MSG_VERBOSE);
                ZipFileSet zf = new ZipFileSet();
                zf.setSrc(new File(basedir, files[j]));
                filesets.addElement(zf);
                filesetsFromGroupfilesets.addElement(zf);
            }
        }

        // collect filesets to pass them to getResourcesToAdd
        Vector vfss = new Vector();
        if (baseDir != null) {
            FileSet fs = (FileSet) getImplicitFileSet().clone();
            fs.setDir(baseDir);
            vfss.addElement(fs);
        }
        for (int i = 0; i < filesets.size(); i++) {
            FileSet fs = (FileSet) filesets.elementAt(i);
            vfss.addElement(fs);
        }

        FileSet[] fss = new FileSet[vfss.size()];
        vfss.copyInto(fss);
        boolean success = false;
        try {
            Resource[][] addThem = getResourcesToAdd(fss, zipFile, false);

            // quick exit if the target is up to date
            // can also handle empty archives
            if (isEmpty(addThem)) {
                return;
            }

            if (doUpdate) {
                renamedFile =
                    fileUtils.createTempFile("zip", ".tmp",
                                             fileUtils.getParentFile(zipFile));

                try {
                    if (!zipFile.renameTo(renamedFile)) {
                        throw new BuildException("Unable to rename old file "
                                                 + "to temporary file");
                    }
                } catch (SecurityException e) {
                    throw new BuildException("Not allowed to rename old file "
                                             + "to temporary file");
                }
            }

            String action = doUpdate ? "Updating " : "Building ";

            log(action + archiveType + ": " + zipFile.getAbsolutePath());

            ZipOutputStream zOut =
                new ZipOutputStream(new FileOutputStream(zipFile));
            zOut.setEncoding(encoding);
            try {
                if (doCompress) {
                    zOut.setMethod(ZipOutputStream.DEFLATED);
                } else {
                    zOut.setMethod(ZipOutputStream.STORED);
                }
                initZipOutputStream(zOut);

                // Add the explicit filesets to the archive.
                for (int i = 0; i < fss.length; i++) {
                    if (addThem[i].length != 0) {
                        addResources(fss[i], addThem[i], zOut);
                    }
                }
               
                if (doUpdate) {
                    addingNewFiles = false;
                    ZipFileSet oldFiles = new ZipFileSet();
                    oldFiles.setSrc(renamedFile);

                    for (int i = 0; i < addedFiles.size(); i++) {
                        PatternSet.NameEntry ne = oldFiles.createExclude();
                        ne.setName((String) addedFiles.elementAt(i));
                    }
                    DirectoryScanner ds =
                        oldFiles.getDirectoryScanner(getProject());
                    String[] f = ds.getIncludedFiles();
                    Resource[] r = new Resource[f.length];
                    for (int i = 0; i < f.length; i++) {
                        r[i] = ds.getResource(f[i]);
                    }
View Full Code Here

        String prefix = "";
        String fullpath = "";
        int dirMode = ZipFileSet.DEFAULT_DIR_MODE;
        int fileMode = ZipFileSet.DEFAULT_FILE_MODE;

        ZipFileSet zfs = null;
        if (fileset instanceof ZipFileSet) {
            zfs = (ZipFileSet) fileset;
            prefix = zfs.getPrefix();
            fullpath = zfs.getFullpath();
            dirMode = zfs.getDirMode();
            fileMode = zfs.getDirMode();
        }

        if (prefix.length() > 0 && fullpath.length() > 0) {
            throw new BuildException("Both prefix and fullpath attributes must"
                                     + " not be set on the same fileset.");
        }

        if (resources.length != 1 && fullpath.length() > 0) {
            throw new BuildException("fullpath attribute may only be specified"
                                     + " for filesets that specify a single"
                                     + " file.");
        }

        if (prefix.length() > 0
            && !prefix.endsWith("/")
            && !prefix.endsWith("\\")) {
            prefix += "/";
        }

        ZipFile zf = null;
        try {
            boolean dealingWithFiles = false;
            File base = null;

            if (zfs == null || zfs.getSrc() == null) {
                dealingWithFiles = true;
                base = fileset.getDir(getProject());
            } else {
                zf = new ZipFile(zfs.getSrc());
            }
           
            for (int i = 0; i < resources.length; i++) {
                String name = null;
                if (fullpath.length() > 0) {
                    name = fullpath;
                } else {
                    name = resources[i].getName();
                }
                name = name.replace(File.separatorChar, '/');
               
                if ("".equals(name)) {
                    continue;
                }
                if (resources[i].isDirectory() && ! name.endsWith("/")) {
                    name = name + "/";
                }
               
                addParentDirs(base, name, zOut, prefix, dirMode);
               
                if (!resources[i].isDirectory() && dealingWithFiles) {
                    File f = fileUtils.resolveFile(base,
                                                   resources[i].getName());
                    zipFile(f, zOut, prefix + name, fileMode);
                } else if (!resources[i].isDirectory()) {
                    java.util.zip.ZipEntry ze =
                        zf.getEntry(resources[i].getName());
                    if (ze != null) {
                        zipFile(zf.getInputStream(ze), zOut, prefix + name,
                                ze.getTime(), zfs.getSrc(), fileMode);
                    }
                }
            }
        } finally {
            if (zf != null) {
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.types.ZipFileSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.