001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.anttasks.builder.tools;
016:
017: import java.io.File;
018: import java.util.Arrays;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.Set;
022:
023: import org.apache.tools.ant.BuildException;
024: import org.apache.tools.ant.Project;
025: import org.apache.tools.ant.taskdefs.Copy;
026: import org.apache.tools.ant.types.FileSet;
027: import org.apache.tools.ant.types.PatternSet;
028:
029: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
030: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
031:
032: /** This definition is responsible for invocation of Mkdir standard ant target */
033: public class AntCopyInvocationDefinition extends
034: ToolInvocationDefinition {
035: private File mDestinationDirectory = null;
036: public File mSourceDirectory = null;
037: public Set mSourceIncludes = new HashSet();
038: public Set mSourceExcludes = new HashSet();
039:
040: /** Public constructor for the invocation */
041: public AntCopyInvocationDefinition(MetaBossBuilderTask pOwnerTask,
042: String pTaskName) {
043: super (pOwnerTask, pTaskName);
044: }
045:
046: /** Setter for the path of the destination directory to be created */
047: public void setDestinationDirectoryPath(
048: String pDestinationDirectoryPath) {
049: mDestinationDirectory = new File(pDestinationDirectoryPath)
050: .getAbsoluteFile();
051: }
052:
053: /** Gets the path of the directory to be created */
054: public File getDestinationDirectory() {
055: if (mDestinationDirectory == null)
056: throw new BuildException(
057: "Missing DestinationDirectoryPath, which is mandatory for copy task invocation.");
058: return mDestinationDirectory;
059: }
060:
061: /** Overridden to make it always not equal unless this is exactly the same object */
062: public boolean equals(Object pOther) {
063: if (this == pOther)
064: return true;
065: return false;
066: }
067:
068: /** Adds single source directory to include */
069: public void setSourceDirectoryPath(String pSourceDirectoryPath) {
070: if (mSourceDirectory != null)
071: throw new BuildException(
072: "One instance of the AntCopyInvocationDefinition can only support one source directory.");
073: mSourceDirectory = new File(pSourceDirectoryPath)
074: .getAbsoluteFile();
075: }
076:
077: /** Adds list of includes to the set of includes */
078: public void addSourceIncludes(String[] pIncludes) {
079: mSourceIncludes.addAll(Arrays.asList(pIncludes));
080: }
081:
082: /** Adds single include to the set of includes */
083: public void addSourceInclude(String pInclude) {
084: mSourceIncludes.add(pInclude);
085: }
086:
087: /** Adds list of excludes to the set of excludes */
088: public void addSourceExcludes(String[] pExcludes) {
089: mSourceExcludes.addAll(Arrays.asList(pExcludes));
090: }
091:
092: /** Adds single exclude to the set of excludes from generated source path */
093: public void addSourceExclude(String pExclude) {
094: mSourceExcludes.add(pExclude);
095: }
096:
097: /** This method will have to invoke the generator */
098: public void invoke() throws BuildException {
099: MetaBossBuilderTask lOwnerTask = getOwnerTask();
100: Project lThisProject = getOwnerTask().getProject();
101: // Now create and execute the java compiler task
102: Copy lCopyTask = (Copy) lThisProject.createTask("copy");
103: lCopyTask.setTaskName(lOwnerTask.getTaskName());
104: lCopyTask.setTodir(getDestinationDirectory());
105:
106: FileSet lSourceFileSet = new FileSet();
107: lSourceFileSet.setDir(mSourceDirectory);
108: // Work on includes
109: for (Iterator lIncludesIterator = mSourceIncludes.iterator(); lIncludesIterator
110: .hasNext();) {
111: PatternSet.NameEntry lIncludeNameEntry = lSourceFileSet
112: .createInclude();
113: lIncludeNameEntry
114: .setName((String) lIncludesIterator.next());
115: }
116: // Work on excludes
117: for (Iterator lExcludesIterator = mSourceExcludes.iterator(); lExcludesIterator
118: .hasNext();) {
119: PatternSet.NameEntry lExcludeNameEntry = lSourceFileSet
120: .createExclude();
121: lExcludeNameEntry
122: .setName((String) lExcludesIterator.next());
123: }
124: lCopyTask.addFileset(lSourceFileSet);
125: lCopyTask.execute();
126: }
127: }
|