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")
56 .orElseThrow(() ->
57 new RuntimeException("jmod tool not found")
58 );
59
60 static final String TEST_SRC = System.getProperty("test.src", ".");
61 static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
62 static final Path EXPLODED_DIR = Paths.get("build");
63 static final Path MODS_DIR = Paths.get("jmods");
64
65 static final String CLASSES_PREFIX = "classes/";
66 static final String CMDS_PREFIX = "bin/";
67 static final String LIBS_PREFIX = "native/";
68 static final String CONFIGS_PREFIX = "conf/";
69
70 @BeforeTest
71 public void buildExplodedModules() throws IOException {
72 if (Files.exists(EXPLODED_DIR))
73 FileUtils.deleteFileTreeWithRetry(EXPLODED_DIR);
74
75 for (String name : new String[] { "foo"/*, "bar", "baz"*/ } ) {
76 Path dir = EXPLODED_DIR.resolve(name);
77 assertTrue(compileModule(name, dir.resolve("classes")));
78 createCmds(dir.resolve("bin"));
79 createLibs(dir.resolve("lib"));
468 Set<String> unexpected = new HashSet<>();
469 for (String name : unexpectedNames) {
470 if (actual.contains(name))
471 unexpected.add(name);
472 }
473 if (!unexpected.isEmpty()) {
474 StringBuilder sb = new StringBuilder();
475 for (String s : unexpected)
476 sb.append("Unexpected but found: " + s + "\n");
477 sb.append("In :");
478 for (String s : actual)
479 sb.append("\t" + s + "\n");
480 assertTrue(false, "Jmod content check failed.\n" + sb.toString());
481 }
482 }
483
484 static JmodResult jmod(String... args) {
485 ByteArrayOutputStream baos = new ByteArrayOutputStream();
486 PrintStream ps = new PrintStream(baos);
487 System.out.println("jmod " + Arrays.asList(args));
488 int ec = JMOD_TOOL.run(ps, ps, args);
489 return new JmodResult(ec, new String(baos.toByteArray(), UTF_8));
490 }
491
492 static class JmodResult {
493 final int exitCode;
494 final String output;
495
496 JmodResult(int exitValue, String output) {
497 this.exitCode = exitValue;
498 this.output = output;
499 }
500 JmodResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
501 JmodResult assertFailure() { assertTrue(exitCode != 0, output); return this; }
502 JmodResult resultChecker(Consumer<JmodResult> r) { r.accept(this); return this; }
503 }
504
505 static void createCmds(Path dir) throws IOException {
506 List<String> files = Arrays.asList(
507 "first", "second", "third" + File.separator + "third");
508 createFiles(dir, files);
|