1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 8047305 8075618
27 * @summary Tests jarsigner tool and JarSigner API work with multi-release JAR files.
28 * @library /test/lib
29 * @build jdk.test.lib.compiler.CompilerUtils
30 * jdk.test.lib.Utils
31 * jdk.test.lib.Asserts
32 * jdk.test.lib.JDKToolFinder
33 * jdk.test.lib.JDKToolLauncher
34 * jdk.test.lib.Platform
35 * jdk.test.lib.process.*
36 * @run main MVJarSigningTest
37 */
38
39 import jdk.security.jarsigner.JarSigner;
40
41 import java.io.BufferedReader;
42 import java.io.File;
43 import java.io.FileInputStream;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.InputStreamReader;
64
65 import jdk.test.lib.JDKToolFinder;
66 import jdk.test.lib.JDKToolLauncher;
67 import jdk.test.lib.Utils;
68 import jdk.test.lib.compiler.CompilerUtils;
69 import jdk.test.lib.process.OutputAnalyzer;
70 import jdk.test.lib.process.ProcessTools;
71
72
73 public class MVJarSigningTest {
74
75 private static final String TEST_SRC = System.getProperty("test.src", ".");
76 private static final String USR_DIR = System.getProperty("user.dir", ".");
77 private static final String JAR_NAME = "MV.jar";
78 private static final String KEYSTORE = "keystore.jks";
79 private static final String ALIAS = "JavaTest";
80 private static final String STOREPASS = "changeit";
81 private static final String KEYPASS = "changeit";
82 private static final String SIGNED_JAR = "Signed.jar";
83 private static final String POLICY_FILE = "SignedJar.policy";
84 private static final String VERSION = "" + Runtime.version().major();
85 private static final String VERSION_MESSAGE = "I am running on version " + VERSION;
86
87 public static void main(String[] args) throws Throwable {
88 // compile java files in jarContent directory
89 compile("jarContent");
90
91 // create multi-release jar
92 Path classes = Paths.get("classes");
93 jar("cf", JAR_NAME, "-C", classes.resolve("base").toString(), ".",
94 "--release", "9", "-C", classes.resolve("v9").toString(), ".",
95 "--release", "10", "-C", classes.resolve("v10").toString(), ".")
96 .shouldHaveExitValue(0);
97
98 genKey();
99 signJar(JAR_NAME)
100 .shouldHaveExitValue(0)
101 .shouldMatch("signing.*META-INF/versions/9/version/Version.class")
102 .shouldMatch("signing.*META-INF/versions/10/version/Version.class")
103 .shouldMatch("signing.*version/Main.class")
104 .shouldMatch("signing.*version/Version.class");
|
1 /*
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 8047305 8075618 8194070
27 * @summary Tests jarsigner tool and JarSigner API work with multi-release JAR files.
28 * @library /test/lib
29 * @build jdk.test.lib.compiler.CompilerUtils
30 * jdk.test.lib.Utils
31 * jdk.test.lib.Asserts
32 * jdk.test.lib.JDKToolFinder
33 * jdk.test.lib.JDKToolLauncher
34 * jdk.test.lib.Platform
35 * jdk.test.lib.process.*
36 * @run main MVJarSigningTest
37 */
38
39 import jdk.security.jarsigner.JarSigner;
40
41 import java.io.BufferedReader;
42 import java.io.File;
43 import java.io.FileInputStream;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.InputStreamReader;
64
65 import jdk.test.lib.JDKToolFinder;
66 import jdk.test.lib.JDKToolLauncher;
67 import jdk.test.lib.Utils;
68 import jdk.test.lib.compiler.CompilerUtils;
69 import jdk.test.lib.process.OutputAnalyzer;
70 import jdk.test.lib.process.ProcessTools;
71
72
73 public class MVJarSigningTest {
74
75 private static final String TEST_SRC = System.getProperty("test.src", ".");
76 private static final String USR_DIR = System.getProperty("user.dir", ".");
77 private static final String JAR_NAME = "MV.jar";
78 private static final String KEYSTORE = "keystore.jks";
79 private static final String ALIAS = "JavaTest";
80 private static final String STOREPASS = "changeit";
81 private static final String KEYPASS = "changeit";
82 private static final String SIGNED_JAR = "Signed.jar";
83 private static final String POLICY_FILE = "SignedJar.policy";
84 private static final String VERSION = "" + Math.min(Runtime.version().major(), 10);
85 private static final String VERSION_MESSAGE = "I am running on version " + VERSION;
86
87 public static void main(String[] args) throws Throwable {
88 // compile java files in jarContent directory
89 compile("jarContent");
90
91 // create multi-release jar
92 Path classes = Paths.get("classes");
93 jar("cf", JAR_NAME, "-C", classes.resolve("base").toString(), ".",
94 "--release", "9", "-C", classes.resolve("v9").toString(), ".",
95 "--release", "10", "-C", classes.resolve("v10").toString(), ".")
96 .shouldHaveExitValue(0);
97
98 genKey();
99 signJar(JAR_NAME)
100 .shouldHaveExitValue(0)
101 .shouldMatch("signing.*META-INF/versions/9/version/Version.class")
102 .shouldMatch("signing.*META-INF/versions/10/version/Version.class")
103 .shouldMatch("signing.*version/Main.class")
104 .shouldMatch("signing.*version/Version.class");
|