mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 22:31:52 +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:
+10
-10
@@ -29,34 +29,34 @@ public class ManifestAddon implements BaseAddon {
|
||||
private final List<AddonInitializer> initializers;
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
|
||||
public ManifestAddon(AddonManifest manifest, List<AddonInitializer> initializers) {
|
||||
this.manifest = manifest;
|
||||
this.initializers = initializers;
|
||||
}
|
||||
|
||||
|
||||
public AddonManifest getManifest() {
|
||||
return manifest;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return manifest.getID();
|
||||
}
|
||||
|
||||
|
||||
public void initialize() {
|
||||
Injector<BaseAddon> addonInjector = Injector.get(this);
|
||||
addonInjector.addExplicitTarget(BaseAddon.class);
|
||||
|
||||
|
||||
Injector<Platform> platformInjector = Injector.get(platform);
|
||||
platformInjector.addExplicitTarget(Platform.class);
|
||||
|
||||
|
||||
logger.debug("Initializing addon {}", getID());
|
||||
|
||||
|
||||
initializers.forEach(initializer -> {
|
||||
Injector<Logger> loggerInjector = Injector.get(LoggerFactory.getLogger(initializer.getClass()));
|
||||
loggerInjector.addExplicitTarget(Logger.class);
|
||||
|
||||
|
||||
logger.debug("Invoking entry point {}", initializer.getClass());
|
||||
addonInjector.inject(initializer);
|
||||
platformInjector.inject(initializer);
|
||||
@@ -64,12 +64,12 @@ public class ManifestAddon implements BaseAddon {
|
||||
initializer.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, VersionRange> getDependencies() {
|
||||
return manifest.getDependencies();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return manifest.getVersion();
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class ManifestAddonClassLoader extends URLClassLoader {
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
|
||||
public ManifestAddonClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
}
|
||||
|
||||
+28
-28
@@ -44,34 +44,34 @@ import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||
public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ManifestAddonLoader.class);
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
|
||||
private final ConfigLoader manifestLoader = new ConfigLoader()
|
||||
.registerLoader(Version.class, new VersionLoader())
|
||||
.registerLoader(VersionRange.class, new VersionRangeLoader())
|
||||
.registerLoader(WebsiteConfig.class, WebsiteConfig::new);
|
||||
|
||||
.registerLoader(Version.class, new VersionLoader())
|
||||
.registerLoader(VersionRange.class, new VersionRangeLoader())
|
||||
.registerLoader(WebsiteConfig.class, WebsiteConfig::new);
|
||||
|
||||
public ManifestAddon loadAddon(Path addonPath, ClassLoader loader) {
|
||||
try(JarFile jar = new JarFile(addonPath.toFile())) {
|
||||
logger.debug("Loading addon from JAR {}", addonPath);
|
||||
|
||||
|
||||
JarEntry manifestEntry = jar.getJarEntry("terra.addon.yml");
|
||||
if(manifestEntry == null) {
|
||||
throw new ManifestNotPresentException("Addon " + addonPath + " does not contain addon manifest.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//noinspection NestedTryStatement
|
||||
try {
|
||||
AddonManifest manifest = manifestLoader.load(new AddonManifest(),
|
||||
new YamlConfiguration(jar.getInputStream(manifestEntry),
|
||||
"terra.addon.yml"));
|
||||
|
||||
new YamlConfiguration(jar.getInputStream(manifestEntry),
|
||||
"terra.addon.yml"));
|
||||
|
||||
logger.debug("Loading addon {}@{}", manifest.getID(), manifest.getVersion().getFormatted());
|
||||
|
||||
|
||||
if(manifest.getSchemaVersion() != 1) {
|
||||
throw new AddonException("Addon " + manifest.getID() + " has unknown schema version: " + manifest.getSchemaVersion());
|
||||
}
|
||||
|
||||
|
||||
List<AddonInitializer> initializers = manifest.getEntryPoints().stream().map(entryPoint -> {
|
||||
try {
|
||||
Object in = loader.loadClass(entryPoint).getConstructor().newInstance();
|
||||
@@ -87,9 +87,9 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
throw new AddonException(String.format("Entry point %s not found in JAR.", entryPoint), e);
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
return new ManifestAddon(manifest, initializers);
|
||||
|
||||
|
||||
} catch(LoadException e) {
|
||||
throw new ManifestException("Failed to load addon manifest", e);
|
||||
}
|
||||
@@ -97,19 +97,19 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
throw new AddonException("Failed to load addon from JAR " + addonPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
|
||||
logger.debug("Loading addons...");
|
||||
|
||||
|
||||
try(Stream<Path> files = Files.walk(addonsFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
|
||||
List<Path> addons = files
|
||||
.filter(path -> path.toFile().isFile())
|
||||
.filter(path -> path.toFile().canRead())
|
||||
.filter(path -> !path.getFileName().startsWith(".")) // ignore hidden files.
|
||||
.filter(path -> path.toString().endsWith(".jar"))
|
||||
.toList();
|
||||
|
||||
.filter(path -> path.toFile().isFile())
|
||||
.filter(path -> path.toFile().canRead())
|
||||
.filter(path -> !path.getFileName().startsWith(".")) // ignore hidden files.
|
||||
.filter(path -> path.toString().endsWith(".jar"))
|
||||
.toList();
|
||||
|
||||
addons.stream().map(path -> {
|
||||
try {
|
||||
return path.toUri().toURL();
|
||||
@@ -117,20 +117,20 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}).forEach(parent::addURL);
|
||||
|
||||
|
||||
return addons.stream()
|
||||
.map(jar -> loadAddon(jar, parent))
|
||||
.collect(Collectors.toList());
|
||||
.map(jar -> loadAddon(jar, parent))
|
||||
.collect(Collectors.toList());
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "MANIFEST";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return VERSION;
|
||||
|
||||
+15
-15
@@ -24,60 +24,60 @@ import com.dfsek.terra.api.registry.key.StringIdentifiable;
|
||||
public class AddonManifest implements ConfigTemplate, StringIdentifiable {
|
||||
@Value("schema-version")
|
||||
private int schemaVersion;
|
||||
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
|
||||
@Value("version")
|
||||
private Version version;
|
||||
|
||||
|
||||
@Value("license")
|
||||
private String license;
|
||||
|
||||
|
||||
@Value("contributors")
|
||||
@Default
|
||||
private List<String> contributors = Collections.emptyList();
|
||||
|
||||
|
||||
@Value("entrypoints")
|
||||
private List<String> entryPoints;
|
||||
|
||||
|
||||
@Value("depends")
|
||||
@Default
|
||||
private Map<String, VersionRange> dependencies = Collections.emptyMap();
|
||||
|
||||
|
||||
@Value("website")
|
||||
@Default
|
||||
private WebsiteConfig website;
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public int getSchemaVersion() {
|
||||
return schemaVersion;
|
||||
}
|
||||
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getContributors() {
|
||||
return contributors;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getEntryPoints() {
|
||||
return entryPoints;
|
||||
}
|
||||
|
||||
|
||||
public String getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
|
||||
public WebsiteConfig getWebsite() {
|
||||
return website;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, VersionRange> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
+6
-6
@@ -14,25 +14,25 @@ import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
public class WebsiteConfig implements ObjectTemplate<WebsiteConfig> {
|
||||
@Value("issues")
|
||||
private String issues;
|
||||
|
||||
|
||||
@Value("source")
|
||||
private String source;
|
||||
|
||||
|
||||
@Value("docs")
|
||||
private String docs;
|
||||
|
||||
|
||||
public String getDocs() {
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
public String getIssues() {
|
||||
return issues;
|
||||
}
|
||||
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WebsiteConfig get() {
|
||||
return this;
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ import java.io.Serial;
|
||||
public class AddonException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -4201912399458420090L;
|
||||
|
||||
|
||||
public AddonException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public AddonException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ import java.io.Serial;
|
||||
public class ManifestException extends AddonException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -2458077663176544645L;
|
||||
|
||||
|
||||
public ManifestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public ManifestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ import java.io.Serial;
|
||||
public class ManifestNotPresentException extends ManifestException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -2116663180747013810L;
|
||||
|
||||
|
||||
public ManifestNotPresentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
public ManifestNotPresentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user