This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/master by this push:
new 7b57859 Feature Converter doesn't cleanup after itself (#28)
7b57859 is described below
commit 7b57859f5d494228aaec1fd2bfc4ea3cc5b2ac7f
Author: kaushalmall <[email protected]>
AuthorDate: Thu Jun 25 22:01:26 2020 -0700
Feature Converter doesn't cleanup after itself (#28)
* added cleanup method to cleanup directories that the converter creates in
java.io.tmpdir
* added debug log to print the current tmp directory since it's a random
path on OS X.
* some minor cleanup and not using file.getAbsolutePath to path to the tmp
dir
* fixed "synthetic" typo
---
.../ContentPackage2FeatureModelConverterLauncher.java | 3 +++
.../sling/feature/cpconverter/cli/ShutDownHook.java | 18 ++++++++++++++++++
.../cpconverter/vltpkg/VaultPackageAssembler.java | 2 +-
.../cpconverter/vltpkg/VaultPackageAssemblerTest.java | 2 +-
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
index 9076be1..ff66e4b 100644
---
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
+++
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ContentPackage2FeatureModelConverterLauncher.java
@@ -108,6 +108,9 @@ public final class
ContentPackage2FeatureModelConverterLauncher implements Runna
String appName =
getClass().getAnnotation(Command.class).description()[0];
final Logger logger = LoggerFactory.getLogger(appName);
+ //output the current tmp directory
+ logger.debug("Using tmp directory {}",
System.getProperty("java.io.tmpdir"));
+
// Add the Shutdown Hook to the Java virtual machine
// in order to destroy all the allocated resources
Runtime.getRuntime().addShutdownHook(new ShutDownHook(logger));
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/cli/ShutDownHook.java
b/src/main/java/org/apache/sling/feature/cpconverter/cli/ShutDownHook.java
index e56629b..6674d11 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/cli/ShutDownHook.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/cli/ShutDownHook.java
@@ -16,9 +16,12 @@
*/
package org.apache.sling.feature.cpconverter.cli;
+import java.io.File;
+import java.io.IOException;
import java.util.Date;
import java.util.Formatter;
+import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
final class ShutDownHook extends Thread {
@@ -33,6 +36,9 @@ final class ShutDownHook extends Thread {
@Override
public void run() {
+
+ cleanUp();
+
// format the uptime string
Formatter uptimeFormatter = new Formatter();
uptimeFormatter.format("Total time:");
@@ -76,4 +82,16 @@ final class ShutDownHook extends Thread {
logger.info("+-----------------------------------------------------+");
}
+ private void cleanUp(){
+ File tmpDir = new File ( System.getProperty("java.io.tmpdir") );
+ logger.info( "Cleaning up tmp directories {}, {}",
tmpDir.getAbsolutePath() + "/sub-content-packages",
+ tmpDir.getAbsolutePath() + "/synthetic-content-packages" );
+
+ try {
+ FileUtils.deleteDirectory( new File (tmpDir,
"synthetic-content-packages") );
+ FileUtils.deleteDirectory( new File(tmpDir,
"sub-content-packages") );
+ } catch (IOException e) {
+ logger.error( "Error Deleting {}, {}", tmpDir +
"sub-content-packages", tmpDir + "syntethic-content-packages" );
+ }
+ }
}
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
index 05ee5a1..ce24227 100644
---
a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
+++
b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
@@ -67,7 +67,7 @@ public class VaultPackageAssembler implements EntryHandler,
FileFilter {
private static final String[] INCLUDE_RESOURCES = {
PACKAGE_DEFINITION_XML, CONFIG_XML, SETTINGS_XML };
- private static final File TMP_DIR = new
File(System.getProperty("java.io.tmpdir"), "syntethic-content-packages");
+ private static final File TMP_DIR = new
File(System.getProperty("java.io.tmpdir"), "synthetic-content-packages");
private static final Pattern OSGI_BUNDLE_PATTERN =
Pattern.compile("(jcr_root)?/apps/[^/]+/install(\\.([^/]+))?/.+\\.jar");
diff --git
a/src/test/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssemblerTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssemblerTest.java
index 71affa0..0f82f1a 100644
---
a/src/test/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssemblerTest.java
+++
b/src/test/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssemblerTest.java
@@ -39,7 +39,7 @@ import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class VaultPackageAssemblerTest {
- private static final File TMP_DIR = new
File(System.getProperty("java.io.tmpdir"), "syntethic-content-packages");
+ private static final File TMP_DIR = new
File(System.getProperty("java.io.tmpdir"), "synthetic-content-packages");
private File testDirectory;