Manifest { public void populateFromBundle() throws IOException { final Set<Path> potentiallyEmptyFolders = new LinkedHashSet<>(); final Set<URI> existingAggregationsToPrune = new HashSet<>( aggregates.keySet()); walkFileTree(bundle.getRoot(), new SimpleFileVisitor<Path>() { @SuppressWarnings("deprecation") @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { super.postVisitDirectory(dir, exc); if (potentiallyEmptyFolders.remove(dir)) { URI uri = relativeToBundleRoot(dir.toUri()); existingAggregationsToPrune.remove(uri); PathMetadata metadata = aggregates.get(uri); if (metadata == null) { metadata = new PathMetadata(); aggregates.put(uri, metadata); } metadata.setFile(dir); metadata.setFolder(dir.getParent()); metadata.setProxy(); metadata.setCreatedOn(getLastModifiedTime(dir)); potentiallyEmptyFolders.remove(dir.getParent()); return CONTINUE; } return CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.startsWith(RO) || dir.startsWith(META_INF)) return SKIP_SUBTREE; potentiallyEmptyFolders.add(dir); potentiallyEmptyFolders.remove(dir.getParent()); return CONTINUE; } @SuppressWarnings("deprecation") @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { potentiallyEmptyFolders.remove(file.getParent()); if (file.startsWith(MIMETYPE)) return CONTINUE; if (manifest.contains(file)) return CONTINUE; URI uri = relativeToBundleRoot(file.toUri()); existingAggregationsToPrune.remove(uri); PathMetadata metadata = aggregates.get(uri); if (metadata == null) { metadata = new PathMetadata(); aggregates.put(uri, metadata); } metadata.setFile(file); if (metadata.getMediatype() == null) metadata.setMediatype(guessMediaType(file)); metadata.setFolder(file.getParent()); metadata.setProxy(); metadata.setCreatedOn(getLastModifiedTime(file)); potentiallyEmptyFolders.remove(file.getParent()); return CONTINUE; } }); for (URI preExisting : existingAggregationsToPrune) { PathMetadata meta = aggregates.get(preExisting); if (meta.getFile() != null) aggregates.remove(preExisting); } } Manifest(Bundle bundle); static FileTime now(); List<PathMetadata> getAggregates(); PathMetadata getAggregation(Path file); PathMetadata getAggregation(URI uri); List<PathAnnotation> getAnnotations(); @JsonIgnore Optional<PathAnnotation> getAnnotation(URI annotation); @JsonIgnore List<PathAnnotation> getAnnotations(final URI about); @JsonIgnore List<PathAnnotation> getAnnotations(Path about); List<Agent> getAuthoredBy(); FileTime getAuthoredOn(); @JsonIgnore URI getBaseURI(); @JsonIgnore Bundle getBundle(); List<URI> getConformsTo(); @JsonProperty(value = "@context") List<Object> getContext(); Agent getCreatedBy(); FileTime getCreatedOn(); URI getRetrievedFrom(); Agent getRetrievedBy(); FileTime getRetrievedOn(); List<String> getGraph(); List<Path> getHistory(); URI getId(); List<Path> getManifest(); String guessMediaType(Path file); void populateFromBundle(); URI relativeToBundleRoot(URI uri); @SuppressWarnings("deprecation") void setAggregates(List<PathMetadata> aggregates); void setAnnotations(List<PathAnnotation> annotations); void setAuthoredBy(List<Agent> authoredBy); void setAuthoredOn(FileTime authoredOn); void setBundle(Bundle bundle); void setConformsTo(List<URI> conformsTo); void setCreatedBy(Agent createdBy); void setCreatedOn(FileTime createdOn); void setRetrievedFrom(URI retrievedFrom); void setRetrievedBy(Agent retrievedBy); void setRetrievedOn(FileTime retrievedOn); void setGraph(List<String> graph); void setHistory(List<Path> history); void setId(URI id); void setManifest(List<Path> manifest); void writeAsCombineManifest(); Path writeAsJsonLD(); Path writeAsODFManifest();  }
@Test public void populateFromBundle() throws Exception { Path r = bundle.getRoot(); URI base = r.toUri(); Manifest manifest = new Manifest(bundle); manifest.populateFromBundle(); List<String> uris = new ArrayList<>(); for (PathMetadata s : manifest.getAggregates()) { uris.add(s.getFile().toString()); Path path = s.getFile(); assertNotNull(path.getParent()); assertEquals(path.getParent(), s.getBundledAs().getFolder()); if (s.getFile().equals(URI.create("/f/nested/empty/"))) { continue; } assertEquals("urn", s.getProxy().getScheme()); UUID.fromString(s.getProxy().getSchemeSpecificPart() .replace("uuid:", "")); assertEquals(s.getCreatedOn(), Files.getLastModifiedTime(path)); } assertFalse(uris.contains("/mimetype")); assertFalse(uris.contains("/META-INF")); assertTrue(uris.remove("/hello.txt")); assertTrue(uris.remove("/f/file1.txt")); assertTrue(uris.remove("/f/file2.txt")); assertTrue(uris.remove("/f/file3.txt")); assertTrue(uris.remove("/f/nested/file1.txt")); assertTrue(uris.remove("/f/nested/empty")); assertTrue(uris.isEmpty()); }