Skip to content

Commit

Permalink
Implement initial convention set.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed May 14, 2024
1 parent 6bca406 commit c2eca1e
Show file tree
Hide file tree
Showing 25 changed files with 811 additions and 75 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,46 @@ Per SourceSet the following configurations are added, where XXX is the SourceSet
> For this to work, your SourceSets need to be defined before your dependency block.
Per Run the following configurations are added:
- XXXRunRuntime
- XXXRun
- XXXMod
> [!NOTE]
> For this to work, your Runs need to be defined before your dependency block.
Globally the following configurations are added:
- runRuntime
- runs
- mods

#### LocalRuntime (Per SourceSet)
This configuration is used to add dependencies to your local projects runtime only, without exposing them to the runtime of other projects.

#### LocalRunRuntime (Per SourceSet)
This configuration is used to add dependencies to the local runtime of the runs you add the SourceSets too, without exposing them to the runtime of other runs.
This requires automatic dependency injection from sourcesets per run to be enabled (see below).

#### RunRuntime (Per Run)
#### Run (Per Run)
This configuration is used to add dependencies to the runtime of a specific run only, without exposing them to the runtime of other runs.

#### runRuntime (Global)
#### Mod (Per Run)
This configuration is used to add dependencies (and their dependencies), straight into the mods folder, without exposing them to the runtime of the run itself, or other runs.

#### run (Global)
This configuration is used to add dependencies to the runtime of all runs.

#### mods (Global)
This configuration is used to add dependencies (and their dependencies), straight into the mods folder of all runs, without exposing them to the runtime of the runs.

### Sourceset Management
To disable the sourceset management, you can set the following property in your gradle.properties:
```properties
neogradle.subsystems.conventions.sourceset.enabled=false
```

#### Automatic inclusion of the current project in its runs
By default, the current project is automatically included in its runs.
If you want to disable this, you can set the following property in your gradle.properties:
```properties
neogradle.subsystems.conventions.sourceset.automatic-inclusion=false
```

This is equivalent to setting the following in your build.gradle:
```groovy
runs {
Expand Down Expand Up @@ -327,3 +340,16 @@ idea {
}
}
```

### Runs
To disable the runs conventions, you can set the following property in your gradle.properties:
```properties
neogradle.subsystems.conventions.runs.enabled=false
```

#### Automatic default run per type
By default, a run is created for each type of run.
If you want to disable this, you can set the following property in your gradle.properties:
```properties
neogradle.subsystems.conventions.runs.create-default-run-per-type=false
```

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.neoforged.gradle.common.extensions.base;

import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;

import java.util.List;

