1. /*
  2. * Copyright 2003-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.sitraka;
  18. import java.io.File;
  19. import org.apache.tools.ant.Task;
  20. import org.apache.tools.ant.taskdefs.condition.Os;
  21. import org.apache.tools.ant.util.FileUtils;
  22. /**
  23. * Base class that deals with JProbe version incompatibilities.
  24. *
  25. * @since Ant 1.6
  26. *
  27. */
  28. public abstract class CovBase extends Task {
  29. private File home;
  30. private static FileUtils fu = FileUtils.newFileUtils();
  31. private boolean isJProbe4 = false;
  32. private static boolean isDos = Os.isFamily("dos");
  33. /**
  34. * The directory where JProbe is installed.
  35. */
  36. public void setHome(File value) {
  37. this.home = value;
  38. }
  39. protected File getHome() {
  40. return home;
  41. }
  42. protected File findCoverageJar() {
  43. File loc = null;
  44. if (isJProbe4) {
  45. loc = fu.resolveFile(home, "lib/coverage.jar");
  46. } else {
  47. loc = fu.resolveFile(home, "coverage/coverage.jar");
  48. if (!loc.canRead()) {
  49. File newLoc = fu.resolveFile(home, "lib/coverage.jar");
  50. if (newLoc.canRead()) {
  51. isJProbe4 = true;
  52. loc = newLoc;
  53. }
  54. }
  55. }
  56. return loc;
  57. }
  58. protected String findExecutable(String relativePath) {
  59. if (isDos) {
  60. relativePath += ".exe";
  61. }
  62. File loc = null;
  63. if (isJProbe4) {
  64. loc = fu.resolveFile(home, "bin/" + relativePath);
  65. } else {
  66. loc = fu.resolveFile(home, relativePath);
  67. if (!loc.canRead()) {
  68. File newLoc = fu.resolveFile(home, "bin/" + relativePath);
  69. if (newLoc.canRead()) {
  70. isJProbe4 = true;
  71. loc = newLoc;
  72. }
  73. }
  74. }
  75. return loc.getAbsolutePath();
  76. }
  77. protected File createTempFile(String prefix) {
  78. return fu.createTempFile(prefix, ".tmp", null);
  79. }
  80. protected String getParamFileArgument() {
  81. return "-" + (!isJProbe4 ? "jp_" : "") + "paramfile=";
  82. }
  83. /**
  84. * Are we running on a version of JProbe 4.x or higher?
  85. */
  86. protected boolean isJProbe4Plus() {
  87. return isJProbe4;
  88. }
  89. }