@Override public void dispose() { File appLocation = this.getLocation(); try { super.dispose(); } catch (Throwable t) { logger.warn(format("Error while disposing application: {} ", this.getArtifactName()), t); } deleteQuietly(appLocation); deleteQuietly(getAppDataFolder(getArtifactName())); }
@Override public void dispose() { File domainLocation = this.getLocation(); try { super.dispose(); } catch (Throwable t) { logger.warn(format("Error while disposing domain: {} ", super.getArtifactName()), t); } deleteQuietly(domainLocation); deleteQuietly(getAppDataFolder(getArtifactName())); }
@Override public NativeLibraryFinder create(String name, URL[] urls) { checkArgument(!isEmpty(name), "appName cannot be empty"); checkArgument(urls != null, "urls cannot be null"); return new ArtifactCopyNativeLibraryFinder(new File(getAppDataFolder(name), "temp"), urls); }
@Test public void ignoresErrorsWhileRemovingArtifactDataFolder() throws Exception { AbstractDeployableArtifactFactory artifactFactory = mock(AbstractDeployableArtifactFactory.class); ArtifactDeployer artifactDeployer = mock(ArtifactDeployer.class); DefaultArchiveDeployer<Application> deployer = new DefaultArchiveDeployer(artifactDeployer, artifactFactory, new ObservableList(), null, null); deployer.setDeploymentListener(mock(DeploymentListener.class)); deployer.deployArtifact(createMockApplication(), empty()); mockStatic(FileUtils.class); PowerMockito.doThrow(new IOException()).when(FileUtils.class); deleteDirectory(Matchers.eq(getAppDataFolder(ARTIFACT_ID))); deployer.undeployArtifact(ARTIFACT_ID); }
private void undeploy(T artifact, boolean removeData) { logRequestToUndeployArtifact(artifact); try { deploymentListener.onUndeploymentStart(artifact.getArtifactName()); artifacts.remove(artifact); deployer.undeploy(artifact); artifactArchiveInstaller.uninstallArtifact(artifact.getArtifactName()); if (removeData) { final File dataFolder = getAppDataFolder(artifact.getDescriptor().getDataFolderName()); try { deleteDirectory(dataFolder); } catch (IOException e) { logger.warn( format("Cannot delete data folder '%s' while undeploying artifact '%s'. This could be related to some files still being used and can cause a memory leak", dataFolder, artifact.getArtifactName()), e); } } deploymentListener.onUndeploymentSuccess(artifact.getArtifactName()); logArtifactUndeployed(artifact); } catch (RuntimeException e) { deploymentListener.onUndeploymentFailure(artifact.getArtifactName(), e); throw e; } }
@Test public void ignoresErrorsWhileRemovingArtifactDataFolder() throws Exception { AbstractDeployableArtifactFactory artifactFactory = mock(AbstractDeployableArtifactFactory.class); ArtifactDeployer artifactDeployer = mock(ArtifactDeployer.class); DefaultArchiveDeployer<Application> deployer = new DefaultArchiveDeployer(artifactDeployer, artifactFactory, new ObservableList(), null, null); deployer.setDeploymentListener(mock(DeploymentListener.class)); deployer.deployArtifact(createMockApplication(), empty()); mockStatic(FileUtils.class); PowerMockito.doThrow(new IOException()).when(FileUtils.class); deleteDirectory(Matchers.eq(getAppDataFolder(ARTIFACT_ID))); deployer.undeployArtifact(ARTIFACT_ID); }
private void undeployArtifact(T artifact, boolean removeData) { logRequestToUndeployArtifact(artifact); try { deploymentListener.onUndeploymentStart(artifact.getArtifactName()); artifacts.remove(artifact); deployer.undeploy(artifact); artifactArchiveInstaller.uninstallArtifact(artifact.getArtifactName()); if (removeData) { final File dataFolder = getAppDataFolder(artifact.getDescriptor().getDataFolderName()); try { deleteDirectory(dataFolder); } catch (IOException e) { logger.warn( format("Cannot delete data folder '%s' while undeploying artifact '%s'. This could be related to some files still being used and can cause a memory leak", dataFolder, artifact.getArtifactName()), e); } } deploymentListener.onUndeploymentSuccess(artifact.getArtifactName()); logArtifactUndeployed(artifact); } catch (RuntimeException e) { deploymentListener.onUndeploymentFailure(artifact.getArtifactName(), e); throw e; } }