/** * Returns the union of constructs of all {@link FileAnalyzer}s created when searching recursivly in the directory. */ @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if(this.constructs==null) { this.constructs = new TreeMap<ConstructId, Construct>(); for(FileAnalyzer fa: this.analyzers) { try { this.constructs.putAll(fa.getConstructs()); } catch(RuntimeException e) { DirAnalyzer.log.error("Error getting constructs from [" + fa + "]: " + e, e); } } DirAnalyzer.log.info("Constructs found: [" + this.constructs.size() + "]"); } return this.constructs; }
@Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if(this.constructs==null) { analyzer = PythonFileAnalyzer.createAnalyzer(this.file); analyzer.analyze(this.file); this.constructs = analyzer.getConstructs(); } return analyzer.getConstructs(); }
public Set<FileAnalyzer> getNestedArchives() { if(this.fileAnalyzer!=null && !(this.fileAnalyzer instanceof DirAnalyzer)) { return this.fileAnalyzer.getChilds(true); } else { return null; } }
for (ConstructId key : this.defAnalyzer.getConstructs().keySet()) { if(this.fixAnalyzer!=null && this.fixAnalyzer.containsConstruct(key)) { if(!this.defAnalyzer.getConstruct(key).equals(this.fixAnalyzer.getConstruct(key))) { final ConstructChange c = new ConstructChange(this.repo, this.repoPath, this.defAnalyzer.getConstruct(key), this.fixAnalyzer.getConstruct(key), this.revision, this.timeStamp); this.changes.add(new ConstructChange(this.repo, this.repoPath, this.defAnalyzer.getConstruct(key), null, this.revision, this.timeStamp)); for (ConstructId key : this.fixAnalyzer.getConstructs().keySet()) { if(this.defAnalyzer!=null && this.defAnalyzer.containsConstruct(key)) { if(!this.fixAnalyzer.getConstruct(key).equals(this.defAnalyzer.getConstruct(key))) { final ConstructChange chg = new ConstructChange(this.repo, this.repoPath, this.defAnalyzer.getConstruct(key), this.fixAnalyzer.getConstruct(key), this.revision, this.timeStamp); this.changes.add(new ConstructChange(this.repo, this.repoPath, null, this.fixAnalyzer.getConstruct(key), this.revision, this.timeStamp));
@Override public FileAnalyzer fetch(Artifact _key) throws CacheException { // The artifact whose JAR is to be downloaded _key.setClassifier(null); RepositoryDispatcher r = new RepositoryDispatcher(); Path file = null; try { file = r.downloadArtifact(_key); } catch (IllegalArgumentException ie) { throw new CacheException("Artifact [" + _key + "] not ready for download",ie); } catch (Exception e) { throw new CacheException("Cannot download ["+ _key + "]",e); } FileAnalyzer fa = new JarAnalyzer(); try{ if (fa.canAnalyze(file.toFile())) { fa.analyze(file.toFile()); } else { fa = new PythonArchiveAnalyzer(); fa.analyze(file.toFile()); fa.getConstructs(); } }catch (FileAnalysisException fe){ throw new CacheException("Cannot Analyze file ["+ file.toString() + "]",fe); } return fa; }
if(fa.hasChilds()) analyzers.addAll(fa.getChilds(true)); if(!(fa instanceof DirAnalyzer)) analyzers.add(fa); final Set<ConstructId> constructs = JavaId.filter(fa2.getConstructs().keySet(), this.appPrefixes); if(constructs.size()==fa2.getConstructs().size()) { log.info(StringUtil.padLeft(++count, 4) + " [" + StringUtil.padLeft(ja.getFileName(), 30) + "]: All [" + fa2.getConstructs().size() + "] constructs matched prefix(es): Constructs added to application, file NOT added as dependency"); log.info(StringUtil.padLeft(++count, 4) + " [" + StringUtil.padLeft(ja.getFileName(), 30) + "]: [" + constructs.size() + "/" + fa2.getConstructs().size() + "] constructs matched prefix(es): Constructs added to application, file added as dependency"); dep_files.put(ja.getPath(), ja); log.info(StringUtil.padLeft(++count, 4) + " [" + StringUtil.padLeft(ja.getFileName(), 30) + "]: None of the [" + fa2.getConstructs().size() + "] constructs matched prefix(es): No constructs added to application, file added as dependency"); dep_files.put(ja.getPath(), ja); log.info(StringUtil.padLeft(++count, 4) + " [" + StringUtil.padLeft(ja.getFileName(), 30) + "]: Filename matches pattern(s), all of its [" + fa2.getConstructs().size() + "] constructs added to application"); app_constructs.addAll(fa2.getConstructs().keySet()); app_constructs.addAll(fa2.getConstructs().keySet()); app_constructs.addAll(fa.getConstructs().keySet()); } catch (FileAnalysisException e) { log.error(e.getMessage(), e);
if(jfa.containsConstruct(jid)) { final String source_code = jfa.getConstruct(jid).getContent(); response.getWriter().print(source_code); response.flushBuffer();
final ServiceLoader<FileAnalyzer> loader = ServiceLoader.load(FileAnalyzer.class); for(FileAnalyzer l: loader) { if(l.canAnalyze(_file)) { try { fa = l; ((DirAnalyzer)fa).setExtensionFilter(_exts); fa.analyze(_file); } catch (FileAnalysisException e) { log.error("Error when creating file analyzer for [" + _file.toString() + "]: " + e.getMessage(), e);
final Construct c = fa.getConstruct(JavaId.toCoreType(_cid)); final Construct c = fa.getConstruct(JavaId.toCoreType(_cid));
if(jfa.containsConstruct(jid)) { final String source_code = jfa.getConstruct(jid).getContent(); response.getWriter().print(source_code); response.flushBuffer();
/** * Potential refactoring: Delete constructor (or make private), see proposal of prev. constructor. * @param _def * @param _fix * @param _rev * @param _repo_path * @throws IOException */ public FileComparator(File _def, File _fix, String _rev, String _repo, String _repo_path, String _time_stamp) throws IOException, FileAnalysisException { if(_def==null && _fix==null) throw new IllegalArgumentException("The comparator requires at least one file as input, either the defective file, the fixed file or both"); this.revision = _rev; this.repo = _repo; this.repoPath = _repo_path; this.timeStamp = _time_stamp; if(_def!=null) { this.def = _def; this.defAnalyzer = FileAnalyzerFactory.buildFileAnalyzer(_def); this.defAnalyzer.getConstructs(); } if(_fix!=null) { this.fix = _fix; this.fixAnalyzer = FileAnalyzerFactory.buildFileAnalyzer(_fix); this.fixAnalyzer.getConstructs(); } }
@Override public Set<FileAnalyzer> getChilds(boolean _recursive) { final Set<FileAnalyzer> nested_fa = new HashSet<FileAnalyzer>(); if(!_recursive) { nested_fa.addAll(this.nestedAnalyzers); } else { for(FileAnalyzer fa: this.nestedAnalyzers) { nested_fa.add(fa); final Set<FileAnalyzer> nfas = fa.getChilds(true); if(nfas!=null && !nfas.isEmpty()) nested_fa.addAll(nfas); } } return nested_fa; }
/** * Identifies all programming constructs of a given revision number. * @param _revision * @return * @throws Exception */ public Map<ConstructId,Construct> identifySourceConstructs(String _rev) throws Exception { if(!(this.sourceRev.equals(_rev)) || this.sourceConstructs==null) { // The revision for which the sources are analyzed this.sourceRev = _rev; // Check out the entire SVN final Path p = this.vcs.checkout(_rev); // Instantiate SrcAnalyzer (using the dir to which the checkout happened) to crawl all files this.sourceConstructs = FileAnalyzerFactory.buildFileAnalyzer(p.toFile()); } return this.sourceConstructs.getConstructs(); }
@Override public Set<FileAnalyzer> getChilds(boolean _recursive) { final Set<FileAnalyzer> nested_fa = new HashSet<FileAnalyzer>(); if(!_recursive) { nested_fa.addAll(this.analyzers); } else { for(FileAnalyzer fa: this.analyzers) { nested_fa.add(fa); final Set<FileAnalyzer> nfas = fa.getChilds(true); if(nfas!=null && !nfas.isEmpty()) nested_fa.addAll(nfas); } } return nested_fa; }
this.fileAnalyzer = FileAnalyzerFactory.buildFileAnalyzer(this.downloadPath.toFile()); if(this.fileAnalyzer!=null) { this.constructs = this.fileAnalyzer.getConstructs(); log.info("Got [" + this.constructs.size() + "] constructs from downloaded file [" + this.downloadPath + "]"); if(this.eggFile!=null) { this.fileAnalyzer = FileAnalyzerFactory.buildFileAnalyzer(this.eggFile.toFile()); this.constructs = this.fileAnalyzer.getConstructs(); log.info("Got [" + this.constructs.size() + "] constructs from egg [" + this.eggFile + "]"); this.constructs = this.fileAnalyzer.getConstructs(); log.info("Got [" + this.constructs.size() + "] constructs from file [" + this.pyFile + "]"); this.constructs = this.fileAnalyzer.getConstructs(); log.info("Got [" + this.constructs.size() + "] constructs from directory [" + this.pyDir + "]");
final Set<com.sap.psr.vulas.ConstructId> constructs_in = fa.getConstructs().keySet(); final Set<com.sap.psr.vulas.shared.json.model.ConstructId> constructs_out = new TreeSet<ConstructId>(); for(com.sap.psr.vulas.ConstructId c: constructs_in) {
final Set<com.sap.psr.vulas.ConstructId> constructs_in = fa.getConstructs().keySet(); for (com.sap.psr.vulas.ConstructId c : constructs_in){ String aaa = c.getQualifiedName(); sign = (PythonConstructDigest)sf.createSignature(fa.getConstructs().get(c)); break;
log.info("Searching for Python constructs in search path [" + p + "] with filter [" + StringUtil.join(EXT_FILTER, ", ") + "]"); final FileAnalyzer da = FileAnalyzerFactory.buildFileAnalyzer(p.toFile(), EXT_FILTER); app_constructs.addAll(da.getConstructs().keySet());