mirror of
https://github.com/apache/jclouds.git
synced 2025-02-21 01:34:48 +00:00
Merge pull request #934 from andrewgaul/filesystem-remove-ioutils
Remove filesystem dependency on Apache commons-io
This commit is contained in:
commit
308416b7b2
@ -52,11 +52,6 @@
|
|||||||
<type>test-jar</type>
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jclouds</groupId>
|
<groupId>org.jclouds</groupId>
|
||||||
<artifactId>jclouds-blobstore</artifactId>
|
<artifactId>jclouds-blobstore</artifactId>
|
||||||
|
@ -35,7 +35,6 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.jclouds.blobstore.LocalStorageStrategy;
|
import org.jclouds.blobstore.LocalStorageStrategy;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobBuilder;
|
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.FilesystemBlobKeyValidator;
|
||||||
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator;
|
||||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||||
|
import org.jclouds.filesystem.util.Utils;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
@ -131,7 +131,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
|||||||
File[] children = containerFile.listFiles();
|
File[] children = containerFile.listFiles();
|
||||||
if (null != children) {
|
if (null != children) {
|
||||||
for (File child : children)
|
for (File child : children)
|
||||||
FileUtils.forceDelete(child);
|
Utils.deleteRecursively(child);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e, "An error occurred while clearing container %s", container);
|
logger.error(e, "An error occurred while clearing container %s", container);
|
||||||
@ -283,7 +283,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
|||||||
// create complete dir path
|
// create complete dir path
|
||||||
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
String fullDirPath = buildPathStartingFromBaseDir(container, directory);
|
||||||
try {
|
try {
|
||||||
FileUtils.forceDelete(new File(fullDirPath));
|
Utils.deleteRecursively(new File(fullDirPath));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("An error occurred removing directory %s.", fullDirPath);
|
logger.error("An error occurred removing directory %s.", fullDirPath);
|
||||||
Throwables.propagate(ex);
|
Throwables.propagate(ex);
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,6 @@ import java.util.Iterator;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.jclouds.ContextBuilder;
|
import org.jclouds.ContextBuilder;
|
||||||
import org.jclouds.blobstore.BlobRequestSigner;
|
import org.jclouds.blobstore.BlobRequestSigner;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
@ -52,6 +51,7 @@ import org.jclouds.blobstore.options.GetOptions;
|
|||||||
import org.jclouds.blobstore.options.ListContainerOptions;
|
import org.jclouds.blobstore.options.ListContainerOptions;
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
import org.jclouds.filesystem.reference.FilesystemConstants;
|
import org.jclouds.filesystem.reference.FilesystemConstants;
|
||||||
|
import org.jclouds.filesystem.util.Utils;
|
||||||
import org.jclouds.filesystem.utils.TestUtils;
|
import org.jclouds.filesystem.utils.TestUtils;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.io.InputSuppliers;
|
import org.jclouds.io.InputSuppliers;
|
||||||
@ -106,7 +106,7 @@ public class FilesystemAsyncBlobStoreTest {
|
|||||||
@AfterMethod
|
@AfterMethod
|
||||||
protected void tearDown() throws IOException {
|
protected void tearDown() throws IOException {
|
||||||
context.close();
|
context.close();
|
||||||
FileUtils.forceDelete(new File(TestUtils.TARGET_BASE_DIR));
|
Utils.deleteRecursively(new File(TestUtils.TARGET_BASE_DIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,10 +28,11 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.jclouds.filesystem.util.Utils;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
|
import com.google.common.io.Files;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for test
|
* Utility class for test
|
||||||
@ -98,7 +99,10 @@ public class TestUtils {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void createContainerAsDirectory(String containerName) 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 parentDirectory = new File(directoryName);
|
||||||
File[] children = parentDirectory.listFiles();
|
File[] children = parentDirectory.listFiles();
|
||||||
if (null != children) {
|
if (null != children) {
|
||||||
for(File child:children) {
|
for (File child : children) {
|
||||||
FileUtils.forceDelete(child);
|
Utils.deleteRecursively(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +190,9 @@ public class TestUtils {
|
|||||||
filePath = containerName + blobKey;
|
filePath = containerName + blobKey;
|
||||||
else
|
else
|
||||||
filePath = containerName + File.separator + blobKey;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user