Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/central-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
distribution: 'temurin'
java-version: |
21
25
17
- name: Publish to Sonatype OSSRH
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['21', '25']
java: ['21', '17']
env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
DEVELOCITY_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
distribution: 'temurin'
java-version: |
21
25
17
- name: Publish to Sonatype Snapshots
if: success()
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
distribution: 'temurin'
java-version: |
21
25
17
- name: Set the current release version
id: release_version
run: echo "release_version=${GITHUB_REF:11}" >> $GITHUB_OUTPUT
Expand Down
1 change: 1 addition & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dependencyResolutionManagement {
}
}
}
rootProject.name = "sourcegen-build-logic"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions sourcegen-generator-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ dependencies {
testImplementation(libs.google.jimfs)
testImplementation(mnTest.mockito.core)
}
micronautBuild {
testFramework = io.micronaut.build.TestFramework.JUNIT5
}
tasks.withType<Test> {
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
Expand All @@ -41,34 +41,35 @@

import static com.google.testing.compile.Compiler.javac;
import static javax.lang.model.util.ElementFilter.fieldsIn;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
import static com.google.common.truth.Truth.assertThat;
import static com.google.testing.compile.CompilationSubject.assertThat;

public abstract class AbstractTypesTest {
protected abstract Elements getElements();
protected abstract Types getTypes();
protected abstract Elements getElements(CompilationRule compilation);
protected abstract Types getTypes(CompilationRule compilation);

private TypeElement getElement(Class<?> clazz) {
return getElements().getTypeElement(clazz.getCanonicalName());
private TypeElement getElement(Class<?> clazz, CompilationRule compilation) {
return getElements(compilation).getTypeElement(clazz.getCanonicalName());
}

private TypeMirror getMirror(Class<?> clazz) {
return getElement(clazz).asType();
private TypeMirror getMirror(Class<?> clazz, CompilationRule compilation) {
return getElement(clazz, compilation).asType();
}

@Test public void getBasicTypeMirror() {
assertThat(TypeName.get(getMirror(Object.class)))
@Test
public void getBasicTypeMirror(CompilationRule compilation) {
assertThat(TypeName.get(getMirror(Object.class, compilation)))
.isEqualTo(ClassName.get(Object.class));
assertThat(TypeName.get(getMirror(Charset.class)))
assertThat(TypeName.get(getMirror(Charset.class, compilation)))
.isEqualTo(ClassName.get(Charset.class));
assertThat(TypeName.get(getMirror(AbstractTypesTest.class)))
assertThat(TypeName.get(getMirror(AbstractTypesTest.class, compilation)))
.isEqualTo(ClassName.get(AbstractTypesTest.class));
}

@Test public void getParameterizedTypeMirror() {
@Test public void getParameterizedTypeMirror(CompilationRule compilation) {
DeclaredType setType =
getTypes().getDeclaredType(getElement(Set.class), getMirror(Object.class));
getTypes(compilation).getDeclaredType(getElement(Set.class, compilation), getMirror(Object.class, compilation));
assertThat(TypeName.get(setType))
.isEqualTo(ParameterizedTypeName.get(ClassName.get(Set.class), ClassName.OBJECT));
}
Expand Down Expand Up @@ -115,9 +116,9 @@ static class Parameterized<
Intersection extends Number & Runnable,
IntersectionOfInterfaces extends Runnable & Serializable> {}

@Test public void getTypeVariableTypeMirror() {
@Test public void getTypeVariableTypeMirror(CompilationRule compilation) {
List<? extends TypeParameterElement> typeVariables =
getElement(Parameterized.class).getTypeParameters();
getElement(Parameterized.class, compilation).getTypeParameters();

// Members of converted types use ClassName and not Class<?>.
ClassName number = ClassName.get(Number.class);
Expand All @@ -143,8 +144,8 @@ static class Parameterized<
static class Recursive<T extends Map<List<T>, Set<T[]>>> {}

@Test
public void getTypeVariableTypeMirrorRecursive() {
TypeMirror typeMirror = getElement(Recursive.class).asType();
public void getTypeVariableTypeMirrorRecursive(CompilationRule compilation) {
TypeMirror typeMirror = getElement(Recursive.class, compilation).asType();
ParameterizedTypeName typeName = (ParameterizedTypeName) TypeName.get(typeMirror);
String className = Recursive.class.getCanonicalName();
assertThat(typeName.toString()).isEqualTo(className + "<T>");
Expand All @@ -162,38 +163,38 @@ public void getTypeVariableTypeMirrorRecursive() {
.isEqualTo("[java.util.Map<java.util.List<T>, java.util.Set<T[]>>]");
}

@Test public void getPrimitiveTypeMirror() {
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.BOOLEAN)))
@Test public void getPrimitiveTypeMirror(CompilationRule compilation) {
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.BOOLEAN)))
.isEqualTo(TypeName.BOOLEAN);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.BYTE)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.BYTE)))
.isEqualTo(TypeName.BYTE);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.SHORT)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.SHORT)))
.isEqualTo(TypeName.SHORT);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.INT)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.INT)))
.isEqualTo(TypeName.INT);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.LONG)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.LONG)))
.isEqualTo(TypeName.LONG);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.CHAR)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.CHAR)))
.isEqualTo(TypeName.CHAR);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.FLOAT)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.FLOAT)))
.isEqualTo(TypeName.FLOAT);
assertThat(TypeName.get(getTypes().getPrimitiveType(TypeKind.DOUBLE)))
assertThat(TypeName.get(getTypes(compilation).getPrimitiveType(TypeKind.DOUBLE)))
.isEqualTo(TypeName.DOUBLE);
}

