Package org.apache.tools.ant.types.resources

Examples of org.apache.tools.ant.types.resources.Union


        if (rc == null) {
            throw new BuildException("Cannot add null ResourceCollection");
        }
        synchronized (this) {
            if (resources == null) {
                resources = new Union();
            }
        }
        resources.add(rc);
    }
View Full Code Here


        checkChildrenAllowed();
        if (c == null) {
            return;
        }
        if (union == null) {
            union = new Union();
            union.setProject(getProject());
            union.setCache(cache);
        }
        union.add(c);
        setChecked(false);
View Full Code Here

        if (getLocation() == null || getLocation().getFileName() == null) {
            throw new BuildException("Unable to get location of import task");
        }

        Union resourcesToImport = new Union(getProject(), resources);
        Resource fromFileAttribute = getFileAttributeResource();
        if (fromFileAttribute != null) {
            resources.add(fromFileAttribute);
        }
        for (Resource r : resourcesToImport) {
View Full Code Here

            return;
        }

        String port = input.getPort();
        FileNameMapper inputMapper = input.getMapper();
        Union resources = input.getResources();

        if (port == null) {
            port = inPort;
        }

        if (inputMapper != null) {
            if (resources.size() != 0) {
                handleError("Both mapper and fileset on input port: " + port);
                return;
            }

            if (port.equals(inPort)) {
                handleError("Cannot use mapper on main input port: " + port);
                return;
            }

            if (inputResources.containsKey(port)) {
                handleError("Mapper used on input port that already has resources: " + port);
                return;
            }

            if (inputMappers.containsKey(port)) {
                handleError("Mapper used on input port that already has a mapper: " + port);
                return;
            }

            inputMappers.put(port, new TypedFileNameMapper(inputMapper, input.getType(), input.getContentType()));
        } else {
            if (inputMappers.containsKey(port)) {
                handleError("Resources used on input port that already has a mapper: " + port);
                return;
            }

            if ((resources.size() != 0) && !inputResources.containsKey(port)) {
                inputResources.put(port, new ArrayList<TypedResource>());
            }

            for (Resource resource : resources.listResources()) {
                inputResources.get(port).add(new TypedResource(resource, input.getType(), input.getContentType()));
            }
        }
    }
View Full Code Here

            return;
        }

        String port = o.getPort();
        FileNameMapper outputMapper = o.getMapper();
        Union resources = o.getResources();

        if (port == null) {
            port = outPort;
        }

        if (outputMapper != null && resources.size() != 0) {
            handleError("Both mapper and fileset on output port: " + port);
            return;
        }

        if (outputMapper != null) {
            if (outputResources.containsKey(port)) {
                handleError("Mapper used on output port that already has resources: " + port);
                return;
            }

            if (outputMappers.containsKey(port)) {
                handleError("Mapper used on output port that already has a mapper: " + port);
                return;
            }

            outputMappers.put(port, outputMapper);
        } else {
            if (outputMappers.containsKey(port)) {
                handleError("Resources used on output port that already has a mapper: " + port);
                return;
            }

            if (!outputResources.containsKey(port)) {
                outputResources.put(port, new Union());
            }
            outputResources.get(port).add(resources);
        }
    }
