generated from sVoxelDev/spigot-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: copy dbmigration from using class to temp dir and execute from t…
…here
- Loading branch information
Showing
5 changed files
with
114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package net.silthus.ebean; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
public class JarUtil { | ||
|
||
public static final char JAR_SEPARATOR = '/'; | ||
|
||
public static void copyFolderFromJar(Class<?> sourceClass, String folderName, File destFolder, CopyOption option) throws IOException { | ||
copyFolderFromJar(sourceClass, folderName, destFolder, option, null); | ||
} | ||
|
||
public static void copyFolderFromJar(Class<?> sourceClass, String folderName, File destFolder, CopyOption option, PathTrimmer trimmer) throws IOException { | ||
if (!destFolder.exists()) | ||
destFolder.mkdirs(); | ||
|
||
byte[] buffer = new byte[1024]; | ||
|
||
File fullPath = null; | ||
String path = sourceClass.getProtectionDomain().getCodeSource().getLocation().getPath(); | ||
if (trimmer != null) | ||
path = trimmer.trim(path); | ||
try { | ||
if (!path.startsWith("file")) | ||
path = "file://" + path; | ||
|
||
fullPath = new File(new URI(path)); | ||
} catch (URISyntaxException e) { | ||
e.printStackTrace(); | ||
} | ||
ZipInputStream zis = new ZipInputStream(new FileInputStream(fullPath)); | ||
|
||
ZipEntry entry; | ||
while ((entry = zis.getNextEntry()) != null) { | ||
if (!entry.getName().startsWith(folderName + JAR_SEPARATOR)) | ||
continue; | ||
|
||
String fileName = entry.getName(); | ||
|
||
if (fileName.charAt(fileName.length() - 1) == JAR_SEPARATOR) { | ||
File file = new File(destFolder + File.separator + fileName); | ||
if (file.isFile()) { | ||
file.delete(); | ||
} | ||
file.mkdirs(); | ||
continue; | ||
} | ||
|
||
File file = new File(destFolder + File.separator + fileName); | ||
if (option == CopyOption.COPY_IF_NOT_EXIST && file.exists()) | ||
continue; | ||
|
||
if (!file.getParentFile().exists()) | ||
file.getParentFile().mkdirs(); | ||
|
||
if (!file.exists()) | ||
file.createNewFile(); | ||
FileOutputStream fos = new FileOutputStream(file); | ||
|
||
int len; | ||
while ((len = zis.read(buffer)) > 0) { | ||
fos.write(buffer, 0, len); | ||
} | ||
fos.close(); | ||
} | ||
|
||
zis.closeEntry(); | ||
zis.close(); | ||
} | ||
|
||
public enum CopyOption { | ||
COPY_IF_NOT_EXIST, REPLACE_IF_EXIST; | ||
} | ||
|
||
@FunctionalInterface | ||
public interface PathTrimmer { | ||
String trim(String original); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
## H2 setup - In memory | ||
datasource: | ||
db: | ||
url: jdbc:h2:~/ebean | ||
driver: org.h2.Driver | ||
ebean: | ||
migration: | ||
run: true |