-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bca406
commit c2eca1e
Showing
25 changed files
with
811 additions
and
75 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
167 changes: 147 additions & 20 deletions
167
common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
common/src/main/java/net/neoforged/gradle/common/extensions/base/WithEnabledProperty.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,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)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/net/neoforged/gradle/common/extensions/base/WithPropertyLookup.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,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; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.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,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"))); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.