Skip to content

Commit

Permalink
fixup! added extractFromJar api from addon
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Dec 31, 2024
1 parent fbfa74a commit 6160579
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public interface GroovierAddon {
/**
* extract file from jar
* @param jar jar class
* @param source source path
* @param target target path
* @param source source folder path
* @throws URISyntaxException uri syntax exception
* @throws IOException io exception
*/
void extractFromJar(Class<?> jar, String source, Path target) throws URISyntaxException, IOException;
void extractFromJar(Class<?> jar, String source) throws URISyntaxException, IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jetbrains.annotations.NotNull;

import javax.inject.Provider;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -47,13 +48,16 @@ public static GroovierAPI getApi() {

private Injector injector;
private GroovierScriptLoader loader;
private File pluginFolder;

private GroovierLifeCycle lifeCycle;


public void onLoad(ScriptPlugin plugin) {
pluginFolder = plugin.getPluginFolder();
groovierModule.bindScriptPlugin(plugin);
plugin.copyResources();

}


Expand Down Expand Up @@ -110,7 +114,7 @@ public void installModule(Module module) {
}

@Override
public void extractFromJar(Class<?> jar, String source, Path target) throws URISyntaxException, IOException {
public void extractFromJar(Class<?> jar, String source) throws URISyntaxException, IOException {
URL url = jar.getResource("");

if (url == null) {
Expand All @@ -124,7 +128,7 @@ public void extractFromJar(Class<?> jar, String source, Path target) throws URIS
Collections.<String, String>emptyMap()
)) {


final Path target = pluginFolder.toPath();
final Path jarPath = fileSystem.getPath(source);

Files.walkFileTree(jarPath, new SimpleFileVisitor<>() {
Expand All @@ -139,7 +143,10 @@ public void extractFromJar(Class<?> jar, String source, Path target) throws URIS
@Override
public @NotNull FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
var targetPath = target.resolve(jarPath.relativize(file).toString());
if (Files.notExists(targetPath)) Files.copy(file, targetPath, StandardCopyOption.REPLACE_EXISTING);
if (Files.notExists(targetPath)) {
targetPath.toFile().mkdirs();
}
Files.copy(file, targetPath, StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}

Expand All @@ -163,7 +170,7 @@ public ArgumentParser getArgumentParser() {
return getBaseInjector().getInstance(ArgumentParser.class);
}

public void copyFromJar(String source, final Path target) throws URISyntaxException, IOException {
extractFromJar(getClass(), source, target);
public void copyFromJar(String source) throws URISyntaxException, IOException {
extractFromJar(getClass(), source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class GroovierPlugin extends Plugin implements ScriptPlugin {
var copyDefault = config.getBoolean("CopyDefaults")
if (!copyDefault) return
try {
core.copyFromJar("bungee", getPluginFolder().toPath())
core.copyFromJar("common", getPluginFolder().toPath())
core.copyFromJar("bungee")
core.copyFromJar("common")
} catch (URISyntaxException | IOException e) {
getLogger().warning("Failed to copy resources: " + e.getMessage())
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class GroovierPlugin extends JavaPlugin implements ScriptPlugin {
var copyDefault = config.getBoolean("CopyDefaults")
if (!copyDefault) return
try {
core.copyFromJar("spigot", getPluginFolder().toPath())
core.copyFromJar("common", getPluginFolder().toPath())
core.copyFromJar("spigot")
core.copyFromJar("common")
} catch (URISyntaxException | IOException e) {
getLogger().warning("Failed to copy resources: " + e.getMessage())
e.printStackTrace()
Expand Down

0 comments on commit 6160579

Please sign in to comment.