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

Remove dependency on Guava #609

Merged
merged 1 commit into from
Oct 2, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ configurations {
dependencies {
compileOnly "com.android.tools.build:gradle:4.1.0"

implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.google.gradle:osdetector-gradle-plugin:1.7.0'

testImplementation 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
package com.google.protobuf.gradle

import com.google.common.base.Preconditions
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.gradle.api.Named
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ package com.google.protobuf.gradle

import static java.nio.charset.StandardCharsets.US_ASCII

import com.google.common.base.Preconditions
import com.google.common.collect.ImmutableList
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import groovy.transform.TypeChecked
Expand Down Expand Up @@ -103,7 +101,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
transient private SourceSet sourceSet
@SuppressWarnings("UnnecessaryTransientModifier") // It is not necessary for task to implement Serializable
transient private Object variant
private ImmutableList<String> flavors
private List<String> flavors
private String buildType
private boolean isTestVariant
private final Provider<Boolean> isAndroidProject = providerFactory.provider { Utils.isAndroidProject(project) }
Expand Down Expand Up @@ -275,11 +273,11 @@ public abstract class GenerateProtoTask extends DefaultTask {
this.isTestVariant = isTestVariant
}

void setFlavors(ImmutableList<String> flavors) {
void setFlavors(List<String> flavors) {
checkInitializing()
Preconditions.checkState(isAndroidProject.get(),
'flavors should not be set in a Java project')
this.flavors = flavors
this.flavors = Collections.unmodifiableList(new ArrayList<String>(flavors))
}

void setBuildType(String buildType) {
Expand Down Expand Up @@ -370,7 +368,7 @@ public abstract class GenerateProtoTask extends DefaultTask {
}

@Internal("Not an actual input to the task, only used to find tasks belonging to a variant")
ImmutableList<String> getFlavors() {
List<String> getFlavors() {
Preconditions.checkState(isAndroidProject.get(),
'flavors should not be used in a Java project')
Preconditions.checkNotNull(flavors, 'flavors is not set')
Expand Down
55 changes: 55 additions & 0 deletions src/main/groovy/com/google/protobuf/gradle/Preconditions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.google.protobuf.gradle;

/**
* Common assertions helper.
*/
final class Preconditions {
private Preconditions() {} // prevent instantiation

public static void checkState(boolean expectedState) {
if (!expectedState) {
throw new IllegalStateException();
}
}

public static void checkState(boolean expectedState, Object errorMessage) {
if (!expectedState) {
throw new IllegalStateException(String.valueOf(errorMessage));
}
}

public static <T> T checkNotNull(T obj, Object errorMessage) {
if (obj == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
return obj;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
package com.google.protobuf.gradle

import com.google.common.collect.ImmutableList
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import groovy.transform.TypeCheckingMode
Expand Down Expand Up @@ -320,7 +319,7 @@ class ProtobufPlugin implements Plugin<Project> {
Provider<GenerateProtoTask> generateProtoTask = addGenerateProtoTask(
variant.name, sourceDirs, extractProtosDirs, extractIncludeProtosTask) {
it.setVariant(variant, isTestVariant)
it.flavors = ImmutableList.copyOf(variant.productFlavors.collect { it.name } )
it.flavors = variant.productFlavors.collect { it.name }
if (variant.hasProperty('buildType')) {
it.buildType = variant.buildType.name
}
Expand Down
1 change: 0 additions & 1 deletion src/main/groovy/com/google/protobuf/gradle/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
package com.google.protobuf.gradle

import com.google.common.base.Preconditions
import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
Expand Down
55 changes: 27 additions & 28 deletions src/test/groovy/com/google/protobuf/gradle/IDESupportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
package com.google.protobuf.gradle

import com.google.common.collect.ImmutableSet
import groovy.transform.CompileDynamic
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
Expand Down Expand Up @@ -80,25 +79,25 @@ class IDESupportTest extends Specification {
}
}

Set<String> expectedSourceDir = ImmutableSet.builder()
.add('file://$MODULE_DIR$/src/main/java')
.add('file://$MODULE_DIR$/src/grpc/proto')
.add('file://$MODULE_DIR$/src/main/proto')
.add('file://$MODULE_DIR$/build/extracted-include-protos/grpc')
.add('file://$MODULE_DIR$/build/extracted-protos/main')
.add('file://$MODULE_DIR$/build/extracted-include-protos/main')
.add('file://$MODULE_DIR$/build/extracted-protos/grpc')
.add('file://$MODULE_DIR$/build/generated/source/proto/grpc/java')
.add('file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output')
.add('file://$MODULE_DIR$/build/generated/source/proto/main/java')
.build()
Set<String> expectedTestSourceDir = ImmutableSet.builder()
.add('file://$MODULE_DIR$/src/test/java')
.add('file://$MODULE_DIR$/src/test/proto')
.add('file://$MODULE_DIR$/build/extracted-protos/test')
.add('file://$MODULE_DIR$/build/extracted-include-protos/test')
.add('file://$MODULE_DIR$/build/generated/source/proto/test/java')
.build()
Set<String> expectedSourceDir = [
'file://$MODULE_DIR$/src/main/java',
'file://$MODULE_DIR$/src/grpc/proto',
'file://$MODULE_DIR$/src/main/proto',
'file://$MODULE_DIR$/build/extracted-include-protos/grpc',
'file://$MODULE_DIR$/build/extracted-protos/main',
'file://$MODULE_DIR$/build/extracted-include-protos/main',
'file://$MODULE_DIR$/build/extracted-protos/grpc',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/java',
'file://$MODULE_DIR$/build/generated/source/proto/grpc/grpc_output',
'file://$MODULE_DIR$/build/generated/source/proto/main/java',
]
Set<String> expectedTestSourceDir = [
'file://$MODULE_DIR$/src/test/java',
'file://$MODULE_DIR$/src/test/proto',
'file://$MODULE_DIR$/build/extracted-protos/test',
'file://$MODULE_DIR$/build/extracted-include-protos/test',
'file://$MODULE_DIR$/build/generated/source/proto/test/java',
]
Set<String> expectedGeneratedDirs = [
'file://$MODULE_DIR$/build/extracted-include-protos/grpc',
'file://$MODULE_DIR$/build/extracted-protos/main',
Expand Down Expand Up @@ -154,14 +153,14 @@ class IDESupportTest extends Specification {
}
}

Set<String> expectedSourceDir = ImmutableSet.builder()
.add('src/main/java')
.add('src/test/java')
.add('build/generated/source/proto/grpc/java')
.add('build/generated/source/proto/grpc/grpc_output')
.add('build/generated/source/proto/main/java')
.add('build/generated/source/proto/test/java')
.build()
Set<String> expectedSourceDir = [
'src/main/java',
'src/test/java',
'build/generated/source/proto/grpc/java',
'build/generated/source/proto/grpc/grpc_output',
'build/generated/source/proto/main/java',
'build/generated/source/proto/test/java',
]
assert Objects.equals(expectedSourceDir, sourceDir)

where:
Expand Down