You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/04/27 10:02:48 UTC
[sling-org-apache-sling-feature-resolver] 04/20: Support the
slinstart maven plugin by providing a model converter API
This is an automated email from the ASF dual-hosted git repository.
davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-resolver.git
commit 00cfb973ff464f89655cb6a87c59211283726b4a
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Fri Mar 9 10:46:10 2018 +0000
Support the slinstart maven plugin by providing a model converter API
---
.../sling/feature/resolver/FrameworkResolver.java | 34 ++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java b/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
index 249f4f2..77a1a51 100644
--- a/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
+++ b/src/main/java/org/apache/sling/feature/resolver/FrameworkResolver.java
@@ -29,6 +29,7 @@ import org.apache.sling.feature.resolver.impl.ResolveContextImpl;
import org.apache.sling.feature.support.ArtifactManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
@@ -48,16 +49,42 @@ import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
+import java.util.Set;
public class FrameworkResolver implements FeatureResolver {
private final ArtifactManager artifactManager;
private final Resolver resolver;
private final FeatureResource frameworkResource;
private final Framework framework;
+ private String tempDirToBeDeleted = null;
+
+ public FrameworkResolver(ArtifactManager am) {
+ this(am, getTempDirProps());
+
+ // Since we create the temp dir, the close() method needs to delete it.
+ tempDirToBeDeleted = framework.getBundleContext().getProperty(Constants.FRAMEWORK_STORAGE);
+ }
+
+ private static Map<String, String> getTempDirProps() {
+ try {
+ String temp = Files.createTempDirectory("frameworkresolver").toFile().getAbsolutePath();
+ return Collections.singletonMap(Constants.FRAMEWORK_STORAGE, temp);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
public FrameworkResolver(ArtifactManager am, Map<String, String> frameworkProperties) {
artifactManager = am;
@@ -101,6 +128,13 @@ public class FrameworkResolver implements FeatureResolver {
@Override
public void close() throws Exception {
framework.stop();
+
+ if (tempDirToBeDeleted != null) {
+ Files.walk(Paths.get(tempDirToBeDeleted))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
}
@Override
--
To stop receiving notification emails like this one, please contact
davidb@apache.org.