Merge
This commit is contained in:
commit
5f83c52141
@ -187,7 +187,7 @@ all: build
|
|||||||
clobber: clean
|
clobber: clean
|
||||||
|
|
||||||
# All ant targets of interest
|
# All ant targets of interest
|
||||||
ANT_TARGETS = build clean sanity post-sanity diagnostics # for now
|
ANT_TARGETS = build clean sanity post-sanity diagnostics build-all-tools # for now
|
||||||
|
|
||||||
# Create diagnostics log (careful, ant 1.8.0 -diagnostics always does an exit 1)
|
# Create diagnostics log (careful, ant 1.8.0 -diagnostics always does an exit 1)
|
||||||
$(OUTPUTDIR)/build/ant-diagnostics.log:
|
$(OUTPUTDIR)/build/ant-diagnostics.log:
|
||||||
|
@ -26,6 +26,12 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
mydir="`dirname $0`"
|
mydir="`dirname $0`"
|
||||||
|
case `uname -s` in
|
||||||
|
CYGWIN*)
|
||||||
|
mydir=`cygpath -m $mydir`
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
mylib="`dirname $mydir`"/lib
|
mylib="`dirname $mydir`"/lib
|
||||||
|
|
||||||
# By default, put the jar file and its dependencies on the bootclasspath.
|
# By default, put the jar file and its dependencies on the bootclasspath.
|
||||||
|
@ -266,82 +266,116 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
|||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert all files in subdirectory `subdirectory' of `directory' which end
|
* Insert all files in subdirectory subdirectory of directory directory
|
||||||
* in one of the extensions in `extensions' into packageSym.
|
* which match fileKinds into resultList
|
||||||
*/
|
*/
|
||||||
private void listDirectory(File directory,
|
private void listDirectory(File directory,
|
||||||
RelativeDirectory subdirectory,
|
RelativeDirectory subdirectory,
|
||||||
Set<JavaFileObject.Kind> fileKinds,
|
Set<JavaFileObject.Kind> fileKinds,
|
||||||
boolean recurse,
|
boolean recurse,
|
||||||
ListBuffer<JavaFileObject> l) {
|
ListBuffer<JavaFileObject> resultList) {
|
||||||
Archive archive = archives.get(directory);
|
File d = subdirectory.getFile(directory);
|
||||||
|
if (!caseMapCheck(d, subdirectory))
|
||||||
|
return;
|
||||||
|
|
||||||
boolean isFile = fsInfo.isFile(directory);
|
File[] files = d.listFiles();
|
||||||
|
if (files == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (archive != null || isFile) {
|
if (sortFiles != null)
|
||||||
if (archive == null) {
|
Arrays.sort(files, sortFiles);
|
||||||
try {
|
|
||||||
archive = openArchive(directory);
|
for (File f: files) {
|
||||||
} catch (IOException ex) {
|
String fname = f.getName();
|
||||||
log.error("error.reading.file",
|
if (f.isDirectory()) {
|
||||||
directory, getMessage(ex));
|
if (recurse && SourceVersion.isIdentifier(fname)) {
|
||||||
return;
|
listDirectory(directory,
|
||||||
|
new RelativeDirectory(subdirectory, fname),
|
||||||
|
fileKinds,
|
||||||
|
recurse,
|
||||||
|
resultList);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if (isValidFile(fname, fileKinds)) {
|
||||||
List<String> files = archive.getFiles(subdirectory);
|
JavaFileObject fe =
|
||||||
if (files != null) {
|
new RegularFileObject(this, fname, new File(d, fname));
|
||||||
for (String file; !files.isEmpty(); files = files.tail) {
|
resultList.append(fe);
|
||||||
file = files.head;
|
|
||||||
if (isValidFile(file, fileKinds)) {
|
|
||||||
l.append(archive.getFileObject(subdirectory, file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (recurse) {
|
|
||||||
for (RelativeDirectory s: archive.getSubdirectories()) {
|
|
||||||
if (subdirectory.contains(s)) {
|
|
||||||
// Because the archive map is a flat list of directories,
|
|
||||||
// the enclosing loop will pick up all child subdirectories.
|
|
||||||
// Therefore, there is no need to recurse deeper.
|
|
||||||
listDirectory(directory, s, fileKinds, false, l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
File d = subdirectory.getFile(directory);
|
|
||||||
if (!caseMapCheck(d, subdirectory))
|
|
||||||
return;
|
|
||||||
|
|
||||||
File[] files = d.listFiles();
|
|
||||||
if (files == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (sortFiles != null)
|
|
||||||
Arrays.sort(files, sortFiles);
|
|
||||||
|
|
||||||
for (File f: files) {
|
|
||||||
String fname = f.getName();
|
|
||||||
if (f.isDirectory()) {
|
|
||||||
if (recurse && SourceVersion.isIdentifier(fname)) {
|
|
||||||
listDirectory(directory,
|
|
||||||
new RelativeDirectory(subdirectory, fname),
|
|
||||||
fileKinds,
|
|
||||||
recurse,
|
|
||||||
l);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isValidFile(fname, fileKinds)) {
|
|
||||||
JavaFileObject fe =
|
|
||||||
new RegularFileObject(this, fname, new File(d, fname));
|
|
||||||
l.append(fe);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert all files in subdirectory subdirectory of archive archive
|
||||||
|
* which match fileKinds into resultList
|
||||||
|
*/
|
||||||
|
private void listArchive(Archive archive,
|
||||||
|
RelativeDirectory subdirectory,
|
||||||
|
Set<JavaFileObject.Kind> fileKinds,
|
||||||
|
boolean recurse,
|
||||||
|
ListBuffer<JavaFileObject> resultList) {
|
||||||
|
// Get the files directly in the subdir
|
||||||
|
List<String> files = archive.getFiles(subdirectory);
|
||||||
|
if (files != null) {
|
||||||
|
for (; !files.isEmpty(); files = files.tail) {
|
||||||
|
String file = files.head;
|
||||||
|
if (isValidFile(file, fileKinds)) {
|
||||||
|
resultList.append(archive.getFileObject(subdirectory, file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (recurse) {
|
||||||
|
for (RelativeDirectory s: archive.getSubdirectories()) {
|
||||||
|
if (subdirectory.contains(s)) {
|
||||||
|
// Because the archive map is a flat list of directories,
|
||||||
|
// the enclosing loop will pick up all child subdirectories.
|
||||||
|
// Therefore, there is no need to recurse deeper.
|
||||||
|
listArchive(archive, s, fileKinds, false, resultList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* container is a directory, a zip file, or a non-existant path.
|
||||||
|
* Insert all files in subdirectory subdirectory of container which
|
||||||
|
* match fileKinds into resultList
|
||||||
|
*/
|
||||||
|
private void listContainer(File container,
|
||||||
|
RelativeDirectory subdirectory,
|
||||||
|
Set<JavaFileObject.Kind> fileKinds,
|
||||||
|
boolean recurse,
|
||||||
|
ListBuffer<JavaFileObject> resultList) {
|
||||||
|
Archive archive = archives.get(container);
|
||||||
|
if (archive == null) {
|
||||||
|
// archives are not created for directories.
|
||||||
|
if (fsInfo.isDirectory(container)) {
|
||||||
|
listDirectory(container,
|
||||||
|
subdirectory,
|
||||||
|
fileKinds,
|
||||||
|
recurse,
|
||||||
|
resultList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not a directory; either a file or non-existant, create the archive
|
||||||
|
try {
|
||||||
|
archive = openArchive(container);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error("error.reading.file",
|
||||||
|
container, getMessage(ex));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listArchive(archive,
|
||||||
|
subdirectory,
|
||||||
|
fileKinds,
|
||||||
|
recurse,
|
||||||
|
resultList);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) {
|
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) {
|
||||||
JavaFileObject.Kind kind = getKind(s);
|
JavaFileObject.Kind kind = getKind(s);
|
||||||
return fileKinds.contains(kind);
|
return fileKinds.contains(kind);
|
||||||
@ -434,95 +468,92 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
|||||||
private static final RelativeDirectory symbolFilePrefix
|
private static final RelativeDirectory symbolFilePrefix
|
||||||
= new RelativeDirectory("META-INF/sym/rt.jar/");
|
= new RelativeDirectory("META-INF/sym/rt.jar/");
|
||||||
|
|
||||||
/** Open a new zip file directory.
|
/** Open a new zip file directory, and cache it.
|
||||||
*/
|
*/
|
||||||
protected Archive openArchive(File zipFileName) throws IOException {
|
protected Archive openArchive(File zipFileName) throws IOException {
|
||||||
Archive archive = archives.get(zipFileName);
|
File origZipFileName = zipFileName;
|
||||||
if (archive == null) {
|
if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) {
|
||||||
File origZipFileName = zipFileName;
|
File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
|
||||||
if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) {
|
if (new File(file.getName()).equals(new File("jre")))
|
||||||
File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
|
file = file.getParentFile();
|
||||||
if (new File(file.getName()).equals(new File("jre")))
|
// file == ${jdk.home}
|
||||||
file = file.getParentFile();
|
for (String name : symbolFileLocation)
|
||||||
// file == ${jdk.home}
|
file = new File(file, name);
|
||||||
for (String name : symbolFileLocation)
|
// file == ${jdk.home}/lib/ct.sym
|
||||||
file = new File(file, name);
|
if (file.exists())
|
||||||
// file == ${jdk.home}/lib/ct.sym
|
zipFileName = file;
|
||||||
if (file.exists())
|
}
|
||||||
zipFileName = file;
|
|
||||||
|
Archive archive;
|
||||||
|
try {
|
||||||
|
|
||||||
|
ZipFile zdir = null;
|
||||||
|
|
||||||
|
boolean usePreindexedCache = false;
|
||||||
|
String preindexCacheLocation = null;
|
||||||
|
|
||||||
|
if (!useZipFileIndex) {
|
||||||
|
zdir = new ZipFile(zipFileName);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
usePreindexedCache = options.isSet("usezipindex");
|
||||||
|
preindexCacheLocation = options.get("java.io.tmpdir");
|
||||||
|
String optCacheLoc = options.get("cachezipindexdir");
|
||||||
|
|
||||||
try {
|
if (optCacheLoc != null && optCacheLoc.length() != 0) {
|
||||||
|
if (optCacheLoc.startsWith("\"")) {
|
||||||
ZipFile zdir = null;
|
if (optCacheLoc.endsWith("\"")) {
|
||||||
|
optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1);
|
||||||
boolean usePreindexedCache = false;
|
|
||||||
String preindexCacheLocation = null;
|
|
||||||
|
|
||||||
if (!useZipFileIndex) {
|
|
||||||
zdir = new ZipFile(zipFileName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
usePreindexedCache = options.isSet("usezipindex");
|
|
||||||
preindexCacheLocation = options.get("java.io.tmpdir");
|
|
||||||
String optCacheLoc = options.get("cachezipindexdir");
|
|
||||||
|
|
||||||
if (optCacheLoc != null && optCacheLoc.length() != 0) {
|
|
||||||
if (optCacheLoc.startsWith("\"")) {
|
|
||||||
if (optCacheLoc.endsWith("\"")) {
|
|
||||||
optCacheLoc = optCacheLoc.substring(1, optCacheLoc.length() - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
optCacheLoc = optCacheLoc.substring(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
optCacheLoc = optCacheLoc.substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File cacheDir = new File(optCacheLoc);
|
File cacheDir = new File(optCacheLoc);
|
||||||
if (cacheDir.exists() && cacheDir.canWrite()) {
|
if (cacheDir.exists() && cacheDir.canWrite()) {
|
||||||
preindexCacheLocation = optCacheLoc;
|
preindexCacheLocation = optCacheLoc;
|
||||||
if (!preindexCacheLocation.endsWith("/") &&
|
if (!preindexCacheLocation.endsWith("/") &&
|
||||||
!preindexCacheLocation.endsWith(File.separator)) {
|
!preindexCacheLocation.endsWith(File.separator)) {
|
||||||
preindexCacheLocation += File.separator;
|
preindexCacheLocation += File.separator;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (origZipFileName == zipFileName) {
|
if (origZipFileName == zipFileName) {
|
||||||
if (!useZipFileIndex) {
|
if (!useZipFileIndex) {
|
||||||
archive = new ZipArchive(this, zdir);
|
archive = new ZipArchive(this, zdir);
|
||||||
} else {
|
} else {
|
||||||
archive = new ZipFileIndexArchive(this,
|
archive = new ZipFileIndexArchive(this,
|
||||||
ZipFileIndex.getZipFileIndex(zipFileName,
|
ZipFileIndex.getZipFileIndex(zipFileName,
|
||||||
null,
|
null,
|
||||||
usePreindexedCache,
|
usePreindexedCache,
|
||||||
preindexCacheLocation,
|
preindexCacheLocation,
|
||||||
options.isSet("writezipindexfiles")));
|
options.isSet("writezipindexfiles")));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (!useZipFileIndex) {
|
||||||
|
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!useZipFileIndex) {
|
archive = new ZipFileIndexArchive(this,
|
||||||
archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
archive = new ZipFileIndexArchive(this,
|
|
||||||
ZipFileIndex.getZipFileIndex(zipFileName,
|
ZipFileIndex.getZipFileIndex(zipFileName,
|
||||||
symbolFilePrefix,
|
symbolFilePrefix,
|
||||||
usePreindexedCache,
|
usePreindexedCache,
|
||||||
preindexCacheLocation,
|
preindexCacheLocation,
|
||||||
options.isSet("writezipindexfiles")));
|
options.isSet("writezipindexfiles")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
archive = new MissingArchive(zipFileName);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (zipFileName.exists())
|
|
||||||
log.error("error.reading.file", zipFileName, getMessage(ex));
|
|
||||||
archive = new MissingArchive(zipFileName);
|
|
||||||
}
|
}
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
archives.put(origZipFileName, archive);
|
archive = new MissingArchive(zipFileName);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
if (zipFileName.exists())
|
||||||
|
log.error("error.reading.file", zipFileName, getMessage(ex));
|
||||||
|
archive = new MissingArchive(zipFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
archives.put(origZipFileName, archive);
|
||||||
return archive;
|
return archive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,8 +620,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
|||||||
ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
|
ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
|
||||||
|
|
||||||
for (File directory : path)
|
for (File directory : path)
|
||||||
listDirectory(directory, subdirectory, kinds, recurse, results);
|
listContainer(directory, subdirectory, kinds, recurse, results);
|
||||||
|
|
||||||
return results.toList();
|
return results.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,19 +689,22 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
for (File dir: path) {
|
for (File dir: path) {
|
||||||
if (dir.isDirectory()) {
|
Archive a = archives.get(dir);
|
||||||
File f = name.getFile(dir);
|
if (a == null) {
|
||||||
if (f.exists())
|
if (fsInfo.isDirectory(dir)) {
|
||||||
return new RegularFileObject(this, f);
|
File f = name.getFile(dir);
|
||||||
} else {
|
if (f.exists())
|
||||||
Archive a = openArchive(dir);
|
return new RegularFileObject(this, f);
|
||||||
if (a.contains(name)) {
|
continue;
|
||||||
return a.getFileObject(name.dirname(), name.basename());
|
|
||||||
}
|
}
|
||||||
|
// Not a directory, create the archive
|
||||||
|
a = openArchive(dir);
|
||||||
|
}
|
||||||
|
// Process the archive
|
||||||
|
if (a.contains(name)) {
|
||||||
|
return a.getFileObject(name.dirname(), name.basename());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,8 +869,9 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
|
|||||||
return false;
|
return false;
|
||||||
if (!path.equals(uri.getPath())) // implicitly checks for embedded . and ..
|
if (!path.equals(uri.getPath())) // implicitly checks for embedded . and ..
|
||||||
return false;
|
return false;
|
||||||
char first = path.charAt(0);
|
if (path.startsWith("/") || path.startsWith("./") || path.startsWith("../"))
|
||||||
return first != '.' && first != '/';
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience method
|
// Convenience method
|
||||||
|
@ -286,9 +286,8 @@ public class Paths {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addFile(File file, boolean warn) {
|
public void addFile(File file, boolean warn) {
|
||||||
File canonFile = fsInfo.getCanonicalFile(file);
|
if (contains(file)) {
|
||||||
if (contains(file) || canonicalValues.contains(canonFile)) {
|
// discard duplicates
|
||||||
/* Discard duplicates and avoid infinite recursion */
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +297,17 @@ public class Paths {
|
|||||||
log.warning(Lint.LintCategory.PATH,
|
log.warning(Lint.LintCategory.PATH,
|
||||||
"path.element.not.found", file);
|
"path.element.not.found", file);
|
||||||
}
|
}
|
||||||
} else if (fsInfo.isFile(file)) {
|
super.add(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File canonFile = fsInfo.getCanonicalFile(file);
|
||||||
|
if (canonicalValues.contains(canonFile)) {
|
||||||
|
/* Discard duplicates and avoid infinite recursion */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fsInfo.isFile(file)) {
|
||||||
/* File is an ordinary file. */
|
/* File is an ordinary file. */
|
||||||
if (!isArchive(file)) {
|
if (!isArchive(file)) {
|
||||||
/* Not a recognized extension; open it to see if
|
/* Not a recognized extension; open it to see if
|
||||||
@ -322,11 +331,11 @@ public class Paths {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now what we have left is either a directory or a file name
|
/* Now what we have left is either a directory or a file name
|
||||||
confirming to archive naming convention */
|
conforming to archive naming convention */
|
||||||
super.add(file);
|
super.add(file);
|
||||||
canonicalValues.add(canonFile);
|
canonicalValues.add(canonFile);
|
||||||
|
|
||||||
if (expandJarClassPaths && fsInfo.exists(file) && fsInfo.isFile(file))
|
if (expandJarClassPaths && fsInfo.isFile(file))
|
||||||
addJarClassPath(file, warn);
|
addJarClassPath(file, warn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@ public class ClassReader implements Completer {
|
|||||||
protected static final Context.Key<ClassReader> classReaderKey =
|
protected static final Context.Key<ClassReader> classReaderKey =
|
||||||
new Context.Key<ClassReader>();
|
new Context.Key<ClassReader>();
|
||||||
|
|
||||||
|
public static final int INITIAL_BUFFER_SIZE = 0x0fff0;
|
||||||
|
|
||||||
Annotate annotate;
|
Annotate annotate;
|
||||||
|
|
||||||
/** Switch: verbose output.
|
/** Switch: verbose output.
|
||||||
@ -185,7 +187,7 @@ public class ClassReader implements Completer {
|
|||||||
|
|
||||||
/** The buffer containing the currently read class file.
|
/** The buffer containing the currently read class file.
|
||||||
*/
|
*/
|
||||||
byte[] buf = new byte[0x0fff0];
|
byte[] buf = new byte[INITIAL_BUFFER_SIZE];
|
||||||
|
|
||||||
/** The current input pointer.
|
/** The current input pointer.
|
||||||
*/
|
*/
|
||||||
@ -2419,8 +2421,14 @@ public class ClassReader implements Completer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* ensureCapacity will increase the buffer as needed, taking note that
|
||||||
|
* the new buffer will always be greater than the needed and never
|
||||||
|
* exactly equal to the needed size or bp. If equal then the read (above)
|
||||||
|
* will infinitely loop as buf.length - bp == 0.
|
||||||
|
*/
|
||||||
private static byte[] ensureCapacity(byte[] buf, int needed) {
|
private static byte[] ensureCapacity(byte[] buf, int needed) {
|
||||||
if (buf.length < needed) {
|
if (buf.length <= needed) {
|
||||||
byte[] old = buf;
|
byte[] old = buf;
|
||||||
buf = new byte[Integer.highestOneBit(needed) << 1];
|
buf = new byte[Integer.highestOneBit(needed) << 1];
|
||||||
System.arraycopy(old, 0, buf, 0, old.length);
|
System.arraycopy(old, 0, buf, 0, old.length);
|
||||||
|
@ -376,7 +376,8 @@ public class JavacPathFileManager extends BaseFileManager implements PathFileMan
|
|||||||
new SimpleFileVisitor<Path>() {
|
new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||||
if (SourceVersion.isIdentifier(dir.getName().toString())) // JSR 292?
|
Path name = dir.getName();
|
||||||
|
if (name == null || SourceVersion.isIdentifier(name.toString())) // JSR 292?
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
else
|
else
|
||||||
return FileVisitResult.SKIP_SUBTREE;
|
return FileVisitResult.SKIP_SUBTREE;
|
||||||
|
146
langtools/test/tools/javac/6567415/T6567415.java
Normal file
146
langtools/test/tools/javac/6567415/T6567415.java
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6567415
|
||||||
|
* @summary Test to ensure javac does not go into an infinite loop, while
|
||||||
|
* reading a classfile of a specific length.
|
||||||
|
* @compile -XDignore.symbol.file T6567415.java
|
||||||
|
* @run main T6567415
|
||||||
|
* @author ksrini
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.MappedByteBuffer;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* this test compiles Bar.java into a classfile and enlarges the file to the
|
||||||
|
* magic file length, then use this mutated file on the classpath to compile
|
||||||
|
* Foo.java which references Bar.java and Ka-boom. QED.
|
||||||
|
*/
|
||||||
|
public class T6567415 {
|
||||||
|
final static String TEST_FILE_NAME = "Bar";
|
||||||
|
final static String TEST_JAVA = TEST_FILE_NAME + ".java";
|
||||||
|
final static String TEST_CLASS = TEST_FILE_NAME + ".class";
|
||||||
|
|
||||||
|
final static String TEST2_FILE_NAME = "Foo";
|
||||||
|
final static String TEST2_JAVA = TEST2_FILE_NAME + ".java";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the following is the initial buffer length set in ClassReader.java
|
||||||
|
* thus this value needs to change if ClassReader buf length changes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final static int BAD_FILE_LENGTH =
|
||||||
|
com.sun.tools.javac.jvm.ClassReader.INITIAL_BUFFER_SIZE;
|
||||||
|
|
||||||
|
static void createClassFile() throws IOException {
|
||||||
|
FileOutputStream fos = null;
|
||||||
|
try {
|
||||||
|
fos = new FileOutputStream(TEST_JAVA);
|
||||||
|
PrintStream ps = new PrintStream(fos);
|
||||||
|
ps.println("public class " + TEST_FILE_NAME + " {}");
|
||||||
|
} finally {
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
String cmds[] = {TEST_JAVA};
|
||||||
|
com.sun.tools.javac.Main.compile(cmds);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void enlargeClassFile() throws IOException {
|
||||||
|
File f = new File(TEST_CLASS);
|
||||||
|
if (!f.exists()) {
|
||||||
|
System.out.println("file not found: " + TEST_CLASS);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
File tfile = new File(f.getAbsolutePath() + ".tmp");
|
||||||
|
f.renameTo(tfile);
|
||||||
|
|
||||||
|
RandomAccessFile raf = null;
|
||||||
|
FileChannel wfc = null;
|
||||||
|
|
||||||
|
FileInputStream fis = null;
|
||||||
|
FileChannel rfc = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
raf = new RandomAccessFile(f, "rw");
|
||||||
|
wfc = raf.getChannel();
|
||||||
|
|
||||||
|
fis = new FileInputStream(tfile);
|
||||||
|
rfc = fis.getChannel();
|
||||||
|
|
||||||
|
ByteBuffer bb = MappedByteBuffer.allocate(BAD_FILE_LENGTH);
|
||||||
|
rfc.read(bb);
|
||||||
|
bb.rewind();
|
||||||
|
wfc.write(bb);
|
||||||
|
wfc.truncate(BAD_FILE_LENGTH);
|
||||||
|
} finally {
|
||||||
|
wfc.close();
|
||||||
|
raf.close();
|
||||||
|
rfc.close();
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
System.out.println("file length = " + f.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void createJavaFile() throws IOException {
|
||||||
|
FileOutputStream fos = null;
|
||||||
|
try {
|
||||||
|
fos = new FileOutputStream(TEST2_JAVA);
|
||||||
|
PrintStream ps = new PrintStream(fos);
|
||||||
|
ps.println("public class " + TEST2_FILE_NAME +
|
||||||
|
" {" + TEST_FILE_NAME + " b = new " +
|
||||||
|
TEST_FILE_NAME + " ();}");
|
||||||
|
} finally {
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) throws Exception {
|
||||||
|
createClassFile();
|
||||||
|
enlargeClassFile();
|
||||||
|
createJavaFile();
|
||||||
|
Thread t = new Thread () {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String cmds[] = {"-verbose", "-cp", ".", TEST2_JAVA};
|
||||||
|
int ret = com.sun.tools.javac.Main.compile(cmds);
|
||||||
|
System.out.println("test compilation returns: " + ret);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.start();
|
||||||
|
t.join(1000*10);
|
||||||
|
System.out.println(t.getState());
|
||||||
|
if (t.isAlive()) {
|
||||||
|
throw new RuntimeException("Error: compilation is looping");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,8 +24,10 @@
|
|||||||
// key: compiler.warn.type.parameter.on.polymorphic.signature
|
// key: compiler.warn.type.parameter.on.polymorphic.signature
|
||||||
// key: compiler.err.unreported.exception.need.to.catch.or.throw
|
// key: compiler.err.unreported.exception.need.to.catch.or.throw
|
||||||
|
|
||||||
import java.dyn.InvokeDynamic;
|
import java.dyn.MethodHandle;
|
||||||
|
|
||||||
class TypeParameterOnPolymorphicSignature {
|
class TypeParameterOnPolymorphicSignature {
|
||||||
{ InvokeDynamic.<void>call("",123); }
|
void test(MethodHandle mh) {
|
||||||
|
mh.<void>invokeExact("",123);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,13 @@ public class CheckAttributedTree {
|
|||||||
error("File " + file + " ignored");
|
error("File " + file + " ignored");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See CR: 6982992 Tests CheckAttributedTree.java, JavacTreeScannerTest.java, and SourceTreeeScannerTest.java timeout
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
Reporter r = new Reporter(pw);
|
||||||
|
JavacTool tool = JavacTool.create();
|
||||||
|
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a file.
|
* Read a file.
|
||||||
* @param file the file to be read
|
* @param file the file to be read
|
||||||
@ -260,12 +267,8 @@ public class CheckAttributedTree {
|
|||||||
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
||||||
*/
|
*/
|
||||||
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
|
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
Reporter r = new Reporter(pw);
|
|
||||||
JavacTool tool = JavacTool.create();
|
JavacTool tool = JavacTool.create();
|
||||||
Charset cs = (encoding == null ? null : Charset.forName(encoding));
|
r.errors = 0;
|
||||||
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
|
||||||
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
||||||
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
|
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
|
||||||
JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
|
JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
* @bug 6754038 6979327
|
|
||||||
* @summary Generate call sites for method handle
|
|
||||||
* @author jrose
|
|
||||||
*
|
|
||||||
* @library ..
|
|
||||||
* @compile -source 7 -target 7 -XDinvokedynamic -XDallowTransitionalJSR292=no InvokeDyn.java
|
|
||||||
*/
|
|
||||||
//No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Standalone testing:
|
|
||||||
* <code>
|
|
||||||
* $ cd $MY_REPO_DIR/langtools
|
|
||||||
* $ (cd make; make)
|
|
||||||
* $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeDyn.java
|
|
||||||
* $ javap -c -classpath dist meth.InvokeDyn
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package meth;
|
|
||||||
|
|
||||||
import java.dyn.*;
|
|
||||||
|
|
||||||
public class InvokeDyn {
|
|
||||||
class CS extends CallSite {
|
|
||||||
CS(Object x, Object y, Object z) { throw new RuntimeException(); }
|
|
||||||
}
|
|
||||||
//@BootstrapMethod(CS.class) //note: requires 6964498
|
|
||||||
void test() throws Throwable {
|
|
||||||
Object x = "hello";
|
|
||||||
Object ojunk; int ijunk;
|
|
||||||
ojunk = InvokeDynamic.greet(x, "world", 123);
|
|
||||||
ojunk = InvokeDynamic.greet(x, "mundus", 456);
|
|
||||||
ojunk = InvokeDynamic.greet(x, "kosmos", 789);
|
|
||||||
ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14);
|
|
||||||
//InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
|
|
||||||
ijunk = (int) InvokeDynamic.invoke("goodbye");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
||||||
*
|
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
* @bug 6754038 6979327
|
|
||||||
* @summary Generate call sites for method handle
|
|
||||||
* @author jrose
|
|
||||||
*
|
|
||||||
* @library ..
|
|
||||||
* @compile/fail/ref=InvokeDynTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeDynTrans.java
|
|
||||||
*/
|
|
||||||
//No: @run main/othervm -XX:+EnableInvokeDynamic meth.InvokeDyn
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Standalone testing:
|
|
||||||
* <code>
|
|
||||||
* $ cd $MY_REPO_DIR/langtools
|
|
||||||
* $ (cd make; make)
|
|
||||||
* $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeDyn.java
|
|
||||||
* $ javap -c -classpath dist meth.InvokeDyn
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package meth;
|
|
||||||
|
|
||||||
import java.dyn.InvokeDynamic;
|
|
||||||
|
|
||||||
public class InvokeDynTrans {
|
|
||||||
void test() throws Throwable {
|
|
||||||
Object x = "hello";
|
|
||||||
InvokeDynamic.greet(x, "world", 123);
|
|
||||||
InvokeDynamic.greet(x, "mundus", 456);
|
|
||||||
InvokeDynamic.greet(x, "kosmos", 789);
|
|
||||||
InvokeDynamic.<String>cogitate(10.11121, 3.14);
|
|
||||||
//InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
|
|
||||||
InvokeDynamic.<int>invoke("goodbye");
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6999067
|
* @bug 6999067 7010194
|
||||||
* @summary cast for invokeExact call gets redundant cast to <type> warnings
|
* @summary cast for invokeExact call gets redundant cast to <type> warnings
|
||||||
* @author mcimadamore
|
* @author mcimadamore
|
||||||
*
|
*
|
||||||
@ -34,9 +34,7 @@ import java.dyn.*;
|
|||||||
|
|
||||||
class XlintWarn {
|
class XlintWarn {
|
||||||
void test(MethodHandle mh) throws Throwable {
|
void test(MethodHandle mh) throws Throwable {
|
||||||
int i1 = (int)mh.invoke();
|
int i1 = (int)mh.invokeExact();
|
||||||
int i2 = (int)mh.invokeExact();
|
int i2 = (int)mh.invokeVarargs();
|
||||||
int i3 = (int)mh.invokeVarargs();
|
|
||||||
int i4 = (int)InvokeDynamic.test();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 6906175 6915476 6915497
|
* @bug 6906175 6915476 6915497 7006564
|
||||||
* @summary Path-based JavaFileManager
|
* @summary Path-based JavaFileManager
|
||||||
* @compile -g HelloPathWorld.java
|
* @compile -g HelloPathWorld.java
|
||||||
* @run main CompileTest
|
* @run main CompileTest
|
||||||
|
@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 6999891
|
||||||
|
* @summary Test valid relative names for Filer.createResource and Filer.getResource
|
||||||
|
* @library ../../lib
|
||||||
|
* @build JavacTestingAbstractProcessor
|
||||||
|
* @compile TestValidRelativeNames.java
|
||||||
|
* @compile/process -processor TestValidRelativeNames -Amode=create java.lang.Object
|
||||||
|
* @compile/process -processor TestValidRelativeNames -Amode=get java.lang.Object
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.annotation.processing.*;
|
||||||
|
import javax.lang.model.*;
|
||||||
|
import javax.lang.model.element.*;
|
||||||
|
import javax.tools.Diagnostic;
|
||||||
|
import javax.tools.StandardLocation;
|
||||||
|
|
||||||
|
@SupportedOptions("mode")
|
||||||
|
public class TestValidRelativeNames extends JavacTestingAbstractProcessor {
|
||||||
|
enum Kind { READER_WRITER, INPUT_OUTPUT_STREAM };
|
||||||
|
|
||||||
|
static final String[] validRelativeNames = {
|
||||||
|
"foo", "foo.bar", ".foo", ".foo.bar", "foodir/bar", "foodir/.bar"
|
||||||
|
};
|
||||||
|
|
||||||
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
if (roundEnv.processingOver()) {
|
||||||
|
String mode = options.get("mode");
|
||||||
|
for (String relativeBase: validRelativeNames) {
|
||||||
|
for (Kind kind: Kind.values()) {
|
||||||
|
if (mode.equals("create"))
|
||||||
|
testCreate(relativeBase, kind);
|
||||||
|
else
|
||||||
|
testGet(relativeBase, kind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testCreate(String relativeBase, Kind kind) {
|
||||||
|
String relative = getRelative(relativeBase, kind);
|
||||||
|
System.out.println("test create relative path: " + relative + ", kind: " + kind);
|
||||||
|
try {
|
||||||
|
switch (kind) {
|
||||||
|
case READER_WRITER:
|
||||||
|
try (Writer writer = filer.createResource(
|
||||||
|
StandardLocation.CLASS_OUTPUT, "", relative).openWriter()) {
|
||||||
|
writer.write(relative);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_OUTPUT_STREAM:
|
||||||
|
try (OutputStream out = filer.createResource(
|
||||||
|
StandardLocation.CLASS_OUTPUT, "", relative).openOutputStream()) {
|
||||||
|
out.write(relative.getBytes());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR,
|
||||||
|
"relative path: " + relative + ", kind: " + kind + ", unexpected exception: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void testGet(String relativeBase, Kind kind) {
|
||||||
|
String relative = getRelative(relativeBase, kind);
|
||||||
|
System.out.println("test get relative path: " + relative + ", kind: " + kind);
|
||||||
|
try {
|
||||||
|
switch (kind) {
|
||||||
|
case READER_WRITER:
|
||||||
|
try (Reader reader = new BufferedReader(filer.getResource(
|
||||||
|
StandardLocation.CLASS_OUTPUT, "", relative).openReader(true))) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
char[] buf = new char[1024];
|
||||||
|
int n;
|
||||||
|
while ((n = reader.read(buf, 0, buf.length)) > 0)
|
||||||
|
sb.append(new String(buf, 0, n));
|
||||||
|
if (!sb.toString().equals(relative)) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, "unexpected content: " + sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT_OUTPUT_STREAM:
|
||||||
|
try (InputStream in = new DataInputStream(filer.getResource(
|
||||||
|
StandardLocation.CLASS_OUTPUT, "", relative).openInputStream())) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int n;
|
||||||
|
while ((n = in.read(buf, 0, buf.length)) > 0)
|
||||||
|
sb.append(new String(buf, 0, n));
|
||||||
|
if (!sb.toString().equals(relative)) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR, "unexpected content: " + sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
messager.printMessage(Diagnostic.Kind.ERROR,
|
||||||
|
"relative path: " + relative + ", kind: " + kind + ", unexpected exception: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String getRelative(String relativeBase, Kind kind) {
|
||||||
|
String suffix = (kind == Kind.READER_WRITER ? "RW" : "IOS");
|
||||||
|
return relativeBase.replace("foo", "foo" + suffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -143,6 +143,13 @@ public abstract class AbstractTreeScannerTest {
|
|||||||
|
|
||||||
abstract int test(JCCompilationUnit t);
|
abstract int test(JCCompilationUnit t);
|
||||||
|
|
||||||
|
// See CR: 6982992 Tests CheckAttributedTree.java, JavacTreeScannerTest.java, and SourceTreeeScannerTest.java timeout
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
Reporter r = new Reporter(pw);
|
||||||
|
JavacTool tool = JavacTool.create();
|
||||||
|
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a file.
|
* Read a file.
|
||||||
* @param file the file to be read
|
* @param file the file to be read
|
||||||
@ -151,11 +158,8 @@ public abstract class AbstractTreeScannerTest {
|
|||||||
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
||||||
*/
|
*/
|
||||||
JCCompilationUnit read(File file) throws IOException, ParseException {
|
JCCompilationUnit read(File file) throws IOException, ParseException {
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
Reporter r = new Reporter(pw);
|
|
||||||
JavacTool tool = JavacTool.create();
|
JavacTool tool = JavacTool.create();
|
||||||
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
r.errors = 0;
|
||||||
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
||||||
JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
|
JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
|
||||||
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
||||||
|
@ -249,6 +249,13 @@ public class TreePosTest {
|
|||||||
error("File " + file + " ignored");
|
error("File " + file + " ignored");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See CR: 6982992 Tests CheckAttributedTree.java, JavacTreeScannerTest.java, and SourceTreeeScannerTest.java timeout
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
Reporter r = new Reporter(pw);
|
||||||
|
JavacTool tool = JavacTool.create();
|
||||||
|
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a file.
|
* Read a file.
|
||||||
* @param file the file to be read
|
* @param file the file to be read
|
||||||
@ -257,12 +264,8 @@ public class TreePosTest {
|
|||||||
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
* @throws TreePosTest.ParseException if any errors occur while parsing the file
|
||||||
*/
|
*/
|
||||||
JCCompilationUnit read(File file) throws IOException, ParseException {
|
JCCompilationUnit read(File file) throws IOException, ParseException {
|
||||||
StringWriter sw = new StringWriter();
|
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
|
||||||
Reporter r = new Reporter(pw);
|
|
||||||
JavacTool tool = JavacTool.create();
|
JavacTool tool = JavacTool.create();
|
||||||
Charset cs = (encoding == null ? null : Charset.forName(encoding));
|
r.errors = 0;
|
||||||
StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null);
|
|
||||||
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
|
||||||
JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
|
JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files);
|
||||||
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
||||||
|
Loading…
Reference in New Issue
Block a user