ZipMetadata archive = new ZipMetadata(); archive.setName(archiveName); archive.setFilePointer(entryOutput); archive.setRelativePath(relativePath); parent.getNestedArchives().add(archive); archive.setArchiveMeta(parent); LOG.trace("Created archive: " + archive.toString());
public boolean isExclusivelyKnownArchive(ZipMetadata archive) { String extension = archive.getFilePointer().getAbsolutePath(); extension = StringUtils.substringAfterLast(extension, "."); Enumeration<?> e = archive.getZipFile().entries(); LOG.debug("Known Package: " + archive.getName() + "; Vendor: " + vendor); exclusivelyKnown = true; archive.getDecorations().add(vr);
public ZipMetadata process(File outputDirectory, File targetArchive) { // Unzip ZipMetadata archiveMeta; LOG.info("Processing: " + targetArchive.getName()); try { ZipFile zf = new ZipFile(targetArchive); archiveMeta = recursiveExtractor.recursivelyExtract(zf); } catch (Exception e) { LOG.error("Error unzipping file: " + targetArchive.getPath(), e); return null; } // Flatten List<ZipMetadata> archiveMetas = new LinkedList<ZipMetadata>(); unfoldRecursion(archiveMeta, archiveMetas); int i = 1; int j = archiveMetas.size(); // Process the flattened list. for (ZipMetadata archive : archiveMetas) { LOG.info("Interrogating (" + i + " of " + j + "): " + archive.getRelativePath()); File archiveOutputDirectory = new File(outputDirectory + File.separator + archive.getRelativePath()); // Using toString()! archive.setArchiveOutputDirectory(archiveOutputDirectory); decoratorPipeline.processMeta(archive); i++; } // Delete the extracted files and return the "tree" metadata. recursiveExtractor.releaseTempFiles(); return archiveMeta; }
protected void recursivelyCollectRequiredProvided(ZipMetadata meta, Map<String, GraphableClz> provided) { try { ZipEntry entry; Enumeration<?> e = meta.getZipFile().entries(); // locate a random class entry... while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); if (StringUtils.endsWith(entry.getName(), ".class")) { String className = extractClassName(entry.getName()); Set<String> required = extractImports(meta.getZipFile(), entry); ApplicationClz cg = new ApplicationClz(meta, className, required); provided.put(className, cg); } } } catch (Exception e) { LOG.error("Exception getting JDK version.", e); } for(ArchiveMetadata child : meta.getNestedArchives()) { ZipMetadata cast = (ZipMetadata) child; this.recursivelyCollectRequiredProvided(cast, provided); } }
for (AbstractDecoration result : meta.getDecorations()) { if (result instanceof PomVersion) { LOG.debug("Already has version result: " + result.toString()); return; LOG.info("No Version Found: " + meta.getRelativePath() + "; trying Maven Central"); if (LOG.isDebugEnabled()) { LOG.debug("SHA1: " + sha1Hash); ClientHttpResponse resp = pomRequest.execute(); String outputDir = meta.getArchiveOutputDirectory().getAbsolutePath() + File.separator + "maven-remote"; FileUtils.forceMkdir(new File(outputDir)); LOG.info("Fetched remote POM for: " + meta.getName()); LOG.error("Exception creating API call to Central Repo for POM: " + meta.getName() + "; skipping.", e);
try { ZipEntry entry; Enumeration<?> e = meta.getZipFile().entries(); DataInputStream in = null; try { in = new DataInputStream(meta.getZipFile().getInputStream(entry)); meta.getDecorations().add(vr);
Enumeration<?> e = archive.getZipFile().entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); LOG.error("Exception processing archive: " + archive.getName(), e);
protected Set<String> extractImports(ZipEntryMetadata archiveEntry) { try { // otherwise, load the class and get its imports. //TODO: make this work for directorymeta too. ZipMetadata zipMeta = (ZipMetadata)archiveEntry.getArchiveMeta(); ZipFile zipFile = zipMeta.getZipFile(); ZipEntry entry = archiveEntry.getZipEntry(); CtClass ctClz = new ClassPool().makeClass(zipFile.getInputStream(entry)); if (LOG.isDebugEnabled()) { for (String clz : ctClz.getClassFile2().getInterfaces()) { LOG.debug("Interfaces: " + clz); } LOG.debug("Super Class: " + ctClz.getClassFile2().getSuperclass()); } Set<String> clzImports = new HashSet<String>(castList(String.class, ctClz.getRefClasses())); return clzImports; } catch (Exception e) { LOG.error(e); return null; } }
/** * Fills the collection archiveMetas from the "tree" given in base. */ protected void unfoldRecursion(ZipMetadata base, Collection<ZipMetadata> archiveMetas) { for (ArchiveMetadata meta : base.getNestedArchives()) { ZipMetadata zipMeta = (ZipMetadata)meta; unfoldRecursion(zipMeta, archiveMetas); } archiveMetas.add(base); }
public boolean isKnownVendor(ZipMetadata archive, String pkg) { for (Pattern cbl : knownPackages.keySet()) { if (cbl.matcher(pkg).find()) { if (LOG.isDebugEnabled()) { LOG.debug("Found known package: " + pkg + " matching: " + cbl.pattern()); } String vendor = knownPackages.get(cbl); VendorResult vr = new VendorResult(); vr.setDescription(vendor); archive.getDecorations().add(vr); return true; } } return false; }
LOG.info("Prepared ZipMetadata: " + arch.getRelativePath()); recursivelyExtract(arch, zf, new File(StringUtils.substringBeforeLast(zf.getName(), File.separator)));
ZipFile zipFile = zipMeta.getZipFile(); ZipEntry entry = archiveEntry.getZipEntry();