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.git
The following commit(s) were added to refs/heads/master by this push:
new ef7cf1f SLING-10567 NPE when obtaining ArtifactManager
new 52c083c Merge pull request #28 from bosschaert/SLING-10567
ef7cf1f is described below
commit ef7cf1f8156ad612d54cbb02b209bae900803e27
Author: David Bosschaert <[email protected]>
AuthorDate: Mon Jun 28 15:38:45 2021 +0100
SLING-10567 NPE when obtaining ArtifactManager
---
.../feature/io/artifacts/ArtifactManager.java | 7 +++++--
.../feature/io/artifacts/ArtifactManagerTest.java | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git
a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
index f56d3af..a71c7df 100644
--- a/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
+++ b/src/main/java/org/apache/sling/feature/io/artifacts/ArtifactManager.java
@@ -17,6 +17,7 @@
package org.apache.sling.feature.io.artifacts;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -354,8 +355,10 @@ public class ArtifactManager
@Override
public void init(final ArtifactProviderContext config) throws
IOException {
- this.cacheDir = config.getCacheDirectory().toPath();
- if (cacheDir == null) {
+ File cd = config.getCacheDirectory();
+ if (cd != null) {
+ this.cacheDir = cd.toPath();
+ } else {
this.cacheDir = Files.createTempDirectory("slingfeature");
isNewlyCreatedCacheDir = true;
}
diff --git
a/src/test/java/org/apache/sling/feature/io/artifacts/ArtifactManagerTest.java
b/src/test/java/org/apache/sling/feature/io/artifacts/ArtifactManagerTest.java
index fd106d3..8bdc9cb 100644
---
a/src/test/java/org/apache/sling/feature/io/artifacts/ArtifactManagerTest.java
+++
b/src/test/java/org/apache/sling/feature/io/artifacts/ArtifactManagerTest.java
@@ -18,11 +18,14 @@ package org.apache.sling.feature.io.artifacts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
@@ -93,4 +96,23 @@ public class ArtifactManagerTest {
assertNotNull(handler);
assertEquals(artifactFile, handler.getLocalURL());
}
+
+ @Test public void testGetArtifactManager() throws Exception {
+ ArtifactManagerConfig cfg = new ArtifactManagerConfig();
+ ArtifactManager am = ArtifactManager.getArtifactManager(cfg);
+
+ am.shutdown();
+ }
+
+ @Test public void testGetArtifactManagerWithCachedir() throws Exception {
+ ArtifactManagerConfig cfg = new ArtifactManagerConfig();
+ Path tempDir =
Files.createTempDirectory("testGetArtifactManagerWithCachedir");
+ cfg.setCacheDirectory(tempDir.toFile());
+
+ ArtifactManager am = ArtifactManager.getArtifactManager(cfg);
+
+ am.shutdown();
+ assertTrue(tempDir.toFile().isDirectory());
+ assertTrue(tempDir.toFile().delete());
+ }
}