Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic mods toml generation + dependencies #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Updates to dependencies block, changed curse block, added all documen…
…tation and javadoc
Thodor12 committed Nov 28, 2024
commit bc52f93d9e7e9072b7b4a9000184161fcc2d340e
4 changes: 2 additions & 2 deletions examples/basic/build.gradle
Original file line number Diff line number Diff line change
@@ -5,6 +5,6 @@ tableau {
group = 'com.example' // Use your own group here.
minecraftVersion = '1.21.3' // Or any other minecraft version.
publisher = 'SomePublisher' // Use your own name here.
url = 'https://github.com/someorg/modid' // Use your own URL here.
repositoryUrl = uri('https://github.com/someorg/modid') // Use your own URL here.
}
}
}
4 changes: 2 additions & 2 deletions examples/maven-publish/build.gradle
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ tableau {
group = 'com.example' // Use your own group here.
minecraftVersion = '1.21.3' // Or any other minecraft version.
publisher = 'SomePublisher' // Use your own name here.
url = 'https://github.com/someorg/modid' // Use your own URL here.
repositoryUrl = uri('https://github.com/someorg/modid') // Use your own URL here.
}

maven {
@@ -14,4 +14,4 @@ tableau {
usingGit()
}
}
}
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -21,10 +21,10 @@ fancyModLoader = { module = "net.neoforged.fancymodloader:loader", version.ref =
secureJarHandler = { module = "cpw.mods:securejarhandler", version.ref = "secureJarHandler" }

[bundles]
neogradle = ["neogradle-userdev"]
neogradle = ["neogradle-userdev", "fancyModLoader"]
crowdin = ["crowdin", "gradle-download"]
sonarqube = ["sonarqube"]
shadow = ["shadow"]
jetbrainsAnnotations = ["jetbrainsAnnotations"]
curseForgeGradle = ["curseForgeGradle"]
fancyModLoader = ["fancyModLoader", "secureJarHandler"]
fancyModLoader = ["fancyModLoader", "secureJarHandler"]
Original file line number Diff line number Diff line change
@@ -90,21 +90,22 @@ public void versioning(final Action<Versioning> action) {
public abstract Property<String> getMinecraftVersion();

/**
* @return The mod id.
*/
public abstract Property<String> getModId();

/**
* The mod display name.
*
* @return The mod display name.
*/
public abstract Property<String> getModName();

/**
* The full mod description.
*
* @return The mod description.
*/
public abstract Property<String> getModDescription();

/**
* The mod logo file.
*
* @return The mod logo.
*/
public abstract Property<String> getModLogo();
@@ -131,11 +132,15 @@ public void versioning(final Action<Versioning> action) {
public abstract Property<URI> getRepositoryUrl();

/**
* The url of the website where the issue tracker can be found for the project.
*
* @return The issue tracker url, where issues may be filed for the mod.
*/
public abstract Property<URI> getIssueTrackerUrl();

/**
* The license for the mod.
*
* @return The license used for the mod.
*/
public abstract Property<String> getLicense();
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.curseforge.extensions.CurseForgeExtension;
import com.ldtteam.tableau.extensions.NeoGradleExtension;
import com.ldtteam.tableau.dependencies.extensions.DependenciesExtension;
import com.ldtteam.tableau.jarjar.JarJarPlugin;
import com.ldtteam.tableau.neogradle.NeoGradlePlugin;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
@@ -14,11 +14,9 @@
import net.darkhax.curseforgegradle.Constants;
import net.darkhax.curseforgegradle.TaskPublishCurseForge;
import net.darkhax.curseforgegradle.UploadArtifact;
import org.gradle.api.GradleException;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Project;
import org.gradle.api.Plugin;
import org.gradle.api.internal.project.IProjectFactory;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.jvm.tasks.Jar;
@@ -70,6 +68,7 @@ private void configureUploadTask(final Project project) {
final TaskProvider<? extends Jar> mainJar = getMainJar(project);
final CurseForgeExtension curse = CurseForgeExtension.get(project);
final SourceSetExtension sourceSets = SourceSetExtension.get(project);
final DependenciesExtension dependencies = DependenciesExtension.get(project);
final ModExtension mod = ModExtension.get(project);

if (!curse.getId().isPresent()) {
@@ -118,6 +117,9 @@ private void configureUploadTask(final Project project) {
}
});

dependencies.getAllRequiredDependencies().get().forEach(dep -> artifact.addRelation(dep.modId(), Constants.RELATION_REQUIRED));
dependencies.getAllOptionalDependencies().get().forEach(dep -> artifact.addRelation(dep.modId(), Constants.RELATION_OPTIONAL));

curse.getRelationships().get().forEach((slug, relationship) -> {
if (!Constants.VALID_RELATION_TYPES.contains(relationship)) {
throw new InvalidUserDataException("Invalid relationship type: %s for project: %s".formatted(relationship, slug));
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ldtteam.tableau.curseforge.extensions;

import com.ldtteam.tableau.extensions.NeoGradleResourceProcessingExtension;
import com.ldtteam.tableau.neogradle.extensions.NeoGradleResourceProcessingExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import net.darkhax.curseforgegradle.Constants;
import org.gradle.api.Action;
@@ -143,8 +143,6 @@ public String toString() {
* <ul>
* <li>embeddedLibrary</li>
* <li>incompatible</li>
* <li>optionalDependency</li>
* <li>requiredDependency</li>
* <li>tool</li>
* </ul>
* @return the relationships this project has with others
@@ -193,8 +191,6 @@ public Relationships(MapProperty<String, String> relationships) {
* <ul>
* <li>embeddedLibrary</li>
* <li>incompatible</li>
* <li>optionalDependency</li>
* <li>requiredDependency</li>
* <li>tool</li>
* </ul>
* @return the relationships this project has with other published projects on CurseForge.
@@ -230,23 +226,5 @@ public void embedded(String slug) {
public void incompatible(String slug) {
getRelationships().put(slug, Constants.RELATION_INCOMPATIBLE);
}

/**
* Marks the given project as an optional dependency.
*
* @param slug the slug of the project
*/
public void optional(String slug) {
getRelationships().put(slug, Constants.RELATION_OPTIONAL);
}

/**
* Marks the given project as a required dependency.
*
* @param slug the slug of the project
*/
public void required(String slug) {
getRelationships().put(slug, Constants.RELATION_REQUIRED);
}
}
}
Original file line number Diff line number Diff line change
@@ -3,12 +3,26 @@
*/
package com.ldtteam.tableau.dependencies;

import org.gradle.api.Project;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;

/**
* The root plugin for the Dependencies module.
* <p>
* Can be applied to any {@link org.gradle.api.plugins.PluginAware} but will only interact with {@link Project projects}
*/
public class DependenciesPlugin implements Plugin<Object> {

/**
* Creates a new plugin instance.
*/
@Inject
public DependenciesPlugin() {
}

@Override
public void apply(@NotNull Object target) {
if (target instanceof Project project) {
Original file line number Diff line number Diff line change
@@ -5,13 +5,25 @@

import com.ldtteam.tableau.dependencies.extensions.DependenciesExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import org.gradle.api.Project;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;

/**
* Defines the Dependencies module plugin for {@link Project projects}
*/
public class DependenciesProjectPlugin implements Plugin<Project> {

/**
* Creates a new plugin instance.
*/
@Inject
public DependenciesProjectPlugin() {
}

@Override
public void apply(@NotNull Project target) {
target.getPlugins().apply(JavaLibraryPlugin.class);
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
package com.ldtteam.tableau.dependencies.extensions;

import com.ldtteam.tableau.dependencies.model.ModDependency;
import com.ldtteam.tableau.dependencies.util.DependencyResolver;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.Dependencies;
import org.gradle.api.artifacts.dsl.DependencyCollector;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

import javax.inject.Inject;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* The Dependencies extension for the Tableau project.
* <p>
* Provides a way to register mod dependencies as project and Neogradle dependencies.
*/
public abstract class DependenciesExtension implements Dependencies
{
public abstract class DependenciesExtension implements Dependencies {

/**
* The name of the extension.
*/
public static final String EXTENSION_NAME = "modDependencies";

/**
* The project this extension is added to.
*/
private final Project project;

/**
* Creates a new extension for the given project.
*
* @param project The project to create the extension for.
*/
@Inject
public DependenciesExtension(final Project project)
{
public DependenciesExtension(final Project project) {
this.project = project;

final SourceSet mainSourceSet = project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME);
@@ -42,28 +56,64 @@ public DependenciesExtension(final Project project)
* @param project The project.
* @return The git extension.
*/
public static DependenciesExtension get(final Project project)
{
public static DependenciesExtension get(final Project project) {
return TableauScriptingExtension.get(project, DependenciesExtension.class);
}

/**
* Get the required dependencies.
*
* @return The dependency collector for required mods.
*/
public abstract DependencyCollector getRequired();

/**
* Get the required runtime dependencies.
*
* @return A set property containing all the required runtime mods.
*/
public abstract SetProperty<ModDependency> getRequiredRuntimeMods();

/**
* Add a required runtime dependency.
*
* @param modId The mod id for the dependency.
* @param versionRange The version range for the dependency.
*/
public void requiredRuntime(final String modId, final String versionRange) {
getRequiredRuntimeMods().add(new ModDependency(modId, versionRange, true));
}

/**
* Get the optional dependencies.
*
* @return The dependency collector for optional mods.
*/
public abstract DependencyCollector getOptional();

/**
* Get the optional runtime dependencies.
*
* @return A set property containing all the optional runtime mods.
*/
public abstract SetProperty<ModDependency> getOptionalRuntimeMods();

/**
* Add an optional runtime dependency.
*
* @param modId The mod id for the dependency.
* @param versionRange The version range for the dependency.
*/
public void optionalRuntime(final String modId, final String versionRange) {
getOptionalRuntimeMods().add(new ModDependency(modId, versionRange, true));
}

/**
* Get the configuration for the required dependencies.
*
* @return The configuration instance.
*/
public Configuration getRequiredConfiguration()
{
public Configuration getRequiredConfiguration() {
final Configuration configuration = project.getConfigurations().detachedConfiguration();
configuration.fromDependencyCollector(getRequired());
return configuration;
@@ -74,10 +124,31 @@ public Configuration getRequiredConfiguration()
*
* @return The configuration instance.
*/
public Configuration getOptionalConfiguration()
{
public Configuration getOptionalConfiguration() {
final Configuration configuration = project.getConfigurations().detachedConfiguration();
configuration.fromDependencyCollector(getOptional());
return configuration;
}

/**
* Get all the required dependencies, combined {@link DependenciesExtension#getRequired()} and {@link DependenciesExtension#getRequiredRuntimeMods()}.
*
* @return The combined set of dependencies.
*/
public Provider<Set<ModDependency>> getAllRequiredDependencies() {
final Provider<Set<ModDependency>> requiredDependencies = DependencyResolver.resolveDependencies(getRequiredConfiguration(), true);

return requiredDependencies.zip(getRequiredRuntimeMods(), (a, b) -> Stream.concat(a.stream(), b.stream()).collect(Collectors.toSet()));
}

/**
* Get all the optional dependencies, combined {@link DependenciesExtension#getOptional()} and {@link DependenciesExtension#getOptionalRuntimeMods()}.
*
* @return The combined set of dependencies.
*/
public Provider<Set<ModDependency>> getAllOptionalDependencies() {
final Provider<Set<ModDependency>> optionalDependencies = DependencyResolver.resolveDependencies(getOptionalConfiguration(), false);

return optionalDependencies.zip(getOptionalRuntimeMods(), (a, b) -> Stream.concat(a.stream(), b.stream()).collect(Collectors.toSet()));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ldtteam.tableau.neogradle.model;
package com.ldtteam.tableau.dependencies.model;

import org.gradle.api.artifacts.result.ResolvedArtifactResult;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
@@ -11,6 +11,6 @@
* @param artifacts The set of the resolved artifacts.
* @param component The resolved component result.
*/
public record CombinedDependency(Set<ResolvedArtifactResult> artifacts, ResolvedComponentResult component)
public record CombinedDependencyData(Set<ResolvedArtifactResult> artifacts, ResolvedComponentResult component)
{
}
Loading