public void populateFromBundle()

in taverna-robundle/src/main/java/org/apache/taverna/robundle/manifest/Manifest.java [294:373]


	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))
					// Don't aggregate the manifests
					return CONTINUE;

				// super.visitFile(file, attrs);
				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)
					// Don't override if already set
					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)
				/*
				 * Don't remove 'virtual' resources, only aggregations that went
				 * to files
				 */
				aggregates.remove(preExisting);
		}
	}