langtools/test/tools/sjavac/ExclPattern.java
changeset 24067 76e7b6bbbd85
child 25603 d5fa4eab2d26
equal deleted inserted replaced
24066:1dfb66929538 24067:76e7b6bbbd85
       
     1 /*
       
     2  * Copyright (c) 2014, 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 import java.io.IOException;
       
    27 import java.io.PrintWriter;
       
    28 import java.nio.charset.Charset;
       
    29 import java.nio.file.Files;
       
    30 import java.nio.file.Path;
       
    31 import java.nio.file.Paths;
       
    32 
       
    33 public class ExclPattern {
       
    34 
       
    35     public static void main(String[] ignore) throws IOException {
       
    36 
       
    37         String toBeExcluded = "pkg/excl-dir/excluded.txt";
       
    38         String toBeIncluded = "pkg/incl-dir/included.txt";
       
    39 
       
    40         // Set up source directory with directory to be excluded
       
    41         populate(Paths.get("srcdir"),
       
    42             "pkg/SomeClass.java",
       
    43             "package pkg; public class SomeClass { }",
       
    44 
       
    45             toBeExcluded,
       
    46             "This file should not end up in the dest directory.",
       
    47 
       
    48             toBeIncluded,
       
    49             "This file should end up in the dest directory.");
       
    50 
       
    51         String[] args = {
       
    52                 "-x", "pkg/excl-dir/*",
       
    53                 "-src", "srcdir",
       
    54                 "-d", "dest",
       
    55                 "-j", "1",
       
    56                 "-copy", ".txt",
       
    57                 "--server:portfile=testserver,background=false",
       
    58                 "--log=debug"
       
    59         };
       
    60 
       
    61         int rc = new com.sun.tools.sjavac.Main().go(args, System.out, System.err);
       
    62         if (rc != 0) throw new RuntimeException("Error during compile!");
       
    63 
       
    64         if (!Files.exists(Paths.get("dest/" + toBeIncluded)))
       
    65             throw new AssertionError("File missing: " + toBeIncluded);
       
    66 
       
    67         if (Files.exists(Paths.get("dest/" + toBeExcluded)))
       
    68             throw new AssertionError("File present: " + toBeExcluded);
       
    69     }
       
    70 
       
    71     static void populate(Path root, String... args) throws IOException {
       
    72         if (!Files.exists(root))
       
    73             Files.createDirectory(root);
       
    74         for (int i = 0; i < args.length; i += 2) {
       
    75             String filename = args[i];
       
    76             String content = args[i+1];
       
    77             Path p = root.resolve(filename);
       
    78             Files.createDirectories(p.getParent());
       
    79             try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(p,
       
    80                     Charset.defaultCharset()))) {
       
    81                 out.println(content);
       
    82             }
       
    83         }
       
    84     }
       
    85 }