Skip to content

Commit

Permalink
Add a PluginContainer for SpongeCommon using the id 'sponge'. Migrate…
Browse files Browse the repository at this point in the history
… version strings to use new format.

Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
  • Loading branch information
gabizou committed Oct 10, 2018
1 parent beeee60 commit f734fd0
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 10 deletions.
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,23 @@ ext.common = project
apply from: 'gradle/minecraft.gradle'

// Inherit SpongeCommon version from SpongeAPI
version = api.version
ext.apiVersion = version
ext {
isSnapshot = api.version.contains('-SNAPSHOT')
isImplRC = common.recommendedVersion.contains('-SNAPSHOT')
trimmedApiVersion = api.version.toString().replace("-SNAPSHOT", "")
apiSplitVersion = trimmedApiVersion.split("\\.")
// This is to determine if the split api version has at the least a minimum version.
apiMinor = apiSplitVersion.length > 1 ? apiSplitVersion[1] : (apiSplitVersion.length > 0 ? apiSplitVersion.last : '0')
correctedMinorVersion = Math.max(Integer.parseInt(apiMinor) - 1, 0)
// And then here, we determine if the api version still has a patch version, to just ignore it.
apiReleaseVersion = apiSplitVersion.length > 2 ? apiSplitVersion[0] + '.' + apiSplitVersion[1] : trimmedApiVersion
apiSuffix = isSnapshot ? ext.apiSplitVersion[0] + '.' + correctedMinorVersion : apiReleaseVersion
fixedApiVersionWithDecreasedMinor = apiSplitVersion.length > 2 ? apiSplitVersion[0] + '.' + correctedMinorVersion + '.' + apiSplitVersion[2] : apiSplitVersion[0] + '.' + correctedMinorVersion
}
version = minecraftVersion + '-' + ext.apiSuffix + '.' + common.recommendedVersion

ext.apiVersion = isSnapshot ? ext.fixedApiVersionWithDecreasedMinor : ext.apiReleaseVersion


