Skip to content

Commit

Permalink
[Feature]: Improved caching (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored May 29, 2024
1 parent a5c57e3 commit e8c6d92
Show file tree
Hide file tree
Showing 57 changed files with 2,264 additions and 473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.neoforged.gradle.common.runtime.definition.CommonRuntimeDefinition;
import net.neoforged.gradle.common.runtime.extensions.RuntimesExtension;
import net.neoforged.gradle.common.runtime.naming.OfficialNamingChannelConfigurator;
import net.neoforged.gradle.common.tasks.CleanCache;
import net.neoforged.gradle.common.tasks.DisplayMappingsLicenseTask;
import net.neoforged.gradle.common.util.ProjectUtils;
import net.neoforged.gradle.common.util.SourceSetUtils;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class CommonProjectPlugin implements Plugin<Project> {

public static final String ASSETS_SERVICE = "ng_assets";
public static final String LIBRARIES_SERVICE = "ng_libraries";
public static final String EXECUTE_SERVICE = "ng_execute";
public static final String ACCESS_TRANSFORMER_ELEMENTS_CONFIGURATION = "accessTransformerElements";
public static final String ACCESS_TRANSFORMER_API_CONFIGURATION = "accessTransformerApi";
public static final String ACCESS_TRANSFORMER_CONFIGURATION = "accessTransformer";
Expand All @@ -72,8 +74,9 @@ public void apply(Project project) {
project.getPluginManager().apply(JavaPlugin.class);

//Register the services
CentralCacheService.register(project, ASSETS_SERVICE);
CentralCacheService.register(project, LIBRARIES_SERVICE);
CentralCacheService.register(project, ASSETS_SERVICE, true);
CentralCacheService.register(project, LIBRARIES_SERVICE, true);
CentralCacheService.register(project, EXECUTE_SERVICE, false);

// Apply both the idea and eclipse IDE plugins
project.getPluginManager().apply(IdeaPlugin.class);
Expand Down Expand Up @@ -136,8 +139,11 @@ public void apply(Project project) {

IdeRunIntegrationManager.getInstance().setup(project);

final TaskProvider<?> cleanCache = project.getTasks().register("cleanCache", CleanCache.class);

project.getTasks().named("clean", Delete.class, delete -> {
delete.delete(configurationData.getLocation());
delete.dependsOn(cleanCache);
});

//Needs to be before after evaluate
Expand Down Expand Up @@ -174,17 +180,22 @@ private void configureSourceSetConventions(Project project, Conventions conventi
}

ProjectUtils.afterEvaluate(project, () -> {
project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runs -> runs.configureEach(run -> {
if (sourceSets.getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) {
//We always register main
run.getModSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("main"));
}
project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runs -> {
runs.configureEach(run -> {
if (sourceSets.getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) {
//We always register main
run.getModSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("main"));
}

if (sourceSets.getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().get() && configurations.getIsEnabled().get())
run.getModSources().get().forEach(sourceSet -> {
run.getDependencies().get().getRuntime().add(project.getConfigurations().getByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())));
});
}));
if (sourceSets.getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().get() && configurations.getIsEnabled().get()) {
run.getModSources().get().forEach(sourceSet -> {
if (project.getConfigurations().findByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())) != null) {
run.getDependencies().get().getRuntime().add(project.getConfigurations().getByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())));
}
});
}
});
});
});

}
Expand Down
Loading

0 comments on commit e8c6d92

Please sign in to comment.