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

Support relative paths #332

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Support relative paths #332

wants to merge 1 commit into from

Conversation

badsyntax
Copy link
Collaborator

@badsyntax badsyntax commented May 5, 2020

Fixes #245
Refs #243

This is still a POC.

What do we want?

We want vscode-gradle and vscode-java to support standard gradle builds with relative paths. There are real uses cases for it as reported by the linked issues.

Where are relative paths defined?

Relative paths can be set is various places, including:

  • vscode settings
    • eg java.import.gradle.user.home
  • build.gradle
    • eg def buildNumber = new File("build.num").text.toInteger() + 1)
  • gradle.properties
    • eg org.gradle.java.home=../../../../../Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
    • eg org.gradle.jvmargs=-Djavax.net.ssl.trustStore="../../../../modules/Common/security/cacerts" -Djavax.net.ssl.trustStorePassword=<trust-password>

How do we support relative paths?

In some cases we can normalise paths in the client (eg for vscode settings), but in the other cases we cannot.

The core of the problem is that, when running ./gradlew from the root of the project, the cwd that gradle uses is the root of the project, and relative paths work. When running gradle from a server, the cwd is not the root of the project, and in the case of vscode, is usually an extension directory.

So the fix/workaround, is to start the server from the root of the project, as demonstrated by the POC code in this PR. Think cp.exec('/absolute/path/to/executable', { cwd: projectRoot })

The problem with this approach, is it doesn't support multi-root workspaces.

@sonarcloud
Copy link

sonarcloud bot commented May 5, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@badsyntax
Copy link
Collaborator Author

To support multi-root workspaces, it would be better to set the process cwd in Java land, before running the gradle process. It looks like gradle reads from user.dir system property, so try to set that instead.

@badsyntax badsyntax marked this pull request as draft May 7, 2020 06:40
@badsyntax
Copy link
Collaborator Author

badsyntax commented May 7, 2020

I'm unable to change cwd in java land, so I don't have a good fix for this. Will keep this PR open for reference.

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

Successfully merging this pull request may close these issues.

Relative Paths in the project gradle.properties do not work
1 participant