001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ant.taskdefs;
023:
024: import org.apache.tools.ant.Task;
025: import org.apache.tools.ant.BuildException;
026: import org.apache.tools.ant.DirectoryScanner;
027: import org.apache.tools.ant.taskdefs.Ant;
028: import org.apache.tools.ant.taskdefs.Property;
029: import org.apache.tools.ant.util.SourceFileScanner;
030: import org.apache.tools.ant.util.FlatFileNameMapper;
031: import org.apache.tools.ant.types.DirSet;
032:
033: import java.util.ArrayList;
034: import java.util.Iterator;
035: import java.io.File;
036:
037: /**
038: * This class will call a specified ant class for each existent file into fileSet or dirSet
039: *
040: * @author Clebert.suconic@jboss.com
041: */
042: public class AntCallOnDirectoryList extends Task {
043: ArrayList list = new ArrayList();
044:
045: String targetToExecute;
046:
047: String directoryProperty;
048: String versionNameProperty;
049:
050: Ant ant = null;
051:
052: public String getVersionNameProperty() {
053: return versionNameProperty;
054: }
055:
056: public void setVersionNameProperty(String versionNameProperty) {
057: this .versionNameProperty = versionNameProperty;
058: }
059:
060: public String getTargetToExecute() {
061: return targetToExecute;
062: }
063:
064: public void setTargetToExecute(String targetToExecute) {
065: this .targetToExecute = targetToExecute;
066: }
067:
068: public String getDirectoryProperty() {
069: return directoryProperty;
070: }
071:
072: public void setDirectoryProperty(String directoryProperty) {
073: this .directoryProperty = directoryProperty;
074: }
075:
076: public void init() {
077: super .init();
078: ant = (Ant) this .getProject().createTask("ant");
079: ant.setAntfile(this .getProject().getProperty("ant.file"));
080: ant.setOwningTarget(getOwningTarget());
081: ant.setTaskName(getTaskName());
082: ant.setLocation(getLocation());
083: ant.init();
084: }
085:
086: public void addDirSet(DirSet dirSet) {
087: list.add(dirSet);
088: }
089:
090: public void execute() throws BuildException {
091: init();
092: ant.setTarget(getTargetToExecute());
093: Property parameterDirectory = ant.createProperty();
094: parameterDirectory.setName(this .getDirectoryProperty());
095:
096: Property parameterName = ant.createProperty();
097: parameterName.setName(this .getVersionNameProperty());
098:
099: Iterator iter = list.iterator();
100: while (iter.hasNext()) {
101: DirSet dirSet = (DirSet) iter.next();
102: File currentDir = dirSet.getDir(this .getProject());
103: DirectoryScanner scanner = dirSet.getDirectoryScanner(this
104: .getProject());
105:
106: SourceFileScanner sourceScanner = new SourceFileScanner(
107: this );
108: String[] strfiles = scanner.getIncludedDirectories();
109: ArrayList files = new ArrayList();
110: for (int i = 0; i < strfiles.length; i++) {
111: File currentFile = new File(currentDir, strfiles[i]);
112: if (currentFile.getParentFile().getAbsolutePath()
113: .equals(currentDir.getAbsolutePath())) {
114: files.add(currentFile);
115: parameterDirectory.setValue(currentFile
116: .getAbsolutePath());
117: parameterName.setValue(currentFile.getName());
118: ant.execute();
119: }
120: }
121:
122: }
123: }
124: }
|