< prev index next >

test/langtools/tools/jdeps/modules/GenOpenModule.java

Print this page


   1 /*
   2  * Copyright (c) 2016, 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  */


  37 import java.nio.file.Files;
  38 import java.nio.file.Path;
  39 import java.nio.file.Paths;
  40 
  41 import java.util.stream.Stream;
  42 
  43 import org.testng.annotations.BeforeTest;
  44 import org.testng.annotations.Test;
  45 
  46 import static org.testng.Assert.assertEquals;
  47 import static org.testng.Assert.assertTrue;
  48 
  49 public class GenOpenModule extends GenModuleInfo {
  50     private static final String MODULE_INFO = "module-info.class";
  51 
  52     private static final Path MODS_DIR = Paths.get("mods");
  53     private static final Path LIBS_DIR = Paths.get("libs");
  54     private static final Path DEST_DIR = Paths.get("moduleinfosrc");
  55     private static final Path NEW_MODS_DIR = Paths.get("new_mods");
  56 
  57     /**
  58      * Compiles all modules used by the test
  59      */
  60     @BeforeTest
  61     public void compileAll() throws Exception {
  62 
  63         compileModules(MODS_DIR);
  64 
  65         createJARFiles(MODS_DIR, LIBS_DIR);
  66     }
  67 
  68     @Test
  69     public void test() throws IOException {





  70         Stream<String> files = MODULES.stream()
  71                 .map(mn -> LIBS_DIR.resolve(mn + ".jar"))
  72                 .map(Path::toString);
  73 
  74         Stream<String> options = Stream.concat(
  75             Stream.of("--generate-open-module", DEST_DIR.toString()), files);
  76         JdepsRunner.run(options.toArray(String[]::new));
  77 
  78         // check file exists
  79         MODULES.stream()
  80              .map(mn -> DEST_DIR.resolve(mn).resolve("module-info.java"))
  81              .forEach(f -> assertTrue(Files.exists(f)));
  82 
  83         // copy classes to a temporary directory
  84         // and then compile new module-info.java
  85         copyClasses(MODS_DIR, NEW_MODS_DIR);
  86         compileNewGenModuleInfo(DEST_DIR, NEW_MODS_DIR);
  87 
  88         for (String mn : MODULES) {
  89             Path p1 = NEW_MODS_DIR.resolve(mn).resolve(MODULE_INFO);
  90             Path p2 = MODS_DIR.resolve(mn).resolve(MODULE_INFO);
  91 
  92             try (InputStream in1 = Files.newInputStream(p1);
  93                  InputStream in2 = Files.newInputStream(p2)) {
  94                 verify(ModuleDescriptor.read(in1),
  95                        ModuleDescriptor.read(in2));
  96             }
  97         }
  98     }
  99 
 100     /*
 101      * Verify the dependences
 102      */
 103     private void verify(ModuleDescriptor openModule, ModuleDescriptor md) {
 104         System.out.println("verifying: " + openModule.name());
 105         assertTrue(openModule.isOpen());
 106         assertTrue(!md.isOpen());
 107         assertEquals(openModule.name(), md.name());
 108         assertEquals(openModule.requires(), md.requires());
 109         assertTrue(openModule.exports().isEmpty());
 110         assertEquals(openModule.provides(), md.provides());
 111     }
   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  */


  37 import java.nio.file.Files;
  38 import java.nio.file.Path;
  39 import java.nio.file.Paths;
  40 
  41 import java.util.stream.Stream;
  42 
  43 import org.testng.annotations.BeforeTest;
  44 import org.testng.annotations.Test;
  45 
  46 import static org.testng.Assert.assertEquals;
  47 import static org.testng.Assert.assertTrue;
  48 
  49 public class GenOpenModule extends GenModuleInfo {
  50     private static final String MODULE_INFO = "module-info.class";
  51 
  52     private static final Path MODS_DIR = Paths.get("mods");
  53     private static final Path LIBS_DIR = Paths.get("libs");
  54     private static final Path DEST_DIR = Paths.get("moduleinfosrc");
  55     private static final Path NEW_MODS_DIR = Paths.get("new_mods");
  56 



  57     @BeforeTest
  58     public void setup() throws Exception {
  59         compileAndCreateJars();



  60     }
  61 
  62     @Test
  63     public void test() throws IOException {
  64         Path dest = DEST_DIR.resolve("open");
  65         Path classes = NEW_MODS_DIR.resolve("open");
  66         Files.createDirectories(dest);
  67         Files.createDirectories(classes);
  68 
  69         Stream<String> files = MODULES.stream()
  70                 .map(mn -> LIBS_DIR.resolve(mn + ".jar"))
  71                 .map(Path::toString);
  72 
  73         Stream<String> options = Stream.concat(
  74             Stream.of("--generate-open-module", dest.toString()), files);
  75         JdepsRunner.run(options.toArray(String[]::new));
  76 
  77         // check file exists
  78         MODULES.stream()
  79              .map(mn -> dest.resolve(mn).resolve("module-info.java"))
  80              .forEach(f -> assertTrue(Files.exists(f)));
  81 
  82         // copy classes to a temporary directory
  83         // and then compile new module-info.java
  84         copyClasses(MODS_DIR, classes);
  85         compileNewGenModuleInfo(dest, classes);
  86 
  87         for (String mn : MODULES) {
  88             Path p1 = classes.resolve(mn).resolve(MODULE_INFO);
  89             Path p2 = MODS_DIR.resolve(mn).resolve(MODULE_INFO);

  90             try (InputStream in1 = Files.newInputStream(p1);
  91                  InputStream in2 = Files.newInputStream(p2)) {
  92                 verify(ModuleDescriptor.read(in1),
  93                        ModuleDescriptor.read(in2));
  94             }
  95         }
  96     }
  97 
  98     /*
  99      * Verify the dependences
 100      */
 101     private void verify(ModuleDescriptor openModule, ModuleDescriptor md) {
 102         System.out.println("verifying: " + openModule.name());
 103         assertTrue(openModule.isOpen());
 104         assertTrue(!md.isOpen());
 105         assertEquals(openModule.name(), md.name());
 106         assertEquals(openModule.requires(), md.requires());
 107         assertTrue(openModule.exports().isEmpty());
 108         assertEquals(openModule.provides(), md.provides());
 109     }
< prev index next >