From a614237f384aa24b892b908164ab96503ba4d399 Mon Sep 17 00:00:00 2001 From: Frank Sanders Date: Tue, 22 Aug 2023 12:59:36 +0200 Subject: [PATCH] easier extension registration --- .../orcas/diff/Parameters.java | 14 +- .../orcas/gradle/BaseOrcasTask.groovy | 135 +++++++++--------- .../orcas/gradle/OrcasGradlePlugin.groovy | 18 ++- 3 files changed, 99 insertions(+), 68 deletions(-) diff --git a/orcas_core/build_source/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/Parameters.java b/orcas_core/build_source/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/Parameters.java index eaf02c58..cb142bd4 100644 --- a/orcas_core/build_source/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/Parameters.java +++ b/orcas_core/build_source/orcas_diff/src/main/java/de/opitzconsulting/orcas/diff/Parameters.java @@ -4,6 +4,7 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -278,11 +279,22 @@ public void setUpdateEnabledStatus(boolean pUpdateEnabledStatus) { updateEnabledStatus = pUpdateEnabledStatus; } + private final List> extensions = new ArrayList<>(); + private final List> reverseExtensions = new ArrayList<>(); + + public void addExtension( UnaryOperator pExtension ) { + extensions.add(pExtension); + } + + public void addReverseExtension( UnaryOperator pExtension ) { + reverseExtensions.add(pExtension); + } + private AdditionalExtensionFactory _additionalExtensionFactory = new AdditionalExtensionFactory() { @SuppressWarnings("unchecked") @Override public List> getAdditionalExtensions(Class pModelClass, boolean pReverseMode) { - return Collections.EMPTY_LIST; + return (List>)(List)(pReverseMode ? reverseExtensions : extensions); } }; diff --git a/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/BaseOrcasTask.groovy b/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/BaseOrcasTask.groovy index 3b3b602c..de5a0f16 100644 --- a/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/BaseOrcasTask.groovy +++ b/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/BaseOrcasTask.groovy @@ -30,98 +30,101 @@ public abstract class BaseOrcasTask extends DefaultTask { ParametersCall lParametersCall = new ParametersCall(); - lParametersCall.getJdbcConnectParameters().setJdbcDriver( project.orcasconfiguration.jdbcdriver ); - lParametersCall.getJdbcConnectParameters().setJdbcUrl( project.orcasconfiguration.jdbcurl ); - lParametersCall.getJdbcConnectParameters().setJdbcUser( project.orcasconfiguration.username ); - lParametersCall.getJdbcConnectParameters().setJdbcPassword( project.orcasconfiguration.password ); + OrcasGradlePluginExtension orcasconfiguration = project.orcasconfiguration + lParametersCall.getJdbcConnectParameters().setJdbcDriver( orcasconfiguration.jdbcdriver ); + lParametersCall.getJdbcConnectParameters().setJdbcUrl( orcasconfiguration.jdbcurl ); + lParametersCall.getJdbcConnectParameters().setJdbcUser( orcasconfiguration.username ); + lParametersCall.getJdbcConnectParameters().setJdbcPassword( orcasconfiguration.password ); - lParametersCall.setTargetplsql( project.orcasconfiguration.targetplsql ); + lParametersCall.setTargetplsql( orcasconfiguration.targetplsql ); - lParametersCall.setScriptprefix( project.orcasconfiguration.scriptfolderPrefix ); - lParametersCall.setScriptpostfix( project.orcasconfiguration.scriptfolderPostfix ); - lParametersCall.setScriptfolderrecursive( project.orcasconfiguration.scriptfolderrecursive ); + lParametersCall.setScriptprefix( orcasconfiguration.scriptfolderPrefix ); + lParametersCall.setScriptpostfix( orcasconfiguration.scriptfolderPostfix ); + lParametersCall.setScriptfolderrecursive( orcasconfiguration.scriptfolderrecursive ); - lParametersCall.setSpoolfile( convertOutFile(project.orcasconfiguration.spoolfile) ); - lParametersCall.setSpoolfolder( convertOutFile(project.orcasconfiguration.spoolfolder) ); + lParametersCall.setSpoolfile( convertOutFile(orcasconfiguration.spoolfile) ); + lParametersCall.setSpoolfolder( convertOutFile(orcasconfiguration.spoolfolder) ); lParametersCall.setLogname( getLogname() ); - lParametersCall.setLoglevel( project.orcasconfiguration.loglevel ); - - lParametersCall.setFailOnErrorMode( failOnErrorMode != null ? failOnErrorMode : project.orcasconfiguration.failOnErrorMode ); - lParametersCall.setExecuteSqlErrorHandler( executeSqlErrorHandler != null ? executeSqlErrorHandler : project.orcasconfiguration.executeSqlErrorHandler ); - - lParametersCall.setLogCompileErrors( project.orcasconfiguration.logCompileErrors ); - - lParametersCall.setExcludewhereview( project.orcasconfiguration.excludewhereview ); - lParametersCall.setExcludewhereobjecttype( project.orcasconfiguration.excludewhereobjecttype ); - lParametersCall.setExcludewherepackage( project.orcasconfiguration.excludewherepackage ); - lParametersCall.setExcludewheretrigger( project.orcasconfiguration.excludewheretrigger ); - lParametersCall.setExcludewherefunction( project.orcasconfiguration.excludewherefunction ); - lParametersCall.setExcludewhereprocedure( project.orcasconfiguration.excludewhereprocedure ); - - lParametersCall.setLogonly( project.orcasconfiguration.logonly ); - lParametersCall.setDropmode( project.orcasconfiguration.dropmode ); - lParametersCall.setIndexparallelcreate( project.orcasconfiguration.indexparallelcreate ); - lParametersCall.setIndexmovetablespace( project.orcasconfiguration.indexmovetablespace ); - lParametersCall.setTablemovetablespace( project.orcasconfiguration.tablemovetablespace ); - lParametersCall.setMviewlogmovetablespace( project.orcasconfiguration.mviewlogmovetablespace ); - lParametersCall.setCreatemissingfkindexes( project.orcasconfiguration.createmissingfkindexes ); - lParametersCall.setExcludewheretable( project.orcasconfiguration.excludewheretable ); - lParametersCall.setExcludewheresequence( project.orcasconfiguration.excludewheresequence ); - lParametersCall.setExcludewheremview( project.orcasconfiguration.excludewheremview ); - lParametersCall.setDateformat( project.orcasconfiguration.dateformat ); - lParametersCall.setExtensionParameter( project.orcasconfiguration.extensionparameter ); - lParametersCall.setAdditionsOnly( project.orcasconfiguration.additionsonly ); - lParametersCall.setLogIgnoredStatements( project.orcasconfiguration.logignoredstatements ); - lParametersCall.setXmlLogFile( convertOutFile( project.orcasconfiguration.xmllogfile ) ); - lParametersCall.setXmlInputFile( project.orcasconfiguration.xmlinputfile ); - lParametersCall.setSetUnusedInsteadOfDropColumn( project.orcasconfiguration.setunusedinsteadofdropcolumn ); - lParametersCall.setCreateIndexOnline( project.orcasconfiguration.indexonlinecreate ); - lParametersCall.setMinimizeStatementCount( project.orcasconfiguration.minimizestatementcount ); - lParametersCall.setCharsetName( project.orcasconfiguration.charsetname ); - lParametersCall.setCharsetNameSqlLog( project.orcasconfiguration.charsetnamesqllog ); - lParametersCall.setMultiSchema( project.orcasconfiguration.multischema ); - lParametersCall.setMultiSchemaDbaViews( project.orcasconfiguration.multischemadbaviews ); - lParametersCall.setMultiSchemaExcludewhereowner( project.orcasconfiguration.multischemaexcludewhereowner ); - lParametersCall.setViewExtractMode( project.orcasconfiguration.viewextractmode ); - lParametersCall.setIsOneTimeScriptLogonlyMode( project.orcasconfiguration.isOneTimeScriptLogonlyMode ); - if (project.orcasconfiguration.isExtractViewCommnets == true) { + lParametersCall.setLoglevel( orcasconfiguration.loglevel ); + + lParametersCall.setFailOnErrorMode( failOnErrorMode != null ? failOnErrorMode : orcasconfiguration.failOnErrorMode ); + lParametersCall.setExecuteSqlErrorHandler( executeSqlErrorHandler != null ? executeSqlErrorHandler : orcasconfiguration.executeSqlErrorHandler ); + + lParametersCall.setLogCompileErrors( orcasconfiguration.logCompileErrors ); + + lParametersCall.setExcludewhereview( orcasconfiguration.excludewhereview ); + lParametersCall.setExcludewhereobjecttype( orcasconfiguration.excludewhereobjecttype ); + lParametersCall.setExcludewherepackage( orcasconfiguration.excludewherepackage ); + lParametersCall.setExcludewheretrigger( orcasconfiguration.excludewheretrigger ); + lParametersCall.setExcludewherefunction( orcasconfiguration.excludewherefunction ); + lParametersCall.setExcludewhereprocedure( orcasconfiguration.excludewhereprocedure ); + + lParametersCall.setLogonly( orcasconfiguration.logonly ); + lParametersCall.setDropmode( orcasconfiguration.dropmode ); + lParametersCall.setIndexparallelcreate( orcasconfiguration.indexparallelcreate ); + lParametersCall.setIndexmovetablespace( orcasconfiguration.indexmovetablespace ); + lParametersCall.setTablemovetablespace( orcasconfiguration.tablemovetablespace ); + lParametersCall.setMviewlogmovetablespace( orcasconfiguration.mviewlogmovetablespace ); + lParametersCall.setCreatemissingfkindexes( orcasconfiguration.createmissingfkindexes ); + lParametersCall.setExcludewheretable( orcasconfiguration.excludewheretable ); + lParametersCall.setExcludewheresequence( orcasconfiguration.excludewheresequence ); + lParametersCall.setExcludewheremview( orcasconfiguration.excludewheremview ); + lParametersCall.setDateformat( orcasconfiguration.dateformat ); + lParametersCall.setExtensionParameter( orcasconfiguration.extensionparameter ); + lParametersCall.setAdditionsOnly( orcasconfiguration.additionsonly ); + lParametersCall.setLogIgnoredStatements( orcasconfiguration.logignoredstatements ); + lParametersCall.setXmlLogFile( convertOutFile( orcasconfiguration.xmllogfile ) ); + lParametersCall.setXmlInputFile( orcasconfiguration.xmlinputfile ); + lParametersCall.setSetUnusedInsteadOfDropColumn( orcasconfiguration.setunusedinsteadofdropcolumn ); + lParametersCall.setCreateIndexOnline( orcasconfiguration.indexonlinecreate ); + lParametersCall.setMinimizeStatementCount( orcasconfiguration.minimizestatementcount ); + lParametersCall.setCharsetName( orcasconfiguration.charsetname ); + lParametersCall.setCharsetNameSqlLog( orcasconfiguration.charsetnamesqllog ); + lParametersCall.setMultiSchema( orcasconfiguration.multischema ); + lParametersCall.setMultiSchemaDbaViews( orcasconfiguration.multischemadbaviews ); + lParametersCall.setMultiSchemaExcludewhereowner( orcasconfiguration.multischemaexcludewhereowner ); + lParametersCall.setViewExtractMode( orcasconfiguration.viewextractmode ); + lParametersCall.setIsOneTimeScriptLogonlyMode( orcasconfiguration.isOneTimeScriptLogonlyMode ); + orcasconfiguration.extensions.forEach{lParametersCall.addExtension(it)}; + orcasconfiguration.reverseExtensions.forEach{lParametersCall.addReverseExtension(it)}; + if (orcasconfiguration.isExtractViewCommnets == true) { lParametersCall.setExtractViewCommnets(true); } else { - lParametersCall.setExtractViewCommnets(project.orcasconfiguration.isExtractViewCommnents); + lParametersCall.setExtractViewCommnets(orcasconfiguration.isExtractViewCommnents); } - lParametersCall.setUpdateEnabledStatus( project.orcasconfiguration.updateEnabledStatus ); + lParametersCall.setUpdateEnabledStatus( orcasconfiguration.updateEnabledStatus ); - lParametersCall.setDbdocPlantuml( project.orcasconfiguration.dbdocPlantuml ); + lParametersCall.setDbdocPlantuml( orcasconfiguration.dbdocPlantuml ); - if( project.orcasconfiguration.extensionHandler != null ) + if( orcasconfiguration.extensionHandler != null ) { - lParametersCall.setExtensionHandler( project.orcasconfiguration.extensionHandler ); + lParametersCall.setExtensionHandler( orcasconfiguration.extensionHandler ); } - if( !project.orcasconfiguration.usernameorcas.equals( "" ) ) + if( !orcasconfiguration.usernameorcas.equals( "" ) ) { - lParametersCall.setOrcasDbUser( project.orcasconfiguration.usernameorcas ); + lParametersCall.setOrcasDbUser( orcasconfiguration.usernameorcas ); } else { - if( project.orcasconfiguration.orcasusername != null ) + if( orcasconfiguration.orcasusername != null ) { - lParametersCall.setOrcasDbUser( project.orcasconfiguration.orcasusername ); + lParametersCall.setOrcasDbUser( orcasconfiguration.orcasusername ); } else { - lParametersCall.setOrcasDbUser( project.orcasconfiguration.username ); + lParametersCall.setOrcasDbUser( orcasconfiguration.username ); } } - if( project.orcasconfiguration.orcasusername != null ) + if( orcasconfiguration.orcasusername != null ) { JdbcConnectParameters lOrcasJdbcConnectParameters = new JdbcConnectParameters(); - lOrcasJdbcConnectParameters.setJdbcDriver( project.orcasconfiguration.orcasjdbcdriver ); - lOrcasJdbcConnectParameters.setJdbcUrl( project.orcasconfiguration.orcasjdbcurl == null ? pParameters.getJdbcConnectParameters().getJdbcUrl() : project.orcasconfiguration.orcasjdbcurl ); - lOrcasJdbcConnectParameters.setJdbcUser( project.orcasconfiguration.orcasusername ); - lOrcasJdbcConnectParameters.setJdbcPassword( project.orcasconfiguration.orcaspassword ); + lOrcasJdbcConnectParameters.setJdbcDriver( orcasconfiguration.orcasjdbcdriver ); + lOrcasJdbcConnectParameters.setJdbcUrl( orcasconfiguration.orcasjdbcurl == null ? pParameters.getJdbcConnectParameters().getJdbcUrl() : orcasconfiguration.orcasjdbcurl ); + lOrcasJdbcConnectParameters.setJdbcUser( orcasconfiguration.orcasusername ); + lOrcasJdbcConnectParameters.setJdbcPassword( orcasconfiguration.orcaspassword ); lParametersCall.setOrcasJdbcConnectParameters( lOrcasJdbcConnectParameters ); } else diff --git a/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/OrcasGradlePlugin.groovy b/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/OrcasGradlePlugin.groovy index 2dffa4fc..9926e147 100644 --- a/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/OrcasGradlePlugin.groovy +++ b/orcas_core/build_source/orcas_gradle_plugin/src/main/groovy/com/opitzconsulting/orcas/gradle/OrcasGradlePlugin.groovy @@ -2,10 +2,13 @@ package com.opitzconsulting.orcas.gradle import de.opitzconsulting.orcas.diff.ExecuteSqlErrorHandler import de.opitzconsulting.orcas.diff.ParameterDefaults +import de.opitzconsulting.orcasDsl.Model import org.gradle.api.Project import org.gradle.api.Plugin -import de.opitzconsulting.orcas.diff.Parameters.FailOnErrorMode; +import de.opitzconsulting.orcas.diff.Parameters.FailOnErrorMode + +import java.util.function.UnaryOperator; class OrcasGradlePlugin implements Plugin { void apply(Project pProject) { @@ -472,6 +475,19 @@ class OrcasGradlePluginExtension { * default: false */ def boolean isOneTimeScriptLogonlyMode = ParameterDefaults.isOneTimeScriptLogonlyMode; + + /** + * List of Extensions. + * + * default: empty list + */ + def List> extensions = new ArrayList<>(); + /** + * List of Reverse-Extensions. + * + * default: empty list + */ + def List> reverseExtensions = new ArrayList<>(); }