/** * Indexes all of the discovered artifacts using the given directory as the base directory * (for determining canonical archive paths). * @param workDir */ public void index(File workDir) { for (DiscoveredArtifact artifact : getArtifacts()) { String archivePath = determineArchivePath(workDir, artifact.getFile()); artifact.setArchivePath(archivePath); index.put(archivePath, artifact); } }
/** * Iterates through all of the entries in the JAR and determines which of them will * be included in the S-RAMP archive. Returns the collection of artifacts that should be * included. */ private DiscoveredArtifacts discoverArtifacts() { DiscoveredArtifacts artifacts = new DiscoveredArtifacts(); Collection<File> files = FileUtils.listFiles(jarWorkDir, null, true); for (File file : files) { CandidateArtifact candidate = new CandidateArtifact(file, jarWorkDir); if (this.artifactFilter.accepts(candidate)) { artifacts.add(file); } } return artifacts; }
/** * @see java.lang.Iterable#iterator() */ @Override public Iterator<DiscoveredArtifact> iterator() { return getArtifacts().iterator(); }
/** * Creates an S-RAMP archive from this JAR. * @return an S-RAMP archive * @throws ZipToSrampArchiveException */ public SrampArchive createSrampArchive() throws ZipToSrampArchiveException { this.artifactFilter.setContext(this.context); this.metaDataFactory.setContext(this.context); DiscoveredArtifacts discoveredArtifacts = discoverArtifacts(); discoveredArtifacts.index(jarWorkDir); generateMetaData(discoveredArtifacts); try { SrampArchive archive = new SrampArchive(); for (DiscoveredArtifact artifact : discoveredArtifacts) { String path = artifact.getArchivePath(); archive.addEntry(path, artifact.getMetaData(), artifact.getContent()); } return archive; } catch (Exception e) { throw new ZipToSrampArchiveException(e); } }
/** * Adds a candidate artifact to the set of collected (accepted/discovered) artifacts. * @param candidate */ public void add(File file) { DiscoveredArtifact artifact = new DiscoveredArtifact(file); getArtifacts().add(artifact); }