dependencies {
compile(api) {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ url=https://www.spongepowered.org
organization=SpongePowered

minecraftVersion=1.12.2
recommendedVersion=1-SNAPSHOT
mcpMappings=snapshot_20180808

# We use VanillaGradle instead of an official ForgeGradle plugin.
Expand Down
29 changes: 26 additions & 3 deletions gradle/implementation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ apply plugin: 'org.spongepowered.meta'
generateMetadata {
dependsOn common.resolveApiRevision
}

ext {
implementationVersion = (common.isImplRC ? common.apiSuffix + '.' + common.recommendedVersion - '-SNAPSHOT' + "-RC$buildNumber" : common.apiSuffix + '.' + common.recommendedVersion)
}
sponge {
plugin {
id = 'sponge'
id = project.ext.implementationId
version = project.version
meta {
inherit project
}
meta.dependencies {
spongeapi {
forceVersion {common.apiVersion}
}

sponge {
forceVersion {common.version}
}
minecraft {
forceVersion project.minecraft.version
}
Expand All @@ -59,6 +67,21 @@ sponge {
version = {common.apiVersion}
}
}
sponge {
meta {
inherit common
name = "Sponge"
version = common.version
dependencies {
spongeapi {
forceVersion {common.apiVersion}
}
minecraft {
forceVersion project.minecraft.version
}
}
}
}
}
}

Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/spongepowered/common/SpongeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.game.state.GameStateEvent;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.asm.util.PrettyPrinter;
import org.spongepowered.common.config.SpongeConfig;
import org.spongepowered.common.config.SpongeConfigSaveManager;
import org.spongepowered.common.config.type.CustomDataConfig;
Expand Down Expand Up @@ -73,7 +74,7 @@ public final class SpongeImpl {

public static final String API_NAME = "SpongeAPI";

public static final String ECOSYSTEM_ID = "sponge";
public static final String ECOSYSTEM_ID = "sponge"; // This is different from the id used by the actual implementation
public static final String ECOSYSTEM_NAME = "Sponge";

// TODO: Keep up to date
Expand All @@ -88,6 +89,7 @@ public final class SpongeImpl {
@Nullable private static SpongeConfig<CustomDataConfig> customDataConfig;
@Nullable private static SpongeConfigSaveManager configSaveManager;
@Nullable private static PluginContainer minecraftPlugin;
@Nullable private static PluginContainer spongecommon;

@Inject @Nullable private static SpongeGame game;
@Inject @Nullable private static SpongeGameRegistry registry;
Expand All @@ -107,9 +109,19 @@ private static void initialize(Platform platform) {
minecraftPlugin = platform.getContainer(Platform.Component.GAME);
}


for (Platform.Component component : Platform.Component.values()) {
internalPlugins.add(platform.getContainer(component));
if (component == Platform.Component.API && platform instanceof SpongePlatform) {
// We want to set up the common version after the api.
internalPlugins.add(((SpongePlatform) platform).getCommon());
}
}

final PrettyPrinter printer = new PrettyPrinter(60).add("InternalPlugins").centre().hr()
.add("Listing plugins:");
internalPlugins.forEach(plugin -> printer.add(" - " + plugin.getId() + " : " + plugin.getVersion().orElse("")));
printer.trace();
}

private static <T> T check(@Nullable T instance) {
Expand Down Expand Up @@ -171,6 +183,16 @@ public static void setMinecraftPlugin(PluginContainer minecraft) {
minecraftPlugin = minecraft;
}

public static void setSpongePlugin(PluginContainer common) {
checkState(spongecommon == null);
spongecommon = common;
}

public static PluginContainer getSpongePlugin() {
checkState(spongecommon != null, "SpongeCommon plugin container is not initialized");
return spongecommon;
}

public static Path getGameDir() {
return SpongeLaunch.getGameDir();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/spongepowered/common/SpongeImplHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,8 @@ public static boolean isMainThread() {
public static boolean creativeExploitCheck(Packet<?> packetIn, EntityPlayerMP playerMP) {
return false;
}

public static String getImplementationId() {
throw new UnsupportedOperationException("SpongeCommon does not have it's own ecosystem, this needs to be mixed into for implementations depending on SpongeCommon");
}
}
12 changes: 10 additions & 2 deletions src/main/java/org/spongepowered/common/SpongePlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
public class SpongePlatform implements Platform {

private final PluginContainer api;
private final PluginContainer common;
private final PluginContainer impl;
private final PluginContainer minecraft;
private final MinecraftVersion minecraftVersion;
Expand All @@ -59,19 +60,22 @@ public Object put(String key, Object value) {

@Inject
public SpongePlatform(PluginManager manager, MinecraftVersion minecraftVersion) {
this(manager, manager.getPlugin(SpongeImpl.ECOSYSTEM_ID).get(), minecraftVersion);
this(manager, manager.getPlugin(SpongeImplHooks.getImplementationId()).get(), minecraftVersion);
}

// For SpongeForge (implementation container isn't registered when SpongePlatform is initialized)
protected SpongePlatform(PluginManager manager, PluginContainer impl, MinecraftVersion minecraftVersion) {
protected SpongePlatform(PluginManager manager, PluginContainer impl, MinecraftVersion minecraftVersion) {
this.api = manager.getPlugin(Platform.API_ID).get();
this.common = manager.getPlugin(SpongeImpl.ECOSYSTEM_ID).get();
this.impl = checkNotNull(impl, "impl");
this.minecraft = manager.getPlugin(SpongeImpl.GAME_ID).get();
this.minecraftVersion = checkNotNull(minecraftVersion, "minecraftVersion");

this.platformMap.put("Type", this.getType());
this.platformMap.put("ApiName", this.api.getName());
this.platformMap.put("ApiVersion", this.api.getVersion());
this.platformMap.put("CommonName", this.common.getName());
this.platformMap.put("CommonVersion", this.common.getVersion());
this.platformMap.put("ImplementationName", this.impl.getName());
this.platformMap.put("ImplementationVersion", this.impl.getVersion());
this.platformMap.put("MinecraftVersion", this.getMinecraftVersion());
Expand All @@ -80,6 +84,10 @@ protected SpongePlatform(PluginManager manager, PluginContainer impl, MinecraftV
// For SpongeCommon we assume that we are always on the server
// SpongeForge overrides this to return CLIENT when running in a client environment

public PluginContainer getCommon() {
return this.common;
}

@Override
public Type getType() {
return Type.SERVER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.plugin.PluginManager;
import org.spongepowered.common.SpongeGame;
import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.SpongePlatform;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.inject.SpongeImplementationModule;
Expand Down Expand Up @@ -63,8 +64,8 @@ protected void configure() {
when(manager.getPlugin(anyString())).thenReturn(Optional.of(mock));
when(manager.fromInstance(any())).thenReturn(Optional.of(mock));
this.bind(PluginManager.class).toInstance(manager);


PluginContainer common = mock(PluginContainer.class);
SpongeImpl.setSpongePlugin(common);
this.bind(EventManager.class).toInstance(mock(EventManager.class));
this.bind(ChannelRegistrar.class).toInstance(mock(ChannelRegistrar.class));
}
Expand Down

0 comments on commit f734fd0

Please sign in to comment.