test_class.declarator: zipFileDir
test_class.modifier: private
test_class.original_string: private Path zipFileDir;
test_class.type: Path
test_class.var_name: zipFileDir
test_class.file: tf-build-tools/tf-maven-plugin/src/test/java/com/deliveredtechnologies/maven/io/ExpandableZippedArtifactTest.java
test_class.identifier: ExpandableZippedArtifactTest
test_case.body: @Test
    public void zippedArtifactExtractsArtifactsWithaDotInTheName() throws URISyntaxException, IOException {
      Path zipFile = zipFileDir.resolve("tf-module-my.module2-0.1.zip");
      Expandable expandableArtifact = new ExpandableZippedArtifact(zipFile);
      expandableArtifact.expand();
  
      Path expandedDir = zipFileDir.resolve("my.module2");
      Assert.assertTrue(expandedDir.toFile().isDirectory());
  
      Assert.assertEquals(Files.walk(expandedDir, 1)
          .filter(path -> !path.equals(expandedDir))
          .count(), 2);
  
      Assert.assertTrue(Files.walk(expandedDir, 1)
          .filter(path -> !path.equals(expandedDir))
          .allMatch(path -> path.getFileName().toString().startsWith("test.file") && path.getFileName().toString().endsWith(".txt")));
  
      Assert.assertFalse(zipFile.toFile().exists());
    }
test_case.class_method_signature: ExpandableZippedArtifactTest.zippedArtifactExtractsArtifactsWithaDotInTheName()
test_case.full_signature: @Test public void zippedArtifactExtractsArtifactsWithaDotInTheName()
test_case.identifier: zippedArtifactExtractsArtifactsWithaDotInTheName
test_case.invocations: resolve expand resolve assertTrue isDirectory toFile assertEquals count filter walk equals assertTrue allMatch filter walk equals startsWith toString getFileName endsWith toString getFileName assertFalse exists toFile
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void zippedArtifactExtractsArtifactsWithaDotInTheName()
focal_class.declarator: BUFFER_SIZE = 4096
focal_class.modifier: private static
focal_class.original_string: private static int BUFFER_SIZE = 4096;
focal_class.type: int
focal_class.var_name: BUFFER_SIZE
focal_class.declarator: zipFile
focal_class.modifier: private
focal_class.original_string: private Path zipFile;
focal_class.type: Path
focal_class.var_name: zipFile
focal_class.declarator: log
focal_class.modifier: private
focal_class.original_string: private Log log;
focal_class.type: Log
focal_class.var_name: log
focal_class.file: tf-build-tools/tf-maven-plugin/src/main/java/com/deliveredtechnologies/maven/io/ExpandableZippedArtifact.java
focal_class.identifier: ExpandableZippedArtifact
focal_class.interfaces: implements Expandable
focal_class.class_method_signature: ExpandableZippedArtifact.ExpandableZippedArtifact(Path zipFile, Log log)
focal_class.full_signature: public  ExpandableZippedArtifact(Path zipFile, Log log)
focal_class.identifier: ExpandableZippedArtifact
focal_class.modifiers: public
focal_class.parameters: (Path zipFile, Log log)
focal_class.signature:  ExpandableZippedArtifact(Path zipFile, Log log)
focal_class.class_method_signature: ExpandableZippedArtifact.ExpandableZippedArtifact(Path zipFile)
focal_class.full_signature: public  ExpandableZippedArtifact(Path zipFile)
focal_class.identifier: ExpandableZippedArtifact
focal_class.modifiers: public
focal_class.parameters: (Path zipFile)
focal_class.signature:  ExpandableZippedArtifact(Path zipFile)
focal_class.class_method_signature: ExpandableZippedArtifact.expand()
focal_class.full_signature: @Override public Optional<Path> expand()
focal_class.identifier: expand
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Optional<Path>
focal_class.signature: Optional<Path> expand()
focal_class.class_method_signature: ExpandableZippedArtifact.extractFile(ZipInputStream zipStream, Path filePath)
focal_class.full_signature: private void extractFile(ZipInputStream zipStream, Path filePath)
focal_class.identifier: extractFile
focal_class.modifiers: private
focal_class.parameters: (ZipInputStream zipStream, Path filePath)
focal_class.return: void
focal_class.signature: void extractFile(ZipInputStream zipStream, Path filePath)
focal_method.body: @Override
    public Optional<Path> expand() {
      log.info("Expanding " + zipFile);
  
      Path artifactDir;
  
      try (IterableZipInputStream zipStream = new IterableZipInputStream(new FileInputStream(zipFile.toFile()))) {
        //split path for Windows or Linux
        String[] zipFilenamePathSplit = zipFile.getFileName().toString().split(File.separator.equals("/") ? "\\/" : "\\\\");
        //split the filename by hyphens, e.g. {artifact}-{version}-{qualifier}.zip
        String[] zipFilenameSplitByHyphen = zipFilenamePathSplit[zipFilenamePathSplit.length - 1].split("-");
  
        //get just the name of the unprefixed Maven artifact (e.g. s3-bucket or lambda or module1, etc.)
        //a supported convention for TerraformCommandLineDecorator Maven artifact prefixes is terraform-module-{artifact}-{version}-{qualifier}
        String artifactName = Arrays.stream(zipFilenameSplitByHyphen)
            .filter(s -> !s.startsWith("SNAPSHOT"))
            .filter(s -> !s.equals("rc"))
            .filter(s -> !s.equals("tf"))
            .filter(s -> !s.equals("module"))
            .filter(s -> {
              if (s.contains(".")) {
                String[] splitByDot = s.split("\\.");
                return !StringUtils.isNumeric(splitByDot[0])
                  && !splitByDot[splitByDot.length - 1].equals("zip");
              }
              return true;
            })
            .reduce("", (s1, s2) -> s1 + (s1.length() > 0 ? "-" : "") + s2);
  
        Path modulesDir = zipFile.getParent();
  
        //create the directory as the name of the artifact
        artifactDir = Paths.get(modulesDir.toString(), artifactName);
        artifactDir.toFile().mkdir();
  
        //extract the contents of the artifact zip file into the directory created immediately above
        for (ZipEntry entry : zipStream) {
          if (entry.isDirectory()) {
            Paths.get(modulesDir.toString(), artifactName, entry.getName()).toFile().mkdir();
          } else {
            extractFile(zipStream, Paths.get(modulesDir.toString(), artifactName, entry.getName()));
          }
        }
      } catch (IOException e) {
        log.error("Error expanding " + zipFile.getFileName(), e);
        return Optional.empty();
      }
  
      if (!zipFile.toFile().delete()) {
        log.warn("Unable to delete " + zipFile.toAbsolutePath());
      }
      return Optional.of(artifactDir);
    }
focal_method.class_method_signature: ExpandableZippedArtifact.expand()
focal_method.full_signature: @Override public Optional<Path> expand()
focal_method.identifier: expand
focal_method.invocations: info toFile split toString getFileName equals split reduce filter filter filter filter filter stream startsWith equals equals equals contains split isNumeric equals length getParent get toString mkdir toFile isDirectory mkdir toFile get toString getName extractFile get toString getName error getFileName empty delete toFile warn toAbsolutePath of
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: Optional<Path>
focal_method.signature: Optional<Path> expand()