mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-12 18:56:04 +00:00
Change Java whitespace handling in .editorconfig (#425)
* Change whitespace handling in .editorconfig * Reformat code * fix format error * Reformat code --------- Co-authored-by: Zoë Gidiere <duplexsys@protonmail.com>
This commit is contained in:
@@ -40,30 +40,30 @@ import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||
public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAddon<?>> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BootstrapAddonLoader.class);
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
|
||||
public BootstrapAddonLoader() { }
|
||||
|
||||
|
||||
private BootstrapBaseAddon<?> loadAddon(Path addonPath, BootstrapAddonClassLoader parent) {
|
||||
logger.debug("Loading bootstrap addon from JAR {}", addonPath);
|
||||
try(JarFile jar = new JarFile(addonPath.toFile())) {
|
||||
String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point");
|
||||
|
||||
|
||||
if(entry == null) {
|
||||
throw new AddonLoadException("No Terra-Bootstrap-Addon-Entry-Point attribute defined in addon's MANIFEST.MF.");
|
||||
}
|
||||
|
||||
|
||||
//noinspection NestedTryStatement
|
||||
try {
|
||||
parent.addURL(addonPath.toUri().toURL());
|
||||
Object addonObject = parent.loadClass(entry).getConstructor().newInstance();
|
||||
|
||||
|
||||
if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) {
|
||||
throw new AddonLoadException(
|
||||
addonObject.getClass() + " does not extend " + BootstrapBaseAddon.class);
|
||||
addonObject.getClass() + " does not extend " + BootstrapBaseAddon.class);
|
||||
}
|
||||
|
||||
|
||||
logger.debug("Loaded bootstrap addon {}@{} with entry point {}",
|
||||
addon.getID(), addon.getVersion().getFormatted(), addonObject.getClass());
|
||||
addon.getID(), addon.getVersion().getFormatted(), addonObject.getClass());
|
||||
return addon;
|
||||
} catch(InvocationTargetException e) {
|
||||
throw new AddonLoadException("Exception occurred while instantiating addon", e);
|
||||
@@ -72,36 +72,36 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
} catch(ClassNotFoundException | NoClassDefFoundError e) {
|
||||
throw new AddonLoadException(String.format("Entry point %s not found in JAR.", entry), e);
|
||||
}
|
||||
|
||||
|
||||
} catch(IOException e) {
|
||||
throw new AddonLoadException("Failed to load addon from path " + addonPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
|
||||
try {
|
||||
Path bootstrapFolder = addonsFolder.resolve("bootstrap");
|
||||
Files.createDirectories(bootstrapFolder);
|
||||
logger.debug("Loading bootstrap addons from {}", bootstrapFolder);
|
||||
|
||||
|
||||
try(Stream<Path> bootstrapAddons = Files.walk(bootstrapFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
|
||||
return bootstrapAddons.filter(path -> path.toFile().isFile())
|
||||
.filter(path -> path.toFile().canRead())
|
||||
.filter(path -> path.toString().endsWith(".jar"))
|
||||
.map(path -> loadAddon(path, parent))
|
||||
.collect(Collectors.toList());
|
||||
.filter(path -> path.toFile().canRead())
|
||||
.filter(path -> path.toString().endsWith(".jar"))
|
||||
.map(path -> loadAddon(path, parent))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "BOOTSTRAP";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return VERSION;
|
||||
|
||||
@@ -23,11 +23,11 @@ import java.io.Serial;
|
||||
public class AddonLoadException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -4949084729296580176L;
|
||||
|
||||
|
||||
public AddonLoadException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public AddonLoadException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user