Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Speed up build configuration time #1451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,7 +26,7 @@ class ApolloPlugin implements Plugin<Project> {

private Project project
private final FileResolver fileResolver
private boolean useGlobalApolloCodegen
private boolean useGlobalApolloCodegen = System.properties['apollographql.useGlobalApolloCodegen']?.toBoolean()

@Inject
ApolloPlugin(FileResolver fileResolver) {
Expand All @@ -48,9 +48,7 @@ class ApolloPlugin implements Plugin<Project> {
}

private void applyApolloPlugin() {
if (isUseGlobalApolloCodegenEnabled() && verifySystemApolloCodegenVersion()) {
useGlobalApolloCodegen = true
} else {
if (!useGlobalApolloCodegen) {
setupNode()
}

Expand Down Expand Up @@ -214,33 +212,4 @@ class ApolloPlugin implements Plugin<Project> {
return project.android.hasProperty(
'libraryVariants') ? project.android.libraryVariants : project.android.applicationVariants
}

private static boolean isUseGlobalApolloCodegenEnabled() {
return (System.properties['apollographql.useGlobalApolloCodegen'] != null) &&
System.properties['apollographql.useGlobalApolloCodegen'].toBoolean()
}

private static boolean verifySystemApolloCodegenVersion() {
println("Verifying system 'apollo-codegen' version (executing command 'apollo-codegen --version') ...")
try {
StringBuilder output = new StringBuilder()
Process checkGlobalApolloCodegen = "apollo-codegen --version".execute()
checkGlobalApolloCodegen.consumeProcessOutput(output, null)
checkGlobalApolloCodegen.waitForOrKill(5000)

if (output.toString().trim() == GraphQLCompiler.APOLLOCODEGEN_VERSION) {
println("Found required 'apollo-codegen@" + GraphQLCompiler.APOLLOCODEGEN_VERSION + "' version.")
println("Skip apollo-codegen installation.")
return true
} else {
println("Required 'apollo-codegen@" + GraphQLCompiler.APOLLOCODEGEN_VERSION + "' version not found.")
println("Installing apollo-codegen ... ")
return false
}
} catch (Exception e) {
println("Failed to verify system 'apollo-codegen' version: " + e)
println("Installing apollo-codegen ... ")
return false
}
}
}
@@ -1,13 +1,16 @@
package com.apollographql.apollo.gradle


import org.gradle.api.GradleException
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.logging.Logger
import org.gradle.api.provider.Property
import org.gradle.api.tasks.AbstractExecTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory

import static com.apollographql.apollo.compiler.GraphQLCompiler.APOLLOCODEGEN_VERSION

class ApolloSystemCodegenGenerationTask extends AbstractExecTask<ApolloSystemCodegenGenerationTask> {
@Input final Property<String> variant = project.objects.property(String.class)
@Input final Property<List> sourceSetNames = project.objects.property(List.class)
Expand All @@ -21,6 +24,7 @@ class ApolloSystemCodegenGenerationTask extends AbstractExecTask<ApolloSystemCod

@Override
void exec() {
verifySystemApolloCodegenVersion(logger)
setCommandLine("apollo-codegen")

List<CodegenGenerationTaskCommandArgsBuilder.CommandArgs> args = new CodegenGenerationTaskCommandArgsBuilder(
Expand All @@ -32,4 +36,24 @@ class ApolloSystemCodegenGenerationTask extends AbstractExecTask<ApolloSystemCod
super.exec()
}
}

private static verifySystemApolloCodegenVersion(Logger logger) {
logger.info("Verifying system 'apollo-codegen' version (executing command 'apollo-codegen --version') ...")
try {
StringBuilder output = new StringBuilder()
Process checkGlobalApolloCodegen = "apollo-codegen --version".execute()
checkGlobalApolloCodegen.consumeProcessOutput(output, null)
checkGlobalApolloCodegen.waitForOrKill(5000)

def version = output.toString().trim()
if (version == APOLLOCODEGEN_VERSION) {
logger.info("Found required 'apollo-codegen@$APOLLOCODEGEN_VERSION' version.")
logger.info("Skip apollo-codegen installation.")
} else {
throw new GradleException("Required 'apollo-codegen@$APOLLOCODEGEN_VERSION' version but found: $version. Consider disabling `apollographql.useGlobalApolloCodegen` in gradle.properties file.")
}
} catch (Exception exception) {
throw new GradleException("Failed to verify system 'apollo-codegen' version. Consider disabling `apollographql.useGlobalApolloCodegen` in gradle.properties file.", exception)
}
}
tasomaniac marked this conversation as resolved.
Show resolved Hide resolved
}