< prev index next >
src/com/sun/javatest/WorkDirectory.java
Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg
@@ -362,13 +362,13 @@
}
return false;
}
- private static void undo(ArrayList undoList) {
+ private static void undo(ArrayList<File> undoList) {
for (int i = undoList.size() - 1; i >= 0; i--) {
- File f = (File) (undoList.get(i));
+ File f = undoList.get(i);
delete(f);
}
}
private static void delete(File f) {
@@ -443,11 +443,11 @@
String templateFile = p.getProperty("file");
if (!new File(templateFile).exists()) {
try {
// try to calculate relocation
- String oldWDpath = loadWdInfo(jtData).getProperty(PREV_WD_PATH);
+ String oldWDpath = loadWdInfo(jtData).get(PREV_WD_PATH);
String[] begins = getDiffInPaths(dir.getPath(), oldWDpath);
if (begins != null) {
if (templateFile.startsWith(begins[1])) {
String candidat = begins[0] + templateFile.substring(begins[1].length());
if (!new File(candidat).exists()) {
@@ -549,32 +549,32 @@
WorkDirectory wd;
synchronized (dirMap) {
// sync-ed to make dirMap data consistent
- WeakReference ref = (WeakReference)(dirMap.get(canonDir));
- wd = (ref == null ? null : (WorkDirectory) (ref.get()));
+ WeakReference<WorkDirectory> ref = dirMap.get(canonDir);
+ wd = (ref == null ? null : ref.get());
if (wd != null)
return wd;
- Properties tsInfo;
+ Map<String, String> tsInfo;
TestSuite ts;
try {
tsInfo = loadTestSuiteInfo(jtData);
- String root = tsInfo.getProperty(TESTSUITE_ROOT);
+ String root = tsInfo.get(TESTSUITE_ROOT);
if (root == null)
throw new BadDirectoryFault(i18n, "wd.noTestSuiteRoot", canonDir);
File tsr = new File(root);
if (!tsr.exists())
throw new TestSuiteFault(i18n, "wd.cantFindTestSuite", canonDir, tsr.getPath());
ts = TestSuite.open(tsr);
- String wdID = (tsInfo == null ? null : (String) (tsInfo.get(TESTSUITE_ID)));
+ String wdID = (tsInfo == null ? null : tsInfo.get(TESTSUITE_ID));
String tsID = ts.getID();
if (!(wdID == null ? "" : wdID).equals(tsID == null ? "" : tsID))
throw new MismatchFault(i18n, "wd.mismatchID", canonDir);
} // try
@@ -631,23 +631,23 @@
File canonDir = canonicalize(dir);
File jtData = new File(canonDir, JTDATA);
WorkDirectory wd = null;
synchronized (dirMap) {
- WeakReference ref = (WeakReference)(dirMap.get(canonDir));
+ WeakReference<WorkDirectory> ref = dirMap.get(canonDir);
if (ref != null)
- wd = (WorkDirectory)(ref.get());
+ wd = ref.get();
if (wd == null) {
- Properties tsInfo;
+ Map<String, String> tsInfo;
try {
tsInfo = loadTestSuiteInfo(jtData);
} catch (IOException e) {
tsInfo = null;
}
- String wdID = (tsInfo == null ? null : (String) (tsInfo.get(TESTSUITE_ID)));
+ String wdID = (tsInfo == null ? null : tsInfo.get(TESTSUITE_ID));
String tsID = testSuite.getID();
if (!(wdID == null ? "" : wdID).equals(tsID == null ? "" : tsID))
throw new MismatchFault(i18n, "wd.mismatchID", canonDir);
// no existing instance, create one
@@ -666,11 +666,11 @@
/**
* Create a WorkDirectory object for a given directory and testsuite.
* The directory is assumed to be valid (exists(), isDirectory(), canRead() etc)
*/
- private WorkDirectory(File root, TestSuite testSuite, Map tsInfo) {
+ private WorkDirectory(File root, TestSuite testSuite, Map<String, String> tsInfo) {
if (root == null || testSuite == null)
throw new NullPointerException();
this.root = root;
this.testSuite = testSuite;
jtData = new File(root, JTDATA);
@@ -689,11 +689,11 @@
// should consider saving parameter interview here;
// -- possibly conditionally (don't need to write it in case of normal open)
if (tsInfo != null) {
- String testC = (String) (tsInfo.get(TESTSUITE_TESTCOUNT));
+ String testC = (tsInfo.get(TESTSUITE_TESTCOUNT));
int tc;
if (testC == null)
tc = -1;
else {
try {
@@ -715,11 +715,11 @@
}
private void doWDinfo(File jtData, TestSuite testSuite) {
try {
- oldWDpath = loadWdInfo(jtData).getProperty(PREV_WD_PATH);
+ oldWDpath = loadWdInfo(jtData).get(PREV_WD_PATH);
} catch (IOException ex) {
oldWDpath = null;
}
try {
Properties p = new Properties();
@@ -1182,25 +1182,22 @@
}
return result;
}
- private static Properties loadTestSuiteInfo(File jtData) throws FileNotFoundException, IOException {
+ private static Map<String, String> loadTestSuiteInfo(File jtData) throws FileNotFoundException, IOException {
return loadInfo(jtData, TESTSUITE);
}
- private static Properties loadWdInfo(File jtData) throws FileNotFoundException, IOException {
+ private static Map<String, String> loadWdInfo(File jtData) throws FileNotFoundException, IOException {
return loadInfo(jtData, WD_INFO);
}
- private static Properties loadInfo(File jtData, String name) throws FileNotFoundException, IOException {
- File f = new File(jtData, name);
- InputStream in = new BufferedInputStream(new FileInputStream(f));
- Properties p = new Properties();
- p.load(in);
- in.close();
- return p;
+ private static Map<String, String> loadInfo(File jtData, String name) throws FileNotFoundException, IOException {
+ try (InputStream in = new BufferedInputStream(new FileInputStream(new File(jtData, name)))) {
+ return com.sun.javatest.util.Properties.load(in);
+ }
}
private synchronized void saveTestSuiteInfo() throws IOException {
Properties p = new Properties();
@@ -1252,11 +1249,11 @@
private TestResultTable testResultTable;
private Map<String, Map<String,String>> annotationMap;
private File jtData;
private String logFileName;
private LogFile logFile;
- private static HashMap dirMap = new HashMap(2); // must be manually synchronized
+ private static HashMap<File, WeakReference<WorkDirectory>> dirMap = new HashMap<>(2); // must be manually synchronized
public static final String JTDATA = "jtData";
private static final String TESTSUITE = "testsuite";
private static final String WD_INFO = "wdinfo";
private static final String PREV_WD_PATH = "prev.wd.path";
private static final String TESTSUITE_ID = "id";
< prev index next >