-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share vanilla installations across projects
- Loading branch information
1 parent
9b53014
commit fc7f73e
Showing
24 changed files
with
721 additions
and
318 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
10 changes: 10 additions & 0 deletions
10
src/main/java/dev/lukebemish/crochet/model/AbstractExternalVanillaInstallation.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,10 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
import javax.inject.Inject; | ||
|
||
public abstract class AbstractExternalVanillaInstallation extends ExternalMinecraftInstallation { | ||
@Inject | ||
public AbstractExternalVanillaInstallation(String name, CrochetExtension extension) { | ||
super(name, extension); | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/main/java/dev/lukebemish/crochet/model/AbstractVanillaInstallationData.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,4 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
interface AbstractVanillaInstallationData extends InstallationData { | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/dev/lukebemish/crochet/model/ExternalAbstractVanillaInstallation.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,23 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
import org.gradle.api.tasks.SourceSet; | ||
|
||
import javax.inject.Inject; | ||
|
||
public abstract class ExternalAbstractVanillaInstallation extends ExternalMinecraftInstallation { | ||
|
||
@Inject | ||
public ExternalAbstractVanillaInstallation(String name, CrochetExtension extension) { | ||
super(name, extension); | ||
} | ||
|
||
@Override | ||
public void forFeature(SourceSet sourceSet) { | ||
super.forFeature(sourceSet); | ||
} | ||
|
||
@Override | ||
public void forLocalFeature(SourceSet sourceSet) { | ||
super.forLocalFeature(sourceSet); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/dev/lukebemish/crochet/model/ExternalMinecraftInstallation.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,75 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
import dev.lukebemish.crochet.internal.ConfigurationUtils; | ||
import dev.lukebemish.crochet.internal.CrochetPlugin; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.gradle.api.Action; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.ModuleDependency; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.provider.Provider; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public abstract class ExternalMinecraftInstallation extends MinecraftInstallation { | ||
final Configuration assetsProperties; | ||
|
||
@Inject | ||
public ExternalMinecraftInstallation(String name, CrochetExtension extension) { | ||
super(name, extension); | ||
|
||
var project = extension.project; | ||
|
||
assetsProperties = project.getConfigurations().maybeCreate("crochet"+ StringUtils.capitalize(name)+"AssetsProperties"); | ||
assetsPropertiesFiles.from(assetsProperties); | ||
} | ||
|
||
boolean linked = false; | ||
|
||
protected abstract String sharingInstallationTypeTag(); | ||
|
||
protected Map<String, Configuration> getConfigurationsToLink() { | ||
return Map.of( | ||
"assets-properties", assetsProperties, | ||
"minecraft", minecraft, | ||
"minecraft-dependencies", minecraftDependencies, | ||
"minecraft-resources", minecraftResources, | ||
"minecraft-line-mapped", minecraftLineMapped, | ||
"non-upgradable", nonUpgradableDependencies | ||
); | ||
} | ||
|
||
public void consume(String project, String name) { | ||
if (linked) { | ||
throw new IllegalStateException("External Minecraft installation already linked"); | ||
} | ||
linked = true; | ||
var dependencies = this.crochetExtension.project.getDependencies(); | ||
Function<String, Action<ModuleDependency>> capabilitiesFunction = tag -> dependency -> { | ||
dependency.capabilities(capabilities -> { | ||
var group = CROSS_PROJECT_SHARING_CAPABILITY_GROUP + sharingInstallationTypeTag(); | ||
var module = tag + "-" + name; | ||
capabilities.requireCapability(group + ":" + module); | ||
}); | ||
dependency.attributes(attribute -> { | ||
attribute.attributeProvider(CrochetPlugin.LOCAL_DISTRIBUTION_ATTRIBUTE, getDistribution().map(it -> it.name().toLowerCase(Locale.ROOT))); | ||
}); | ||
}; | ||
Supplier<Provider<Dependency>> projectDependencyProvider = () -> crochetExtension.project.provider(() -> dependencies.project(Map.of("path", project))); | ||
for (var entry : getConfigurationsToLink().entrySet()) { | ||
var configuration = entry.getValue(); | ||
configuration.getAttributes().attributeProvider(CrochetPlugin.LOCAL_DISTRIBUTION_ATTRIBUTE, getDistribution().map(it -> it.name().toLowerCase(Locale.ROOT))); | ||
var tag = entry.getKey(); | ||
dependencies.addProvider( | ||
configuration.getName(), | ||
projectDependencyProvider.get(), | ||
capabilitiesFunction.apply(tag) | ||
); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/dev/lukebemish/crochet/model/ExternalVanillaInstallation.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,69 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
import dev.lukebemish.crochet.internal.CrochetPlugin; | ||
|
||
import javax.inject.Inject; | ||
|
||
public abstract class ExternalVanillaInstallation extends AbstractExternalVanillaInstallation { | ||
@Inject | ||
public ExternalVanillaInstallation(String name, CrochetExtension extension) { | ||
super(name, extension); | ||
} | ||
|
||
@Override | ||
void forRun(Run run, RunType runType) { | ||
super.forRun(run, runType); | ||
run.argFilesTask.configure(task -> task.getMinecraftVersion().set(getMinecraft())); | ||
|
||
run.classpath.fromDependencyCollector(run.getImplementation()); | ||
|
||
switch (runType) { | ||
case CLIENT -> { | ||
run.getMainClass().convention("net.minecraft.client.main.Main"); | ||
run.classpath.attributes(attributes -> attributes.attribute(CrochetPlugin.NEO_DISTRIBUTION_ATTRIBUTE, "client")); | ||
crochetExtension.project.afterEvaluate(p -> { | ||
if (run.getAvoidNeedlessDecompilation().get()) { | ||
run.classpath.extendsFrom(minecraft); | ||
} else { | ||
run.classpath.extendsFrom(minecraftLineMapped); | ||
} | ||
}); | ||
run.getArgs().addAll( | ||
"--gameDir", ".", | ||
"--assetIndex", "${assets_index_name}", | ||
"--assetsDir", "${assets_root}", | ||
"--accessToken", "NotValid", | ||
"--version", "${minecraft_version}" | ||
); | ||
} | ||
case SERVER -> { | ||
run.classpath.attributes(attributes -> attributes.attribute(CrochetPlugin.NEO_DISTRIBUTION_ATTRIBUTE, "server")); | ||
crochetExtension.project.afterEvaluate(p -> { | ||
if (run.getAvoidNeedlessDecompilation().get()) { | ||
run.classpath.extendsFrom(minecraft); | ||
} else { | ||
run.classpath.extendsFrom(minecraftLineMapped); | ||
} | ||
}); | ||
run.getMainClass().convention("net.minecraft.server.Main"); | ||
} | ||
case DATA -> { | ||
// TODO: what's the right stuff to go here? | ||
run.classpath.attributes(attributes -> attributes.attribute(CrochetPlugin.NEO_DISTRIBUTION_ATTRIBUTE, "client")); | ||
crochetExtension.project.afterEvaluate(p -> { | ||
if (run.getAvoidNeedlessDecompilation().get()) { | ||
run.classpath.extendsFrom(minecraft); | ||
} else { | ||
run.classpath.extendsFrom(minecraftLineMapped); | ||
} | ||
}); | ||
run.getMainClass().convention("net.minecraft.data.Main"); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected String sharingInstallationTypeTag() { | ||
return "vanilla"; | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/main/java/dev/lukebemish/crochet/model/FabricInstallationData.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,4 @@ | ||
package dev.lukebemish.crochet.model; | ||
|
||
interface FabricInstallationData extends AbstractVanillaInstallationData { | ||
} |
Oops, something went wrong.