/** * Deletes all files and subdirectories under dir. * Returns true if all deletions were successful. * If a deletion fails, the method stops attempting to delete and returns false. * * @param dir The directory to be deleted * @return true if the directory and its descendents were deleted */ public static boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list(); if (children != null) { for (String child : children) { boolean success = deleteDir(new File(dir, child)); if (!success) { return false; } } } } // The directory is now empty so delete it return dir.delete(); }
/** * This method will be called externally to deploy an artifact by giving the artifact deployment * directory and the path. The consumers of the DeploymentService will be calling this method. * * @param artifactPath path where the artifact resides. This has to be the full qualified path * of the artifact * @param artifactType the type of the artifact going to be dpeloyed * Eg : webapp, dataservice, sequence * @throws CarbonDeploymentException this will be thrown on error situation while trying deploy the given artifact */ public void deploy(String artifactPath, ArtifactType artifactType) throws CarbonDeploymentException { Utils.checkSecurity(); Deployer deployer = carbonDeploymentEngine.getDeployer(artifactType); if (deployer == null) { throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); } try { Path destination = Paths.get(carbonDeploymentEngine.getServerRepositoryDirectory().getAbsolutePath(), deployer.getLocation().getFile()); FileUtils.copyFileToDir(new File(artifactPath), destination.toFile()); } catch (IOException e) { throw new CarbonDeploymentException("Error wile copying artifact", e); } }
/** * This method will be called externally to undeploy an artifact by giving the artifact deployment * directory and the path. The consumers of the DeploymentService will be calling this method. * * @param key artifact key to uniquely identify an artifact in a runtime * Eg: for webapps this can be webapp context such as /foo , /bar, etc * for service this can be service name such as EchoService, VersionService, etc * @param artifactType the type of the artifact going to be deployed * Eg : webapp, dataservice, sequence * @throws CarbonDeploymentException this will be thrown on error situation while trying undeploy the given artifact */ public void undeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { Utils.checkSecurity(); Deployer deployer = carbonDeploymentEngine.getDeployer(artifactType); if (deployer == null) { throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); } Artifact deployedArtifact = carbonDeploymentEngine.getDeployedArtifact(artifactType, key); if (deployedArtifact != null) { FileUtils.deleteDir(new File(deployedArtifact.getPath())); } else { throw new CarbonDeploymentException("Cannot find artifact with key : " + key + " to undeploy"); } }