< prev index next >

langtools/test/tools/sjavac/ClasspathDependencies.java

Print this page




  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 8054717
  27  * @summary Make sure changes of public API on classpath triggers recompilation
  28  * @library /tools/lib
  29  * @modules jdk.compiler/com.sun.tools.javac.api
  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.compiler/com.sun.tools.sjavac
  32  *          jdk.jdeps/com.sun.tools.javap
  33  * @build Wrapper toolbox.ToolBox
  34  * @run main Wrapper ClasspathDependencies
  35  */
  36 
  37 import static com.sun.tools.javac.util.Assert.check;
  38 
  39 import java.io.IOException;
  40 import java.nio.file.FileVisitResult;
  41 import java.nio.file.Files;
  42 import java.nio.file.Path;
  43 import java.nio.file.Paths;
  44 import java.nio.file.SimpleFileVisitor;
  45 import java.nio.file.attribute.BasicFileAttributes;
  46 import java.nio.file.attribute.FileTime;
  47 


  48 public class ClasspathDependencies extends SjavacBase {
  49 
  50     public static void main(String... args) throws Exception {
  51 
  52         Path root = Paths.get(ClasspathDependencies.class.getSimpleName() + "Test");
  53 
  54         delete(root);
  55 
  56         Path src = root.resolve("src");
  57         Path classes = root.resolve("classes");
  58         Path srcDep = root.resolve("srcDep");
  59         Path classesDep = root.resolve("classesDep");
  60 
  61         ////////////////////////////////////////////////////////////////////////
  62         headline("Create a test dependency, Dep.class, and put it in the classpath dir");
  63         String depCode = "package dep; public class Dep { public void m1() {} }";
  64         toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
  65         int rc = compile("-d", classesDep, "--state-dir=" + classesDep, srcDep);
  66         check(rc == 0, "Compilation failed unexpectedly");
  67 


 117             return;
 118         Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
 119                  @Override
 120                  public FileVisitResult visitFile(Path f, BasicFileAttributes a)
 121                          throws IOException {
 122                      Files.delete(f);
 123                      return FileVisitResult.CONTINUE;
 124                  }
 125 
 126                  @Override
 127                  public FileVisitResult postVisitDirectory(Path dir, IOException e)
 128                          throws IOException {
 129                      if (e != null)
 130                          throw e;
 131                      if (!dir.equals(root))
 132                          Files.delete(dir);
 133                      return FileVisitResult.CONTINUE;
 134                  }
 135             });
 136     }
 137 
 138 }


  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 8054717
  27  * @summary Make sure changes of public API on classpath triggers recompilation
  28  * @library /tools/lib
  29  * @modules jdk.compiler/com.sun.tools.javac.api
  30  *          jdk.compiler/com.sun.tools.javac.main
  31  *          jdk.compiler/com.sun.tools.sjavac
  32  * @build Wrapper toolbox.ToolBox toolbox.Assert

  33  * @run main Wrapper ClasspathDependencies
  34  */
  35 

  36 
  37 import java.io.IOException;
  38 import java.nio.file.FileVisitResult;
  39 import java.nio.file.Files;
  40 import java.nio.file.Path;
  41 import java.nio.file.Paths;
  42 import java.nio.file.SimpleFileVisitor;
  43 import java.nio.file.attribute.BasicFileAttributes;
  44 import java.nio.file.attribute.FileTime;
  45 
  46 import static toolbox.Assert.check;
  47 
  48 public class ClasspathDependencies extends SjavacBase {
  49 
  50     public static void main(String... args) throws Exception {
  51 
  52         Path root = Paths.get(ClasspathDependencies.class.getSimpleName() + "Test");
  53 
  54         delete(root);
  55 
  56         Path src = root.resolve("src");
  57         Path classes = root.resolve("classes");
  58         Path srcDep = root.resolve("srcDep");
  59         Path classesDep = root.resolve("classesDep");
  60 
  61         ////////////////////////////////////////////////////////////////////////
  62         headline("Create a test dependency, Dep.class, and put it in the classpath dir");
  63         String depCode = "package dep; public class Dep { public void m1() {} }";
  64         toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
  65         int rc = compile("-d", classesDep, "--state-dir=" + classesDep, srcDep);
  66         check(rc == 0, "Compilation failed unexpectedly");
  67 


 117             return;
 118         Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
 119                  @Override
 120                  public FileVisitResult visitFile(Path f, BasicFileAttributes a)
 121                          throws IOException {
 122                      Files.delete(f);
 123                      return FileVisitResult.CONTINUE;
 124                  }
 125 
 126                  @Override
 127                  public FileVisitResult postVisitDirectory(Path dir, IOException e)
 128                          throws IOException {
 129                      if (e != null)
 130                          throw e;
 131                      if (!dir.equals(root))
 132                          Files.delete(dir);
 133                      return FileVisitResult.CONTINUE;
 134                  }
 135             });
 136     }

 137 }
< prev index next >