PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/ant-1.8.2/src/main/org/apache/tools/ant/util/facade/FacadeTaskHelper.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 165 lines | 59 code | 18 blank | 88 comment | 9 complexity | ae755a3b02926e45635ff944facb8d47 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.util.facade;
  19. import java.util.ArrayList;
  20. import java.util.Iterator;
  21. import java.util.List;
  22. import org.apache.tools.ant.Project;
  23. import org.apache.tools.ant.types.Path;
  24. /**
  25. * Helper class for facade implementations - encapsulates treatment of
  26. * explicit implementation choices, magic properties and
  27. * implementation specific command line arguments.
  28. *
  29. *
  30. * @since Ant 1.5
  31. */
  32. public class FacadeTaskHelper {
  33. /**
  34. * Command line arguments.
  35. */
  36. private List args = new ArrayList();
  37. /**
  38. * The explicitly chosen implementation.
  39. */
  40. private String userChoice;
  41. /**
  42. * The magic property to consult.
  43. */
  44. private String magicValue;
  45. /**
  46. * The default value.
  47. */
  48. private String defaultValue;
  49. /**
  50. * User specified path used as classpath when loading the implementation.
  51. */
  52. private Path implementationClasspath;
  53. /**
  54. * @param defaultValue The default value for the implementation.
  55. * Must not be null.
  56. */
  57. public FacadeTaskHelper(String defaultValue) {
  58. this(defaultValue, null);
  59. }
  60. /**
  61. * @param defaultValue The default value for the implementation.
  62. * Must not be null.
  63. * @param magicValue the value of a magic property that may hold a user.
  64. * choice. May be null.
  65. */
  66. public FacadeTaskHelper(String defaultValue, String magicValue) {
  67. this.defaultValue = defaultValue;
  68. this.magicValue = magicValue;
  69. }
  70. /**
  71. * Used to set the value of the magic property.
  72. * @param magicValue the value of a magic property that may hold a user.
  73. */
  74. public void setMagicValue(String magicValue) {
  75. this.magicValue = magicValue;
  76. }
  77. /**
  78. * Used for explicit user choices.
  79. * @param userChoice the explicitly chosen implementation.
  80. */
  81. public void setImplementation(String userChoice) {
  82. this.userChoice = userChoice;
  83. }
  84. /**
  85. * Retrieves the implementation.
  86. * @return the implementation.
  87. */
  88. public String getImplementation() {
  89. return userChoice != null ? userChoice
  90. : (magicValue != null ? magicValue
  91. : defaultValue);
  92. }
  93. /**
  94. * Retrieves the explicit user choice.
  95. * @return the explicit user choice.
  96. */
  97. public String getExplicitChoice() {
  98. return userChoice;
  99. }
  100. /**
  101. * Command line argument.
  102. * @param arg an argument to add.
  103. */
  104. public void addImplementationArgument(ImplementationSpecificArgument arg) {
  105. args.add(arg);
  106. }
  107. /**
  108. * Retrieves the command line arguments enabled for the current
  109. * facade implementation.
  110. * @return an array of command line arguements.
  111. */
  112. public String[] getArgs() {
  113. List tmp = new ArrayList(args.size());
  114. for (Iterator e = args.iterator(); e.hasNext();) {
  115. ImplementationSpecificArgument arg =
  116. ((ImplementationSpecificArgument) e.next());
  117. String[] curr = arg.getParts(getImplementation());
  118. for (int i = 0; i < curr.length; i++) {
  119. tmp.add(curr[i]);
  120. }
  121. }
  122. String[] res = new String[tmp.size()];
  123. return (String[]) tmp.toArray(res);
  124. }
  125. /**
  126. * Tests whether the implementation has been chosen by the user
  127. * (either via a magic property or explicitly.
  128. * @return true if magic or user choice has be set.
  129. * @since Ant 1.5.2
  130. */
  131. public boolean hasBeenSet() {
  132. return userChoice != null || magicValue != null;
  133. }
  134. /**
  135. * The classpath to use when loading the implementation.
  136. *
  137. * @param project the current project
  138. * @return a Path instance that may be appended to
  139. * @since Ant 1.8.0
  140. */
  141. public Path getImplementationClasspath(Project project) {
  142. if (implementationClasspath == null) {
  143. implementationClasspath = new Path(project);
  144. }
  145. return implementationClasspath;
  146. }
  147. }