test_class.file: lang-python/src/test/java/org/eclipse/steady/python/PythonArchiveAnalyzerTest.java
test_class.identifier: PythonArchiveAnalyzerTest
test_case.body: @Test
    public void testGunicorn() throws FileAnalysisException {
      final FileAnalyzer f3 =
          FileAnalyzerFactory.buildFileAnalyzer(
              new File("src/test/resources/gunicorn-19.7.1-py2.py3-none-any.whl"));
      final Map<ConstructId, Construct> c3 = f3.getConstructs();
  
      /*for(ConstructId cid: c3.keySet())
      System.out.println(cid);*/
  
      // 1. parse errors happen in the following method. Check it is nevertheless among the identified
      // constructs
      // PY METH [gunicorn.workers._gaiohttp.AiohttpWorker(base.Worker).run(self)]
      final PythonId pack = new PythonId(null, PythonId.Type.PACKAGE, "gunicorn.workers");
      PythonId modu = new PythonId(pack, PythonId.Type.MODULE, "_gaiohttp");
      final PythonId clas = new PythonId(modu, PythonId.Type.CLASS, "AiohttpWorker(base.Worker)");
      final PythonId meth = new PythonId(clas, PythonId.Type.METHOD, "run(self)");
      assertTrue(c3.containsKey(pack));
      assertTrue(c3.containsKey(modu));
      assertTrue(c3.containsKey(clas));
      assertTrue(c3.containsKey(meth));
  
      // 2. parse errors happen in the following module. Check it is nevertheless among the identified
      // constructs
      //   PY MODU [gunicorn.workers.geventlet]
      modu = new PythonId(pack, PythonId.Type.MODULE, "geventlet");
      assertTrue(c3.containsKey(modu));
  
      // 3. parse errors happen in the following module. Check it is nevertheless among the identified
      // constructs
      //   PY MODU [gunicorn.workers.ggevent]
      modu = new PythonId(pack, PythonId.Type.MODULE, "ggevent");
      assertTrue(c3.containsKey(modu));
    }
