< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/sjavac/Source.java

Print this page




 164         Source s = new Source(lastPackage, name, last_modified);
 165         s.file = new File(name);
 166         if (isGenerated) s.markAsGenerated();
 167         if (isLinkedOnly) s.markAsLinkedOnly();
 168         return s;
 169     }
 170 
 171     public static void saveSources(Map<String,Source> sources, StringBuilder b) {
 172         List<String> sorted_sources = new ArrayList<>();
 173         for (String key : sources.keySet()) {
 174             sorted_sources.add(key);
 175         }
 176         Collections.sort(sorted_sources);
 177         for (String key : sorted_sources) {
 178             Source s = sources.get(key);
 179             s.save(b);
 180         }
 181     }
 182 
 183     /**
 184      * Recurse into the directory root and find all files matchine the excl/incl/exclfiles/inclfiles rules.
 185      * Detects the existence of module-info.java files and presumes that the directory it resides in
 186      * is the name of the current module.
 187      */
 188     static public void scanRoot(File root,
 189                                 Set<String> suffixes,
 190                                 List<String> excludes,
 191                                 List<String> includes,
 192                                 Map<String,Source> foundFiles,
 193                                 Map<String,Module> foundModules,
 194                                 final Module currentModule,
 195                                 boolean permitSourcesWithoutPackage,
 196                                 boolean inGensrc,
 197                                 boolean inLinksrc)
 198                                         throws IOException, ProblemException {
 199 
 200         if (root == null)
 201             return;
 202 
 203         FileSystem fs = root.toPath().getFileSystem();
 204 


 210         List<PathMatcher> excludeMatchers = createPathMatchers(fs, excludes);
 211 
 212         Files.walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() {
 213             @Override
 214             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
 215 
 216                 Path relToRoot = root.toPath().relativize(file);
 217 
 218                 if (includeMatchers.stream().anyMatch(im -> im.matches(relToRoot))
 219                         && excludeMatchers.stream().noneMatch(em -> em.matches(relToRoot))
 220                         && suffixes.contains(Util.fileSuffix(file))) {
 221 
 222                     // TODO: Test this.
 223                     Source existing = foundFiles.get(file);
 224                     if (existing != null) {
 225                         throw new IOException("You have already added the file "+file+" from "+existing.file().getPath());
 226                     }
 227                     existing = currentModule.lookupSource(file.toString());
 228                     if (existing != null) {
 229 
 230                             // Oups, the source is already added, could be ok, could be not, lets check.
 231                             if (inLinksrc) {
 232                                 // So we are collecting sources for linking only.
 233                                 if (existing.isLinkedOnly()) {
 234                                     // Ouch, this one is also for linking only. Bad.
 235                                     throw new IOException("You have already added the link only file " + file + " from " + existing.file().getPath());
 236                                 }
 237                                 // Ok, the existing source is to be compiled. Thus this link only is redundant
 238                                 // since all compiled are also linked to. Continue to the next source.
 239                                 // But we need to add the source, so that it will be visible to linking,
 240                                 // if not the multi core compile will fail because a JavaCompiler cannot
 241                                 // find the necessary dependencies for its part of the source.
 242                                 foundFiles.put(file.toString(), existing);
 243                             } else {
 244                                 // We are looking for sources to compile, if we find an existing to be compiled
 245                                 // source with the same name, it is an internal error, since we must
 246                                 // find the sources to be compiled before we find the sources to be linked to.
 247                                 throw new IOException("Internal error: Double add of file " + file + " from " + existing.file().getPath());
 248                             }
 249 
 250                     } else {




 164         Source s = new Source(lastPackage, name, last_modified);
 165         s.file = new File(name);
 166         if (isGenerated) s.markAsGenerated();
 167         if (isLinkedOnly) s.markAsLinkedOnly();
 168         return s;
 169     }
 170 
 171     public static void saveSources(Map<String,Source> sources, StringBuilder b) {
 172         List<String> sorted_sources = new ArrayList<>();
 173         for (String key : sources.keySet()) {
 174             sorted_sources.add(key);
 175         }
 176         Collections.sort(sorted_sources);
 177         for (String key : sorted_sources) {
 178             Source s = sources.get(key);
 179             s.save(b);
 180         }
 181     }
 182 
 183     /**
 184      * Recurse into the directory root and find all files matching the excl/incl/exclfiles/inclfiles rules.
 185      * Detects the existence of module-info.java files and presumes that the directory it resides in
 186      * is the name of the current module.
 187      */
 188     static public void scanRoot(File root,
 189                                 Set<String> suffixes,
 190                                 List<String> excludes,
 191                                 List<String> includes,
 192                                 Map<String,Source> foundFiles,
 193                                 Map<String,Module> foundModules,
 194                                 final Module currentModule,
 195                                 boolean permitSourcesWithoutPackage,
 196                                 boolean inGensrc,
 197                                 boolean inLinksrc)
 198                                         throws IOException, ProblemException {
 199 
 200         if (root == null)
 201             return;
 202 
 203         FileSystem fs = root.toPath().getFileSystem();
 204 


 210         List<PathMatcher> excludeMatchers = createPathMatchers(fs, excludes);
 211 
 212         Files.walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() {
 213             @Override
 214             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
 215 
 216                 Path relToRoot = root.toPath().relativize(file);
 217 
 218                 if (includeMatchers.stream().anyMatch(im -> im.matches(relToRoot))
 219                         && excludeMatchers.stream().noneMatch(em -> em.matches(relToRoot))
 220                         && suffixes.contains(Util.fileSuffix(file))) {
 221 
 222                     // TODO: Test this.
 223                     Source existing = foundFiles.get(file);
 224                     if (existing != null) {
 225                         throw new IOException("You have already added the file "+file+" from "+existing.file().getPath());
 226                     }
 227                     existing = currentModule.lookupSource(file.toString());
 228                     if (existing != null) {
 229 
 230                             // Oops, the source is already added, could be ok, could be not, lets check.
 231                             if (inLinksrc) {
 232                                 // So we are collecting sources for linking only.
 233                                 if (existing.isLinkedOnly()) {
 234                                     // Ouch, this one is also for linking only. Bad.
 235                                     throw new IOException("You have already added the link only file " + file + " from " + existing.file().getPath());
 236                                 }
 237                                 // Ok, the existing source is to be compiled. Thus this link only is redundant
 238                                 // since all compiled are also linked to. Continue to the next source.
 239                                 // But we need to add the source, so that it will be visible to linking,
 240                                 // if not the multi core compile will fail because a JavaCompiler cannot
 241                                 // find the necessary dependencies for its part of the source.
 242                                 foundFiles.put(file.toString(), existing);
 243                             } else {
 244                                 // We are looking for sources to compile, if we find an existing to be compiled
 245                                 // source with the same name, it is an internal error, since we must
 246                                 // find the sources to be compiled before we find the sources to be linked to.
 247                                 throw new IOException("Internal error: Double add of file " + file + " from " + existing.file().getPath());
 248                             }
 249 
 250                     } else {


< prev index next >