mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-15 12:02:48 +01:00
Removed commons-io as compile dependency to fix weird pom issues.
This commit is contained in:
parent
6ebc1188e8
commit
7762aca019
35
pom.xml
35
pom.xml
@ -189,9 +189,6 @@
|
|||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<artifactSet>
|
|
||||||
<excludes>commons-io:commons-io</excludes>
|
|
||||||
</artifactSet>
|
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>me.main__.util</pattern>
|
<pattern>me.main__.util</pattern>
|
||||||
@ -228,27 +225,6 @@
|
|||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</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>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -268,11 +244,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
@ -372,6 +343,12 @@
|
|||||||
<version>4.0.2</version>
|
<version>4.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -11,7 +11,11 @@ import com.dumptruckman.minecraft.util.Logging;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
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.logging.Logger;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File-utilities.
|
* File-utilities.
|
||||||
@ -28,8 +32,8 @@ public class FileUtils {
|
|||||||
* @return true if the folder was successfully deleted.
|
* @return true if the folder was successfully deleted.
|
||||||
*/
|
*/
|
||||||
public static boolean deleteFolder(File file) {
|
public static boolean deleteFolder(File file) {
|
||||||
try {
|
try (Stream<Path> files = Files.walk(file.toPath())) {
|
||||||
org.apache.commons.io.FileUtils.deleteDirectory(file);
|
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.warning(e.getMessage());
|
Logging.warning(e.getMessage());
|
||||||
@ -44,8 +48,11 @@ public class FileUtils {
|
|||||||
* @return true if the contents were successfully deleted
|
* @return true if the contents were successfully deleted
|
||||||
*/
|
*/
|
||||||
public static boolean deleteFolderContents(File file) {
|
public static boolean deleteFolderContents(File file) {
|
||||||
try {
|
try (Stream<Path> files = Files.walk(file.toPath())){
|
||||||
org.apache.commons.io.FileUtils.cleanDirectory(file);
|
files.sorted(Comparator.reverseOrder())
|
||||||
|
.map(Path::toFile)
|
||||||
|
.filter(f -> !f.equals(file))
|
||||||
|
.forEach(File::delete);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.warning(e.getMessage());
|
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.
|
* Helper method to copy the world-folder.
|
||||||
* @param source Source-File
|
* @param source Source-File
|
||||||
@ -64,8 +69,16 @@ public class FileUtils {
|
|||||||
* @return if it had success
|
* @return if it had success
|
||||||
*/
|
*/
|
||||||
public static boolean copyFolder(File source, File target, Logger log) {
|
public static boolean copyFolder(File source, File target, Logger log) {
|
||||||
|
Path sourcePath = source.toPath();
|
||||||
|
Path destPath = target.toPath();
|
||||||
|
try (Stream<Path> files = Files.walk(source.toPath())) {
|
||||||
|
files.forEachOrdered(src -> {
|
||||||
try {
|
try {
|
||||||
org.apache.commons.io.FileUtils.copyDirectory(source, target);
|
Files.copy(src, sourcePath.resolve(destPath.relativize(src)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warning(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warning(e.getMessage());
|
log.warning(e.getMessage());
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user