2008-08-26 14:52:59 -07:00
|
|
|
/*
|
2015-05-21 11:41:04 -07:00
|
|
|
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
2008-08-26 14:52:59 -07:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-25 15:54:51 -07:00
|
|
|
* 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.
|
2008-08-26 14:52:59 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 6508981
|
|
|
|
* @summary cleanup file separator handling in JavacFileManager
|
|
|
|
* (This test is specifically to test the new impl of inferBinaryName)
|
2014-11-07 14:51:35 -08:00
|
|
|
* @library /tools/lib
|
2015-05-21 11:41:04 -07:00
|
|
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.file
|
|
|
|
* jdk.compiler/com.sun.tools.javac.main
|
|
|
|
* jdk.compiler/com.sun.tools.javac.util
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* jdk.jdeps/com.sun.tools.javap
|
2014-11-07 14:51:35 -08:00
|
|
|
* @build ToolBox p.A
|
2008-08-26 14:52:59 -07:00
|
|
|
* @run main TestInferBinaryName
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import javax.tools.*;
|
|
|
|
|
|
|
|
import com.sun.tools.javac.file.JavacFileManager;
|
|
|
|
import com.sun.tools.javac.util.Context;
|
|
|
|
import com.sun.tools.javac.util.Options;
|
|
|
|
|
|
|
|
import static javax.tools.JavaFileObject.Kind.*;
|
|
|
|
import static javax.tools.StandardLocation.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify the various implementations of inferBinaryName, but configuring
|
|
|
|
* different instances of a file manager, getting a file object, and checking
|
|
|
|
* the impl of inferBinaryName for that file object.
|
|
|
|
*/
|
|
|
|
public class TestInferBinaryName {
|
|
|
|
public static void main(String... args) throws Exception {
|
|
|
|
new TestInferBinaryName().run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() throws Exception {
|
|
|
|
testDirectory();
|
2014-11-07 14:51:35 -08:00
|
|
|
|
|
|
|
File testJar = createJar();
|
|
|
|
testZipArchive(testJar);
|
2014-12-03 14:25:46 +00:00
|
|
|
|
2008-08-26 14:52:59 -07:00
|
|
|
if (errors > 0)
|
|
|
|
throw new Exception(errors + " error found");
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:51:35 -08:00
|
|
|
File createJar() throws IOException {
|
|
|
|
File f = new File("test.jar");
|
|
|
|
try (JavaFileManager fm = new JavacFileManager(new Context(), false, null)) {
|
|
|
|
ToolBox tb = new ToolBox();
|
|
|
|
tb.new JarTask(f.getPath())
|
|
|
|
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, "java.lang.*")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2008-08-26 14:52:59 -07:00
|
|
|
void testDirectory() throws IOException {
|
|
|
|
String testClassName = "p.A";
|
2014-11-07 14:51:35 -08:00
|
|
|
List<File> testClasses = Arrays.asList(new File(System.getProperty("test.classes")));
|
2015-12-07 14:02:55 -08:00
|
|
|
try (JavaFileManager fm = getFileManager(testClasses)) {
|
2014-11-07 14:51:35 -08:00
|
|
|
test("testDirectory",
|
2015-12-07 14:02:55 -08:00
|
|
|
fm, testClassName, "SimpleFileObject");
|
2014-11-07 14:51:35 -08:00
|
|
|
}
|
2008-08-26 14:52:59 -07:00
|
|
|
}
|
|
|
|
|
2014-11-07 14:51:35 -08:00
|
|
|
void testZipArchive(File testJar) throws IOException {
|
2008-08-26 14:52:59 -07:00
|
|
|
String testClassName = "java.lang.String";
|
2014-11-07 14:51:35 -08:00
|
|
|
List<File> path = Arrays.asList(testJar);
|
2015-12-07 14:02:55 -08:00
|
|
|
try (JavaFileManager fm = getFileManager(path)) {
|
2014-11-07 14:51:35 -08:00
|
|
|
test("testZipArchive",
|
2015-12-07 14:02:55 -08:00
|
|
|
fm, testClassName, "JarFileObject");
|
2014-11-07 14:51:35 -08:00
|
|
|
}
|
2008-08-26 14:52:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param testName for debugging
|
|
|
|
* @param fm suitably configured file manager
|
|
|
|
* @param testClassName the classname to test
|
|
|
|
* @param implClassName the expected classname of the JavaFileObject impl,
|
|
|
|
* used for checking that we are checking the expected impl of
|
|
|
|
* inferBinaryName
|
|
|
|
*/
|
|
|
|
void test(String testName,
|
|
|
|
JavaFileManager fm, String testClassName, String implClassName) throws IOException {
|
|
|
|
JavaFileObject fo = fm.getJavaFileForInput(CLASS_PATH, testClassName, CLASS);
|
|
|
|
if (fo == null) {
|
|
|
|
System.err.println("Can't find " + testClassName);
|
|
|
|
errors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:02:55 -08:00
|
|
|
String cn = fo.getClass().getSimpleName();
|
2008-08-26 14:52:59 -07:00
|
|
|
String bn = fm.inferBinaryName(CLASS_PATH, fo);
|
|
|
|
System.err.println(testName + " " + cn + " " + bn);
|
2015-12-07 14:02:55 -08:00
|
|
|
checkEqual(cn, implClassName);
|
|
|
|
checkEqual(bn, testClassName);
|
2008-08-26 14:52:59 -07:00
|
|
|
System.err.println("OK");
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:02:55 -08:00
|
|
|
JavaFileManager getFileManager(List<File> path)
|
2008-08-26 14:52:59 -07:00
|
|
|
throws IOException {
|
|
|
|
Context ctx = new Context();
|
2011-02-18 08:12:06 -08:00
|
|
|
|
2008-08-26 14:52:59 -07:00
|
|
|
JavacFileManager fm = new JavacFileManager(ctx, false, null);
|
|
|
|
fm.setLocation(CLASS_PATH, path);
|
|
|
|
return fm;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<File> getPath(String s) {
|
2015-12-07 14:02:55 -08:00
|
|
|
List<File> path = new ArrayList<>();
|
2008-08-26 14:52:59 -07:00
|
|
|
for (String f: s.split(File.pathSeparator)) {
|
|
|
|
if (f.length() > 0)
|
|
|
|
path.add(new File(f));
|
|
|
|
}
|
|
|
|
//System.err.println("path: " + path);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2015-12-07 14:02:55 -08:00
|
|
|
void checkEqual(String found, String expect) {
|
2008-08-26 14:52:59 -07:00
|
|
|
if (!found.equals(expect)) {
|
|
|
|
System.err.println("Expected: " + expect);
|
|
|
|
System.err.println(" Found: " + found);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
class A { }
|
|
|
|
|