test_class.declarator: tfInitWorkingDir
test_class.original_string: Path tfInitWorkingDir;
test_class.type: Path
test_class.var_name: tfInitWorkingDir
test_class.declarator: tfModulesWorkingDir
test_class.original_string: Path tfModulesWorkingDir;
test_class.type: Path
test_class.var_name: tfModulesWorkingDir
test_class.file: tf-build-tools/tf-cmd-api/src/test/java/com/deliveredtechnologies/terraform/api/TerraformCleanTest.java
test_class.identifier: TerraformCleanTest
test_case.body: @Test
    public void terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory() throws IOException, TerraformException {
      TerraformClean terraformClean = new TerraformClean(
          this.tfModulesWorkingDir.toString(),
          this.tfInitWorkingDir.resolve("root").toString());
  
      terraformClean.execute(new Properties());
  
      Assert.assertFalse(this.tfModulesWorkingDir.toFile().exists());
  
      Assert.assertFalse(Files.walk(this.tfInitWorkingDir)
          .filter(path -> path.getFileName().toString().endsWith(".terraform") || path.getFileName().toString().endsWith(".tfstate"))
          .findAny().isPresent());
    }
test_case.class_method_signature: TerraformCleanTest.terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory()
test_case.full_signature: @Test public void terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory()
test_case.identifier: terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory
test_case.invocations: toString toString resolve execute assertFalse exists toFile assertFalse isPresent findAny filter walk endsWith toString getFileName endsWith toString getFileName
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void terraformCleanCleansUpTerraformStateFilesAndTerraformWorkingDirectory()
focal_class.declarator: tfRootModulePath
focal_class.modifier: private
focal_class.original_string: private Path tfRootModulePath;
focal_class.type: Path
focal_class.var_name: tfRootModulePath
focal_class.declarator: tfModulesPath
focal_class.modifier: private
focal_class.original_string: private Path tfModulesPath;
focal_class.type: Path
focal_class.var_name: tfModulesPath
focal_class.file: tf-build-tools/tf-cmd-api/src/main/java/com/deliveredtechnologies/terraform/api/TerraformClean.java
focal_class.identifier: TerraformClean
focal_class.interfaces: implements TerraformOperation<String>
focal_class.class_method_signature: TerraformClean.TerraformClean(String tfModules, String tfRootModule)
focal_class.full_signature: public  TerraformClean(String tfModules, String tfRootModule)
focal_class.identifier: TerraformClean
focal_class.modifiers: public
focal_class.parameters: (String tfModules, String tfRootModule)
focal_class.signature:  TerraformClean(String tfModules, String tfRootModule)
focal_class.class_method_signature: TerraformClean.execute(Properties properties)
focal_class.full_signature: @Override public String execute(Properties properties)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (Properties properties)
focal_class.return: String
focal_class.signature: String execute(Properties properties)
focal_class.class_method_signature: TerraformClean.recursivelyWalk(Path path, Predicate<Path> condition)
focal_class.full_signature: private List<Path> recursivelyWalk(Path path, Predicate<Path> condition)
focal_class.identifier: recursivelyWalk
focal_class.modifiers: private
focal_class.parameters: (Path path, Predicate<Path> condition)
focal_class.return: List<Path>
focal_class.signature: List<Path> recursivelyWalk(Path path, Predicate<Path> condition)
focal_method.body: @Override
    public String execute(Properties properties) throws TerraformException {
      boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
  
      try {
        if (!this.tfRootModulePath.toFile().exists()) {
          throw new IOException(this.tfRootModulePath.toString() + " does not exist!");
        }
  
        //delete .tfmodules
        StringBuilder response = new StringBuilder("Deleting...\n");
        if (this.tfModulesPath.toFile().exists()) {
          response.append(this.tfModulesPath.toString()).append('\n');
          FileUtils.forceDelete(this.tfModulesPath.toFile());
        }
  
        //delete terraform files in terraform root module
        List<Path> terraformModuleFiles = recursivelyWalk(this.tfRootModulePath.getParent(), path -> path.getParent().toAbsolutePath().toString().endsWith(String.format(".terraform%1$smodules", File.separator)) || path.getFileName().toString().contains(".tfstate"));
  
        for (Path file : terraformModuleFiles) {
  
          //if it's Windows, remove the hard link to the local Terraform module
          if (isWindows && file.getParent().endsWith(String.format(".terraform%1$smodules", File.separator))) {
            try {
              response.append(file.toString()).append('\n');
              file.toFile().delete();
            } catch (Exception e) {
              response.append("**failed to delete ").append(file.toString()).append('\n');
            }
          }
  
          //if it's not running on Windows or if it is and the file/dir is still there, force delete
          if (file.toFile().exists()) {
            response.append(file.toString()).append('\n');
            FileUtils.forceDelete(file.toFile());
          }
        }
  
        //delete .terraform directories
        Files.walk(this.tfRootModulePath.getParent()).filter(path -> path.toString().endsWith(".terraform"))
            .map(Path::toFile)
            .forEach(file -> {
              response.append(file.toString()).append('\n');
              try {
                FileUtils.forceDelete(file);
              } catch (Exception ex) {
                response.append("**failed to delete ").append(file.toString()).append('\n');
              }
            });
        return response.toString();
      } catch (IOException e) {
        throw new TerraformException(e);
      }
    }
focal_method.class_method_signature: TerraformClean.execute(Properties properties)
focal_method.full_signature: @Override public String execute(Properties properties)
focal_method.identifier: execute
focal_method.invocations: startsWith toLowerCase getProperty exists toFile toString exists toFile append append toString forceDelete toFile recursivelyWalk getParent endsWith toString toAbsolutePath getParent format contains toString getFileName endsWith getParent format append append toString delete toFile append append append toString exists toFile append append toString forceDelete toFile forEach map filter walk getParent endsWith toString append append toString forceDelete append append append toString toString
focal_method.modifiers: @Override public
focal_method.parameters: (Properties properties)
focal_method.return: String
focal_method.signature: String execute(Properties properties)