1. /*
  2. * Copyright 2002-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. package org.apache.tools.ant.taskdefs.optional.extension.resolvers;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.Project;
  22. import org.apache.tools.ant.taskdefs.Ant;
  23. import org.apache.tools.ant.taskdefs.optional.extension.Extension;
  24. import org.apache.tools.ant.taskdefs.optional.extension.ExtensionResolver;
  25. /**
  26. * Resolver that just returns s specified location.
  27. *
  28. * @version $Revision: 1.6.2.4 $ $Date: 2004/03/09 17:01:46 $
  29. */
  30. public class AntResolver
  31. implements ExtensionResolver {
  32. private File m_antfile;
  33. private File m_destfile;
  34. private String m_target;
  35. public void setAntfile(File antfile) {
  36. m_antfile = antfile;
  37. }
  38. public void setDestfile(File destfile) {
  39. m_destfile = destfile;
  40. }
  41. public void setTarget(final String target) {
  42. m_target = target;
  43. }
  44. public File resolve(final Extension extension,
  45. final Project project)
  46. throws BuildException {
  47. validate();
  48. final Ant ant = (Ant) project.createTask("ant");
  49. ant.setInheritAll(false);
  50. ant.setAntfile(m_antfile.getName());
  51. try {
  52. final File dir =
  53. m_antfile.getParentFile().getCanonicalFile();
  54. ant.setDir(dir);
  55. } catch (final IOException ioe) {
  56. throw new BuildException(ioe.getMessage(), ioe);
  57. }
  58. if (null != m_target) {
  59. ant.setTarget(m_target);
  60. }
  61. ant.execute();
  62. return m_destfile;
  63. }
  64. private void validate() {
  65. if (null == m_antfile) {
  66. final String message = "Must specify Buildfile";
  67. throw new BuildException(message);
  68. }
  69. if (null == m_destfile) {
  70. final String message = "Must specify destination file";
  71. throw new BuildException(message);
  72. }
  73. }
  74. public String toString() {
  75. return "Ant[" + m_antfile + "==>" + m_destfile + "]";
  76. }
  77. }