Skip to content

Commit

Permalink
Turn jakarta-inject into an optionally provided dependency (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Jul 9, 2023
1 parent 85d1f11 commit de17b59
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2021 Anand Beh
* Copyright © 2023 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
Expand Down Expand Up @@ -42,6 +42,7 @@
enum DependencyBundle {

CAFFEINE(Repositories.CENTRAL_REPO),
JAKARTA(Repositories.CENTRAL_REPO),
KYORI(Repositories.CENTRAL_REPO),
SELF_IMPLEMENTATION(Repositories.ARIM_AFFERO_GPL3),
SLF4J(Repositories.CENTRAL_REPO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2022 Anand Beh
* Copyright © 2023 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
Expand Down Expand Up @@ -116,6 +116,11 @@ private Set<DependencyBundle> determineNeededDependencies(Set<ProtectedLibrary>
} else {
bundles.add(DependencyBundle.CAFFEINE);
}
if (platform.isJakartaProvided()) {
librariesRequiringProtection.remove(ProtectedLibrary.JAKARTA_INJECT);
} else {
bundles.add(DependencyBundle.JAKARTA);
}
if (platform.hasKyoriAdventureSupport()) {
librariesRequiringProtection.remove(ProtectedLibrary.KYORI_ADVENTURE);
librariesRequiringProtection.remove(ProtectedLibrary.KYORI_EXAMINATION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2022 Anand Beh
* Copyright © 2023 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
Expand Down Expand Up @@ -28,15 +28,17 @@ public final class Platform {
private final boolean slf4j;
private final boolean kyoriAdventure;
private final boolean caffeine;
private final boolean jakarta;
private final boolean hikariCP;

Platform(Category category, String platformName,
boolean slf4j, boolean kyoriAdventure, boolean caffeine, boolean hikariCP) {
boolean slf4j, boolean kyoriAdventure, boolean caffeine, boolean jakarta, boolean hikariCP) {
this.category = Objects.requireNonNull(category, "category");
this.platformName = Objects.requireNonNull(platformName, "platformName");
this.slf4j = slf4j;
this.kyoriAdventure = kyoriAdventure;
this.caffeine = caffeine;
this.jakarta = jakarta;
this.hikariCP = hikariCP;
}

Expand All @@ -60,6 +62,10 @@ public boolean isCaffeineProvided() {
return caffeine;
}

public boolean isJakartaProvided() {
return jakarta;
}

public boolean hasHiddenHikariCP() {
return hikariCP;
}
Expand All @@ -74,6 +80,7 @@ public static final class Builder {
private boolean slf4j;
private boolean kyoriAdventure;
private boolean caffeine;
private boolean jakarta;
private boolean hikariCP;

private Builder(Category category) {
Expand All @@ -95,13 +102,18 @@ public Builder caffeineProvided(LibraryDetection caffeine) {
return this;
}

public Builder jakartaProvided(LibraryDetection jakarta) {
this.jakarta = jakarta.evaluatePresence();
return this;
}

public Builder hiddenHikariCP(LibraryDetection hikariCP) {
this.hikariCP = hikariCP.evaluatePresence();
return this;
}

public Platform build(String platformName) {
return new Platform(category, platformName, slf4j, kyoriAdventure, caffeine, hikariCP);
return new Platform(category, platformName, slf4j, kyoriAdventure, caffeine, jakarta, hikariCP);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* LibertyBans
* Copyright © 2022 Anand Beh
* Copyright © 2023 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
Expand Down Expand Up @@ -54,25 +54,26 @@ public static Platform velocity(ClassLoader platformClassLoader) {
.kyoriAdventureSupport(LibraryDetection.enabled())
// Caffeine is an internal dependency
.caffeineProvided(new LibraryDetection.ByClassLoaderScan(ProtectedLibrary.CAFFEINE, platformClassLoader))
.jakartaProvided(new LibraryDetection.ByClassLoaderScan(ProtectedLibrary.JAKARTA_INJECT, platformClassLoader))
.build("Velocity");
}

// Used for testing purposes
public static Stream<Platform> allPossiblePlatforms(String platformName) {
Set<Platform> platforms = new HashSet<>();
for (Platform.Category category : Platform.Category.values()) {
for (boolean adventure : new boolean[] {true, false}) {
for (boolean slf4j : new boolean[] {true, false}) {
for (boolean caffeine : new boolean[] {true, false}) {
platforms.add(Platform.builderForCategory(category)
.kyoriAdventureSupport(() -> adventure)
.slf4jSupport(() -> slf4j)
.caffeineProvided(() -> caffeine)
.build("Testing"));
}
}
// Count from 0000 to 1111 in binary
for (int setting = 0; setting < 0b10000; setting++) {
final int flags = setting;
platforms.add(Platform.builderForCategory(category)
.kyoriAdventureSupport(() -> (flags & 0b0001) != 0)
.slf4jSupport(() -> (flags & 0b0010) != 0)
.caffeineProvided(() -> (flags & 0b0100) != 0)
.jakartaProvided(() -> (flags & 0b1000) != 0)
.build(platformName));
}
}
return platforms.stream();
}

}
4 changes: 4 additions & 0 deletions bans-bootstrap/src/main/resources/dependencies/jakarta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jakarta.inject
jakarta.inject-api
${jakarta-inject.version}
5512882113f8dcb70b087f01e3c11d7d3d505c1671bee6dc47208014599d7830d6f184d249b9db72b351c05dd33259c821b80b784c7b3b6e961eeb03a689644b
1 change: 1 addition & 0 deletions bans-distribution/download/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<exclude>net.kyori:*</exclude>
<exclude>org.jetbrains:annotations</exclude>
<exclude>com.github.ben-manes.caffeine:caffeine</exclude>
<exclude>jakarta.inject:jakarta.inject-api</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions bans-distribution/executable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<attach>false</attach>
<descriptors>
<descriptor>src/assembly/caffeine.xml</descriptor>
<descriptor>src/assembly/jakarta.xml</descriptor>
<descriptor>src/assembly/kyori.xml</descriptor>
<descriptor>src/assembly/self-implementation.xml</descriptor>
<descriptor>src/assembly/slf4j.xml</descriptor>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
~ LibertyBans
~ Copyright © 2022 Anand Beh
~ Copyright © 2023 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
Expand Down Expand Up @@ -38,6 +38,11 @@
<source>${project.build.directory}/bundles/${project.build.finalName}-caffeine-bundle.jar</source>
<destName>caffeine-bundle.jar</destName>
</file>
<file>
<outputDirectory>/dependencies/jars/</outputDirectory>
<source>${project.build.directory}/bundles/${project.build.finalName}-jakarta-bundle.jar</source>
<destName>jakarta-bundle.jar</destName>
</file>
<file>
<outputDirectory>/dependencies/jars/</outputDirectory>
<source>${project.build.directory}/bundles/${project.build.finalName}-kyori-bundle.jar</source>
Expand Down
39 changes: 39 additions & 0 deletions bans-distribution/executable/src/assembly/jakarta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
~ LibertyBans
~ Copyright © 2023 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.
-->

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>jakarta-bundle</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<useStrictFiltering>true</useStrictFiltering>
<includes>
<include>jakarta.inject:jakarta.inject-api</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
~ LibertyBans
~ Copyright © 2022 Anand Beh
~ Copyright © 2023 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
Expand Down Expand Up @@ -34,6 +34,8 @@
<excludes>
<!-- caffeine.xml -->
<exclude>com.github.ben-manes.caffeine:caffeine</exclude>
<!-- jakarta.xml -->
<exclude>jakarta.inject:jakarta.inject-api</exclude>
<!-- kyori.xml -->
<exclude>net.kyori:*</exclude>
<!-- slf4j.xml -->
Expand Down

0 comments on commit de17b59

Please sign in to comment.