From b4adac4e820fac3466ed0c7d40779db263a42557 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Tue, 1 Oct 2024 17:33:06 -0500 Subject: [PATCH] Accommodate Liquibase update --- .../java/org/dcache/util/SpringLiquibase.java | 112 +----------------- 1 file changed, 2 insertions(+), 110 deletions(-) diff --git a/modules/dcache/src/main/java/org/dcache/util/SpringLiquibase.java b/modules/dcache/src/main/java/org/dcache/util/SpringLiquibase.java index 8dff13acf72..c8d31c8b45d 100644 --- a/modules/dcache/src/main/java/org/dcache/util/SpringLiquibase.java +++ b/modules/dcache/src/main/java/org/dcache/util/SpringLiquibase.java @@ -1,41 +1,22 @@ package org.dcache.util; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; import java.sql.Connection; import java.sql.SQLException; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashSet; import java.util.List; -import java.util.Set; -import java.util.Vector; -import java.util.jar.Manifest; import liquibase.Contexts; import liquibase.LabelExpression; import liquibase.Liquibase; import liquibase.changelog.ChangeSet; import liquibase.exception.LiquibaseException; import liquibase.exception.MigrationFailedException; -import liquibase.exception.UnexpectedLiquibaseException; -import liquibase.logging.LogFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.ConnectionCallback; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.lang.Nullable; public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibase { - private static final Logger LOGGER = - LoggerFactory.getLogger(SpringLiquibase.class); - private boolean _shouldUpdate = true; public void setShouldUpdate(boolean shouldUpdate) { @@ -55,98 +36,9 @@ protected JdbcTemplate getJdbcTemplate() { return new JdbcTemplate(getDataSource()); } - protected SpringResourceOpener createResourceOpener() { - return new DcacheSpringResourceOpener(getChangeLog()); - } - - protected class DcacheSpringResourceOpener extends SpringResourceOpener { - - public DcacheSpringResourceOpener(String parentFile) { - super(parentFile); - } - - // Workaround for https://liquibase.jira.com/browse/CORE-3001 - @Override - protected void init() { - try { - Enumeration baseUrls; - ClassLoader classLoader = toClassLoader(); - if (classLoader != null) { - if (classLoader instanceof URLClassLoader) { - baseUrls = new Vector( - Arrays.asList(((URLClassLoader) classLoader).getURLs())).elements(); - - while (baseUrls.hasMoreElements()) { - addRootPath(baseUrls.nextElement()); - } - } - - baseUrls = classLoader.getResources(""); - - while (baseUrls.hasMoreElements()) { - addRootPath(baseUrls.nextElement()); - } - } - } catch (IOException e) { - throw new UnexpectedLiquibaseException(e); - } - try { - Resource[] resources = ResourcePatternUtils.getResourcePatternResolver( - getResourceLoader()).getResources(""); - if (resources.length == 0 || resources.length == 1 - && !resources[0].exists()) { //sometimes not able to look up by empty string, try all the liquibase packages - Set liquibasePackages = new HashSet<>(); - for (Resource manifest : ResourcePatternUtils.getResourcePatternResolver( - getResourceLoader()).getResources( - ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX - + "META-INF/MANIFEST.MF")) { - if (manifest.exists()) { - InputStream inputStream = null; - try { - inputStream = manifest.getInputStream(); - Manifest manifestObj = new Manifest(inputStream); - String attr = manifestObj.getMainAttributes() - .getValue("Liquibase-Package"); - if (attr != null) { - String packages = "\\s*,\\s*"; - for (String fullPackage : attr.split(packages)) { - liquibasePackages.add(fullPackage.split("\\.")[0]); - } - } - } finally { - if (inputStream != null) { - inputStream.close(); - } - } - } - } - - if (liquibasePackages.size() == 0) { - LogFactory.getInstance().getLog().warning( - "No Liquibase-Packages entry found in MANIFEST.MF. Using fallback of entire 'liquibase' package"); - liquibasePackages.add("liquibase"); - } - - for (String foundPackage : liquibasePackages) { - resources = ResourcePatternUtils.getResourcePatternResolver( - getResourceLoader()).getResources(foundPackage); - for (Resource res : resources) { - addRootPath(res.getURL()); - } - } - } else { - for (Resource res : resources) { - addRootPath(res.getURL()); - } - } - } catch (IOException e) { - LogFactory.getInstance().getLog().warning("Error initializing SpringLiquibase", e); - } - } - } - private class SchemaMigrator implements ConnectionCallback { + @Nullable @Override public Void doInConnection(Connection c) throws SQLException, DataAccessException {