Skip to content

Commit

Permalink
perf(gradle-plugin): Avoid running asset/native downloads when unnece…
Browse files Browse the repository at this point in the history
…ssary (#103)

Assets are only needed for actually running the game.
In submodules with no run configs, we can skip these steps in
order to improve the speed of project import.

See #102
  • Loading branch information
zml2008 authored Jan 24, 2024
1 parent 3565743 commit 56026f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private void applyToProject(final Project project) {

this.configureIDEIntegrations(
project,
minecraft.needsPrepareWorkspace(),
p.getTasks().named(Constants.Tasks.PREPARE_WORKSPACE)
);
});
Expand Down Expand Up @@ -158,6 +159,7 @@ private void createDisplayMinecraftVersions(final Provider<MinecraftProviderServ

private void configureIDEIntegrations(
final Project project,
final Provider<Boolean> shouldRunPrepare,
final TaskProvider<?> prepareWorkspaceTask
) {
project.getPlugins().apply(IdeaExtPlugin.class);
Expand All @@ -171,12 +173,16 @@ public void idea(final Project project, final IdeaModel idea, final ProjectSetti
final TaskTriggersConfig taskTriggers = ((ExtensionAware) ideaExtension).getExtensions().getByType(TaskTriggersConfig.class);

// Automatically prepare a workspace after importing
taskTriggers.afterSync(prepareWorkspaceTask);
if (shouldRunPrepare.get()) {
taskTriggers.afterSync(prepareWorkspaceTask);
}
}

@Override
public void eclipse(final Project project, final EclipseModel eclipse) {
eclipse.synchronizationTasks(prepareWorkspaceTask);
if (shouldRunPrepare.get()) {
eclipse.synchronizationTasks(prepareWorkspaceTask);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.util.ConfigureUtil;
import org.spongepowered.gradle.vanilla.MinecraftExtension;
import org.spongepowered.gradle.vanilla.internal.model.VersionClassifier;
Expand All @@ -44,6 +45,7 @@
import org.spongepowered.gradle.vanilla.internal.repository.modifier.AccessWidenerModifier;
import org.spongepowered.gradle.vanilla.internal.repository.modifier.ArtifactModifier;
import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform;
import org.spongepowered.gradle.vanilla.repository.MinecraftSide;
import org.spongepowered.gradle.vanilla.runs.RunConfiguration;
import org.spongepowered.gradle.vanilla.runs.RunConfigurationContainer;

Expand Down Expand Up @@ -79,8 +81,10 @@ public class MinecraftExtensionImpl implements MinecraftExtension {
private final RunConfigurationContainer runConfigurations;
private volatile Set<ArtifactModifier> lazyModifiers;

private final Provider<Boolean> needsPrepareWorkspace;

@Inject
public MinecraftExtensionImpl(final Gradle gradle, final ObjectFactory factory, final Project project, final Provider<MinecraftProviderService> providerService) {
public MinecraftExtensionImpl(final Gradle gradle, final ObjectFactory factory, final ProviderFactory providers, final Project project, final Provider<MinecraftProviderService> providerService) {
this.project = project;
this.providerService = providerService;
this.version = factory.property(String.class);
Expand Down Expand Up @@ -129,6 +133,7 @@ public MinecraftExtensionImpl(final Gradle gradle, final ObjectFactory factory,
this.targetVersion.finalizeValueOnRead();

this.runConfigurations = factory.newInstance(RunConfigurationContainer.class, factory.domainObjectContainer(RunConfiguration.class), this);
this.needsPrepareWorkspace = providers.provider(() -> !this.runConfigurations.isEmpty() && this.platform.get().includes(MinecraftSide.CLIENT));
}

@Override
Expand Down Expand Up @@ -270,4 +275,8 @@ public Provider<VersionDescriptor.Full> targetVersion() {
return this.targetVersion;
}

public Provider<Boolean> needsPrepareWorkspace() {
return this.needsPrepareWorkspace;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void apply(final Project target) {
this.configureRepositories(minecraft, p.getRepositories());

prepareWorkspace.configure(task -> {
if (minecraft.platform().get().includes(MinecraftSide.CLIENT)) {
if (minecraft.needsPrepareWorkspace().get()) {
task.dependsOn(assets);
}
});
Expand Down

0 comments on commit 56026f5

Please sign in to comment.