6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8149757
27 * @summary Test that StandardJavaFileManager uses the correct version of a
28 * class from a multi-release jar on classpath
29 * @library /tools/lib
30 * @modules jdk.compiler/com.sun.tools.javac.api
31 * jdk.compiler/com.sun.tools.javac.main
32 * @build toolbox.ToolBox
33 * @run testng MultiReleaseJarAwareSJFM
34 */
35
36 import org.testng.Assert;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41
42 import javax.tools.FileObject;
43 import javax.tools.JavaFileManager;
44 import javax.tools.StandardJavaFileManager;
45 import javax.tools.ToolProvider;
46 import java.io.File;
147 "classes/META-INF/versions/10/",
148 "classes/META-INF/versions/9/version/Version.class",
149 "classes/META-INF/versions/9/version/PackagePrivate.class",
150 "classes/META-INF/versions/9/version",
151 "classes/META-INF/versions/9",
152 "classes/META-INF/versions",
153 "classes/META-INF",
154 "classes/version/Version.class",
155 "classes/version",
156 "classes",
157 "multi-release.jar"
158 );
159 }
160
161 @DataProvider(name = "versions")
162 public Object[][] data() {
163 return new Object[][] {
164 {"", 8},
165 {"8", 8},
166 {"9", 9},
167 {"runtime", jdk.Version.current().major()}
168 };
169 }
170
171 @Test(dataProvider = "versions")
172 public void test(String version, int expected) throws Throwable {
173 StandardJavaFileManager jfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
174 jfm.setLocation(jloc, List.of(new File("multi-release.jar")));
175
176 if (version.length() > 0) {
177 jfm.handleOption("-multi-release", List.of(version).iterator());
178 }
179
180 CustomClassLoader cldr = new CustomClassLoader(jfm);
181 Class<?> versionClass = cldr.loadClass("version.Version");
182 MethodType mt = MethodType.methodType(int.class);
183 MethodHandle mh = MethodHandles.lookup().findVirtual(versionClass, "getVersion", mt);
184 int v = (int)mh.invoke(versionClass.newInstance());
185 Assert.assertEquals(v, expected);
186
187 jfm.close();
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8149757 8144062
27 * @summary Test that StandardJavaFileManager uses the correct version of a
28 * class from a multi-release jar on classpath
29 * @library /tools/lib
30 * @modules jdk.compiler/com.sun.tools.javac.api
31 * jdk.compiler/com.sun.tools.javac.main
32 * @build toolbox.ToolBox
33 * @run testng MultiReleaseJarAwareSJFM
34 */
35
36 import org.testng.Assert;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.DataProvider;
40 import org.testng.annotations.Test;
41
42 import javax.tools.FileObject;
43 import javax.tools.JavaFileManager;
44 import javax.tools.StandardJavaFileManager;
45 import javax.tools.ToolProvider;
46 import java.io.File;
147 "classes/META-INF/versions/10/",
148 "classes/META-INF/versions/9/version/Version.class",
149 "classes/META-INF/versions/9/version/PackagePrivate.class",
150 "classes/META-INF/versions/9/version",
151 "classes/META-INF/versions/9",
152 "classes/META-INF/versions",
153 "classes/META-INF",
154 "classes/version/Version.class",
155 "classes/version",
156 "classes",
157 "multi-release.jar"
158 );
159 }
160
161 @DataProvider(name = "versions")
162 public Object[][] data() {
163 return new Object[][] {
164 {"", 8},
165 {"8", 8},
166 {"9", 9},
167 {"runtime", Runtime.version().major()}
168 };
169 }
170
171 @Test(dataProvider = "versions")
172 public void test(String version, int expected) throws Throwable {
173 StandardJavaFileManager jfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
174 jfm.setLocation(jloc, List.of(new File("multi-release.jar")));
175
176 if (version.length() > 0) {
177 jfm.handleOption("-multi-release", List.of(version).iterator());
178 }
179
180 CustomClassLoader cldr = new CustomClassLoader(jfm);
181 Class<?> versionClass = cldr.loadClass("version.Version");
182 MethodType mt = MethodType.methodType(int.class);
183 MethodHandle mh = MethodHandles.lookup().findVirtual(versionClass, "getVersion", mt);
184 int v = (int)mh.invoke(versionClass.newInstance());
185 Assert.assertEquals(v, expected);
186
187 jfm.close();
|