source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.2 KB
Line 
1/*
2 * Copyright 2002-2005 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 */
17package org.apache.tools.ant.taskdefs.optional.extension.resolvers;
18
19import java.io.File;
20import java.io.IOException;
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.Project;
23import org.apache.tools.ant.taskdefs.Ant;
24import org.apache.tools.ant.taskdefs.optional.extension.Extension;
25import org.apache.tools.ant.taskdefs.optional.extension.ExtensionResolver;
26
27/**
28 * Resolver that just returns s specified location.
29 *
30 */
31public class AntResolver implements ExtensionResolver {
32 private File antfile;
33 private File destfile;
34 private String target;
35
36 /**
37 * Sets the ant file
38 * @param antfile the ant file to set
39 */
40 public void setAntfile(final File antfile) {
41 this.antfile = antfile;
42 }
43
44 /**
45 * Sets the destination file
46 * @param destfile the destination file
47 */
48 public void setDestfile(final File destfile) {
49 this.destfile = destfile;
50 }
51
52 /**
53 * Sets the target
54 * @param target the target
55 */
56 public void setTarget(final String target) {
57 this.target = target;
58 }
59
60 /**
61 * Returns the resolved file
62 * @param extension the extension
63 * @param project the project
64 * @return the file resolved
65 * @throws BuildException if the file cannot be resolved
66 */
67 public File resolve(final Extension extension,
68 final Project project) throws BuildException {
69 validate();
70
71 final Ant ant = (Ant) project.createTask("ant");
72 ant.setInheritAll(false);
73 ant.setAntfile(antfile.getName());
74
75 try {
76 final File dir =
77 antfile.getParentFile().getCanonicalFile();
78 ant.setDir(dir);
79 } catch (final IOException ioe) {
80 throw new BuildException(ioe.getMessage(), ioe);
81 }
82
83 if (null != target) {
84 ant.setTarget(target);
85 }
86
87 ant.execute();
88
89 return destfile;
90 }
91
92 /*
93 * Validates URL
94 */
95 private void validate() {
96 if (null == antfile) {
97 final String message = "Must specify Buildfile";
98 throw new BuildException(message);
99 }
100
101 if (null == destfile) {
102 final String message = "Must specify destination file";
103 throw new BuildException(message);
104 }
105 }
106
107 /**
108 * Returns a string representation
109 * @return the string representation
110 */
111 public String toString() {
112 return "Ant[" + antfile + "==>" + destfile + "]";
113 }
114}
Note: See TracBrowser for help on using the repository browser.