Skip to content

Commit

Permalink
Fix issues and make it possible to use tableau without configuring mo…
Browse files Browse the repository at this point in the history
…d id and group if it is not needed.
  • Loading branch information
marchermans committed Jan 7, 2025
1 parent 76ad409 commit 46f2425
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.ldtteam.tableau.common;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.common.extensions.VersioningExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import com.ldtteam.tableau.utilities.extensions.UtilityFunctions;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void apply(@NotNull Project target) {
target.getPlugins().apply("eclipse");

//The DSL Extension.
TableauScriptingExtension.register(target, ModExtension.EXTENSION_NAME, ModExtension.class, target);
TableauScriptingExtension.register(target, ProjectExtension.EXTENSION_NAME, ProjectExtension.class, target);

//Configure processing.
configureVersioning(target);
Expand All @@ -72,22 +72,12 @@ public void apply(@NotNull Project target) {

//Validate that the user configured a mod id, error out if not set.
target.afterEvaluate(ignored -> {
if (!ModExtension.get(target).getModId().isPresent()) {
throw problems.getReporter().throwing(spec -> {
//TODO: Configure documentation link.
spec.id("missing-mod-id", "Mod id is not configured.")
.details("Without a specified mod id a lot of systems can not be configured.")
.solution("Configure the mod id, in tableau's mod block.");
});
if (!ProjectExtension.get(target).getModId().isPresent()) {

}

if (!ModExtension.get(target).getGroup().isPresent()) {
throw problems.getReporter().throwing(spec -> {
//TODO: Configure documentation link.
spec.id("missing-mod-group", "Mod group is not configured.")
.details("Without a specified mod group a lot of systems can not be configured.")
.solution("Configure the mod group, in tableau's mod block.");
});
if (!ProjectExtension.get(target).getGroup().isPresent()) {

}
});
}
Expand Down Expand Up @@ -156,7 +146,7 @@ private void configureVersioning(@NotNull Project target) {
target.setVersion(projectVersion);

//Set the group of the project.
target.setGroup(new ProjectGroup(ModExtension.get(target).getGroup()));
target.setGroup(new ProjectGroup(ProjectExtension.get(target).getGroup()));
}

/**
Expand All @@ -166,7 +156,7 @@ private void configureVersioning(@NotNull Project target) {
*/
private void configureBase(final Project project) {
final BasePluginExtension base = project.getExtensions().getByType(BasePluginExtension.class);
base.getArchivesName().set(ModExtension.get(project).getModId());
base.getArchivesName().set(ProjectExtension.get(project).getModId());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@

import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import org.gradle.api.Action;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Project;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.problems.Problems;
import org.gradle.api.problems.Severity;
import org.gradle.api.provider.Property;

import javax.inject.Inject;

/**
* Mod extension, handles the project configuration for the mod.
*/
public abstract class ModExtension {
@SuppressWarnings("UnstableApiUsage")
public abstract class ProjectExtension {

/**
* Gets the mod extension for a given project.
*
* @param project The project.
* @return The mod extension.
*/
public static ModExtension get(final Project project) {
return TableauScriptingExtension.get(project, ModExtension.class);
public static ProjectExtension get(final Project project) {
return TableauScriptingExtension.get(project, ProjectExtension.class);
}

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

private final Versioning versioning;

Expand All @@ -36,12 +39,35 @@ public static ModExtension get(final Project project) {
* @param project The project for the model.
*/
@Inject
public ModExtension(final Project project) {
public ProjectExtension(final Project project) {
versioning = project.getObjects().newInstance(Versioning.class);

getPublisher().convention("ldtteam");

getModId().convention(project.provider(() -> {
throw getProblems().getReporter().throwing(spec -> {
//TODO: Configure documentation link.
spec.id("missing-mod-id", "Mod id is not configured.")
.details("Without a specified mod id a lot of systems can not be configured.")
.solution("Configure the mod id, in tableau's project block.")
.withException(new IllegalStateException("Mod id is not configured."));
});
}));

getGroup().convention(project.provider(() -> {
throw getProblems().getReporter().throwing(spec -> {
//TODO: Configure documentation link.
spec.id("missing-mod-group", "Mod group is not configured.")
.details("Without a specified project group a lot of systems can not be configured.")
.solution("Configure the projects group, in tableau's project block.")
.withException(new IllegalStateException("Mod group is not configured."));
});
}));
}

@Inject
protected abstract Problems getProblems();

/**
* The versioning model for this mod.
*
Expand All @@ -63,7 +89,7 @@ public void versioning(final Action<Versioning> action) {
/**
* The current mod id for the mod.
* <p>
* Not configuring the mod id, will likely result in an error during the build.
* Not configuring the mod id, will likely result in an error during the build.
*
* @return The mod id.
*/
Expand All @@ -72,10 +98,10 @@ public void versioning(final Action<Versioning> action) {
/**
* The mod group.
* <p>
* Generally the mod group is the name of the modding team or the name of the modding group, in reverse DNS order.
* So, for example: com.ldtteam, or com.github.example-team
* Generally the mod group is the name of the modding team or the name of the modding group, in reverse DNS order.
* So, for example: com.ldtteam, or com.github.example-team
* <p>
* Not configuring the mod group, will likely result in an error during the build.
* Not configuring the mod group, will likely result in an error during the build.
*
* @return The mod group.
*/
Expand Down Expand Up @@ -119,9 +145,9 @@ public Versioning() {
/**
* The semver or maven compatible version string.
* <p>
* Mods should generally use maven versioning.
* Mods should generally use maven versioning.
* <p>
* The default value is 0.0.0
* The default value is 0.0.0
*
* @return The mod version.
*/
Expand All @@ -130,9 +156,9 @@ public Versioning() {
/**
* The version suffix.
* <p>
* This should generally be something like -SNAPSHOT, -RELEASE or empty.
* This should generally be something like -SNAPSHOT, -RELEASE or empty.
* <p>
* Might also indicate the branch that was used as source to build this version of the mod.
* Might also indicate the branch that was used as source to build this version of the mod.
*
* @return The mod version suffix.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static VersioningExtension get(final Project project) {
public static final String EXTENSION_NAME = "versioning";

private final MinecraftBasedVersioning minecraft;
private final ModExtension.Versioning mod;
private final ProjectExtension.Versioning mod;

/**
* Creates a new versioning extension model.
Expand All @@ -38,7 +38,7 @@ public static VersioningExtension get(final Project project) {
@Inject
public VersioningExtension(final Project project) {
minecraft = project.getObjects().newInstance(MinecraftBasedVersioning.class, project);
mod = ModExtension.get(project).getVersioning();
mod = ProjectExtension.get(project).getVersioning();
}

/**
Expand All @@ -65,7 +65,7 @@ public void minecraft(final Action<MinecraftBasedVersioning> action) {
*
* @return The mod versioning configuration setup.
*/
public ModExtension.Versioning getMod() {
public ProjectExtension.Versioning getMod() {
return mod;
}

Expand All @@ -74,7 +74,7 @@ public ModExtension.Versioning getMod() {
*
* @param action The action to execute.
*/
public void mod(final Action<ModExtension.Versioning> action) {
public void mod(final Action<ProjectExtension.Versioning> action) {
action.execute(mod);
}

Expand All @@ -91,7 +91,7 @@ public static abstract class MinecraftBasedVersioning {
@Inject
public MinecraftBasedVersioning(final Project project) {
getEnabled().convention(false);
getMinecraftVersion().convention(ModExtension.get(project).getMinecraftVersion());
getMinecraftVersion().convention(ProjectExtension.get(project).getMinecraftVersion());
getMinecraftVersionElementIndex().convention(1);
getSourceVersionElementIndex().convention(1);
getSourceVersionName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public void apply(@NotNull Project target) {
throw problems.getReporter().throwing(spec -> {
spec.id("crowdin-no-source-files", "Missing source files for Crowdin")
.details("No source files specified for Crowdin, please specify at least one source file to manage")
.solution("Add at least one source file to the crowdin block of the Tableau DSL");
.solution("Add at least one source file to the crowdin block of the Tableau DSL")
.withException(new InvalidUserDataException("No source files specified for Crowdin"));
});
}

Expand All @@ -82,7 +83,8 @@ public void apply(@NotNull Project target) {
throw problems.getReporter().throwing(spec -> {
spec.id("crowdin-no-target-files", "Missing target files for Crowdin")
.details("No target files specified for Crowdin, if you specify more then one source file, they need to be merged into at least one target file.")
.solution("Add at least one target file to the crowdin block of the Tableau DSL");
.solution("Add at least one target file to the crowdin block of the Tableau DSL")
.withException(new InvalidUserDataException("No target files specified for Crowdin"));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ldtteam.tableau.crowdin.extensions;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
Expand Down Expand Up @@ -37,7 +37,7 @@ public static CrowdinExtension get(Project project) {
@SuppressWarnings("UnstableApiUsage")
@Inject
public CrowdinExtension(Project project) {
final ModExtension mod = ModExtension.get(project);
final ProjectExtension mod = ProjectExtension.get(project);

getSourceFiles().convention(mod.getModId().map(id -> project.file("src/main/resources/assets/" + id + "/lang/en_us.json")));
getTargetFiles().convention(mod.getModId().map(id -> project.file("src/main/resources/assets/" + id + "/lang/en_us.json")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
*/
package com.ldtteam.tableau.curseforge;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.curseforge.extensions.CurseForgeExtension;
import com.ldtteam.tableau.extensions.NeoGradleExtension;
import com.ldtteam.tableau.jarjar.JarJarPlugin;
import com.ldtteam.tableau.neogradle.NeoGradlePlugin;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
Expand All @@ -14,11 +13,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;
Expand Down Expand Up @@ -70,7 +67,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 ModExtension mod = ModExtension.get(project);
final ProjectExtension mod = ProjectExtension.get(project);

if (!curse.getId().isPresent()) {
project.getLogger().debug("Skipping CurseForge upload task as no project id is set.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package com.ldtteam.tableau.java;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.java.extensions.JavaExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import com.ldtteam.tableau.sourceset.management.extensions.SourceSetExtension;
Expand All @@ -16,7 +16,6 @@
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
import java.io.File;
import java.util.Locale;
import java.util.Map;

Expand Down Expand Up @@ -61,7 +60,7 @@ private void configureJarTask(final Project project) {
});

jar.manifest(manifest -> {
final ModExtension mod = ModExtension.get(project);
final ProjectExtension mod = ProjectExtension.get(project);
final JavaExtension java = JavaExtension.get(project);

manifest.attributes(Map.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.ldtteam.tableau.java.extensions;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import com.ldtteam.tableau.utilities.extensions.UtilityFunctions;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Property;
Expand Down Expand Up @@ -40,7 +39,7 @@ public JavaExtension(final Project project) {
final JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
java.getToolchain().getLanguageVersion().set(getJavaVersion().map(JavaLanguageVersion::of));

getAutomaticModuleName().convention(ModExtension.get(project).getModId());
getAutomaticModuleName().convention(ProjectExtension.get(project).getModId());

//By default, we run with the current JDKs java.
//noinspection UnstableApiUsage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ldtteam.tableau.maven.publishing;

import com.ldtteam.tableau.common.extensions.ModExtension;
import com.ldtteam.tableau.common.extensions.ProjectExtension;
import com.ldtteam.tableau.git.extensions.GitExtension;
import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension;
import org.gradle.api.Action;
Expand Down Expand Up @@ -83,8 +83,11 @@ public void publishToLDTTeam() {
pom(POM::distributeOnLDTTeamMaven);

final PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
final Provider<String> username = project.getProviders().environmentVariable("LDTTeamJfrogUsername");
final Provider<String> password = project.getProviders().environmentVariable("LDTTeamJfrogPassword");
final Provider<String> username = project.getProviders().environmentVariable("LDTTeamJfrogUsername")
.orElse(project.getProviders().environmentVariable("MAVEN_USERNAME"));
final Provider<String> password = project.getProviders().environmentVariable("LDTTeamJfrogPassword")
.orElse(project.getProviders().environmentVariable("MAVEN_PASSWORD"))
.orElse(project.getProviders().environmentVariable("MAVEN_TOKEN"));

if (username.isPresent() && password.isPresent()) {
publishing.repositories(mavenRepositories -> {
Expand Down Expand Up @@ -191,7 +194,7 @@ void configure(MavenPom pom) {
configurator.execute(new POM(project, pom));
}

final ModExtension mod = ModExtension.get(project);
final ProjectExtension mod = ProjectExtension.get(project);

pom.getUrl().set(mod.getUrl());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.inject.Inject;

import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
Expand Down Expand Up @@ -85,6 +86,7 @@ private FileSystem openFileSystem(Path path) {
spec.contextualLabel("Metadata generation")
.details("Tableau was not able to properly open the NeoForge jar to search for the currently supported loader range!")
.solution("Configure the supported loader range your self, validate your dependencies, or try again later")
.withException(new GradleException("Failed to open the NeoForge jar to search for the currently supported loader range!", e))
.severity(Severity.ERROR);
});
}
Expand Down
Loading

0 comments on commit 46f2425

Please sign in to comment.