Examples of ZipFileSet


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

        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

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

                continue;
            }
           
            FileNameMapper myMapper = new IdentityMapper();
            if (filesets[i] instanceof ZipFileSet) {
                ZipFileSet zfs = (ZipFileSet) filesets[i];
                if (zfs.getFullpath() != null
                    && !zfs.getFullpath().equals("") ) {
                    // in this case all files from origin map to
                    // the fullPath attribute of the zipfileset at
                    // destination
                    MergingMapper fm = new MergingMapper();
                    fm.setTo(zfs.getFullpath());
                    myMapper = fm;

                } else if (zfs.getPrefix() != null
                           && !zfs.getPrefix().equals("")) {
                    GlobPatternMapper gm=new GlobPatternMapper();
                    gm.setFrom("*");
                    String prefix = zfs.getPrefix();
                    if (!prefix.endsWith("/") && !prefix.endsWith("\\")) {
                        prefix += "/";
                    }
                    gm.setTo(prefix + "*");
                    myMapper = gm;
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setFile(deploymentDescriptor);
        fs.setFullpath("WEB-INF/web.xml");
        super.addFileset(fs);
    }
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setFile(deploymentDescriptor);
        fs.setFullpath("META-INF/application.xml");
        super.addFileset(fs);
    }
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setFile(deploymentDescriptor);
        fs.setFullpath(XML_DESCRIPTOR_PATH);
        super.addFileset(fs);
    }
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setFile(deploymentDescriptor);
        fs.setFullpath(XML_DESCRIPTOR_PATH);
        super.addFileset(fs);
    }
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setDir(new File(deploymentDescriptor.getParent()));
        fs.setIncludes(deploymentDescriptor.getName());
        fs.setFullpath("WEB-INF/web.xml");
        super.addFileset(fs);
    }
View Full Code Here

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

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

        // Create the scanners to pass to isUpToDate().
        Vector dss = new Vector();
        if (baseDir != null) {
            dss.addElement(getDirectoryScanner(baseDir));
        }
        for (int i = 0; i < filesets.size(); i++) {
            FileSet fs = (FileSet) filesets.elementAt(i);
            dss.addElement (fs.getDirectoryScanner(project));
        }
        int dssSize = dss.size();
        FileScanner[] scanners = new FileScanner[dssSize];
        dss.copyInto(scanners);

        boolean success = false;
        try {
            // quick exit if the target is up to date
            // can also handle empty archives
            if (isUpToDate(scanners, zipFile)) {
                return;
            }
           
            if (doUpdate) {
                FileUtils fileUtils = FileUtils.newFileUtils();
                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 implicit fileset to the archive.
                if (baseDir != null) {
                    addFiles(getDirectoryScanner(baseDir), zOut, "", "");
                }
                // Add the explicit filesets to the archive.
                addFiles(filesets, 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));
                    }
                    Vector tmp = new Vector(1);
                    tmp.addElement(oldFiles);
                    addFiles(tmp, zOut);
View Full Code Here

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

            DirectoryScanner ds = fs.getDirectoryScanner(project);

            String prefix = "";
            String fullpath = "";
            if (fs instanceof ZipFileSet) {
                ZipFileSet zfs = (ZipFileSet) fs;
                prefix = zfs.getPrefix();
                fullpath = zfs.getFullpath();
            }

            if (prefix.length() > 0
                && !prefix.endsWith("/")
                && !prefix.endsWith("\\")) {
View Full Code Here

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

                                     + deploymentDescriptor
                                     + " does not exist.");
        }

        // Create a ZipFileSet for this file, and pass it up.
        ZipFileSet fs = new ZipFileSet();
        fs.setDir(new File(deploymentDescriptor.getParent()));
        fs.setIncludes(deploymentDescriptor.getName());
        fs.setFullpath("META-INF/application.xml");
        super.addFileset(fs);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.