|
|
5da7f3 |
diff --git a/gson/pom.xml b/gson/pom.xml
|
|
|
5da7f3 |
index ffe41ac..5ce5d96 100644
|
|
|
5da7f3 |
--- a/gson/pom.xml
|
|
|
5da7f3 |
+++ b/gson/pom.xml
|
|
|
5da7f3 |
@@ -56,23 +56,6 @@
|
|
|
5da7f3 |
<groupId>org.apache.felix</groupId>
|
|
|
5da7f3 |
<artifactId>maven-bundle-plugin</artifactId>
|
|
|
5da7f3 |
</plugin>
|
|
|
5da7f3 |
- <plugin>
|
|
|
5da7f3 |
- <groupId>org.codehaus.mojo</groupId>
|
|
|
5da7f3 |
- <artifactId>templating-maven-plugin</artifactId>
|
|
|
5da7f3 |
- <version>1.0.0</version>
|
|
|
5da7f3 |
- <executions>
|
|
|
5da7f3 |
- <execution>
|
|
|
5da7f3 |
- <id>filtering-java-templates</id>
|
|
|
5da7f3 |
- <goals>
|
|
|
5da7f3 |
- <goal>filter-sources</goal>
|
|
|
5da7f3 |
- </goals>
|
|
|
5da7f3 |
- <configuration>
|
|
|
5da7f3 |
- <sourceDirectory>${basedir}/src/main/java-templates</sourceDirectory>
|
|
|
5da7f3 |
- <outputDirectory>${project.build.directory}/generated-sources/java-templates</outputDirectory>
|
|
|
5da7f3 |
- </configuration>
|
|
|
5da7f3 |
- </execution>
|
|
|
5da7f3 |
- </executions>
|
|
|
5da7f3 |
- </plugin>
|
|
|
5da7f3 |
</plugins>
|
|
|
5da7f3 |
</build>
|
|
|
5da7f3 |
</project>
|
|
|
5da7f3 |
diff --git a/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java b/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java
|
|
|
5da7f3 |
deleted file mode 100644
|
|
|
5da7f3 |
index a94c96b..0000000
|
|
|
5da7f3 |
--- a/gson/src/main/java-templates/com/google/gson/internal/GsonBuildConfig.java
|
|
|
5da7f3 |
+++ /dev/null
|
|
|
5da7f3 |
@@ -1,32 +0,0 @@
|
|
|
5da7f3 |
-/*
|
|
|
5da7f3 |
- * Copyright (C) 2018 The Gson authors
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5da7f3 |
- * you may not use this file except in compliance with the License.
|
|
|
5da7f3 |
- * You may obtain a copy of the License at
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
5da7f3 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
5da7f3 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
5da7f3 |
- * See the License for the specific language governing permissions and
|
|
|
5da7f3 |
- * limitations under the License.
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-package com.google.gson.internal;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-/**
|
|
|
5da7f3 |
- * Build configuration for Gson. This file is automatically populated by
|
|
|
5da7f3 |
- * templating-maven-plugin and .java/.class files are generated for use in Gson.
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * @author Inderjeet Singh
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-public final class GsonBuildConfig {
|
|
|
5da7f3 |
- // Based on https://stackoverflow.com/questions/2469922/generate-a-version-java-file-in-maven
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- /** This field is automatically populated by Maven when a build is triggered */
|
|
|
5da7f3 |
- public static final String VERSION = "${project.version}";
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- private GsonBuildConfig() { }
|
|
|
5da7f3 |
-}
|
|
|
5da7f3 |
diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java
|
|
|
5da7f3 |
index 27f3ee9..d584ece 100644
|
|
|
5da7f3 |
--- a/gson/src/main/java/com/google/gson/Gson.java
|
|
|
5da7f3 |
+++ b/gson/src/main/java/com/google/gson/Gson.java
|
|
|
5da7f3 |
@@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicLongArray;
|
|
|
5da7f3 |
|
|
|
5da7f3 |
import com.google.gson.internal.ConstructorConstructor;
|
|
|
5da7f3 |
import com.google.gson.internal.Excluder;
|
|
|
5da7f3 |
-import com.google.gson.internal.GsonBuildConfig;
|
|
|
5da7f3 |
import com.google.gson.internal.Primitives;
|
|
|
5da7f3 |
import com.google.gson.internal.Streams;
|
|
|
5da7f3 |
import com.google.gson.internal.bind.ArrayTypeAdapter;
|
|
|
5da7f3 |
@@ -462,7 +461,7 @@ public final class Gson {
|
|
|
5da7f3 |
return candidate;
|
|
|
5da7f3 |
}
|
|
|
5da7f3 |
}
|
|
|
5da7f3 |
- throw new IllegalArgumentException("GSON (" + GsonBuildConfig.VERSION + ") cannot handle " + type);
|
|
|
5da7f3 |
+ throw new IllegalArgumentException("GSON cannot handle " + type);
|
|
|
5da7f3 |
} finally {
|
|
|
5da7f3 |
threadCalls.remove(type);
|
|
|
5da7f3 |
|
|
|
5da7f3 |
@@ -704,10 +703,6 @@ public final class Gson {
|
|
|
5da7f3 |
((TypeAdapter<Object>) adapter).write(writer, src);
|
|
|
5da7f3 |
} catch (IOException e) {
|
|
|
5da7f3 |
throw new JsonIOException(e);
|
|
|
5da7f3 |
- } catch (AssertionError e) {
|
|
|
5da7f3 |
- AssertionError error = new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage());
|
|
|
5da7f3 |
- error.initCause(e);
|
|
|
5da7f3 |
- throw error;
|
|
|
5da7f3 |
} finally {
|
|
|
5da7f3 |
writer.setLenient(oldLenient);
|
|
|
5da7f3 |
writer.setHtmlSafe(oldHtmlSafe);
|
|
|
5da7f3 |
@@ -784,10 +779,6 @@ public final class Gson {
|
|
|
5da7f3 |
Streams.write(jsonElement, writer);
|
|
|
5da7f3 |
} catch (IOException e) {
|
|
|
5da7f3 |
throw new JsonIOException(e);
|
|
|
5da7f3 |
- } catch (AssertionError e) {
|
|
|
5da7f3 |
- AssertionError error = new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage());
|
|
|
5da7f3 |
- error.initCause(e);
|
|
|
5da7f3 |
- throw error;
|
|
|
5da7f3 |
} finally {
|
|
|
5da7f3 |
writer.setLenient(oldLenient);
|
|
|
5da7f3 |
writer.setHtmlSafe(oldHtmlSafe);
|
|
|
5da7f3 |
@@ -945,10 +936,6 @@ public final class Gson {
|
|
|
5da7f3 |
} catch (IOException e) {
|
|
|
5da7f3 |
// TODO(inder): Figure out whether it is indeed right to rethrow this as JsonSyntaxException
|
|
|
5da7f3 |
throw new JsonSyntaxException(e);
|
|
|
5da7f3 |
- } catch (AssertionError e) {
|
|
|
5da7f3 |
- AssertionError error = new AssertionError("AssertionError (GSON " + GsonBuildConfig.VERSION + "): " + e.getMessage());
|
|
|
5da7f3 |
- error.initCause(e);
|
|
|
5da7f3 |
- throw error;
|
|
|
5da7f3 |
} finally {
|
|
|
5da7f3 |
reader.setLenient(oldLenient);
|
|
|
5da7f3 |
}
|
|
|
5da7f3 |
diff --git a/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java b/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java
|
|
|
5da7f3 |
deleted file mode 100644
|
|
|
5da7f3 |
index 36eff8e..0000000
|
|
|
5da7f3 |
--- a/gson/src/test/java/com/google/gson/functional/GsonVersionDiagnosticsTest.java
|
|
|
5da7f3 |
+++ /dev/null
|
|
|
5da7f3 |
@@ -1,96 +0,0 @@
|
|
|
5da7f3 |
-/*
|
|
|
5da7f3 |
- * Copyright (C) 2018 Gson Authors
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5da7f3 |
- * you may not use this file except in compliance with the License.
|
|
|
5da7f3 |
- * You may obtain a copy of the License at
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
5da7f3 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
5da7f3 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
5da7f3 |
- * See the License for the specific language governing permissions and
|
|
|
5da7f3 |
- * limitations under the License.
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-package com.google.gson.functional;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import java.io.IOException;
|
|
|
5da7f3 |
-import java.util.regex.Pattern;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import org.junit.Before;
|
|
|
5da7f3 |
-import org.junit.Test;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import com.google.gson.Gson;
|
|
|
5da7f3 |
-import com.google.gson.GsonBuilder;
|
|
|
5da7f3 |
-import com.google.gson.TypeAdapter;
|
|
|
5da7f3 |
-import com.google.gson.stream.JsonReader;
|
|
|
5da7f3 |
-import com.google.gson.stream.JsonWriter;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import junit.framework.TestCase;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-/**
|
|
|
5da7f3 |
- * Functional tests to validate printing of Gson version on AssertionErrors
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * @author Inderjeet Singh
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-public class GsonVersionDiagnosticsTest extends TestCase {
|
|
|
5da7f3 |
- private static final Pattern GSON_VERSION_PATTERN = Pattern.compile("(\\(GSON \\d\\.\\d\\.\\d)(?:[-.][A-Z]+)?\\)$");
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- private Gson gson;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- @Before
|
|
|
5da7f3 |
- public void setUp() {
|
|
|
5da7f3 |
- gson = new GsonBuilder().registerTypeAdapter(TestType.class, new TypeAdapter<TestType>() {
|
|
|
5da7f3 |
- @Override public void write(JsonWriter out, TestType value) {
|
|
|
5da7f3 |
- throw new AssertionError("Expected during serialization");
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
- @Override public TestType read(JsonReader in) throws IOException {
|
|
|
5da7f3 |
- throw new AssertionError("Expected during deserialization");
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
- }).create();
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- @Test
|
|
|
5da7f3 |
- public void testVersionPattern() {
|
|
|
5da7f3 |
- assertTrue(GSON_VERSION_PATTERN.matcher("(GSON 2.8.5)").matches());
|
|
|
5da7f3 |
- assertTrue(GSON_VERSION_PATTERN.matcher("(GSON 2.8.5-SNAPSHOT)").matches());
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- @Test
|
|
|
5da7f3 |
- public void testAssertionErrorInSerializationPrintsVersion() {
|
|
|
5da7f3 |
- try {
|
|
|
5da7f3 |
- gson.toJson(new TestType());
|
|
|
5da7f3 |
- fail();
|
|
|
5da7f3 |
- } catch (AssertionError expected) {
|
|
|
5da7f3 |
- ensureAssertionErrorPrintsGsonVersion(expected);
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- @Test
|
|
|
5da7f3 |
- public void testAssertionErrorInDeserializationPrintsVersion() {
|
|
|
5da7f3 |
- try {
|
|
|
5da7f3 |
- gson.fromJson("{'a':'abc'}", TestType.class);
|
|
|
5da7f3 |
- fail();
|
|
|
5da7f3 |
- } catch (AssertionError expected) {
|
|
|
5da7f3 |
- ensureAssertionErrorPrintsGsonVersion(expected);
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- private void ensureAssertionErrorPrintsGsonVersion(AssertionError expected) {
|
|
|
5da7f3 |
- String msg = expected.getMessage();
|
|
|
5da7f3 |
- // System.err.println(msg);
|
|
|
5da7f3 |
- int start = msg.indexOf("(GSON");
|
|
|
5da7f3 |
- assertTrue(start > 0);
|
|
|
5da7f3 |
- int end = msg.indexOf("):") + 1;
|
|
|
5da7f3 |
- assertTrue(end > 0 && end > start + 6);
|
|
|
5da7f3 |
- String version = msg.substring(start, end);
|
|
|
5da7f3 |
- // System.err.println(version);
|
|
|
5da7f3 |
- assertTrue(GSON_VERSION_PATTERN.matcher(version).matches());
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- private static final class TestType {
|
|
|
5da7f3 |
- @SuppressWarnings("unused")
|
|
|
5da7f3 |
- String a;
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-}
|
|
|
5da7f3 |
diff --git a/gson/src/test/java/com/google/gson/internal/GsonBuildConfigTest.java b/gson/src/test/java/com/google/gson/internal/GsonBuildConfigTest.java
|
|
|
5da7f3 |
deleted file mode 100644
|
|
|
5da7f3 |
index dc39bc0..0000000
|
|
|
5da7f3 |
--- a/gson/src/test/java/com/google/gson/internal/GsonBuildConfigTest.java
|
|
|
5da7f3 |
+++ /dev/null
|
|
|
5da7f3 |
@@ -1,33 +0,0 @@
|
|
|
5da7f3 |
-/*
|
|
|
5da7f3 |
- * Copyright (C) 2018 The Gson authors
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5da7f3 |
- * you may not use this file except in compliance with the License.
|
|
|
5da7f3 |
- * You may obtain a copy of the License at
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * Unless required by applicable law or agreed to in writing, software
|
|
|
5da7f3 |
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
5da7f3 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
5da7f3 |
- * See the License for the specific language governing permissions and
|
|
|
5da7f3 |
- * limitations under the License.
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-package com.google.gson.internal;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import static org.junit.Assert.assertFalse;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-import org.junit.Test;
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
-/**
|
|
|
5da7f3 |
- * Unit tests for {@code GsonBuildConfig}
|
|
|
5da7f3 |
- *
|
|
|
5da7f3 |
- * @author Inderjeet Singh
|
|
|
5da7f3 |
- */
|
|
|
5da7f3 |
-public class GsonBuildConfigTest {
|
|
|
5da7f3 |
-
|
|
|
5da7f3 |
- @Test
|
|
|
5da7f3 |
- public void testEnsureGsonBuildConfigGetsUpdatedToMavenVersion() {
|
|
|
5da7f3 |
- assertFalse("${project.version}".equals(GsonBuildConfig.VERSION));
|
|
|
5da7f3 |
- }
|
|
|
5da7f3 |
-}
|