protected boolean buildVendorResult(ArchiveMetadata meta) { for (AbstractDecoration result : meta.getDecorations()) { if (result instanceof VendorResult) { return true; } } return false; }
public DirectoryMetadata recursivelyExtract() { DirectoryMetadata dirMeta = new DirectoryMetadata(); dirMeta.setFilePointer(start); dirMeta.setName(start.getName()); dirMeta.setRelativePath("windup"); populateChildren(dirMeta); return dirMeta; }
protected File generateScorecardName(ArchiveMetadata archive, File reportDirectory) { Validate.notNull(archive, "Archive is required, but null."); Validate.notNull(reportDirectory, "Report directory is required, but null."); String scorecardName = "scorecard-" + StringUtils.replace(archive.getName(), ".", "-") + ".xlsx"; String outputName = reportDirectory.getAbsolutePath() + File.separator + scorecardName; File output = new File(outputName); return output; }
protected void populateChildren(DirectoryMetadata parent) { File[] files = parent.getFilePointer().listFiles(); if(LOG.isDebugEnabled()) { LOG.debug(files.length + " Children of "+parent.getFilePointer().getAbsolutePath()); } for(File file : files) { if(file.isDirectory()) { if(file.isHidden()) { LOG.debug("Skipping hidden directory: "+file.getAbsolutePath()); continue; } DirectoryMetadata dirMeta = new DirectoryMetadata(); parent.getNestedArchives().add(dirMeta); dirMeta.setArchiveMeta(parent); dirMeta.setFilePointer(file); dirMeta.setRelativePath(generateRelativePath(file)); dirMeta.setName(file.getName()); if(LOG.isTraceEnabled()) { LOG.trace("Added child: "+dirMeta.getRelativePath()); } populateChildren(dirMeta); } } }
tempMeta.setFilePointer(targetFile); DirectoryMetadata dirMeta = new DirectoryMetadata(); dirMeta.setRelativePath(targetFile.getParentFile().getPath()); tempMeta.setArchiveMeta(dirMeta); for(FileMetadata archiveEntryMeta : tempMeta.getArchiveMeta().getEntries()) { if(archiveEntryMeta.getFilePointer().equals(tempMeta.getFilePointer())) { result = archiveEntryMeta;
protected void unfoldRecursion(DirectoryMetadata base, Collection<DirectoryMetadata> archiveMetas) { if(LOG.isDebugEnabled()) { LOG.debug("Directory: "+base.getName()+" Children: "+base.getNestedArchives().size()+" Path: "+base.getFilePointer().getAbsolutePath()); } for (ArchiveMetadata meta : base.getNestedArchives()) { DirectoryMetadata child = (DirectoryMetadata)meta; unfoldRecursion(child, archiveMetas); } archiveMetas.add(base); }
protected void generateReport(ArchiveMetadata archive, File reportDirectory) { if (archive.getName() == null) { LOG.info("Processing reports for: " + archive.getFilePointer().toString()); } else { LOG.info("Processing reports for: "+archive.getName()); } if( this.reporters != null ) { for(Reporter reporter : this.reporters) { reporter.process(archive, reportDirectory); } } if( this.reporters == null || this.reporters.size() == 0 ){ LOG.warn("No reporters are currently registered."); } LOG.info("Reporting complete."); }
@Override public void processMeta(XmlMetadata fileMeta) { Document document = fileMeta.getParsedDocument(); if (document == null) { if (LOG.isDebugEnabled()) { LOG.debug("Document was null. Problem parsing: " + fileMeta.getFilePointer().getAbsolutePath()); } // attach the bad file so we see it in the reports... fileMeta.getArchiveMeta().getEntries().add(fileMeta); return; } super.processMeta(fileMeta); }
protected String buildTitle(T meta, File rootDirectory) { String title = StringUtils.removeStart(meta.getFilePointer().getAbsolutePath(), rootDirectory.getAbsolutePath()); title = StringUtils.replace(title, "\\", "/"); title = StringUtils.removeStart(title, "/"); if(meta instanceof FileMetadata) { String starter = ((FileMetadata)meta).getArchiveMeta().getRelativePath(); if(LOG.isDebugEnabled()) { LOG.debug("Removing: " + starter + " from "+title); } title = StringUtils.removeStart(title, starter); } title = StringUtils.removeStart(title, "/"); return title; }
private void unwind(ArchiveMetadata result, List<ArchiveMetadata> unwound) { for(ArchiveMetadata meta : result.getNestedArchives()) { unwind(meta, unwound); } unwound.add(result); }
/** * 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; }
protected boolean isActive(XmlMetadata file) { for (AbstractDecoration dr : file.getArchiveMeta().getDecorations()) { if (dr instanceof PomVersion) { LOG.debug("Already has version result: " + dr.toString()); return false; } } return true; }
@Override public void processMeta(T fileMeta) { File file = fileMeta.getFilePointer(); if (LOG.isTraceEnabled()) { LOG.trace("Processing Extension: " + file.getAbsolutePath()); } decoratorPipeline.processMeta(fileMeta); if (isOfInterest(fileMeta)) { // add it to it's parent's results. fileMeta.getArchiveMeta().getEntries().add(fileMeta); } }
@Override public ResourceReport toResourceReport(FileMetadata meta, File reportDirectory, ArchiveReport parent) { ArchiveReport report = new ArchiveReport(); populateResourceData(meta, reportDirectory, report); report.setTitle(report.getRelativePathFromRoot()); ArchiveMetadata am = (ArchiveMetadata)meta; report.setVendorResult(buildVendorResult(am)); report.setRelativePathFromRoot(am.getRelativePath()); return report; }
@Override public void processMeta(XmlMetadata file) { Document doc = file.getParsedDocument(); try { String description = extractStringValue(xPath, doc); if (StringUtils.isNotBlank(description)) { Summary result = new Summary(); result.setDescription(description); // add the link to the archive. file.getArchiveMeta().getDecorations().add(result); } } catch (XPathExpressionException e) { LOG.error("Exception running xpath expression.", e); } }
@Override public void processMeta(XmlMetadata file) { Document doc = file.getParsedDocument(); try { String link = extractStringValue(linkXPath, doc); if (StringUtils.isNotBlank(link)) { Link result = new Link(); result.setLink(link); result.setDescription("Project Site"); // add the link to the archive. file.getArchiveMeta().getDecorations().add(result); } } catch (XPathExpressionException e) { LOG.error("Exception running xpath expression.", e); } }
@Override public void processMeta(ManifestMetadata file) { // Look for default description information. String description = extractValue(file.getManifest(), descriptionPriority); if (description == null) { return; } // if it exists, cleanse it. description = cleanseValue(description); if (StringUtils.isNotBlank(description)) { Summary vr = new Summary(); vr.setDescription(description); file.getArchiveMeta().getDecorations().add(vr); return; } }
@Override public void processMeta(ManifestMetadata file) { // Look for default description information. String link = extractValue(file.getManifest(), linkPriority); if (link == null) { return; } // if it exists, cleanse it. link = cleanseValue(link); if (StringUtils.isNotBlank(link)) { Link vr = new Link(); vr.setDescription("Project Site"); vr.setLink(link); file.getArchiveMeta().getDecorations().add(vr); return; } }
protected void createVersionResult(XmlMetadata file, String groupId, String artifactId, String versionId, String name) { PomVersion vr = new PomVersion(); // default to artifact ID if name isn't provided. if (StringUtils.isBlank(name)) { name = artifactId; } vr.setName(name); vr.setVersion(versionId); vr.setArchetypeId(artifactId); vr.setGroupId(groupId); file.getArchiveMeta().getDecorations().add(vr); if(file.getArchiveMeta() instanceof ZipMetadata) { ZipMetadata zip = (ZipMetadata)file.getArchiveMeta(); knownArchiveProfiler.isKnownVendor(zip, groupId); } }