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 * @library /lib/testlibrary
27 * @modules jdk.jlink/jdk.tools.jmod
28 * jdk.compiler
29 * @build jdk.testlibrary.FileUtils CompilerUtils
30 * @run testng JmodTest
31 * @summary Basic test for jmod
32 */
33
34 import java.io.*;
35 import java.lang.module.ModuleDescriptor;
36 import java.lang.reflect.Method;
37 import java.nio.file.*;
38 import java.util.*;
39 import java.util.function.Consumer;
40 import java.util.regex.Pattern;
41 import java.util.stream.Stream;
42 import jdk.testlibrary.FileUtils;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
45
46 import static java.io.File.pathSeparator;
47 import static java.lang.module.ModuleDescriptor.Version;
48 import static java.nio.charset.StandardCharsets.UTF_8;
49 import static java.util.stream.Collectors.toSet;
50 import static org.testng.Assert.*;
51
52 public class JmodTest {
53
54 static final String TEST_SRC = System.getProperty("test.src", ".");
55 static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
56 static final Path EXPLODED_DIR = Paths.get("build");
57 static final Path MODS_DIR = Paths.get("jmods");
58
59 static final String CLASSES_PREFIX = "classes/";
60 static final String CMDS_PREFIX = "bin/";
61 static final String LIBS_PREFIX = "native/";
62 static final String CONFIGS_PREFIX = "conf/";
63
64 @BeforeTest
65 public void buildExplodedModules() throws IOException {
66 if (Files.exists(EXPLODED_DIR))
67 FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR);
68
69 for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) {
70 Path dir = EXPLODED_DIR.resolve(name);
71 assertTrue(compileModule(name, dir.resolve("classes")));
72 createCmds(dir.resolve("bin"));
73 createLibs(dir.resolve("lib"));
462 Set<String> unexpected = new HashSet<>();
463 for (String name : unexpectedNames) {
464 if (actual.contains(name))
465 unexpected.add(name);
466 }
467 if (!unexpected.isEmpty()) {
468 StringBuilder sb = new StringBuilder();
469 for (String s : unexpected)
470 sb.append("Unexpected but found: " + s + "\n");
471 sb.append("In :");
472 for (String s : actual)
473 sb.append("\t" + s + "\n");
474 assertTrue(false, "Jmod content check failed.\n" + sb.toString());
475 }
476 }
477
478 static JmodResult jmod(String... args) {
479 ByteArrayOutputStream baos = new ByteArrayOutputStream();
480 PrintStream ps = new PrintStream(baos);
481 System.out.println("jmod " + Arrays.asList(args));
482 int ec = jdk.tools.jmod.Main.run(args, ps);
483 return new JmodResult(ec, new String(baos.toByteArray(), UTF_8));
484 }
485
486 static class JmodResult {
487 final int exitCode;
488 final String output;
489
490 JmodResult(int exitValue, String output) {
491 this.exitCode = exitValue;
492 this.output = output;
493 }
494 JmodResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
495 JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; }
496 JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; }
497 }
498
499 static void createCmds(Path dir) throws IOException {
500 List<String> files = Arrays.asList(
501 "first", "second", "third" + File.separator + "third");
502 createFiles(dir, files);
|
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 * @library /lib/testlibrary
27 * @modules jdk.compiler
28 * jdk.jlink
29 * @build jdk.testlibrary.FileUtils CompilerUtils
30 * @run testng JmodTest
31 * @summary Basic test for jmod
32 */
33
34 import java.io.*;
35 import java.lang.module.ModuleDescriptor;
36 import java.lang.reflect.Method;
37 import java.nio.file.*;
38 import java.util.*;
39 import java.util.function.Consumer;
40 import java.util.regex.Pattern;
41 import java.util.spi.ToolProvider;
42 import java.util.stream.Stream;
43 import jdk.testlibrary.FileUtils;
44 import org.testng.annotations.BeforeTest;
45 import org.testng.annotations.Test;
46
47 import static java.io.File.pathSeparator;
48 import static java.lang.module.ModuleDescriptor.Version;
49 import static java.nio.charset.StandardCharsets.UTF_8;
50 import static java.util.stream.Collectors.toSet;
51 import static org.testng.Assert.*;
52
53 public class JmodTest {
54
55 static final ToolProvider JMOD_TOOL = ToolProvider.findFirst("jmod").get();
56
57 static final String TEST_SRC = System.getProperty("test.src", ".");
58 static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
59 static final Path EXPLODED_DIR = Paths.get("build");
60 static final Path MODS_DIR = Paths.get("jmods");
61
62 static final String CLASSES_PREFIX = "classes/";
63 static final String CMDS_PREFIX = "bin/";
64 static final String LIBS_PREFIX = "native/";
65 static final String CONFIGS_PREFIX = "conf/";
66
67 @BeforeTest
68 public void buildExplodedModules() throws IOException {
69 if (Files.exists(EXPLODED_DIR))
70 FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR);
71
72 for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) {
73 Path dir = EXPLODED_DIR.resolve(name);
74 assertTrue(compileModule(name, dir.resolve("classes")));
75 createCmds(dir.resolve("bin"));
76 createLibs(dir.resolve("lib"));
465 Set<String> unexpected = new HashSet<>();
466 for (String name : unexpectedNames) {
467 if (actual.contains(name))
468 unexpected.add(name);
469 }
470 if (!unexpected.isEmpty()) {
471 StringBuilder sb = new StringBuilder();
472 for (String s : unexpected)
473 sb.append("Unexpected but found: " + s + "\n");
474 sb.append("In :");
475 for (String s : actual)
476 sb.append("\t" + s + "\n");
477 assertTrue(false, "Jmod content check failed.\n" + sb.toString());
478 }
479 }
480
481 static JmodResult jmod(String... args) {
482 ByteArrayOutputStream baos = new ByteArrayOutputStream();
483 PrintStream ps = new PrintStream(baos);
484 System.out.println("jmod " + Arrays.asList(args));
485 int ec = JMOD_TOOL.run(ps, ps, args);
486 return new JmodResult(ec, new String(baos.toByteArray(), UTF_8));
487 }
488
489 static class JmodResult {
490 final int exitCode;
491 final String output;
492
493 JmodResult(int exitValue, String output) {
494 this.exitCode = exitValue;
495 this.output = output;
496 }
497 JmodResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
498 JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; }
499 JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; }
500 }
501
502 static void createCmds(Path dir) throws IOException {
503 List<String> files = Arrays.asList(
504 "first", "second", "third" + File.separator + "third");
505 createFiles(dir, files);
|