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

DDLDatabase cannot load relative paths in Maven modules that do not contain wildcards #8336

Closed
lukaseder opened this issue Feb 19, 2019 · 4 comments

Comments

@lukaseder
Copy link
Member

Just like when specifying the <target/> directory (#2887), when specifying external configuration files, the Maven plugin should make sure to load files from relative paths relative to the module, not to the parent pom for repeatable builds.

Example:

<execution>
	<id>generate-externalconfigurationfile</id>
	<phase>generate-sources</phase>
	<goals>
		<goal>generate</goal>
	</goals>
	<configuration>
		<configurationFile>src/main/resources/externalconfigurationfile/externalconfigurationfile.xml</configurationFile>
	</configuration>
</execution>

When this is run in a maven module, currently, the canonical path resolved from the above relative path depends on whether the run command is issued from the module directory, or from the parent pom directory. The path should always be relative to the module directory.

@lukaseder
Copy link
Member Author

Hmm, the file is already loaded from the right location in the plugin:

    private void read(String file) {
        getLog().info("Reading external configuration: " + file);
        File f = new File(file);

        if (!f.isAbsolute())
            f = new File(project.getBasedir(), file);

        FileInputStream in = null;
        try {
            in = new FileInputStream(f);

@lukaseder
Copy link
Member Author

This is probably the same problem as #8336. When loading an external configuration file with relative paths, the relative paths are resolved with respect to the working directory not the module directory.

@lukaseder
Copy link
Member Author

lukaseder commented Feb 19, 2019

The issue observed here is different from #8336 as the relative path does not contain any wildcards. In the absence of wildcards, we're currently assuming that the file must exist, and in case we're running the code generation from a parent module, it doesn't seem to exist:

                if (file.exists()) {
                    load(encoding, file, fileComparator, null, loader);
                    loaded = true;
                }
                else if (pattern.contains("*") || pattern.contains("?")) {
                    file = new File(pattern.replaceAll("[*?].*", "")).getCanonicalFile();

                    Pattern regex = Pattern.compile("^.*?"
                       + pattern
                        .replace("\\", "/")
                        ...

The workaround for now is to scan the subdirectories of the working directory just like when there are wildcards.

A more thorough solution will be implemented through #8337

@lukaseder lukaseder changed the title Maven code generator doesn't use module-relative path to load external configuration files DDLDatabase cannot load relative paths in Maven modules that do not contain wildcards Feb 19, 2019
lukaseder added a commit that referenced this issue Feb 19, 2019
@lukaseder
Copy link
Member Author

This current fix will introduce even more cases where too many files are loaded by a relative path configuration (see #8335), which may lead to regressions where accidental schema files from a different modules are matched and code is generated for that schema as well, or there are conflicting object names.

This is why this fix will not be backported to 3.11

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

No branches or pull requests

1 participant