Browse Source

Fix some JDK 1.1 issues - only culprit remaining is Diagnostics with

its class locating code.

Learned by failing <xmlvalidate> tests that FileUtils.getFileURL
wouldn't append slashes where it should (because normalize strips
them).


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273824 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
8ca6f54b9a
3 changed files with 19 additions and 14 deletions
  1. +8
    -4
      src/main/org/apache/tools/ant/types/XMLCatalog.java
  2. +9
    -8
      src/main/org/apache/tools/ant/util/FileUtils.java
  3. +2
    -2
      src/main/org/apache/tools/ant/util/LazyHashtable.java

+ 8
- 4
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -76,6 +76,7 @@ import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils; import org.apache.tools.ant.util.JAXPUtils;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
@@ -162,6 +163,9 @@ import org.xml.sax.XMLReader;
public class XMLCatalog extends DataType public class XMLCatalog extends DataType
implements Cloneable, EntityResolver, URIResolver { implements Cloneable, EntityResolver, URIResolver {


/** helper for some File.toURL connversions */
private static FileUtils fileUtils = FileUtils.newFileUtils();

//-- Fields ---------------------------------------------------------------- //-- Fields ----------------------------------------------------------------


/** Holds dtd/entity objects until needed. */ /** Holds dtd/entity objects until needed. */
@@ -477,7 +481,7 @@ public class XMLCatalog extends DataType
URL baseURL = null; URL baseURL = null;
try { try {
if (base == null) { if (base == null) {
baseURL = getProject().getBaseDir().toURL();
baseURL = fileUtils.getFileURL(getProject().getBaseDir());
} }
else { else {
baseURL = new URL(base); baseURL = new URL(base);
@@ -646,7 +650,7 @@ public class XMLCatalog extends DataType
baseURL = matchingEntry.getBase(); baseURL = matchingEntry.getBase();
} else { } else {
try { try {
baseURL = getProject().getBaseDir().toURL();
baseURL = fileUtils.getFileURL(getProject().getBaseDir());
} }
catch (MalformedURLException ex) { catch (MalformedURLException ex) {
throw new BuildException("Project basedir cannot be converted to a URL"); throw new BuildException("Project basedir cannot be converted to a URL");
@@ -666,7 +670,7 @@ public class XMLCatalog extends DataType
if (url != null) { if (url != null) {
String fileName = url.getFile(); String fileName = url.getFile();
if (fileName != null) { if (fileName != null) {
log("fileName"+fileName, Project.MSG_DEBUG);
log("fileName " + fileName, Project.MSG_DEBUG);
File resFile = new File(fileName); File resFile = new File(fileName);
if (resFile.exists() && resFile.canRead()) { if (resFile.exists() && resFile.canRead()) {
try { try {
@@ -743,7 +747,7 @@ public class XMLCatalog extends DataType
baseURL = matchingEntry.getBase(); baseURL = matchingEntry.getBase();
} else { } else {
try { try {
baseURL = getProject().getBaseDir().toURL();
baseURL = fileUtils.getFileURL(getProject().getBaseDir());
} }
catch (MalformedURLException ex) { catch (MalformedURLException ex) {
throw new BuildException("Project basedir cannot be converted to a URL"); throw new BuildException("Project basedir cannot be converted to a URL");


+ 9
- 8
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -154,11 +154,7 @@ public class FileUtils {
* formed. * formed.
*/ */
public URL getFileURL(File file) throws MalformedURLException { public URL getFileURL(File file) throws MalformedURLException {
String path = file.getAbsolutePath();
if (file.isDirectory()) {
path += "/";
}
return new URL(toURI(path));
return new URL(toURI(file.getAbsolutePath()));
} }


/** /**
@@ -706,8 +702,7 @@ public class FileUtils {
synchronized (rand) { synchronized (rand) {
do { do {
result = new File(parent, result = new File(parent,
prefix
+ fmt.format(rand.nextInt(Integer.MAX_VALUE))
prefix + fmt.format(Math.abs(rand.nextInt()))
+ suffix); + suffix);
} while (result.exists()); } while (result.exists());
} }
@@ -915,6 +910,8 @@ public class FileUtils {
* @since Ant 1.6 * @since Ant 1.6
*/ */
public String toURI(String path) { public String toURI(String path) {
boolean isDir = (new File(path)).isDirectory();

StringBuffer sb = new StringBuffer("file:"); StringBuffer sb = new StringBuffer("file:");


// catch exception if normalize thinks this is not an absolute path // catch exception if normalize thinks this is not an absolute path
@@ -931,6 +928,7 @@ public class FileUtils {
} }


path = path.replace('\\', '/'); path = path.replace('\\', '/');
CharacterIterator iter = new StringCharacterIterator(path); CharacterIterator iter = new StringCharacterIterator(path);
for (char c = iter.first(); c != CharacterIterator.DONE; for (char c = iter.first(); c != CharacterIterator.DONE;
c = iter.next()) { c = iter.next()) {
@@ -942,6 +940,9 @@ public class FileUtils {
sb.append(c); sb.append(c);
} }
} }
if (isDir && !path.endsWith("/")) {
sb.append('/');
}
return sb.toString(); return sb.toString();
} }




+ 2
- 2
src/main/org/apache/tools/ant/util/LazyHashtable.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -101,7 +101,7 @@ public class LazyHashtable extends Hashtable {


public boolean containsValue( Object value ) { public boolean containsValue( Object value ) {
initAll(); initAll();
return super.containsValue( value );
return super.contains( value );
} }


public Enumeration keys() { public Enumeration keys() {


Loading…
Cancel
Save