Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

since refacoring of ClassLoaderResourceAccessor in 4..0.0-beta2, searchPath "classpath*:" is not handled anymore correctly #1595

Closed
chadoc opened this issue Dec 17, 2020 · 15 comments · Fixed by #1665

Comments

@chadoc
Copy link

chadoc commented Dec 17, 2020

Environment

Liquibase Version: 4.2.2

Liquibase Integration & Version: spring-boot 2.3.7.RELEASE

Liquibase Extension(s) & Version: -

Database Vendor & Version: Postgres (but doesn't matter)

Operating System Type & Version: Linux mint (but doesn't matter)

Description

includeAll in a spring-boot project with a searchPath containing a "classpath*:" doesn't find anything.

Steps To Reproduce

Define an "includeAll" task in a spring boot project with a searchPath set to "classpath*:db/changelog" and changelog files available on the searchPath failed because not found
`

  • includeAll:
    path: classpath*:db/changelog
    `

Actual Behavior

Doesn't find changelogs

Expected/Desired Behavior

Should find changelog to include

Screenshots (if appropriate)

Additional Context

Problem comes from SpringResourceAccessor.finalizeSearchPath method which expect to always have "classpath:classpath:" and in that case, path is "classpath:classpath*:" so not replaced.

@chadoc chadoc changed the title since introduction of SpringResourceAccessor in 4.1.1, searchPath "classpath*:" is not handled anymore correctly since refacoring of ClassLoaderResourceAccessor in 4..0.0-beta2, searchPath "classpath*:" is not handled anymore correctly Dec 17, 2020
@chadoc
Copy link
Author

chadoc commented Dec 17, 2020

After having tested different version, it looks the issue was introduced by the refactoring of ClassLoaderResourceAccessor already in 4.0.0-beta2:

protected SortedSet<String> listFromClassLoader(String path, boolean recursive, boolean includeFiles, boolean includeDirectories) {

@molivasdat
Copy link
Contributor

Hi @chadoc Thank you for bringing this to our attention. Since you have identified the code that was changed, if you have a suggested fix, you can create a PR and reference this issue.

@oleksanderkorn
Copy link

oleksanderkorn commented Jan 5, 2021

I have similar issue. I am using Spring Boot and Liquibase. And I have defined changelog file as following:

databaseChangeLog:
  - includeAll:
      path: db/changelog/0.0.1

When I use liquibase-core version 4.0.0 it works as expected, and changelog files inside db/changelog/0.0.1 are found and applied correctly:
image

When I only change liquibase version to 4.2.2 the resolved path is now absolute and starts with file: and changeLogStream is null:
image

SpringResourceAccessor has been rewritten from simple one:

    public class SpringResourceAccessor extends ClassLoaderResourceAccessor {
		public SpringResourceAccessor() {
			super(Thread.currentThread().getContextClassLoader());
		}
	}

Now it is a separate implementation and resolves files to absolute path format file://ABSOLUTE_PATH_TO_FILE which leads to an empty stream at the end.

It works if I use include instead of includeAll, but I would need to include every single file in this case:

databaseChangeLog:
  - include:
      file: db/changelog/0.0.1/MAIN_SCHEMA-changelog.yaml

And in this case file oath is not absolute but relative:

image

@dekar91
Copy link

dekar91 commented Jan 28, 2021

Same as @oleksanderkorn. Liqubase 4.0.0 works fine, but 4.2.2 creates an ampty stream.
OpenJdk 15, Windows 10.

@tecaz
Copy link

tecaz commented Feb 2, 2021

Similar setup to @oleksanderkorn (includeAll + path + relativeToChangelogFile), can confirm 4.1.0 is the last version to work as expected, 4.1.1 and the 4.2.x branch all end up in "File was not found in Spring resources" errors.

@nvoxland
Copy link
Contributor

nvoxland commented Feb 2, 2021

That should have continued to work, I'll try to replicate it and debug it to see what is going on.

@nvoxland
Copy link
Contributor

nvoxland commented Feb 3, 2021

PR #1665 should fix this.

@molivasdat molivasdat linked a pull request Feb 4, 2021 that will close this issue
@sync-by-unito
Copy link

sync-by-unito bot commented Feb 9, 2021

➤ Wesley Willard commented:

Looks good

@sync-by-unito
Copy link

sync-by-unito bot commented Feb 10, 2021

➤ Nargiz Huss commented:

Liquibase Version: 4.2.2
Liquibase Integration & Version: spring-boot 2.3.7.RELEASE

I was able to replicate the issue using xml file.
includeAll:
path: classpath*:db/changelog and path: classpath:db/changelog

Fix works in 4.3.0-LB-714-SNAPSHOT
For negative testing in my master changelog file I've added an emptyFolder directory that doesn't include anything and it failed. Works as expected.

@nikomiranda
Copy link

Still not working on 4.3.1.

SpringResourceAccessor:168 replaces the classpath*: then spring is not searching on all jars.

    protected String finalizeSearchPath(String searchPath) {
        searchPath = "classpath:"+searchPath;
        searchPath = searchPath
                .replaceAll("classpath\\*:", "classpath:")     // <----- LINE 168 
                .replace("\\", "/")
                .replaceAll("//+", "/")
                .replace("classpath:classpath:", "classpath:");

        return searchPath;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants