/** * Scan all output dirs for artifacts and remove those files (artifacts?) that are not recognized * as such, in the javac_state file. */ public void removeUnidentifiedArtifacts() { Set<File> allKnownArtifacts = new HashSet<>(); for (Package pkg : prev.packages().values()) { for (File f : pkg.artifacts().values()) { allKnownArtifacts.add(f); } } // Do not forget about javac_state.... allKnownArtifacts.add(javacState); for (File f : binArtifacts) { if (!allKnownArtifacts.contains(f) && !options.isUnidentifiedArtifactPermitted(f.getAbsolutePath())) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } for (File f : headerArtifacts) { if (!allKnownArtifacts.contains(f)) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } for (File f : gensrcArtifacts) { if (!allKnownArtifacts.contains(f)) { Log.debug("Removing " + f.getPath() + " since it is unknown to the javac_state."); f.delete(); } } }
/** Recursively delete a directory and all its contents. */ private void deleteContents(File dir) { if (dir != null && dir.exists()) { for (File f : dir.listFiles()) { if (f.isDirectory()) { deleteContents(f); } if (!options.isUnidentifiedArtifactPermitted(f.getAbsolutePath())) { Log.debug("Removing " + f.getAbsolutePath()); f.delete(); } } } }