001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.ant;
019:
020: import org.apache.tools.ant.BuildException;
021: import org.apache.tools.ant.Project;
022: import org.apache.tools.ant.Task;
023: import org.apache.tools.ant.types.DirSet;
024: import org.apache.tools.ant.types.FileList;
025: import org.apache.tools.ant.types.FileSet;
026: import org.apache.tools.ant.types.Path;
027: import org.apache.tools.ant.types.Path.PathElement;
028:
029: /**
030: * This task is not directly related to ivy, but is useful in some modular build systems. The idea
031: * is to be able to contribute new sub path elements to an existing path.
032: */
033: public class AddPathTask extends Task {
034: private String toPath;
035:
036: private boolean first = false;
037:
038: private Path toAdd;
039:
040: public String getTopath() {
041: return toPath;
042: }
043:
044: public void setTopath(String toPath) {
045: this .toPath = toPath;
046: }
047:
048: public void setProject(Project project) {
049: super .setProject(project);
050: toAdd = new Path(project);
051: }
052:
053: public void execute() throws BuildException {
054: Object element = getProject().getReference(toPath);
055: if (element == null) {
056: throw new BuildException("destination path not found: "
057: + toPath);
058: }
059: if (!(element instanceof Path)) {
060: throw new BuildException("destination path is not a path: "
061: + element.getClass());
062: }
063: Path dest = (Path) element;
064: if (first) {
065: // now way to add path elements at te beginning of the existing path: we do the opposite
066: // and replace the reference
067: toAdd.append(dest);
068: getProject().addReference(toPath, toAdd);
069: } else {
070: dest.append(toAdd);
071: }
072: }
073:
074: public void add(Path path) throws BuildException {
075: toAdd.add(path);
076: }
077:
078: public void addDirset(DirSet dset) throws BuildException {
079: toAdd.addDirset(dset);
080: }
081:
082: public void addFilelist(FileList fl) throws BuildException {
083: toAdd.addFilelist(fl);
084: }
085:
086: public void addFileset(FileSet fs) throws BuildException {
087: toAdd.addFileset(fs);
088: }
089:
090: public Path createPath() throws BuildException {
091: return toAdd.createPath();
092: }
093:
094: public PathElement createPathElement() throws BuildException {
095: return toAdd.createPathElement();
096: }
097:
098: public boolean isFirst() {
099: return first;
100: }
101:
102: public void setFirst(boolean first) {
103: this.first = first;
104: }
105: }
|