public JarAnalyzer getJarAnalyzerByPath(String _jar_path){ if(!this.jarAnalyzerCache.containsKey(_jar_path)){ try { final JarAnalyzer ja = new JarAnalyzer(); ja.analyze(Paths.get(_jar_path).toFile()); this.jarAnalyzerCache.put(_jar_path, ja); } catch(FileAnalysisException e) { TouchPointCollector.getLog().error("Error while reading JAR file from URL [" + _jar_path + "]: " + e.getMessage()); } } return this.jarAnalyzerCache.get(_jar_path); }
@Override public void analyze(final File _file) throws FileAnalysisException { try { this.jar = new JarFile(_file, false, java.util.zip.ZipFile.OPEN_READ); this.jarWriter = new JarWriter(_file.toPath()); this.url = _file.getAbsolutePath().toString(); } catch (IllegalStateException e) { log.error("IllegalStateException when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (IOException e) { log.error("IOException when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (Exception e) { log.error("Exception when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } }
public ArchiveFixContainmentCheck(String _b, Path _p) throws IOException, IllegalArgumentException { if(_p==null) throw new IllegalArgumentException("Filesystem path to JAR is required"); try { this.ja = new JarAnalyzer(); this.ja.analyze(_p.toFile()); ArchiveFixContainmentCheck.cp.appendClassPath(this.ja.getPath().toString()); } catch (NotFoundException e) { throw new IllegalArgumentException("JAR cannot be added to classpath: " + e.getMessage()); } catch (FileAnalysisException e) { throw new IllegalArgumentException("JAR cannot be added to classpath: " + e.getMessage()); } this.bugId = _b; } /*
throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (IOException e) { log.error("IOException when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (Exception e) { log.error("Exception when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e);
private synchronized String getShaFromCachedJarAnalyzer(URL _jar_url) { // Build the JarAnalyzer (if possible) and put it into the cache if(!this.jarAnalyzersCache.containsKey(_jar_url)) { JarAnalyzer ja = null; try { final URI uri = _jar_url.toURI(); final File file = Paths.get(uri).toFile(); ja = new JarAnalyzer(); ja.analyze(file); } catch (InvalidPathException ex) { log.error("Invalid path [" + _jar_url + "]: " + ex.getMessage(), ex); } catch (FileAnalysisException ex) { log.error("Error analyzing the JAR at [" + _jar_url + "]: " + ex.getMessage(), ex); } catch(java.nio.file.FileSystemNotFoundException fsnfe) { log.error("File system not found for [" + _jar_url + "]: " + fsnfe.getMessage(), fsnfe); } catch (URISyntaxException e) { log.error("URI syntax exception for [" + _jar_url + "]: " + e.getMessage(), e); } this.jarAnalyzersCache.put(_jar_url, ja); // ja can be null } // Return the digest or null (if the JarAnalyzer could not be built) final JarAnalyzer ja = this.jarAnalyzersCache.get(_jar_url); if(ja!=null) return ja.getSHA1(); else return null; } }
@Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if(this.constructs==null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException("Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }
log.error("Error when creating file analyzer for [" + _file.toString() + "]: " + e.getMessage(), e);
throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (IOException e) { log.error("IOException when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e); } catch (Exception e) { log.error("Exception when analyzing file [" + _file + "]: " + e.getMessage()); throw new FileAnalysisException("Error when analyzing file [" + _file + "]: " + e.getMessage(), e);
JavaSignatureFactory.log.error(e.getMessage()); } catch (FileAnalysisException e) { JavaSignatureFactory.log.error(e.getMessage()); JavaSignatureFactory.log.error(e.getMessage()); } catch (FileAnalysisException e) { JavaSignatureFactory.log.error(e.getMessage());
throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("IO exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e);
/** * Filter the given packages according to whether the artifact name is (or is not, depending on the boolean flag) contained in the given filter. * @param _packages * @param _filter * @param _include * @return */ public static Set<PipInstalledPackage> filterUsingArtifact(Set<PipInstalledPackage> _packages, StringList _filter, boolean _include) { final Set<PipInstalledPackage> r = new HashSet<PipInstalledPackage>(); for(PipInstalledPackage p: _packages) { try { if(_include) { if(_filter.contains(p.getLibrary().getLibraryId().getArtifact())) r.add(p); } else { if(!_filter.contains(p.getLibrary().getLibraryId().getArtifact())) r.add(p); } } catch (FileAnalysisException e) { log.error("Error getting library ID of package [" + p + "]: " + e.getMessage(), e); } } return r; }
throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("IO exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e);
this.getLog().error("Error while reading JAR file from URL [" + jar_path + "]: " + e.getMessage());
throw new FileAnalysisException(e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("IO exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (RuntimeException e) { throw new FileAnalysisException("Runtime exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e);
FileComparator.log.error("Error while comparing defective and fixed version: " + e.getMessage(), e); FileComparator.log.error("Error while comparing defective and fixed version: " + e.getMessage(), e);
public Map<ConstructId, Construct> getConstructs(InputStream m) throws FileAnalysisException, IOException, RecognitionException { final ANTLRInputStream input = new ANTLRInputStream(m); final Python3Lexer lexer = new Python3Lexer(input); final CommonTokenStream tokens = new CommonTokenStream(lexer); final Python3Parser parser = new Python3Parser(tokens); final ParseTree root = parser.file_input(); final ParseTreeWalker walker = new ParseTreeWalker(); try { walker.walk(this, root); } catch(IllegalStateException ise) { throw new FileAnalysisException(ise.getMessage(), ise); } // Update module body after the parsing of the entire file if(this.stmts!=null && this.stmts.size()>0) { final StringBuffer b = new StringBuffer(); for(String stmt: this.stmts) if(!stmt.trim().equals("")) b.append(stmt); this.constructs.get(this.module).setContent(b.toString()); } return this.constructs; }
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
public Map<ConstructId, Construct> getConstructs(InputStream m) throws FileAnalysisException, IOException, RecognitionException { final ANTLRInputStream input = new ANTLRInputStream(m); final Python335Lexer lexer = new Python335Lexer(input); final CommonTokenStream tokens = new CommonTokenStream(lexer); final Python335Parser parser = new Python335Parser(tokens); final ParseTree root = parser.file_input(); final ParseTreeWalker walker = new ParseTreeWalker(); try { walker.walk(this, root); } catch(IllegalStateException ise) { throw new FileAnalysisException("Parser error", ise); } // Update module body after the parsing of the entire file if(this.stmts!=null && this.stmts.size()>0) { final StringBuffer b = new StringBuffer(); for(String stmt: this.stmts) if(!stmt.trim().equals("")) b.append(stmt); this.constructs.get(this.module).setContent(b.toString()); } return this.constructs; }
log.error(e.getMessage(), e); app_constructs.addAll(fa.getConstructs().keySet()); } catch (FileAnalysisException e) { log.error(e.getMessage(), e); log.error(e.getMessage(), e); log.error(e.getMessage(), e);