diff --git a/apis/filesystem/pom.xml b/apis/filesystem/pom.xml index 2276667ec3..517a236e90 100644 --- a/apis/filesystem/pom.xml +++ b/apis/filesystem/pom.xml @@ -52,11 +52,6 @@ test-jar test - - commons-io - commons-io - 2.4 - org.jclouds jclouds-blobstore diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 7cb61e8de1..07c2efb001 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.io.ByteStreams; import com.google.common.io.Files; -import org.apache.commons.io.FileUtils; import org.jclouds.blobstore.LocalStorageStrategy; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobBuilder; @@ -46,6 +45,7 @@ import org.jclouds.domain.Location; import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator; import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator; import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.util.Utils; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; @@ -131,7 +131,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { File[] children = containerFile.listFiles(); if (null != children) { for (File child : children) - FileUtils.forceDelete(child); + Utils.deleteRecursively(child); } } catch (IOException e) { logger.error(e, "An error occurred while clearing container %s", container); @@ -283,7 +283,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy { // create complete dir path String fullDirPath = buildPathStartingFromBaseDir(container, directory); try { - FileUtils.forceDelete(new File(fullDirPath)); + Utils.deleteRecursively(new File(fullDirPath)); } catch (IOException ex) { logger.error("An error occurred removing directory %s.", fullDirPath); Throwables.propagate(ex); diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java new file mode 100644 index 0000000000..5d29fd6596 --- /dev/null +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/util/Utils.java @@ -0,0 +1,49 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.filesystem.util; + +import java.io.File; +import java.io.IOException; + +/** + * Utilities for the filesystem blobstore. + * + * @author Andrew Gaul + */ +public class Utils { + /** Private constructor for utility class. */ + private Utils() { + // Do nothing + } + + /** Delete a file or a directory recursively. */ + public static void deleteRecursively(File file) throws IOException { + if (file.isDirectory()) { + File[] children = file.listFiles(); + if (children != null) { + for (File child : children) { + deleteRecursively(child); + } + } + } + if (!file.delete()) { + throw new IOException("Could not delete: " + file); + } + } +} diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java index 5d84b6d127..8f76971549 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java @@ -36,7 +36,6 @@ import java.util.Iterator; import java.util.Properties; import java.util.Set; -import org.apache.commons.io.FileUtils; import org.jclouds.ContextBuilder; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.BlobStore; @@ -52,6 +51,7 @@ import org.jclouds.blobstore.options.GetOptions; import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.crypto.CryptoStreams; import org.jclouds.filesystem.reference.FilesystemConstants; +import org.jclouds.filesystem.util.Utils; import org.jclouds.filesystem.utils.TestUtils; import org.jclouds.http.HttpRequest; import org.jclouds.io.InputSuppliers; @@ -106,7 +106,7 @@ public class FilesystemAsyncBlobStoreTest { @AfterMethod protected void tearDown() throws IOException { context.close(); - FileUtils.forceDelete(new File(TestUtils.TARGET_BASE_DIR)); + Utils.deleteRecursively(new File(TestUtils.TARGET_BASE_DIR)); } /** diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java index f068f25df9..6d6be707e1 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java @@ -28,10 +28,11 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.jclouds.filesystem.util.Utils; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterators; - -import org.apache.commons.io.FileUtils; +import com.google.common.io.Files; /** * Utility class for test @@ -98,7 +99,10 @@ public class TestUtils { * @throws IOException */ public static void createContainerAsDirectory(String containerName) throws IOException { - FileUtils.forceMkdir(new File(TARGET_BASE_DIR + containerName)); + File file = new File(TARGET_BASE_DIR, containerName); + if (!file.mkdirs()) { + throw new IOException("Could not mkdir: " + file); + }; } /** @@ -167,8 +171,8 @@ public class TestUtils { File parentDirectory = new File(directoryName); File[] children = parentDirectory.listFiles(); if (null != children) { - for(File child:children) { - FileUtils.forceDelete(child); + for (File child : children) { + Utils.deleteRecursively(child); } } } @@ -186,7 +190,9 @@ public class TestUtils { filePath = containerName + blobKey; else filePath = containerName + File.separator + blobKey; - FileUtils.copyFile(source, new File(TARGET_BASE_DIR + filePath)); + File file = new File(TARGET_BASE_DIR + filePath); + Files.createParentDirs(file); + Files.copy(source, file); }