public abstract class WithEnabledProperty extends WithPropertyLookup {

private final String prefix;

public WithEnabledProperty(Project project, String prefix) {
super(project);
this.prefix = prefix;

getIsEnabled().convention(
getBooleanProperty("enabled").orElse(true)
);
};

public WithEnabledProperty(WithEnabledProperty parent, String prefix) {
super(parent.project);

this.prefix = String.format("%s.%s", parent.prefix, prefix);
getIsEnabled().convention(
parent.getIsEnabled().zip(getBooleanProperty("enabled"), (parentEnabled, enabled) -> parentEnabled && enabled).orElse(true)
);
}

public abstract Property<Boolean> getIsEnabled();

@Override
protected Provider<String> getStringProperty(String propertyName) {
return super.getStringProperty(String.format("%s.%s", prefix, propertyName));
}

@Override
protected Provider<Boolean> getBooleanProperty(String propertyName) {
return super.getBooleanProperty(String.format("%s.%s", prefix, propertyName));
}

@Override
protected Provider<List<String>> getSpaceSeparatedListProperty(String propertyName) {
return super.getSpaceSeparatedListProperty(String.format("%s.%s", prefix, propertyName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.neoforged.gradle.common.extensions.base;

import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;

import java.util.Arrays;
import java.util.List;

import static net.neoforged.gradle.dsl.common.util.Constants.SUBSYSTEM_PROPERTY_PREFIX;

public abstract class WithPropertyLookup {
protected final Project project;

public WithPropertyLookup(Project project) {
this.project = project;
}

protected Provider<String> getStringProperty(String propertyName) {
return this.project.getProviders().gradleProperty(SUBSYSTEM_PROPERTY_PREFIX + propertyName);
}

protected Provider<Boolean> getBooleanProperty(String propertyName) {
String fullPropertyName = SUBSYSTEM_PROPERTY_PREFIX + propertyName;
return this.project.getProviders().gradleProperty(fullPropertyName)
.map(value -> {
try {
return Boolean.valueOf(value);
} catch (Exception e) {
throw new GradleException("Gradle Property " + fullPropertyName + " is not set to a boolean value: '" + value + "'");
}
});
}

protected Provider<List<String>> getSpaceSeparatedListProperty(String propertyName) {
return this.project.getProviders().gradleProperty(SUBSYSTEM_PROPERTY_PREFIX + propertyName)
.map(s -> Arrays.asList(s.split("\\s+")));
}

public Project getProject() {
return project;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package net.neoforged.gradle.common.extensions.subsystems;

import net.minecraftforge.gdi.BaseDSLElement;
import net.neoforged.gradle.common.extensions.base.WithEnabledProperty;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Conventions;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.Configurations;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.IDE;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.Runs;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.SourceSets;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.ide.IDEA;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;

import javax.inject.Inject;

public abstract class ConventionsExtension extends WithEnabledProperty implements BaseDSLElement<Conventions>, Conventions {

private final Configurations configurations;
private final SourceSets sourceSets;
private final IDE ide;
private final Runs runs;

@Inject
public ConventionsExtension(Project project) {
super(project, "conventions");

this.configurations = project.getObjects().newInstance(ConfigurationsExtension.class, this);
this.sourceSets = project.getObjects().newInstance(SourceSetsExtension.class, this);
this.ide = project.getObjects().newInstance(IDEExtension.class, this);
this.runs = project.getObjects().newInstance(RunsExtension.class, this);
}

@Override
public Configurations getConfigurations() {
return configurations;
}

@Override
public SourceSets getSourceSets() {
return sourceSets;
}

@Override
public IDE getIde() {
return ide;
}

@Override
public Runs getRuns() {
return runs;
}

public static abstract class ConfigurationsExtension extends WithEnabledProperty implements BaseDSLElement<Configurations>, Configurations {

@Inject
public ConfigurationsExtension(WithEnabledProperty parent) {
super(parent, "configurations");

getLocalRuntimeConfigurationPostFix().convention(getStringProperty("localRuntimeConfigurationPostFix").orElse("LocalRuntime"));
getRunRuntimeConfigurationPostFix().convention(getStringProperty("perSourceSetRunRuntimeConfigurationPostFix").orElse("LocalRunRuntime"));
getPerRunRuntimeConfigurationPostFix().convention(getStringProperty("perRunRuntimeConfigurationPostFix").orElse("Run"));
getPerRunModsConfigurationPostFix().convention(getStringProperty("perRunModsConfigurationPostFix").orElse("Mod"));
getRunRuntimeConfigurationName().convention(getStringProperty("runRuntimeConfigurationName").orElse("runs"));
getRunModsConfigurationName().convention(getStringProperty("runModsConfigurationName").orElse("mods"));
}
}

public static abstract class SourceSetsExtension extends WithEnabledProperty implements BaseDSLElement<SourceSets>, SourceSets {

@Inject
public SourceSetsExtension(WithEnabledProperty parent) {
super(parent, "sourceSets");

getShouldMainSourceSetBeAutomaticallyAddedToRuns().convention(getBooleanProperty("automatic-inclusion").orElse(true));
getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().convention(getBooleanProperty("automatic-inclusion-local-run-runtime").orElse(true));
}
}

public static abstract class IDEExtension extends WithEnabledProperty implements BaseDSLElement<IDE>, IDE {

private final IDEA idea;

@Inject
public IDEExtension(WithEnabledProperty parent) {
super(parent, "ide");

this.idea = getProject().getObjects().newInstance(IDEAExtension.class, this);
}

@Override
public IDEA getIdea() {
return idea;
}
}

public static abstract class RunsExtension extends WithEnabledProperty implements BaseDSLElement<Runs>, Runs {

@Inject
public RunsExtension(WithEnabledProperty parent) {
super(parent, "runs");

getShouldDefaultRunsBeCreated().convention(getBooleanProperty("create-default-run-per-type").orElse(true));
}
}

public static abstract class IDEAExtension extends WithEnabledProperty implements BaseDSLElement<IDEA>, IDEA {

@Inject
public IDEAExtension(WithEnabledProperty parent) {
super(parent, "idea");

getShouldUseCompilerDetection().convention(getBooleanProperty("compiler-detection").orElse(true));
getCompilerOutputDir().convention(getProject().getLayout().getProjectDirectory().dir(getStringProperty("compiler-output-dir").orElse("out")));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
package net.neoforged.gradle.common.extensions.subsystems;

import net.minecraftforge.gdi.ConfigurableDSLElement;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Decompiler;
import net.neoforged.gradle.dsl.common.extensions.subsystems.DecompilerLogLevel;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Parchment;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Recompiler;
import net.neoforged.gradle.dsl.common.extensions.subsystems.Subsystems;
import net.neoforged.gradle.common.extensions.base.WithPropertyLookup;
import net.neoforged.gradle.dsl.common.extensions.subsystems.*;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.provider.Provider;

import javax.inject.Inject;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_ARTIFACT_PREFIX;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_GROUP;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_MAVEN_URL;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_PARCHMENT_TOOL_ARTIFACT;
import static net.neoforged.gradle.dsl.common.util.Constants.DEFAULT_RECOMPILER_MAX_MEMORY;
import static net.neoforged.gradle.dsl.common.util.Constants.SUBSYSTEM_PROPERTY_PREFIX;

public abstract class SubsystemsExtension implements ConfigurableDSLElement<Subsystems>, Subsystems {
public abstract class SubsystemsExtension extends WithPropertyLookup implements ConfigurableDSLElement<Subsystems>, Subsystems {

private final Project project;
private final Conventions conventions;

@Inject
public SubsystemsExtension(Project project) {
this.project = project;
super(project);

this.conventions = project.getObjects().newInstance(ConventionsExtension.class, project);

configureDecompilerDefaults();
configureRecompilerDefaults();
Expand Down Expand Up @@ -106,29 +102,8 @@ private void configureParchmentDefaults() {
});
}

private Provider<String> getStringProperty(String propertyName) {
return this.project.getProviders().gradleProperty(SUBSYSTEM_PROPERTY_PREFIX + propertyName);
}

private Provider<Boolean> getBooleanProperty(String propertyName) {
String fullPropertyName = SUBSYSTEM_PROPERTY_PREFIX + propertyName;
return this.project.getProviders().gradleProperty(fullPropertyName)
.map(value -> {
try {
return Boolean.valueOf(value);
} catch (Exception e) {
throw new GradleException("Gradle Property " + fullPropertyName + " is not set to a boolean value: '" + value + "'");
}
});
}

private Provider<List<String>> getSpaceSeparatedListProperty(String propertyName) {
return this.project.getProviders().gradleProperty(SUBSYSTEM_PROPERTY_PREFIX + propertyName)
.map(s -> Arrays.asList(s.split("\\s+")));
}

@Override
public Project getProject() {
return project;
public Conventions getConventions() {
return conventions;
}
}
Loading

0 comments on commit c2eca1e

Please sign in to comment.