KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sitraka > CovBase


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
18 package org.apache.tools.ant.taskdefs.optional.sitraka;
19
20 import java.io.File JavaDoc;
21 import org.apache.tools.ant.Task;
22 import org.apache.tools.ant.taskdefs.condition.Os;
23 import org.apache.tools.ant.util.FileUtils;
24
25 /**
26  * Base class that deals with JProbe version incompatibilities.
27  *
28  * @since Ant 1.6
29  *
30  */

31 public abstract class CovBase extends Task {
32     private File JavaDoc home;
33     private static FileUtils fu = FileUtils.newFileUtils();
34     private boolean isJProbe4 = false;
35     private static boolean isDos = Os.isFamily("dos");
36
37     /**
38      * The directory where JProbe is installed.
39      */

40     public void setHome(File JavaDoc value) {
41         this.home = value;
42     }
43
44     protected File JavaDoc getHome() {
45         return home;
46     }
47
48     protected File JavaDoc findCoverageJar() {
49         File JavaDoc loc = null;
50         if (isJProbe4) {
51             loc = fu.resolveFile(home, "lib/coverage.jar");
52         } else {
53             loc = fu.resolveFile(home, "coverage/coverage.jar");
54             if (!loc.canRead()) {
55                 File JavaDoc newLoc = fu.resolveFile(home, "lib/coverage.jar");
56                 if (newLoc.canRead()) {
57                     isJProbe4 = true;
58                     loc = newLoc;
59                 }
60             }
61         }
62
63         return loc;
64     }
65
66     protected String JavaDoc findExecutable(String JavaDoc relativePath) {
67         if (isDos) {
68             relativePath += ".exe";
69         }
70
71         File JavaDoc loc = null;
72         if (isJProbe4) {
73             loc = fu.resolveFile(home, "bin/" + relativePath);
74         } else {
75             loc = fu.resolveFile(home, relativePath);
76             if (!loc.canRead()) {
77                 File JavaDoc newLoc = fu.resolveFile(home, "bin/" + relativePath);
78                 if (newLoc.canRead()) {
79                     isJProbe4 = true;
80                     loc = newLoc;
81                 }
82             }
83         }
84         return loc.getAbsolutePath();
85     }
86
87     protected File JavaDoc createTempFile(String JavaDoc prefix) {
88         return fu.createTempFile(prefix, ".tmp", null);
89     }
90
91     protected String JavaDoc getParamFileArgument() {
92         return "-" + (!isJProbe4 ? "jp_" : "") + "paramfile=";
93     }
94
95     /**
96      * Are we running on a version of JProbe 4.x or higher?
97      */

98     protected boolean isJProbe4Plus() {
99         return isJProbe4;
100     }
101 }
102
Popular Tags