Search in sources :

Example 1 with LiquibaseRecorder

use of io.quarkus.liquibase.runtime.LiquibaseRecorder in project quarkus by quarkusio.

the class LiquibaseProcessor method nativeImageConfiguration.

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
@Record(STATIC_INIT)
void nativeImageConfiguration(LiquibaseRecorder recorder, LiquibaseBuildTimeConfig liquibaseBuildConfig, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems, CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflective, BuildProducer<NativeImageResourceBuildItem> resource, BuildProducer<ServiceProviderBuildItem> services, BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitialized, BuildProducer<RuntimeReinitializedClassBuildItem> runtimeReInitialized, BuildProducer<NativeImageResourceBundleBuildItem> resourceBundle) {
    runtimeInitialized.produce(new RuntimeInitializedClassBuildItem(liquibase.diff.compare.CompareControl.class.getName()));
    reflective.produce(new ReflectiveClassBuildItem(false, true, false, liquibase.change.AbstractSQLChange.class.getName(), liquibase.database.jvm.JdbcConnection.class.getName()));
    reflective.produce(new ReflectiveClassBuildItem(true, false, false, "liquibase.command.LiquibaseCommandFactory", liquibase.command.CommandFactory.class.getName()));
    reflective.produce(new ReflectiveClassBuildItem(true, true, true, liquibase.parser.ChangeLogParserCofiguration.class.getName(), liquibase.hub.HubServiceFactory.class.getName(), liquibase.logging.core.DefaultLoggerConfiguration.class.getName(), liquibase.configuration.GlobalConfiguration.class.getName(), com.datical.liquibase.ext.config.LiquibaseProConfiguration.class.getName(), liquibase.license.LicenseServiceFactory.class.getName(), liquibase.executor.ExecutorService.class.getName(), liquibase.change.ChangeFactory.class.getName(), liquibase.logging.core.LogServiceFactory.class.getName(), liquibase.logging.LogFactory.class.getName(), liquibase.change.ColumnConfig.class.getName(), liquibase.change.AddColumnConfig.class.getName(), liquibase.change.core.LoadDataColumnConfig.class.getName(), liquibase.sql.visitor.PrependSqlVisitor.class.getName(), liquibase.sql.visitor.ReplaceSqlVisitor.class.getName(), liquibase.sql.visitor.AppendSqlVisitor.class.getName(), liquibase.sql.visitor.RegExpReplaceSqlVisitor.class.getName()));
    reflective.produce(new ReflectiveClassBuildItem(false, false, true, liquibase.change.ConstraintsConfig.class.getName()));
    // register classes marked with @DatabaseChangeProperty for reflection
    Set<String> classesMarkedWithDatabaseChangeProperty = new HashSet<>();
    for (AnnotationInstance databaseChangePropertyInstance : combinedIndex.getIndex().getAnnotations(DATABASE_CHANGE_PROPERTY)) {
        // the annotation is only supported on methods but let's be safe
        AnnotationTarget annotationTarget = databaseChangePropertyInstance.target();
        if (annotationTarget.kind() == AnnotationTarget.Kind.METHOD) {
            classesMarkedWithDatabaseChangeProperty.add(annotationTarget.asMethod().declaringClass().name().toString());
        }
    }
    reflective.produce(new ReflectiveClassBuildItem(true, true, true, classesMarkedWithDatabaseChangeProperty.toArray(new String[0])));
    Collection<String> dataSourceNames = jdbcDataSourceBuildItems.stream().map(i -> i.getName()).collect(Collectors.toSet());
    resource.produce(new NativeImageResourceBuildItem(getChangeLogs(dataSourceNames, liquibaseBuildConfig).toArray(new String[0])));
    Stream.of(liquibase.change.Change.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.command.LiquibaseCommand.class, liquibase.database.Database.class, liquibase.database.DatabaseConnection.class, liquibase.datatype.LiquibaseDataType.class, liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.diff.DiffGenerator.class, liquibase.diff.output.changelog.ChangeGenerator.class, liquibase.executor.Executor.class, liquibase.license.LicenseService.class, liquibase.lockservice.LockService.class, liquibase.logging.LogService.class, liquibase.parser.ChangeLogParser.class, liquibase.parser.NamespaceDetails.class, liquibase.parser.SnapshotParser.class, liquibase.precondition.Precondition.class, liquibase.serializer.ChangeLogSerializer.class, liquibase.serializer.SnapshotSerializer.class, liquibase.servicelocator.ServiceLocator.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.sqlgenerator.SqlGenerator.class, liquibase.structure.DatabaseObject.class, liquibase.hub.HubService.class).forEach(t -> consumeService(t, (serviceClass, implementations) -> {
        services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
        reflective.produce(new ReflectiveClassBuildItem(true, true, false, implementations.toArray(new String[0])));
    }));
    // Register Precondition services, and the implementation class for reflection while also registering fields for reflection
    consumeService(liquibase.precondition.Precondition.class, (serviceClass, implementations) -> {
        services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
        reflective.produce(new ReflectiveClassBuildItem(true, true, true, implementations.toArray(new String[0])));
    });
    // CommandStep implementations are needed
    consumeService(liquibase.command.CommandStep.class, (serviceClass, implementations) -> {
        services.produce(new ServiceProviderBuildItem(serviceClass.getName(), implementations.toArray(new String[0])));
        reflective.produce(new ReflectiveClassBuildItem(true, false, false, implementations.toArray(new String[0])));
        for (String implementation : implementations) {
            runtimeInitialized.produce(new RuntimeInitializedClassBuildItem(implementation));
        }
    });
    // liquibase XSD
    resource.produce(new NativeImageResourceBuildItem("www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.7.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.2.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.5.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.6.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.7.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.8.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd", "www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-3.9.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-3.10.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.2.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.3.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.4.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.5.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.6.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.7.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.8.xsd", "www.liquibase.org/xml/ns/pro/liquibase-pro-4.9.xsd", "liquibase.build.properties"));
    // liquibase resource bundles
    resourceBundle.produce(new NativeImageResourceBundleBuildItem("liquibase/i18n/liquibase-core"));
}
Also used : DotNames(io.quarkus.arc.processor.DotNames) SystemPropertyBuildItem(io.quarkus.deployment.builditem.SystemPropertyBuildItem) LiquibaseFactoryProducer(io.quarkus.liquibase.runtime.LiquibaseFactoryProducer) SQLFileChange(liquibase.change.core.SQLFileChange) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) LiquibaseRecorder(io.quarkus.liquibase.runtime.LiquibaseRecorder) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) LoadDataChange(liquibase.change.core.LoadDataChange) AnnotationTarget(org.jboss.jandex.AnnotationTarget) Consume(io.quarkus.deployment.annotations.Consume) NativeImageResourceBundleBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem) STATIC_INIT(io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) NativeOrNativeSourcesBuild(io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild) SyntheticBeansRuntimeInitBuildItem(io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem) Collectors(java.util.stream.Collectors) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Feature(io.quarkus.deployment.Feature) List(java.util.List) Stream(java.util.stream.Stream) LiquibaseBuildTimeConfig(io.quarkus.liquibase.runtime.LiquibaseBuildTimeConfig) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ServiceProviderBuildItem(io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) ChangeLogParserFactory(liquibase.parser.ChangeLogParserFactory) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) RuntimeReinitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem) LiquibaseFactory(io.quarkus.liquibase.LiquibaseFactory) Change(liquibase.change.Change) ArrayList(java.util.ArrayList) ChangeSet(liquibase.changelog.ChangeSet) HashSet(java.util.HashSet) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) BiConsumer(java.util.function.BiConsumer) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) ChangeLogParser(liquibase.parser.ChangeLogParser) DataSourceUtil(io.quarkus.datasource.common.runtime.DataSourceUtil) LinkedHashSet(java.util.LinkedHashSet) DatabaseChangeProperty(liquibase.change.DatabaseChangeProperty) Default(javax.enterprise.inject.Default) RuntimeInitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem) IOException(java.io.IOException) JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) LiquibaseDataSource(io.quarkus.liquibase.LiquibaseDataSource) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) Paths(java.nio.file.Paths) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) CreateViewChange(liquibase.change.core.CreateViewChange) ServiceUtil(io.quarkus.deployment.util.ServiceUtil) LiquibaseException(liquibase.exception.LiquibaseException) Collections(java.util.Collections) CreateProcedureChange(liquibase.change.core.CreateProcedureChange) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) AnnotationTarget(org.jboss.jandex.AnnotationTarget) NativeImageResourceBundleBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem) ChangeLogParser(liquibase.parser.ChangeLogParser) ServiceProviderBuildItem(io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem) RuntimeInitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem) SQLFileChange(liquibase.change.core.SQLFileChange) LoadDataChange(liquibase.change.core.LoadDataChange) Change(liquibase.change.Change) CreateViewChange(liquibase.change.core.CreateViewChange) CreateProcedureChange(liquibase.change.core.CreateProcedureChange) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Aggregations

JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)1 JdbcDataSourceSchemaReadyBuildItem (io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 SyntheticBeanBuildItem (io.quarkus.arc.deployment.SyntheticBeanBuildItem)1 SyntheticBeansRuntimeInitBuildItem (io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem)1 DotNames (io.quarkus.arc.processor.DotNames)1 DataSourceUtil (io.quarkus.datasource.common.runtime.DataSourceUtil)1 Feature (io.quarkus.deployment.Feature)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Consume (io.quarkus.deployment.annotations.Consume)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 STATIC_INIT (io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT)1 Record (io.quarkus.deployment.annotations.Record)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)1 IndexDependencyBuildItem (io.quarkus.deployment.builditem.IndexDependencyBuildItem)1 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)1 SystemPropertyBuildItem (io.quarkus.deployment.builditem.SystemPropertyBuildItem)1 NativeImageResourceBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem)1