Skip to content

Commit

Permalink
IPROTO-158 Remove autoImportClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant committed Oct 11, 2024
1 parent b28aa2e commit a666bba
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@
Class<?>[] excludeClasses() default {};

/**
* Indicates if we accept classes not explicitly included by the {@link #includeClasses} or {@link #basePackages} to
* be auto-detected by reference from the already included classes and to be added automatically. If this is set to
* {@code false} (which is the default) it results in a compilation error when such a case is encountered.
*
* @deprecated since 4.3.4. This will be removed in version 5. See <a href="https://issues.redhat.com/browse/IPROTO-158">IPROTO-158</a>.
* @deprecated since 4.3.4. This does nothing and is only present for backwards compatibility and will be removed in a
* future version.
*/
@Deprecated
boolean autoImportClasses() default false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public abstract class BaseProtoSchemaGenerator {
*/
protected final Set<XClass> classes;

/**
* Indicates if class dependencies are automatically added when discovered or will generate an error.
*/
protected final boolean autoImportClasses;

/**
* Known classes: the user-added classes ({@link #classes}) plus all their superclasses and superinterfaces. This is
* only used when auto-import is disabled.
Expand All @@ -87,7 +82,7 @@ public abstract class BaseProtoSchemaGenerator {

protected BaseProtoSchemaGenerator(XTypeFactory typeFactory, SerializationContext serializationContext,
String generator, String fileName, String packageName, Set<XClass> classes,
boolean autoImportClasses, ProtoSyntax syntax, boolean allowNullFields) {
ProtoSyntax syntax, boolean allowNullFields) {
if (fileName == null) {
throw new ProtoSchemaBuilderException("fileName cannot be null");
}
Expand All @@ -98,7 +93,6 @@ protected BaseProtoSchemaGenerator(XTypeFactory typeFactory, SerializationContex
this.fileName = fileName;
this.packageName = packageName;
this.classes = classes;
this.autoImportClasses = autoImportClasses;
this.syntax = syntax;
this.allowNullFields = allowNullFields;
}
Expand Down Expand Up @@ -276,7 +270,7 @@ protected ProtoTypeMetadata makeMessageTypeMetadata(XClass javaType) {
void collectMetadata(ProtoTypeMetadata protoTypeMetadata) {
boolean isUnknownClass = isUnknownClass(protoTypeMetadata.getJavaClass());

if (isUnknownClass && !autoImportClasses && !protoTypeMetadata.isImported()) {
if (isUnknownClass && !protoTypeMetadata.isImported()) {
// autoImportClasses is off and we are attempting expanding the class set -> NOPE!
throw new ProtoSchemaBuilderException("Found a reference to class "
+ protoTypeMetadata.getJavaClassName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void testDiscoveryWithoutAutoImport() {
assertThat(compilation).hadErrorContaining("Found a reference to class"
+ " test_discovery_without_auto_import.InnerMessage1 which was not explicitly included by"
+ " @AutoProtoSchemaBuilder and the combination of relevant attributes"
+ " (basePackages, includeClasses, excludeClasses, autoImportClasses) do not allow it to be included.");
+ " (basePackages, includeClasses, excludeClasses) do not allow it to be included.");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import test_basic_stuff.TestMessage;

@AutoProtoSchemaBuilder(schemaFilePath = "/", dependsOn = test_basic_stuff.AbstractFirstInitializer.class,
includeClasses = DependentInitializer.A.class, autoImportClasses = false, service = true)
includeClasses = DependentInitializer.A.class, service = true)
interface DependentInitializer extends SerializationContextInitializer {

class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import org.infinispan.protostream.annotations.ProtoField;

@AutoProtoSchemaBuilder(includeClasses = OuterMessage1.class, autoImportClasses = false)
@AutoProtoSchemaBuilder(includeClasses = OuterMessage1.class)
public interface DiscoveryWithoutAutoImport extends SerializationContextInitializer {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import org.infinispan.protostream.annotations.ProtoField;

@AutoProtoSchemaBuilder(includeClasses = {OuterMessage2.class, OuterMessage3.class},
autoImportClasses = false, schemaFilePath = "/")
schemaFilePath = "/")
interface NestedDiscoveryWithoutAutoImport extends SerializationContextInitializer {
}

@AutoProtoSchemaBuilder(basePackages = "test_nested_discovery_without_auto_import",
autoImportClasses = false, schemaFilePath = "/")
schemaFilePath = "/")
interface NestedDiscoveryWithoutAutoImport2 extends SerializationContextInitializer {
}

@AutoProtoSchemaBuilder(autoImportClasses = false, schemaFilePath = "/")
@AutoProtoSchemaBuilder(schemaFilePath = "/")
interface NestedDiscoveryWithoutAutoImport3 extends SerializationContextInitializer {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ boolean isClassAcceptable(XClass c) {
return false;
}

// we're including based on packages only, or we have autoImportClasses enabled
return includedClasses.isEmpty() || builderAnnotation.autoImportClasses();
// we're including based on packages only
return includedClasses.isEmpty();
}

private Set<String> getBasePackages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void processPackage(RoundEnvironment roundEnv, SerializationContext serC
Set<XClass> xclasses = classScanner.getXClasses();

CompileTimeProtoSchemaGenerator protoSchemaGenerator = new CompileTimeProtoSchemaGenerator(typeFactory, generatedFilesWriter, serCtx,
initializerPackageName, protobufFileName, protobufPackageName, dependencies.marshalledClasses, xclasses, builderAnnotation.autoImportClasses(),
initializerPackageName, protobufFileName, protobufPackageName, dependencies.marshalledClasses, xclasses,
builderAnnotation.syntax(), builderAnnotation.allowNullFields(), classScanner);
String schemaSrc = protoSchemaGenerator.generateAndRegister();

Expand Down Expand Up @@ -306,7 +306,7 @@ private void processClass(RoundEnvironment roundEnv, SerializationContext serCtx

CompileTimeProtoSchemaGenerator protoSchemaGenerator = new CompileTimeProtoSchemaGenerator(typeFactory, generatedFilesWriter, serCtx,
typeElement.getQualifiedName().toString(), protobufFileName, protobufPackageName, dependencies.marshalledClasses,
xclasses, annotation.autoImportClasses(), annotation.syntax(), annotation.allowNullFields(), classScanner);
xclasses, annotation.syntax(), annotation.allowNullFields(), classScanner);

String schemaSrc = protoSchemaGenerator.generateAndRegister();

Expand Down Expand Up @@ -613,7 +613,6 @@ private static void addSchemaBuilderAnnotation(IndentWriter iw, String className
}
iw.append("service = ").append(String.valueOf(annotation.service())).append(",\n");
iw.append("marshallersOnly = ").append(String.valueOf(marshallersOnly)).append(",\n");
iw.append("autoImportClasses = ").append(String.valueOf(annotation.autoImportClasses())).append(",\n");
iw.append("includeClasses = {");
iw.inc();
boolean first = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final class CompileTimeProtoSchemaGenerator extends BaseProtoSchemaGenerator {
CompileTimeProtoSchemaGenerator(XTypeFactory typeFactory, GeneratedFilesWriter generatedFilesWriter,
SerializationContext serializationContext, String generator,
String fileName, String packageName, Map<XClass, CompileTimeDependency> dependencies,
Set<XClass> classes, boolean autoImportClasses, ProtoSyntax syntax, boolean allowNullFields,
Set<XClass> classes, ProtoSyntax syntax, boolean allowNullFields,
AnnotatedClassScanner classScanner) {
super(typeFactory, serializationContext, generator, fileName, packageName, classes, autoImportClasses, syntax, allowNullFields);
super(typeFactory, serializationContext, generator, fileName, packageName, classes, syntax, allowNullFields);
this.dependencies = dependencies;
this.marshallerSourceCodeGenerator = new MarshallerSourceCodeGenerator(generatedFilesWriter, typeFactory, packageName);
this.classScanner = classScanner;
Expand Down Expand Up @@ -84,7 +84,7 @@ protected boolean isUnknownClass(XClass c) {
if (super.isUnknownClass(c) && !dependencies.containsKey(c) && !classScanner.isClassAcceptable(c)) {
throw new ProtoSchemaBuilderException("Found a reference to class " + c.getCanonicalName() +
" which was not explicitly included by @AutoProtoSchemaBuilder and the combination of" +
" relevant attributes (basePackages, includeClasses, excludeClasses, autoImportClasses)" +
" relevant attributes (basePackages, includeClasses, excludeClasses)" +
" do not allow it to be included.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class ProtoSchemaAnnotation {

private final boolean autoImportClasses;
private final String[] basePackages;
private final String className;
private final boolean marshallersOnly;
Expand All @@ -20,15 +19,14 @@ class ProtoSchemaAnnotation {
private final String schemaPackageName;
private final boolean service;
private final ProtoSyntax syntax;
private boolean allowNullFields;
private final boolean allowNullFields;
private final String[] value;
private final Annotation annotation;
private final String annotationName;

public ProtoSchemaAnnotation(AutoProtoSchemaBuilder annotation) {
this.annotation = annotation;
this.annotationName = AutoProtoSchemaBuilder.class.getSimpleName();
autoImportClasses = annotation.autoImportClasses();
basePackages = annotation.basePackages();
className = annotation.className();
marshallersOnly = annotation.marshallersOnly();
Expand All @@ -44,7 +42,6 @@ public ProtoSchemaAnnotation(AutoProtoSchemaBuilder annotation) {
public ProtoSchemaAnnotation(ProtoSchema annotation) {
this.annotation = annotation;
this.annotationName = ProtoSchema.class.getSimpleName();
autoImportClasses = false;
basePackages = annotation.basePackages();
className = annotation.className();
marshallersOnly = annotation.marshallersOnly();
Expand All @@ -57,10 +54,6 @@ public ProtoSchemaAnnotation(ProtoSchema annotation) {
value = annotation.value();
}

public boolean autoImportClasses() {
return autoImportClasses;
}

public String[] basePackages() {
return basePackages;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void testGeneratedInitializer() throws Exception {
assertTrue(protoFile.contains("@MyCustomAnnotation("));
}

@AutoProtoSchemaBuilder(schemaFilePath = "second_initializer", className = "TestInitializer", autoImportClasses = true,
@AutoProtoSchemaBuilder(schemaFilePath = "second_initializer", className = "TestInitializer",
basePackages = "org.infinispan.protostream.annotations.impl.processor", syntax = ProtoSyntax.PROTO3)
abstract static class SecondInitializer implements GeneratedSchema {
SecondInitializer() {
Expand Down Expand Up @@ -207,7 +207,7 @@ abstract class LocalInitializer implements SerializationContextInitializer {
}

// Using a fully implemented initializer as a base is not the usual use case but some users might need this and we do support it.
@AutoProtoSchemaBuilder(className = "NonAbstractInitializerImpl", autoImportClasses = true,
@AutoProtoSchemaBuilder(className = "NonAbstractInitializerImpl",
basePackages = "org.infinispan.protostream.annotations.impl.processor", syntax = ProtoSyntax.PROTO3)
static class NonAbstractInitializer implements GeneratedSchema {

Expand Down

0 comments on commit a666bba

Please sign in to comment.