-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Sponge support (#99) + Substantial refactoring
* Closes #99 * Generate event listeners by manual method scan when running on Sponge API 9. Using the standard approach, registration fails due use of an isolated classloader. See SpongePowered/Sponge#3747 * Some refactoring. Use '.plugin' package for plugin entrypoints. Define SCM in main pom; add codecov profile. Use futures in EnvEnforcer, EnvUserResolver: this may alter the thread context of some command executions. * Remove Java 8 detection entirely. LibertyBans never was a popular plugin, so there's no need to cater to those who forget to read. More importantly, Java 8 usage dwindles and many other plugins now require newer Java versions. * Add relocation protection. We now serve and appease users who suffer unrelocated libraries. However, the real motivation is to support Sponge, which is warranted in its inclusion of an older version of HikariCP. * Refactor bootstrap loggers and avoid depending on slf4j in bans-bootstrap. * Extract executable jar without relying on plugin jar file. The Sponge API does not provide a method to access a plugin's jar file. Neither does it allow dynamically scanning plugin resources. As such, including directories of jars inside the executable distribution as used to occur requires us to squeeze from rock the Path to our plugin jar while running on Sponge or else manually list each dependency jar. To solve this, the directory of dependencies belonging to a dependency bundle is now zipped as its own jar, after which the launcher performs double-extraction on the twice-nested jars. With this solution, adding dependencies to bans-core remains trivial, requiring only the XML dependency declaration. * Update contribution guide, CONTRIBUTING.md, with code style basics and information on addons.
- Loading branch information
Showing
145 changed files
with
4,928 additions
and
2,078 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
50 changes: 50 additions & 0 deletions
50
bans-bootstrap/src/main/java/space/arim/libertybans/bootstrap/AttachableClassLoader.java
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,50 @@ | ||
/* | ||
* LibertyBans | ||
* Copyright © 2022 Anand Beh | ||
* | ||
* LibertyBans is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* LibertyBans is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/> | ||
* and navigate to version 3 of the GNU Affero General Public License. | ||
*/ | ||
|
||
package space.arim.libertybans.bootstrap; | ||
|
||
import space.arim.libertybans.bootstrap.depend.BootstrapException; | ||
import space.arim.libertybans.bootstrap.depend.JarAttachment; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.nio.file.Path; | ||
|
||
final class AttachableClassLoader extends URLClassLoader implements JarAttachment { | ||
|
||
static { | ||
ClassLoader.registerAsParallelCapable(); | ||
} | ||
|
||
AttachableClassLoader(String classLoaderName, ClassLoader parent) { | ||
super(classLoaderName, new URL[] {}, parent); | ||
} | ||
|
||
@Override | ||
public void addJarPath(Path jarFile) { | ||
URL url; | ||
try { | ||
url = jarFile.toUri().toURL(); | ||
} catch (MalformedURLException ex) { | ||
throw new BootstrapException("Unable to convert Path to URL", ex); | ||
} | ||
addURL(url); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
bans-bootstrap/src/main/java/space/arim/libertybans/bootstrap/FilteringClassLoader.java
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,58 @@ | ||
/* | ||
* LibertyBans | ||
* Copyright © 2022 Anand Beh | ||
* | ||
* LibertyBans is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* LibertyBans is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with LibertyBans. If not, see <https://www.gnu.org/licenses/> | ||
* and navigate to version 3 of the GNU Affero General Public License. | ||
*/ | ||
|
||
package space.arim.libertybans.bootstrap; | ||
|
||
import java.util.Set; | ||
|
||
final class FilteringClassLoader extends ClassLoader { | ||
|
||
private static final ClassNotFoundException FAILED_FILTER; | ||
private static final ClassNotFoundException DOES_NOT_LOAD_CLASSES; | ||
|
||
static { | ||
ClassLoader.registerAsParallelCapable(); | ||
FAILED_FILTER = new ClassNotFoundException( | ||
"Class is filtered from the eyes of child classloaders"); | ||
DOES_NOT_LOAD_CLASSES = new ClassNotFoundException( | ||
FilteringClassLoader.class.getName() + " does not itself load classes"); | ||
} | ||
|
||
private final Set<ProtectedLibrary> protectedLibraries; | ||
|
||
FilteringClassLoader(ClassLoader parent, Set<ProtectedLibrary> protectedLibraries) { | ||
super(parent); | ||
this.protectedLibraries = Set.copyOf(protectedLibraries); | ||
} | ||
|
||
@Override | ||
protected Class<?> loadClass(String className, boolean resolve) throws ClassNotFoundException { | ||
for (ProtectedLibrary protectedLibrary : protectedLibraries) { | ||
if (className.startsWith(protectedLibrary.basePackage())) { | ||
throw FAILED_FILTER; | ||
} | ||
} | ||
return super.loadClass(className, resolve); | ||
} | ||
|
||
@Override | ||
public Class<?> findClass(String className) throws ClassNotFoundException { | ||
throw DOES_NOT_LOAD_CLASSES; | ||
} | ||
} |
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
Oops, something went wrong.