View Full Code Here

                            String[] outputFileNames = outputMapper.mapFileName(typedResource.getResource().getName());
                            // Mapper may produce zero or more filenames,
                            // which may or may not be what was wanted but
                            // only the user will know that.
                            if (outputFileNames != null) {
                                Union outputResources = new Union();
                                for (String fileName : outputFileNames) {
                                    outputResources.add(new FileResource(destDir, fileName));
                                }
                                useOutputResources.put(port, outputResources);
                            }
                        }
                    }
                }
                process(useInputResources, useOutputResources);
            } else { // Using implicit and/or explicit filesets
                if (useImplicitFileset) {
                    DirectoryScanner scanner = getDirectoryScanner(baseDir);
                    log("Pipelining into " + destDir, Project.MSG_INFO);

                    // Process all the files marked for styling
                    String[] includedFiles = scanner.getIncludedFiles();
                    for (int i = 0; i < includedFiles.length; ++i) {
                        resources.add(new FileResource(baseDir, includedFiles[i]));
                    }
                    if (performDirectoryScan) {
                        // Process all the directories marked for styling
                        String[] includedDirs = scanner.getIncludedDirectories();
                        for (int j = 0; j < includedDirs.length; ++j) {
                            includedFiles = new File(baseDir, includedDirs[j]).list();
                            for (int i = 0; i < includedFiles.length; ++i) {
                                resources.add(new FileResource(baseDir, includedDirs[j] + File.separator + includedFiles[i]));
                            }
                        }
                    }
                } else { // only resource collections, there better be some
                    if (resources.size() == 0) {
                        if (failOnNoResources) {
                            handleError("no resources specified");
                        }
                        return;
                    }
                }

                FileNameMapper useMapper = null;
                if (!outputResources.containsKey(outPort)) {
                    if (mapper != null) {
                        useMapper = mapper;
                    } else {
                        useMapper = new ExtensionMapper();
                    }
                }

                // Process implicit and/or explicit resources one at a
                // time.
                for (Resource resource : resources.listResources()) {
                    log("Resource: " + resource.getName(), Project.MSG_DEBUG);
                    Map<String, List<TypedResource>> useInputResources = new HashMap<String, List<TypedResource>>();

                    // Any fixed resources on other input ports.
                    useInputResources.putAll(inputResources);
                    // The resource.
                    useInputResources.put(inPort, asList(new TypedResource(resource, inType)));
                    // Any mapped resources on other input ports.
                    for (String port : inputMappers.keySet()) {
                        TypedFileNameMapper inputMapper = inputMappers.get(port);

                        String[] inputFileNames = inputMapper.mapFileName(resource.getName());
                        // Mapper may produce zero or more filenames,
                        // which may or may not be what was wanted but
                        // only the user will know that.
                        if (inputFileNames != null) {
                            List<TypedResource> mappedResources = new ArrayList<TypedResource>();
                            for (String fileName : inputFileNames) {
                                FileResource mappedResource = new FileResource(baseDir, fileName);
                                mappedResources.add(new TypedResource(mappedResource, inputMapper.getType(), inputMapper.getContentType()));
                            }
                            useInputResources.put(port, mappedResources);
                        }
                    }

                    HashMap<String, Union> useOutputResources = new HashMap<String, Union>();
                    useOutputResources.putAll(outputResources);
                    // FIXME: Why is it necessary to check for null?
                    if (useMapper != null) {
                        String[] outFileName = useMapper.mapFileName(resource.getName());
                        // Require exactly one output for each mapped
                        // input.
                        if (outFileName == null || outFileName.length == 0) {
                            log("Skipping '" + resource.getName() + "' as it cannot be mapped to output.", Project.MSG_VERBOSE);
                            continue;
                        } else if (outFileName == null || outFileName.length > 1) {
                            log("Skipping " + resource.getName() + " as its mapping is ambiguous.", Project.MSG_VERBOSE);
                            continue;
                        }
                        useOutputResources.put(outPort, new Union(new FileResource(destDir, outFileName[0])));
                    }

                    // Any mapped resources on other output ports.
                    for (String port : outputMappers.keySet()) {
                        FileNameMapper outputMapper = outputMappers.get(port);

                        String[] outputFileNames = outputMapper.mapFileName(resource.getName());
                        // Mapper may produce zero or more filenames,
                        // which may or may not be what was wanted but
                        // only the user will know that.
                        if (outputFileNames != null) {
                            Union outputResources = new Union();
                            for (String fileName : outputFileNames) {
                                outputResources.add(new FileResource(destDir, fileName));
                            }
                            useOutputResources.put(port, outputResources);
                        }
                    }
                    process(useInputResources, useOutputResources);
                }
            }
        } finally {
            // Same instance is reused when Ant runs this task
            // again, so reset everything.
            userArgs = new UserArgs();
            inputResources.clear();
            inputMappers.clear();
            baseDir = null;
            inPort = null;
            inResource = null;
            inType = XML;
            failOnNoResources = true;
            pipelineResource = null;
            destDir = null;
            outPort = null;
            outResource = null;
            outputResources.clear();
            outputMappers.clear();
            targetExtension = "-out.xml";
            isTargetExtensionSet = false;
            failOnError = true;
            resources = new Union();
            useImplicitFileset = true;
            performDirectoryScan = true;
            mapper = null;
            force = false;
            if (sysProperties.size() > 0) {
View Full Code Here

            }
        }

        try {
            for (String port : outputResources.keySet()) {
                Union resources = outputResources.get(port);
                for (Iterator<Resource> iterator = resources.iterator(); iterator.hasNext(); ) {
                    Resource resource = iterator.next();
                    userArgs.addOutput(port, resource.getOutputStream());
                }
            }
            for (String port : inputResources.keySet()) {
View Full Code Here

     */
    public void add(ResourceCollection rc) {
        if (rc == null) {
            return;
        }
        resources = resources == null ? new Union() : resources;
        resources.add(rc);
    }
View Full Code Here

     * @param rc resource collection to add.
     * @since Ant 1.7
     */
    public void add(ResourceCollection rc) {
        if (resources == null) {
            resources = new Union();
        }
        resources.add(rc);
    }
View Full Code Here

    /**
     * Create a nested sources element.
     * @return a Union instance.
     */
    public synchronized Union createSources() {
        sources = (sources == null) ? new Union() : sources;
        return sources;
    }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.types.resources.Union

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.