Skip to content

Do not make absolute paths relative if they aren't under the base#143

Draft
byteit101 wants to merge 2 commits intomojohaus:masterfrom
byteit101:master
Draft

Do not make absolute paths relative if they aren't under the base#143
byteit101 wants to merge 2 commits intomojohaus:masterfrom
byteit101:master

Conversation

@byteit101
Copy link

@byteit101 byteit101 commented Aug 6, 2019

This only makes paths relative if they are under the base, and does not relativeize those absolute paths.

This caused issues with paths with spaces for xjc. Now paths with spaces work with xjc again (originally broken in 2.4, worked in 2.3.1).

Fixes #131

@patrickptibco
Copy link

I have updated this with the latest changes

@tibco-jufernan
Copy link

Can this be merged for the next release?

@slachiewicz slachiewicz marked this pull request as draft December 22, 2024 21:17
@ratoaq2
Copy link

ratoaq2 commented Nov 4, 2025

On 4.0.0

    public static String relativize(final String path, final File parentDir, final boolean removeInitialFileSep) {

        // Check sanity
        Validate.notNull(path, "path");
        Validate.notNull(parentDir, "parentDir");

        final Path p = Paths.get(path);
        final Path pd = parentDir.toPath();

        String platformSpecificPath;
        if (p.normalize().startsWith(pd.normalize().toString())) {
            platformSpecificPath = pd.relativize(p).toString();
            if (removeInitialFileSep && platformSpecificPath.startsWith(File.separator)) {
                platformSpecificPath = platformSpecificPath.substring(File.separator.length());
            }
        } else {
            platformSpecificPath = p.toString();
        }

        // NOTE: it appears this function is meant to preserve the file separator that was passed in the path
        if (path.indexOf('\\') == -1) {
            platformSpecificPath = platformSpecificPath.replace('\\', '/');
        }

        return platformSpecificPath;
    }

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileNotFoundException when sources are relatively referenced outside maven project

5 participants