hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeFileSupport.java
changeset 43464 f38fde4a6b52
child 44081 5dbc6c93f9bf
equal deleted inserted replaced
43462:cde11973a86a 43464:f38fde4a6b52
       
     1 /*
       
     2  * Copyright (c) 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  */
       
    23 package jdk.tools.jaotc.test.collect;
       
    24 
       
    25 import java.net.MalformedURLException;
       
    26 import java.nio.file.Path;
       
    27 import java.util.HashSet;
       
    28 import java.util.Set;
       
    29 
       
    30 public class FakeFileSupport extends FileSupport {
       
    31     private final Set<String> exists = new HashSet<>();
       
    32     private final Set<String> directories = new HashSet<>();
       
    33 
       
    34     private final Set<String> checkedExists = new HashSet<>();
       
    35     private final Set<String> checkedDirectory = new HashSet<>();
       
    36     private final Set<String> checkedJarFileSystemRoots = new HashSet<>();
       
    37     private final Set<String> classloaderPaths = new HashSet<>();
       
    38 
       
    39     private Path jarFileSystemRoot = null;
       
    40     private final ClassLoader classLoader;
       
    41 
       
    42     public FakeFileSupport(Set<String> existing, Set<String> directories) {
       
    43         this.exists.addAll(existing);
       
    44         this.directories.addAll(directories);
       
    45 
       
    46         classLoader = new ClassLoader() {
       
    47             @Override
       
    48             public Class<?> loadClass(String name) throws ClassNotFoundException {
       
    49                 return null;
       
    50             }
       
    51         };
       
    52     }
       
    53 
       
    54     public void setJarFileSystemRoot(Path path) {
       
    55         jarFileSystemRoot = path;
       
    56     }
       
    57 
       
    58     @Override
       
    59     public boolean exists(Path path) {
       
    60         checkedExists.add(path.toString());
       
    61         return exists.contains(path.toString());
       
    62     }
       
    63 
       
    64     @Override
       
    65     public boolean isDirectory(Path path) {
       
    66         checkedDirectory.add(path.toString());
       
    67         return directories.contains(path.toString());
       
    68     }
       
    69 
       
    70     @Override
       
    71     public ClassLoader createClassLoader(Path path) throws MalformedURLException {
       
    72         classloaderPaths.add(path.toString());
       
    73         return classLoader;
       
    74     }
       
    75 
       
    76     @Override
       
    77     public Path getJarFileSystemRoot(Path jarFile) {
       
    78         checkedJarFileSystemRoots.add(jarFile.toString());
       
    79         return jarFileSystemRoot;
       
    80     }
       
    81 
       
    82     @Override
       
    83     public boolean isAbsolute(Path entry) {
       
    84         return entry.toString().startsWith("/");
       
    85     }
       
    86 
       
    87     public void addExist(String name) {
       
    88         exists.add(name);
       
    89     }
       
    90 
       
    91     public void addDirectory(String name) {
       
    92         directories.add(name);
       
    93     }
       
    94 
       
    95     public Set<String> getCheckedExists() {
       
    96         return checkedExists;
       
    97     }
       
    98 
       
    99     public Set<String> getCheckedDirectory() {
       
   100         return checkedDirectory;
       
   101     }
       
   102 
       
   103     public Set<String> getCheckedJarFileSystemRoots() {
       
   104         return checkedJarFileSystemRoots;
       
   105     }
       
   106 
       
   107     public Set<String> getClassloaderPaths() {
       
   108         return classloaderPaths;
       
   109     }
       
   110 }