langtools/test/tools/javac/options/xprefer/XPreferTest.java
changeset 25005 645284cd7d1d
parent 24395 5c541aef1350
child 27319 030080f03e4f
equal deleted inserted replaced
25004:b33effe4f252 25005:645284cd7d1d
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @summary Tests which path is used to represent an implicit type given
    26  * @summary Tests which path is used to represent an implicit type given
    27  * various xprefer arguments and multiple .class / .java files involved.
    27  * various xprefer arguments and multiple .class / .java files involved.
    28  * @bug 8028196
    28  * @bug 8028196
    29  * @ignore 8042839 XPreferTest fails on Windows
       
    30  */
    29  */
    31 
    30 
    32 import java.io.File;
    31 import java.io.File;
    33 import java.io.FileWriter;
    32 import java.io.FileWriter;
    34 import java.io.IOException;
    33 import java.io.IOException;
    40 import java.util.Iterator;
    39 import java.util.Iterator;
    41 import java.util.List;
    40 import java.util.List;
    42 import java.util.ListIterator;
    41 import java.util.ListIterator;
    43 import java.util.NoSuchElementException;
    42 import java.util.NoSuchElementException;
    44 import java.util.Scanner;
    43 import java.util.Scanner;
       
    44 import java.util.regex.Pattern;
    45 
    45 
    46 import javax.tools.JavaCompiler;
    46 import javax.tools.JavaCompiler;
    47 import javax.tools.JavaCompiler.CompilationTask;
    47 import javax.tools.JavaCompiler.CompilationTask;
    48 import javax.tools.ToolProvider;
    48 import javax.tools.ToolProvider;
    49 
    49 
   178 
   178 
   179         Dir getChosenOrigin(String compilerOutput) {
   179         Dir getChosenOrigin(String compilerOutput) {
   180             Scanner s = new Scanner(compilerOutput);
   180             Scanner s = new Scanner(compilerOutput);
   181             while (s.hasNextLine()) {
   181             while (s.hasNextLine()) {
   182                 String line = s.nextLine();
   182                 String line = s.nextLine();
   183                 if (line.matches("\\[loading .*\\]"))
   183                 if (line.matches("\\[loading .*\\]")) {
   184                     for (Dir dir : Dir.values())
   184                     for (Dir dir : Dir.values()) {
   185                         if (line.contains(dir.file.getName() + "/" + classId))
   185                         // On Windows all paths are printed with '/' except
       
   186                         // paths inside zip-files, which are printed with '\'.
       
   187                         // For this reason we accept both '/' and '\' below.
       
   188                         String regex = dir.file.getName() + "[\\\\/]" + classId;
       
   189                         if (Pattern.compile(regex).matcher(line).find())
   186                             return dir;
   190                             return dir;
       
   191                     }
       
   192                 }
   187             }
   193             }
   188             return null;
   194             return null;
   189         }
   195         }
   190 
   196 
   191         String compile() throws IOException {
   197         String compile() throws IOException {