Source:
<code>private void setUpClusterArtifacts(Topology topology) throws IOException { String config = topology.getConfig(); ObjectMapper objectMapper = new ObjectMapper(); Map jsonMap = objectMapper.readValue(config, Map.class); if (jsonMap != null) { List<Object> clusterList = (List<Object>) jsonMap.get(TopologyLayoutConstants.JSON_KEY_CLUSTERS); if (clusterList != null) { List<Cluster> clusters = objectMapper.readValue(objectMapper.writeValueAsString(clusterList), new TypeReference<List<Cluster>>() { }); Path artifactsDir = topologyActions.getArtifactsLocation(topology); <START> if (artifactsDir.toFile().isDirectory()) { <END> FileUtils.cleanDirectory(artifactsDir.toFile()); } else if (!artifactsDir.toFile().mkdirs()) { LOG.error("Could not create artifacts dir {}", artifactsDir); throw new IOException("Could not create artifacts dir: " + artifactsDir); } for (Cluster c : clusters) { Cluster cluster = getCluster(c.getId()); String resource = cluster.getClusterConfigStorageName(); File destPath = Paths.get(artifactsDir.toString(), cluster.getClusterConfigFileName()).toFile(); try ( InputStream src = jarStorage.downloadJar(resource); FileOutputStream dest = new FileOutputStream(destPath); ) { IOUtils.copy(src, dest); LOG.debug("Resource copied to {}", resource, destPath); } } } } }</code><technical_language>a condition covers message artifactsDir is a dir a file. java if(artifactsDir.toFile().exists()) { if (artifactsDir.toFile().isDirectory()) { FileUtils.cleanDirectory(artifactsDir.toFile()); } else { final String errorMessage = String.format("artifacts location [%s] a directory.", artifactsDir); LOG.error(errorMessage); throw new IOException(errorMessage); } } else if (!artifactsDir.toFile().mkdirs()) { LOG.error("Could create artifacts dir {}", artifactsDir); throw new IOException("Could create artifacts dir: " + artifactsDir); }</technical_language>

Target:
private void setUpClusterArtifacts(Topology topology) throws IOException { String config = topology.getConfig(); ObjectMapper objectMapper = new ObjectMapper(); Map jsonMap = objectMapper.readValue(config, Map.class); if (jsonMap != null) { List<Object> clusterList = (List<Object>) jsonMap.get(TopologyLayoutConstants.JSON_KEY_CLUSTERS); if (clusterList != null) { List<Cluster> clusters = objectMapper.readValue(objectMapper.writeValueAsString(clusterList), new TypeReference<List<Cluster>>() { }); Path artifactsDir = topologyActions.getArtifactsLocation(topology); if (artifactsDir.toFile().exists()) { if (artifactsDir.toFile().isDirectory()) { FileUtils.cleanDirectory(artifactsDir.toFile()); } else { final String errorMessage = String.format("Artifacts location '%s' must be a directory.", artifactsDir); LOG.error(errorMessage); throw new IOException(errorMessage); } } else if (!artifactsDir.toFile().mkdirs()) { LOG.error("Could not create artifacts dir {}", artifactsDir); throw new IOException("Could not create artifacts dir: " + artifactsDir); } for (Cluster c : clusters) { Cluster cluster = getCluster(c.getId()); String resource = cluster.getClusterConfigStorageName(); File destPath = Paths.get(artifactsDir.toString(), cluster.getClusterConfigFileName()).toFile(); try ( InputStream src = fileStorage.downloadFile(resource); FileOutputStream dest = new FileOutputStream(destPath); ) { IOUtils.copy(src, dest); LOG.debug("Resource copied to {}", resource, destPath); } } } } }