source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/DotnetBaseMatchingTask.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 5.6 KB
Line 
1/*
2 * Copyright 2000-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.optional.dotnet;
19
20import org.apache.tools.ant.taskdefs.MatchingTask;
21import org.apache.tools.ant.types.FileSet;
22import org.apache.tools.ant.Project;
23import org.apache.tools.ant.DirectoryScanner;
24
25import java.io.File;
26import java.util.Vector;
27import java.util.Hashtable;
28import java.util.Enumeration;
29
30/**
31 * refactoring of some stuff so that different things (like ILASM)
32 * can use shared code.
33 */
34public class DotnetBaseMatchingTask extends MatchingTask {
35 /**
36 * output file. If not supplied this is derived from the source file
37 */
38 protected File outputFile;
39 /**
40 * filesets of file to compile
41 */
42 protected Vector filesets = new Vector();
43
44 /**
45 * source directory upon which the search pattern is applied
46 */
47 protected File srcDir;
48
49 /**
50 * Overridden because we need to be able to set the srcDir.
51 */
52 public File getSrcDir() {
53 return this.srcDir;
54 }
55
56 /**
57 * Set the source directory of the files to be compiled.
58 *
59 *@param srcDirName The new SrcDir value
60 */
61 public void setSrcDir(File srcDirName) {
62 this.srcDir = srcDirName;
63 }
64
65 /**
66 * Set the name of exe/library to create.
67 *
68 *@param file The new outputFile value
69 */
70 public void setDestFile(File file) {
71 outputFile = file;
72 }
73
74 /**
75 * add a new source directory to the compile
76 * @param src
77 */
78 public void addSrc(FileSet src) {
79 filesets.add(src);
80 }
81
82 /**
83 * get the destination file
84 * @return the dest file or null for not assigned
85 */
86 public File getDestFile() {
87 return outputFile;
88 }
89
90 /**
91 * create the list of files
92 * @param filesToBuild vector to add files to
93 * @param outputTimestamp timestamp to compare against
94 * @return number of files out of date
95 */
96 protected int buildFileList(NetCommand command, Hashtable filesToBuild, long outputTimestamp) {
97 int filesOutOfDate = 0;
98 boolean scanImplicitFileset
99 = getSrcDir() != null || filesets.size() == 0;
100 if (scanImplicitFileset) {
101 //scan for an implicit fileset if there was a srcdir set
102 //or there was no srcDir set but there was no contained classes
103 if (getSrcDir() == null) {
104 //if there is no src dir here, set it
105 setSrcDir(getProject().resolveFile("."));
106 }
107 log("working from source directory " + getSrcDir(),
108 Project.MSG_VERBOSE);
109 //get dependencies list.
110 DirectoryScanner scanner = getDirectoryScanner(getSrcDir());
111 filesOutOfDate = command.scanOneFileset(scanner,
112 filesToBuild, outputTimestamp);
113 }
114 //get any included source directories
115 for (int i = 0; i < filesets.size(); i++) {
116 FileSet fs = (FileSet) filesets.elementAt(i);
117 filesOutOfDate += command.scanOneFileset(
118 fs.getDirectoryScanner(getProject()),
119 filesToBuild,
120 outputTimestamp);
121 }
122
123 return filesOutOfDate;
124 }
125
126 /**
127 * add the list of files to a command
128 * @param filesToBuild vector of files
129 * @param command the command to append to
130 */
131 protected void addFilesToCommand(Hashtable filesToBuild, NetCommand command) {
132 int count = filesToBuild.size();
133 log("compiling " + count + " file" + ((count == 1) ? "" : "s"));
134 Enumeration files = filesToBuild.elements();
135 while (files.hasMoreElements()) {
136 File file = (File) files.nextElement();
137 command.addArgument(file.toString());
138 }
139 }
140
141 /**
142 * determine the timestamp of the output file
143 * @return a timestamp or 0 for no output file known/exists
144 */
145 protected long getOutputFileTimestamp() {
146 long outputTimestamp;
147 if (getDestFile() != null && getDestFile().exists()) {
148 outputTimestamp = getDestFile().lastModified();
149 } else {
150 outputTimestamp = 0;
151 }
152 return outputTimestamp;
153 }
154
155 /**
156 * finish off the command by adding all dependent files, execute
157 * @param command
158 */
159 protected void addFilesAndExecute(NetCommand command, boolean ignoreTimestamps) {
160 long outputTimestamp = getOutputFileTimestamp();
161 Hashtable filesToBuild = new Hashtable();
162 int filesOutOfDate = buildFileList(command, filesToBuild, outputTimestamp);
163
164 //add the files to the command
165 addFilesToCommand(filesToBuild, command);
166
167
168 //now run the command of exe + settings + files
169 if (filesOutOfDate > 0) {
170 command.runCommand();
171 } else {
172 log("output file is up to date", Project.MSG_VERBOSE);
173 }
174 }
175
176
177
178}
Note: See TracBrowser for help on using the repository browser.