Skip to content

Commit

Permalink
Remove support from AutoValue for generating Java 7 code.
Browse files Browse the repository at this point in the history
We now only support Java 8. 1.10.4 was the last AutoValue release that could generate Java 7 code.

Fixes #1683.

RELNOTES=Support for generating Java 7 code has been removed from AutoValue, AutoAnnotation, and AutoBuilder. You must be on at least Java 8, or an Android version with desugaring that allows it to pass for Java 8. 1.10.4 is the last AutoValue version with support for Java 7.
PiperOrigin-RevId: 597954833
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Jan 12, 2024
1 parent 446ad61 commit b9142b7
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 74 deletions.
2 changes: 1 addition & 1 deletion value/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AutoValue

*Generated immutable value classes for Java 7+* <br />
*Generated immutable value classes for Java 8+* <br />
***Kevin Bourrillion, Éamonn McManus*** <br />
**Google, Inc.**

Expand Down
4 changes: 2 additions & 2 deletions value/annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<version>HEAD-SNAPSHOT</version>
<name>AutoValue Annotations</name>
<description>
Immutable value-type code generation for Java 1.7+.
Immutable value-type code generation for Java 8+.
</description>
<url>https://github.com/google/auto/tree/main/value</url>

<properties>
<java.version>1.7</java.version>
<java.version>1.8</java.version>
</properties>

<scm>
Expand Down
2 changes: 1 addition & 1 deletion value/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<version>HEAD-SNAPSHOT</version>
<name>AutoValue Parent</name>
<description>
Immutable value-type code generation for Java 7+.
Immutable value-type code generation for Java 8+.
</description>
<packaging>pom</packaging>
<url>https://github.com/google/auto/tree/main/value</url>
Expand Down
2 changes: 1 addition & 1 deletion value/processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<version>HEAD-SNAPSHOT</version>
<name>AutoValue Processor</name>
<description>
Immutable value-type code generation for Java 1.7+.
Immutable value-type code generation for Java 8+.
</description>
<url>https://github.com/google/auto/tree/main/value</url>

Expand Down
19 changes: 0 additions & 19 deletions value/src/it/functional/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,6 @@
</build>
</profile>

<profile>
<id>exclude-java8-tests</id>
<activation>
<jdk>(,1.7]</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testExcludes>
<exclude>**/AutoValueJava8Test.java</exclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>open-modules</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,8 @@ public void testEqualsParameterAnnotation() throws ReflectiveOperationException
@SuppressWarnings("GetClassOnAnnotation") // yes, I really want the implementation class
Class<? extends StringValues> autoAnnotationImpl = newStringValues(new String[0]).getClass();
Method equals = autoAnnotationImpl.getDeclaredMethod("equals", Object.class);
// The remaining faffing around with reflection is there because we have a Google-internal test
// that runs this code with -source 7 -target 7. We're really just doing this:
// assertThat(equals.getAnnotatedParameterTypes()[0].isAnnotationPresent(jspecifyNullable))
// .isTrue();
Method getAnnotatedParameterTypes = Method.class.getMethod("getAnnotatedParameterTypes");
Object[] annotatedParameterTypes = (Object[]) getAnnotatedParameterTypes.invoke(equals);
Method isAnnotationPresent =
annotatedParameterTypes[0].getClass().getMethod("isAnnotationPresent", Class.class);
assertThat(isAnnotationPresent.invoke(annotatedParameterTypes[0], jspecifyNullable))
.isEqualTo(true);
assertThat(equals.getAnnotatedParameterTypes()[0].isAnnotationPresent(jspecifyNullable))
.isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.util.stream.Collectors.joining;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -412,14 +413,10 @@ public void staticMethodOfContainingClass() {

@Test
public void missingRequiredProperty() {
// This test is compiled at source level 7 by CompileWithEclipseTest, so we can't use
// assertThrows with a lambda.
try {
localTimeBuilder().hour(12).minute(34).build();
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessageThat().isEqualTo("Missing required properties: second");
}
IllegalStateException e =
assertThrows(
IllegalStateException.class, () -> localTimeBuilder().hour(12).minute(34).build());
assertThat(e).hasMessageThat().isEqualTo("Missing required properties: second");
}

static void throwException() throws IOException {
Expand Down Expand Up @@ -507,12 +504,7 @@ public void propertyBuilder() {
}

static <T> String concatList(ImmutableList<T> list) {
// We're avoiding streams for now since we compile this in Java 7 mode in CompileWithEclipseTest
StringBuilder sb = new StringBuilder();
for (T element : list) {
sb.append(element);
}
return sb.toString();
return list.stream().map(String::valueOf).collect(joining());
}

@AutoBuilder(callMethod = "concatList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,16 @@ public static void setSourceRoot() {
private static final Predicate<File> JAVA_FILE =
f -> f.getName().endsWith(".java") && !IGNORED_TEST_FILES.contains(f.getName());

private static final ImmutableSet<String> JAVA8_TEST_FILES =
ImmutableSet.of(
"AutoBuilderTest.java",
"AutoOneOfJava8Test.java",
"AutoValueJava8Test.java",
"EmptyExtension.java");
private static final Predicate<File> JAVA8_TEST = f -> JAVA8_TEST_FILES.contains(f.getName());

@Test
public void compileWithEclipseJava7() throws Exception {
compileWithEclipse("7", JAVA_FILE.and(JAVA8_TEST.negate()));
}

@Test
public void compileWithEclipseJava8() throws Exception {
compileWithEclipse("8", JAVA_FILE);
}

private void compileWithEclipse(String version, Predicate<File> predicate) throws IOException {
public void compileWithEclipse() throws IOException {
String version = "8";
File sourceRootFile = new File(SOURCE_ROOT);
File javaDir = new File(sourceRootFile, "src/main/java");
File javatestsDir = new File(sourceRootFile, "src/test/java");
Set<File> sources =
new ImmutableSet.Builder<File>()
.addAll(filesUnderDirectory(javaDir, predicate))
.addAll(filesUnderDirectory(javatestsDir, predicate))
.addAll(filesUnderDirectory(javaDir, JAVA_FILE))
.addAll(filesUnderDirectory(javatestsDir, JAVA_FILE))
.build();
assertThat(sources).isNotEmpty();
JavaCompiler compiler = new EclipseCompiler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.LLOAD;
import static org.objectweb.asm.Opcodes.NEW;
import static org.objectweb.asm.Opcodes.V1_7;
import static org.objectweb.asm.Opcodes.V1_8;

import com.google.auto.common.MoreElements;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -90,7 +90,7 @@ static byte[] makeConstructorForwarder(

ClassWriter classWriter = new ClassWriter(COMPUTE_MAXS);
classWriter.visit(
V1_7,
V1_8,
ACC_FINAL | ACC_SUPER,
internalName(forwardingClassName),
null,
Expand Down
6 changes: 2 additions & 4 deletions value/userguide/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AutoValue


*Generated immutable value classes for Java 7+* <br />
*Generated immutable value classes for Java 8+* <br />
***Éamonn McManus, Kevin Bourrillion*** <br />
**Google, Inc.**

Expand Down Expand Up @@ -241,9 +241,7 @@ See [Why AutoValue?](why.md).

## <a name="versions"></a>What Java versions does it work with?

AutoValue requires that your compiler be at least Java 8. However, the code that
it generates is compatible with Java 7. That means that you can use it with
`-source 7 -target 7` or (for Java 9+) `--release 7`.
AutoValue requires that your compiler be at least Java 8.

## <a name="more_howto"></a>How do I...

Expand Down

0 comments on commit b9142b7

Please sign in to comment.