@Test public void testFlaskOIDCConstructs() throws FileAnalysisException { final FileAnalyzer f1 = FileAnalyzerFactory.buildFileAnalyzer( new File("./src/test/resources/flask-oidc_e4ce5/flask_oidc/__init__.py")); final Map<ConstructId, Construct> c1 = f1.getConstructs(); final FileAnalyzer f2 = FileAnalyzerFactory.buildFileAnalyzer( new File("./src/test/resources/flask-oidc_f2ef8/flask_oidc/__init__.py")); final Map<ConstructId, Construct> c2 = f2.getConstructs(); assertEquals(c1.size(), c2.size()); }
@Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs.isEmpty()) { final List<String> inits = new ArrayList<String>(); boolean pre_processed = false; try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } pre_processed = true; } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream && pre_processed) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } } return constructs; }
PythonArchiveAnalyzer implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs.isEmpty()) { final List<String> inits = new ArrayList<String>(); boolean pre_processed = false; try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } pre_processed = true; } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream && pre_processed) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } } return constructs; } }
PythonArchiveAnalyzer implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs.isEmpty()) { final List<String> inits = new ArrayList<String>(); boolean pre_processed = false; try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } pre_processed = true; } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream && pre_processed) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } } return constructs; }  }
PythonArchiveAnalyzer implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs.isEmpty()) { final List<String> inits = new ArrayList<String>(); boolean pre_processed = false; try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } pre_processed = true; } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream && pre_processed) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } } return constructs; }  @Override String[] getSupportedFileExtensions(); @Override boolean canAnalyze(File _file); @Override void analyze(final File _file); Path getArchivePath(); String getDigest(); @Override Map<ConstructId, Construct> getConstructs(); Library getLibrary(); @Override boolean containsConstruct(ConstructId _id); @Override Construct getConstruct(ConstructId _id); @Override boolean hasChilds(); @Override Set<FileAnalyzer> getChilds(boolean _recursive); List<org.eclipse.steady.shared.json.model.ConstructId> getSharedConstructs(); }
PythonArchiveAnalyzer implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs.isEmpty()) { final List<String> inits = new ArrayList<String>(); boolean pre_processed = false; try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (this.isPackage(en.getName())) { inits.add(en.getName()); } } } } pre_processed = true; } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } try (InputStream is = this.getArchiveInputStream()) { if (is instanceof ZipInputStream && pre_processed) { ZipEntry en = null; while ((en = ((ZipInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } else if (is instanceof TarArchiveInputStream) { ArchiveEntry en = null; while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) { if (!en.isDirectory()) { if (en.getName().endsWith(".whl") || en.getName().endsWith(".egg") || en.getName().endsWith(".gz")) { final FileAnalyzer fa = DirAnalyzer.createAnalyzerForArchiveEntry(is, en.getName()); if (fa != null) this.nestedAnalyzers.add(fa); } else if (en.getName().endsWith(".py")) { final List<String> package_name = this.getPackageName(en.getName(), inits); PythonId pack = null; if (!package_name.isEmpty()) pack = new PythonId(null, PythonId.Type.PACKAGE, StringUtil.join(package_name, ".")); final String module_name = this.getModuleName(en.getName()); final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name); final byte[] py_bytes = FileUtil.readInputStream(is); final FileAnalyzer fa = PythonFileAnalyzer.createAnalyzer(new ByteArrayInputStream(py_bytes)); if (fa instanceof Python3FileAnalyzer) { ((Python3FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python3FileAnalyzer) fa).getConstructs(new ByteArrayInputStream(py_bytes))); } else if (fa instanceof Python335FileAnalyzer) { ((Python335FileAnalyzer) fa).setContext(module, pack); this.constructs.putAll( ((Python335FileAnalyzer) fa) .getConstructs(new ByteArrayInputStream(py_bytes))); } } } } } } catch (IOException e) { log.error( "IOException analyzing Python archive [" + this.archive.getAbsolutePath() + "]", e); } } return constructs; }  @Override String[] getSupportedFileExtensions(); @Override boolean canAnalyze(File _file); @Override void analyze(final File _file); Path getArchivePath(); String getDigest(); @Override Map<ConstructId, Construct> getConstructs(); Library getLibrary(); @Override boolean containsConstruct(ConstructId _id); @Override Construct getConstruct(ConstructId _id); @Override boolean hasChilds(); @Override Set<FileAnalyzer> getChilds(boolean _recursive); List<org.eclipse.steady.shared.json.model.ConstructId> getSharedConstructs();  }