/maven-amps-plugin/src/main/java/com/atlassian/maven/plugins/amps/util/ant/DefaultAntTaskFactory.java

https://bitbucket.org/mmeinhold/amps · Java · 102 lines · 38 code · 8 blank · 56 comment · 2 complexity · f6d64cb634f4dbe703b84d8d8384db85 MD5 · raw file

  1. /*
  2. * ========================================================================
  3. *
  4. * Copyright 2003-2004 The Apache Software Foundation. Code from this file
  5. * was originally imported from the Jakarta Cactus project.
  6. *
  7. * Codehaus CARGO, copyright 2004-2010 Vincent Massol.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * ========================================================================
  22. */
  23. package com.atlassian.maven.plugins.amps.util.ant;
  24. import org.apache.tools.ant.Location;
  25. import org.apache.tools.ant.Project;
  26. import org.apache.tools.ant.Target;
  27. import org.apache.tools.ant.Task;
  28. /**
  29. * Default {@link AntTaskFactory} for creating Ant tasks.
  30. *
  31. * @version $Id$
  32. */
  33. public class DefaultAntTaskFactory implements AntTaskFactory
  34. {
  35. /**
  36. * The current {@link org.apache.tools.ant.Project} being executed.
  37. */
  38. private Project currentProject;
  39. /**
  40. * The current Ant task being executed.
  41. */
  42. private String currentTaskName;
  43. /**
  44. * The current {@link org.apache.tools.ant.Location} of the Task being executed.
  45. */
  46. private Location currentLocation;
  47. /**
  48. * The current {@link org.apache.tools.ant.Target} being executed.
  49. */
  50. private Target currentOwningTarget;
  51. /**
  52. * Constructor using default values for the current task name, current location and current
  53. * target.
  54. *
  55. * @param project the Ant project used when creating Ant tasks
  56. */
  57. public DefaultAntTaskFactory(Project project)
  58. {
  59. this.currentProject = project;
  60. this.currentTaskName = "cargo";
  61. this.currentLocation = new Location("in cargo code");
  62. this.currentOwningTarget = new Target();
  63. }
  64. /**
  65. * @param project the Ant project used when creating Ant tasks
  66. * @param currentTaskName the current Ant task being executed
  67. * @param currentLocation the current {@link org.apache.tools.ant.Location} of the Task being
  68. * executed.
  69. * @param currentTarget the current {@link org.apache.tools.ant.Target} being executed
  70. */
  71. public DefaultAntTaskFactory(Project project, String currentTaskName, Location currentLocation,
  72. Target currentTarget)
  73. {
  74. this.currentProject = project;
  75. this.currentTaskName = currentTaskName;
  76. this.currentLocation = currentLocation;
  77. this.currentOwningTarget = currentTarget;
  78. }
  79. /**
  80. * {@inheritDoc}
  81. * @see AntTaskFactory#createTask(String)
  82. */
  83. public Task createTask(String theName)
  84. {
  85. Task retVal = this.currentProject.createTask(theName);
  86. if (retVal != null)
  87. {
  88. retVal.setTaskName(this.currentTaskName);
  89. retVal.setLocation(this.currentLocation);
  90. retVal.setOwningTarget(this.currentOwningTarget);
  91. }
  92. return retVal;
  93. }
  94. }