|
Java example source code file (CompileTest.java)
The CompileTest.java Java example source code
/*
* Copyright (c) 2009, 2011, 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 6906175 6915476 6915497 7006564
* @summary Path-based JavaFileManager
* @compile -g CompileTest.java HelloPathWorld.java
* @run main CompileTest
*/
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.jar.*;
import javax.tools.*;
import com.sun.tools.javac.nio.*;
import com.sun.tools.javac.util.Context;
import java.nio.file.spi.FileSystemProvider;
public class CompileTest {
public static void main(String[] args) throws Exception {
new CompileTest().run();
}
public void run() throws Exception {
File rtDir = new File("rt.dir");
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File rtJar = new File(new File(new File(javaHome, "jre"), "lib"), "rt.jar");
expand(rtJar, rtDir);
String[] rtDir_opts = {
"-bootclasspath", rtDir.toString(),
"-classpath", "",
"-sourcepath", "",
"-extdirs", ""
};
test(rtDir_opts, "HelloPathWorld");
if (isJarFileSystemAvailable()) {
String[] rtJar_opts = {
"-bootclasspath", rtJar.toString(),
"-classpath", "",
"-sourcepath", "",
"-extdirs", ""
};
test(rtJar_opts, "HelloPathWorld");
String[] default_opts = { };
test(default_opts, "HelloPathWorld");
// finally, a non-trivial program
test(default_opts, "CompileTest");
} else
System.err.println("jar file system not available: test skipped");
}
void test(String[] opts, String className) throws Exception {
count++;
System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className);
Path testSrcDir = Paths.get(System.getProperty("test.src"));
Path testClassesDir = Paths.get(System.getProperty("test.classes"));
Path classes = Files.createDirectory(Paths.get("classes." + count));
Context ctx = new Context();
PathFileManager fm = new JavacPathFileManager(ctx, true, null);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
List<String> options = new ArrayList
Other Java examples (source code examples)Here is a short list of links related to this Java CompileTest.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.