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

[MCLEAN-93] Support junctions on NTFS #10

Merged
merged 2 commits into from Jun 14, 2023
Merged

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Jan 10, 2022

Jira issue: MCLEAN-93

@gnodet
Copy link
Contributor Author

gnodet commented Jan 10, 2022

I'm investigating if I can setup a test on windows. I've been sidetracked by trying to switch the tests to junit 5 / plexus-testing, but it's missing the helper methods to setup/lookup mojos...
I'll provide one asap.

Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can this happen? I mean, can we create a junction in Java without using native code?

src/main/java/org/apache/maven/plugins/clean/Cleaner.java Outdated Show resolved Hide resolved
@gnodet
Copy link
Contributor Author

gnodet commented Jan 10, 2022

When can this happen? I mean, can we create a junction in Java without using native code?

I'm going to experiment with something like:

        Path testDir = Paths.get( "target/test-dir" ).toAbsolutePath();
        Files.createDirectories( testDir );
        Path orgDir = testDir.resolve( "org-dir" );
        Path jctDir = testDir.resolve( "jct-dir" );
        Files.createDirectories( orgDir );

        Process process = new ProcessBuilder()
                .directory( testDir.toFile() )
                .command( "mklink", "/J", jctDir.toString(), orgDir.toString() )
                .start();
        int result = process.waitFor();

The idea comes from https://www.geeksforgeeks.org/creating-junction-points/

@gnodet
Copy link
Contributor Author

gnodet commented Jan 11, 2022

When can this happen? I mean, can we create a junction in Java without using native code?

@michael-o The test is here: https://github.com/apache/maven-clean-plugin/pull/10/files#diff-f51e0a6f6bcc199bb061d2f1b751c0740ae8cd016a1e87b5349758c4ee96e7d1R297-R321

@jvoccia
Copy link

jvoccia commented Aug 22, 2022

When can this happen? I mean, can we create a junction in Java without using native code?

Not sure if you are asking about this regarding "tests" or regarding what "real world" use case this could occur in, but if asking in the second case:

NPM does this on Windows. So if you link a NPM component with a package.json like:

{
  ...
  "dependencies": {
    "someTestServer": "file:src/test/node_server/someTestServer"
  }
}

You will get a node_modules directory like:
node_modules/someTestServer <- Junction Point pointing to: src/test/node_server/someTestServer

If you configure mvn clean to delete node_modules (or a directory above node_modules) - it will walk the junction point and delete your src files.

@michael-o
Copy link
Member

Stupid Windows!

@gnodet gnodet merged commit 7350464 into apache:master Jun 14, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants