Skip to content

Commit

Permalink
Spotless: the rest™
Browse files Browse the repository at this point in the history
  • Loading branch information
oldergod committed Jul 7, 2023
1 parent 25d75ff commit cc55349
Show file tree
Hide file tree
Showing 183 changed files with 3,694 additions and 2,642 deletions.
58 changes: 30 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,38 @@ allprojects {
}

subprojects {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
val licenseHeaderFile = rootProject.file("gradle/license-header.txt")
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
)
trimTrailingWhitespace()
endWithNewline()
toggleOffOn()
// We cannot use it because the licensing job happens before. The header will be replaced and
// spotless will throw. We have to manually exclude stuff for now.
// See https://github.com/diffplug/spotless/discussions/1738
toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""")
if (name != "wire-golden-files") {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
val licenseHeaderFile = rootProject.file("gradle/license-header.txt")
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
)
trimTrailingWhitespace()
endWithNewline()
toggleOffOn()
// We cannot use it because the licensing job happens before. The header will be replaced
// and spotless will throw. We have to manually exclude stuff for now.
// See https://github.com/diffplug/spotless/discussions/1738
toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""")

licenseHeaderFile(licenseHeaderFile)
}
java {
target("**/*.java")
googleJavaFormat(libs.googleJavaFormat.get().version)
trimTrailingWhitespace()
endWithNewline()
toggleOffOn()
// We cannot use it because the licensing job happens before. The header will be replaced and
// spotless will throw. We have to manually exclude stuff for now.
// See https://github.com/diffplug/spotless/discussions/1738
// toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""")
licenseHeaderFile(licenseHeaderFile)
}
java {
target("**/*.java")
googleJavaFormat(libs.googleJavaFormat.get().version)
trimTrailingWhitespace()
endWithNewline()
toggleOffOn()
// We cannot use it because the licensing job happens before. The header will be replaced
// and spotless will throw. We have to manually exclude stuff for now.
// See https://github.com/diffplug/spotless/discussions/1738
toggleOffOnRegex("""^(// Code generated by Wire protocol buffer compiler[\s\S]*)$""")

licenseHeaderFile(licenseHeaderFile)
licenseHeaderFile(licenseHeaderFile)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2021 Square Inc.
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,10 +15,9 @@
*/
package com.squareup.wire.android.app.java;

import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;


public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2021 Square Inc.
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire.android.app.variants

import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire.android.app.variants

import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire.android.app.variants

import org.junit.Assert.fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.wire.android.app.variants

import org.junit.Assert.fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2021 Square Inc.
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2021 Square Inc.
* Copyright (C) 2021 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
15 changes: 15 additions & 0 deletions samples/js/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import human.Person

fun main() {
Expand Down
15 changes: 15 additions & 0 deletions samples/native/src/nativeMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2023 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import human.Person

fun main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2015 Square Inc.
* Copyright (C) 2015 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -23,24 +23,27 @@
public final class Sample {
public void run() throws IOException {
// Create an immutable value object with the Builder API.
Dinosaur stegosaurus = new Dinosaur.Builder()
.name("Stegosaurus")
.period(Period.JURASSIC)
.length_meters(9.0)
.mass_kilograms(5_000.0)
.picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67"))
.build();
Dinosaur stegosaurus =
new Dinosaur.Builder()
.name("Stegosaurus")
.period(Period.JURASSIC)
.length_meters(9.0)
.mass_kilograms(5_000.0)
.picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67"))
.build();

// Encode that value to bytes, and print that as base64.
byte[] stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus);
System.out.println(ByteString.of(stegosaurusEncoded).base64());

// Decode base64 bytes, and decode those bytes as a dinosaur.
ByteString tyrannosaurusEncoded = ByteString.decodeBase64("Cg1UeXJhbm5vc2F1cnVzEmhodHRwOi8vdmln"
+ "bmV0dGUxLndpa2lhLm5vY29va2llLm5ldC9qdXJhc3NpY3BhcmsvaW1hZ2VzLzYvNmEvTGVnbzUuanBnL3Jldmlz"
+ "aW9uL2xhdGVzdD9jYj0yMDE1MDMxOTAxMTIyMRJtaHR0cDovL3ZpZ25ldHRlMy53aWtpYS5ub2Nvb2tpZS5uZXQv"
+ "anVyYXNzaWNwYXJrL2ltYWdlcy81LzUwL1JleHlfcHJlcGFyaW5nX2Zvcl9iYXR0bGVfd2l0aF9JbmRvbWludXNf"
+ "cmV4LmpwZxmamZmZmZkoQCEAAAAAAJC6QCgB");
ByteString tyrannosaurusEncoded =
ByteString.decodeBase64(
"Cg1UeXJhbm5vc2F1cnVzEmhodHRwOi8vdmln"
+ "bmV0dGUxLndpa2lhLm5vY29va2llLm5ldC9qdXJhc3NpY3BhcmsvaW1hZ2VzLzYvNmEvTGVnbzUuanBnL3Jldmlz"
+ "aW9uL2xhdGVzdD9jYj0yMDE1MDMxOTAxMTIyMRJtaHR0cDovL3ZpZ25ldHRlMy53aWtpYS5ub2Nvb2tpZS5uZXQv"
+ "anVyYXNzaWNwYXJrL2ltYWdlcy81LzUwL1JleHlfcHJlcGFyaW5nX2Zvcl9iYXR0bGVfd2l0aF9JbmRvbWludXNf"
+ "cmV4LmpwZxmamZmZmZkoQCEAAAAAAJC6QCgB");
Dinosaur tyrannosaurus = Dinosaur.ADAPTER.decode(tyrannosaurusEncoded.toByteArray());

// Print both of our dinosaurs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,6 +15,9 @@
*/
package com.squareup.wire.sample;

import static javax.lang.model.element.Modifier.ABSTRACT;
import static javax.lang.model.element.Modifier.PUBLIC;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeName;
Expand All @@ -24,9 +27,6 @@
import com.squareup.wire.schema.Rpc;
import com.squareup.wire.schema.Service;

import static javax.lang.model.element.Modifier.ABSTRACT;
import static javax.lang.model.element.Modifier.PUBLIC;

final class ServiceGenerator {
final JavaGenerator javaGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -21,21 +21,22 @@ import com.squareup.wire.java.JavaGenerator
import com.squareup.wire.schema.Location
import com.squareup.wire.schema.Schema
import com.squareup.wire.schema.SchemaLoader
import java.io.File
import java.io.IOException
import java.nio.file.FileSystems
import okio.buffer
import okio.sink
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.io.IOException
import java.nio.file.FileSystems

class ServiceGeneratorTest {
@get:Rule
var temporaryFolder = TemporaryFolder()

@Test @Throws(IOException::class)
@Test
@Throws(IOException::class)
fun service() {
val schema = schema(
mapOf(
Expand All @@ -62,8 +63,9 @@ class ServiceGeneratorTest {
| rpc FirstRpc (SampleRequest) returns (SampleResponse);
| rpc OtherOne (SampleRequest) returns (SampleResponse);
|}
|""".trimMargin()
)
|
""".trimMargin(),
),
)
val service = schema.getService("squareup.wire.sample.SampleApi")
val javaGenerator = JavaGenerator.get(schema)
Expand All @@ -85,7 +87,8 @@ class ServiceGeneratorTest {
|
| SampleResponse OtherOne(SampleRequest request);
|}
|""".trimMargin()
|
""".trimMargin(),
)
}

Expand Down
Loading

0 comments on commit cc55349

Please sign in to comment.