Removed commons-io as compile dependency to fix weird pom issues.

This commit is contained in:
Jeremy Wood 2019-02-02 00:53:51 -05:00
parent 6ebc1188e8
commit 7762aca019
3 changed files with 112 additions and 37 deletions

35
pom.xml
View File

@ -189,9 +189,6 @@
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>commons-io:commons-io</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>me.main__.util</pattern>
@ -228,27 +225,6 @@
</relocations>
</configuration>
</execution>
<execution>
<id>apache-commons-io</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-io:commons-io</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>com.onarandombox.commons</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@ -268,11 +244,6 @@
</build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
@ -372,6 +343,12 @@
<version>4.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>

View File

@ -11,7 +11,11 @@ import com.dumptruckman.minecraft.util.Logging;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.logging.Logger;
import java.util.stream.Stream;
/**
* File-utilities.
@ -28,8 +32,8 @@ public class FileUtils {
* @return true if the folder was successfully deleted.
*/
public static boolean deleteFolder(File file) {
try {
org.apache.commons.io.FileUtils.deleteDirectory(file);
try (Stream<Path> files = Files.walk(file.toPath())) {
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
return true;
} catch (IOException e) {
Logging.warning(e.getMessage());
@ -44,8 +48,11 @@ public class FileUtils {
* @return true if the contents were successfully deleted
*/
public static boolean deleteFolderContents(File file) {
try {
org.apache.commons.io.FileUtils.cleanDirectory(file);
try (Stream<Path> files = Files.walk(file.toPath())){
files.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.filter(f -> !f.equals(file))
.forEach(File::delete);
return true;
} catch (IOException e) {
Logging.warning(e.getMessage());
@ -53,8 +60,6 @@ public class FileUtils {
}
}
private static final int COPY_BLOCK_SIZE = 1024;
/**
* Helper method to copy the world-folder.
* @param source Source-File
@ -64,8 +69,16 @@ public class FileUtils {
* @return if it had success
*/
public static boolean copyFolder(File source, File target, Logger log) {
try {
org.apache.commons.io.FileUtils.copyDirectory(source, target);
Path sourcePath = source.toPath();
Path destPath = target.toPath();
try (Stream<Path> files = Files.walk(source.toPath())) {
files.forEachOrdered(src -> {
try {
Files.copy(src, sourcePath.resolve(destPath.relativize(src)));
} catch (IOException e) {
log.warning(e.getMessage());
}
});
return true;
} catch (IOException e) {
log.warning(e.getMessage());

View File

@ -0,0 +1,85 @@
package com.onarandombox.MultiverseCore.utils;
import com.dumptruckman.minecraft.util.Logging;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.Assert.*;
public class FileUtilsTest {
private File parentDir;
private File parentDirFile;
private File childDir;
private File childDirFile;
private File dest;
@Before
public void setUp() throws Exception {
parentDir = Files.createTempDirectory("parentDir").toFile();
parentDirFile = new File(parentDir, "parentDirFile.txt");
parentDirFile.createNewFile();
childDir = Files.createTempDirectory(parentDir.toPath(), "childDir").toFile();
childDirFile = new File(childDir, "childDirFile.txt");
childDirFile.createNewFile();
dest = Files.createTempDirectory("dest").toFile();
assertTrue(parentDir.exists());
assertTrue(parentDirFile.exists());
assertTrue(childDir.exists());
assertTrue(childDirFile.exists());
assertTrue(dest.exists());
}
@After
public void tearDown() throws Exception {
try {
org.apache.commons.io.FileUtils.deleteDirectory(parentDir);
} catch (IOException e) {
if (parentDir.exists()) {
throw e;
}
}
try {
org.apache.commons.io.FileUtils.deleteDirectory(dest);
} catch (IOException e) {
if (parentDir.exists()) {
throw e;
}
}
}
@Test
public void deleteFolder() {
FileUtils.deleteFolder(parentDir);
assertFalse(parentDir.exists());
assertFalse(parentDirFile.exists());
assertFalse(childDir.exists());
assertFalse(childDirFile.exists());
}
@Test
public void deleteFolderContents() {
FileUtils.deleteFolderContents(parentDir);
assertTrue(parentDir.exists());
assertFalse(parentDirFile.exists());
assertFalse(childDir.exists());
assertFalse(childDirFile.exists());
}
@Test
public void copyFolder() {
File destFile = new File(dest, "parentDirFile.txt");
File destChildDir = new File(dest, "childDir");
File destChildDirFile = new File(destChildDir, "childDirFile.txt");
assertFalse(destFile.exists());
assertFalse(destChildDir.exists());
assertFalse(destChildDirFile.exists());
FileUtils.copyFolder(parentDir, dest, Logging.getLogger());
}
}