test_case.class_method_signature: PythonArchiveAnalyzerTest.testGunicorn()
test_case.full_signature: @Test public void testGunicorn()
test_case.identifier: testGunicorn
test_case.invocations: buildFileAnalyzer getConstructs assertTrue containsKey assertTrue containsKey assertTrue containsKey assertTrue containsKey assertTrue containsKey assertTrue containsKey
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGunicorn()
focal_class.declarator: log = org.apache.logging.log4j.LogManager.getLogger()
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = org.apache.logging.log4j.LogManager.getLogger();
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: constructs = new TreeMap<ConstructId, Construct>()
focal_class.original_string: Map<ConstructId, Construct> constructs = new TreeMap<ConstructId, Construct>();
focal_class.type: Map<ConstructId, Construct>
focal_class.var_name: constructs
focal_class.declarator: archive = null
focal_class.modifier: private
focal_class.original_string: private File archive = null;
focal_class.type: File
focal_class.var_name: archive
focal_class.declarator: nestedAnalyzers = new HashSet<FileAnalyzer>()
focal_class.modifier: private
focal_class.original_string: private Set<FileAnalyzer> nestedAnalyzers = new HashSet<FileAnalyzer>();
focal_class.type: Set<FileAnalyzer>
focal_class.var_name: nestedAnalyzers
focal_class.file: lang-python/src/main/java/org/eclipse/steady/python/PythonArchiveAnalyzer.java
focal_class.identifier: PythonArchiveAnalyzer
focal_class.interfaces: implements FileAnalyzer
focal_class.class_method_signature: PythonArchiveAnalyzer.getSupportedFileExtensions()
focal_class.full_signature: @Override public String[] getSupportedFileExtensions()
focal_class.identifier: getSupportedFileExtensions
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String[]
focal_class.signature: String[] getSupportedFileExtensions()
focal_class.class_method_signature: PythonArchiveAnalyzer.canAnalyze(File _file)
focal_class.full_signature: @Override public boolean canAnalyze(File _file)
focal_class.identifier: canAnalyze
focal_class.modifiers: @Override public
focal_class.parameters: (File _file)
focal_class.return: boolean
focal_class.signature: boolean canAnalyze(File _file)
focal_class.class_method_signature: PythonArchiveAnalyzer.analyze(final File _file)
focal_class.full_signature: @Override public void analyze(final File _file)
focal_class.identifier: analyze
focal_class.modifiers: @Override public
focal_class.parameters: (final File _file)
focal_class.return: void
focal_class.signature: void analyze(final File _file)
focal_class.class_method_signature: PythonArchiveAnalyzer.getArchivePath()
focal_class.full_signature: public Path getArchivePath()
focal_class.identifier: getArchivePath
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Path
focal_class.signature: Path getArchivePath()
focal_class.class_method_signature: PythonArchiveAnalyzer.getDigest()
focal_class.full_signature: public String getDigest()
focal_class.identifier: getDigest
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getDigest()
focal_class.class_method_signature: PythonArchiveAnalyzer.getArchiveInputStream()
focal_class.full_signature: private InputStream getArchiveInputStream()
focal_class.identifier: getArchiveInputStream
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: InputStream
focal_class.signature: InputStream getArchiveInputStream()
focal_class.class_method_signature: PythonArchiveAnalyzer.getModuleName(String _name)
focal_class.full_signature: private String getModuleName(String _name)
focal_class.identifier: getModuleName
focal_class.modifiers: private
focal_class.parameters: (String _name)
focal_class.return: String
focal_class.signature: String getModuleName(String _name)
focal_class.class_method_signature: PythonArchiveAnalyzer.getPackageName(String _name, List<String> _inits)
focal_class.full_signature: private List<String> getPackageName(String _name, List<String> _inits)
focal_class.identifier: getPackageName
focal_class.modifiers: private
focal_class.parameters: (String _name, List<String> _inits)
focal_class.return: List<String>
focal_class.signature: List<String> getPackageName(String _name, List<String> _inits)
focal_class.class_method_signature: PythonArchiveAnalyzer.isPackage(String _en)
focal_class.full_signature: private Boolean isPackage(String _en)
focal_class.identifier: isPackage
focal_class.modifiers: private
focal_class.parameters: (String _en)
focal_class.return: Boolean
focal_class.signature: Boolean isPackage(String _en)
focal_class.class_method_signature: PythonArchiveAnalyzer.getConstructs()
focal_class.full_signature: @Override public Map<ConstructId, Construct> getConstructs()
focal_class.identifier: getConstructs
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Map<ConstructId, Construct>
focal_class.signature: Map<ConstructId, Construct> getConstructs()
focal_class.class_method_signature: PythonArchiveAnalyzer.getLibrary()
focal_class.full_signature: public Library getLibrary()
focal_class.identifier: getLibrary
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Library
focal_class.signature: Library getLibrary()
focal_class.class_method_signature: PythonArchiveAnalyzer.containsConstruct(ConstructId _id)
focal_class.full_signature: @Override public boolean containsConstruct(ConstructId _id)
focal_class.identifier: containsConstruct
focal_class.modifiers: @Override public
focal_class.parameters: (ConstructId _id)
focal_class.return: boolean
focal_class.signature: boolean containsConstruct(ConstructId _id)
focal_class.class_method_signature: PythonArchiveAnalyzer.getConstruct(ConstructId _id)
focal_class.full_signature: @Override public Construct getConstruct(ConstructId _id)
focal_class.identifier: getConstruct
focal_class.modifiers: @Override public
focal_class.parameters: (ConstructId _id)
focal_class.return: Construct
focal_class.signature: Construct getConstruct(ConstructId _id)
focal_class.class_method_signature: PythonArchiveAnalyzer.hasChilds()
focal_class.full_signature: @Override public boolean hasChilds()
focal_class.identifier: hasChilds
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean hasChilds()
focal_class.class_method_signature: PythonArchiveAnalyzer.getChilds(boolean _recursive)
focal_class.full_signature: @Override public Set<FileAnalyzer> getChilds(boolean _recursive)
focal_class.identifier: getChilds
focal_class.modifiers: @Override public
focal_class.parameters: (boolean _recursive)
focal_class.return: Set<FileAnalyzer>
focal_class.signature: Set<FileAnalyzer> getChilds(boolean _recursive)
focal_class.class_method_signature: PythonArchiveAnalyzer.getSharedConstructs()
focal_class.full_signature: public List<org.eclipse.steady.shared.json.model.ConstructId> getSharedConstructs()
focal_class.identifier: getSharedConstructs
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<org.eclipse.steady.shared.json.model.ConstructId>
focal_class.signature: List<org.eclipse.steady.shared.json.model.ConstructId> getSharedConstructs()
focal_method.body: @Override
    public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException {
      if (this.constructs.isEmpty()) {
  
        // list of __init__.py files (to become packages)
        final List<String> inits = new ArrayList<String>();
        boolean pre_processed = false;
        try (InputStream is = this.getArchiveInputStream()) {
  
          // Read archive to look for __init__.py
          if (is instanceof ZipInputStream) {
            ZipEntry en = null;
            while ((en = ((ZipInputStream) is).getNextEntry()) != null) {
              // loop over the archive to understand which files has an __init__.py
              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) {
              // Loop over the archive to understand which files has an __init__.py
              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);
        }
  
        // Re-read archive to create constructs
        try (InputStream is = this.getArchiveInputStream()) {
  
          if (is instanceof ZipInputStream && pre_processed) {
            ZipEntry en = null;
            while ((en = ((ZipInputStream) is).getNextEntry()) != null) {
  
              if (!en.isDirectory()) {
                // check if it is a tar (wheel egg), then extract and analyze it (here or where??) !!!
                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")) {
  
                  // Create the package (if any)
                  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, "."));
  
                  // Create module
                  final String module_name = this.getModuleName(en.getName());
                  final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name);
  
                  // We put everything into a byte[] to avoid that the stream gets closed when read by
                  // antlr
                  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)));
                  }
                }
              }
            }
          }
          // almost duplicated code from the alternative above as we have another type for the entry
          // (ArchiveEntry from commons compress instead of ZipEntry from java.util.zip)
          else if (is instanceof TarArchiveInputStream) {
            ArchiveEntry en = null;
            while ((en = ((TarArchiveInputStream) is).getNextEntry()) != null) {
              if (!en.isDirectory()) {
                // check if it is a tar (wheel egg), then extract and analyze it (here or where??) !!!
                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")) {
  
                  // Create the package (if any)
                  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, "."));
  
                  // Create module
                  final String module_name = this.getModuleName(en.getName());
                  final PythonId module = new PythonId(pack, PythonId.Type.MODULE, module_name);
  
                  // We put everything into a byte[] to avoid that the stream gets closed when read by
                  // antlr
                  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;
    }
focal_method.class_method_signature: PythonArchiveAnalyzer.getConstructs()
focal_method.full_signature: @Override public Map<ConstructId, Construct> getConstructs()
focal_method.identifier: getConstructs
focal_method.invocations: isEmpty getArchiveInputStream getNextEntry isDirectory isPackage getName add getName getNextEntry isDirectory isPackage getName add getName error getAbsolutePath getArchiveInputStream getNextEntry isDirectory endsWith getName endsWith getName endsWith getName createAnalyzerForArchiveEntry getName add endsWith getName getPackageName getName isEmpty join getModuleName getName readInputStream createAnalyzer setContext putAll getConstructs setContext putAll getConstructs getNextEntry isDirectory endsWith getName endsWith getName endsWith getName createAnalyzerForArchiveEntry getName add endsWith getName getPackageName getName isEmpty join getModuleName getName readInputStream createAnalyzer setContext putAll getConstructs setContext putAll getConstructs error getAbsolutePath
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: Map<ConstructId, Construct>
focal_method.signature: Map<ConstructId, Construct> getConstructs()