@Test public void getArrayTypeMirror() {
assertThat(TypeName.get(getTypes().getArrayType(getMirror(Object.class))))
@Test public void getArrayTypeMirror(CompilationRule compilation) {
assertThat(TypeName.get(getTypes(compilation).getArrayType(getMirror(Object.class, compilation))))
.isEqualTo(ArrayTypeName.of(ClassName.OBJECT));
}

@Test public void getVoidTypeMirror() {
assertThat(TypeName.get(getTypes().getNoType(TypeKind.VOID)))
@Test public void getVoidTypeMirror(CompilationRule compilation) {
assertThat(TypeName.get(getTypes(compilation).getNoType(TypeKind.VOID)))
.isEqualTo(TypeName.VOID);
}

@Test public void getNullTypeMirror() {
@Test public void getNullTypeMirror(CompilationRule compilation) {
try {
TypeName.get(getTypes().getNullType());
TypeName.get(getTypes(compilation).getNullType());
fail();
} catch (IllegalArgumentException expected) {
}
Expand Down Expand Up @@ -224,24 +225,24 @@ public void getTypeVariableTypeMirrorRecursive() {
assertThat(type.toString()).isEqualTo("? super java.lang.String");
}

@Test public void wildcardMirrorNoBounds() throws Exception {
WildcardType wildcard = getTypes().getWildcardType(null, null);
@Test public void wildcardMirrorNoBounds(CompilationRule compilation) throws Exception {
WildcardType wildcard = getTypes(compilation).getWildcardType(null, null);
TypeName type = TypeName.get(wildcard);
assertThat(type.toString()).isEqualTo("?");
}

@Test public void wildcardMirrorExtendsType() throws Exception {
Types types = getTypes();
Elements elements = getElements();
@Test public void wildcardMirrorExtendsType(CompilationRule compilation) throws Exception {
Types types = getTypes(compilation);
Elements elements = getElements(compilation);
TypeMirror charSequence = elements.getTypeElement(CharSequence.class.getName()).asType();
WildcardType wildcard = types.getWildcardType(charSequence, null);
TypeName type = TypeName.get(wildcard);
assertThat(type.toString()).isEqualTo("? extends java.lang.CharSequence");
}

@Test public void wildcardMirrorSuperType() throws Exception {
Types types = getTypes();
Elements elements = getElements();
@Test public void wildcardMirrorSuperType(CompilationRule compilation) throws Exception {
Types types = getTypes(compilation);
Elements elements = getElements(compilation);
TypeMirror string = elements.getTypeElement(String.class.getName()).asType();
WildcardType wildcard = types.getWildcardType(null, string);
TypeName type = TypeName.get(wildcard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
*/
package io.micronaut.sourcegen.javapoet;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.List;
import java.util.Map;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AnnotatedTypeNameTest {

Expand All @@ -43,12 +44,18 @@ public class AnnotatedTypeNameTest {
public @interface TypeUseAnnotation {}


@Test(expected=NullPointerException.class) public void nullAnnotationArray() {
TypeName.BOOLEAN.annotated((AnnotationSpec[]) null);
@Test
void nullAnnotationArray() {
assertThrows(NullPointerException.class, () ->
TypeName.BOOLEAN.annotated((AnnotationSpec[]) null)
);
}

@Test(expected=NullPointerException.class) public void nullAnnotationList() {
TypeName.DOUBLE.annotated((List<AnnotationSpec>) null);
@Test
void nullAnnotationList() {
assertThrows(NullPointerException.class, () ->
TypeName.DOUBLE.annotated((List<AnnotationSpec>) null)
);
}

@Test public void annotated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package io.micronaut.sourcegen.javapoet;

import com.google.testing.compile.CompilationRule;
import io.micronaut.sourcegen.javapoet.AnnotationSpec.CodeAnnotationValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import javax.lang.model.element.TypeElement;
import java.lang.annotation.Annotation;
Expand All @@ -28,8 +27,9 @@
import java.util.List;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(CompilationRule.class)
public final class AnnotationSpecTest {

@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -105,7 +105,6 @@ public class IsAnnotated {
// empty
}

@Rule public final CompilationRule compilation = new CompilationRule();

@Test
void equalsAndHashCode() {
Expand All @@ -120,7 +119,7 @@ void equalsAndHashCode() {
}

@Test
void defaultAnnotation() {
void defaultAnnotation(CompilationRule compilation) {
String name = IsAnnotated.class.getCanonicalName();
TypeElement element = compilation.getElements().getTypeElement(name);
AnnotationSpec annotation = AnnotationSpec.get(element.getAnnotationMirrors().get(0));
Expand Down Expand Up @@ -157,7 +156,7 @@ void defaultAnnotation() {
}

@Test
void defaultAnnotationWithImport() {
void defaultAnnotationWithImport(CompilationRule compilation) {
String name = IsAnnotated.class.getCanonicalName();
TypeElement element = compilation.getElements().getTypeElement(name);
AnnotationSpec annotation = AnnotationSpec.get(element.getAnnotationMirrors().get(0));
Expand Down Expand Up @@ -248,7 +247,7 @@ void dynamicArrayOfEnumConstants() {
}

@Test
void defaultAnnotationToBuilder() {
void defaultAnnotationToBuilder(CompilationRule compilation) {
String name = IsAnnotated.class.getCanonicalName();
TypeElement element = compilation.getElements().getTypeElement(name);
AnnotationSpec.Builder builder = AnnotationSpec.get(element.getAnnotationMirrors().get(0))
Expand Down
Loading
Loading