theia icon indicating copy to clipboard operation
theia copied to clipboard

Unable create maven project with latest theia (windows) IDE

Open octopus88888 opened this issue 1 year ago • 16 comments

Scenario 1:

  1. Create Maven Project

  2. Select spring-boot-blank-archetype image

  3. Faced error to create maven project image

Scenario 2: Similar error message with command line if provide -DoutputDirectory with invalid path:

mvn archetype:generate -DarchetypeGroupId=com.nokia.dos -DarchetypeArtifactId=mechanism-driver-archetype -DarchetypeVersion=24.1.2 -DoutputDirectory=file:///c%3A/<path>
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: java.io.IOException: The file
name, directory name, or volume label syntax is incorrect -> [Help 1]

octopus88888 avatar Jan 18 '24 05:01 octopus88888

Does this only occur with the Spring Boot archetype or with all templates?

JonasHelming avatar Jan 18 '24 11:01 JonasHelming

Since the task tries to execute the -DoutputDirectory=file:///c%3A/ argument, I assume there's something wrong with out URI decoding/encoding in this part of the API.

msujew avatar Jan 18 '24 12:01 msujew

Does this only occur with the Spring Boot archetype or with all templates?

not only occur with the Spring Boot archetype, tried others also get the same error.

octopus88888 avatar Jan 19 '24 00:01 octopus88888

I can take a look!

sgraband avatar Jan 22 '24 13:01 sgraband

Doesn't this sound like a problem in https://github.com/eclipse-jdtls/eclipse.jdt.ls ?

tsmaeder avatar Jan 24 '24 09:01 tsmaeder

@tsmaeder I haven't confirmed this bug in vscode yet (I don't do Java coding these days), but I assume it works as expected there. In that case it's probably related to Theia in some way or another.

msujew avatar Jan 24 '24 11:01 msujew

I just checked. The extension (and command) works in VSCode. So i would assume, that the API that the extension uses does not behave the same in Theia. Probably due to the file path decoding/encoding.

sgraband avatar Jan 24 '24 13:01 sgraband

I found where this issue comes from, but i am unsure on how to deal with it:

The extension provides the args for the call like this:

    "org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate",
    `-DarchetypeArtifactId="${archetypeArtifactId}"`,
    `-DarchetypeGroupId="${archetypeGroupId}"`,
    `-DarchetypeVersion="${archetypeVersion}"`,
    `-DgroupId="${groupId}"`,
    `-DartifactId="${artifactId}"`

Note, that the values for the parameters are wrapped in ".

This is how the commandLine value looks for the task on the backend then:

cmd.exe /S /C ""mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId="spring-boot-blank-archetype" -DarchetypeGroupId="am.ik.archetype" -DarchetypeVersion="1.0.6" -DgroupId="com.example" -DartifactId="demo"""

We use the commandLine value for tasks on windows.

When i try to run that commandLine statement i get the following error message:

The syntax of the command is incorrect.

As far as i know the /S argument should remove the first and last " of a command. So i would expect the following command to work, but for some reason it doesn't (same command as above without duplicate "):

cmd.exe /S /C "mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId="spring-boot-blank-archetype" -DarchetypeGroupId="am.ik.archetype" -DarchetypeVersion="1.0.6" -DgroupId="com.example" -DartifactId="demo""

After some testing in the commandline i came to the conclusion that the command works when you either remove the wrapping set of ":

cmd.exe /S /C mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId="spring-boot-blank-archetype" -DarchetypeGroupId="am.ik.archetype" -DarchetypeVersion="1.0.6" -DgroupId="com.example" -DartifactId="demo"

(This also works without the /S argument)

Or if you remove the " around the arguments.

cmd.exe /S /C "mvn org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId=spring-boot-blank-archetype -DarchetypeGroupId=am.ik.archetype -DarchetypeVersion=1.0.6 -DgroupId=com.example -DartifactId=demo"

I am unsure on how we should tackle that issue, because other commands will likely need the wrapping " for them to work correctly, right? Any ideas @tsmaeder or @msujew ?

Just as a note: During debugging i also found that this.workspaceService.workspace?.resource.toString(); in the getContext() function of task-service.ts returns file:///c%3A/<path> on Windows. It seems to not cause any problems with this extension, but it does not seem correct, does it?

sgraband avatar Feb 06 '24 09:02 sgraband

@sgraband why would file:///c%3A/<path> not be the correct url? Looks like the url-encoded form of c:/<path> to me.

tsmaeder avatar Feb 06 '24 09:02 tsmaeder

@sgraband can you give more context on "how the extension provides the args for the call"? Is this a json file, an API call?

tsmaeder avatar Feb 06 '24 09:02 tsmaeder

@sgraband I'm not sure whether the file URI is correct or not. It might need to return uri.path.fsPath instead. However, we should take a look at what vscode provides there.

msujew avatar Feb 06 '24 09:02 msujew

@sgraband why would file:///c%3A/ not be the correct url? Looks like the url-encoded form of c:/ to me.

@tsmaeder might be, like i said it did not have any impact on executing the task, but i am unsure on what is expected there. I looked at this due to the comment and Issue description above that indicated it might have something to do with this. However like @msujew suggested i can take a look on what vscode provides there.

can you give more context on "how the extension provides the args for the call"? Is this a json file, an API call?

I took a look at this function. I mainly debugged the commandLine values from above at this line.

sgraband avatar Feb 06 '24 09:02 sgraband

@sgraband the last url is broken.

tsmaeder avatar Feb 06 '24 09:02 tsmaeder

Sorry about that: https://github.com/eclipse-theia/theia/blob/3e7f6eec297c4029ef01b2ef2c8f20361360c48c/packages/task/src/node/process/process-task-runner.ts#L88 (also fixed it above)

sgraband avatar Feb 06 '24 11:02 sgraband

@tsmaeder did you already have time to take a look and/or have an idea on how we could tackle this issue? I would have time this month to provide a fix, but like indicated in my earlier comment i am missing an idea on how to solve this issue.

sgraband avatar Mar 07 '24 11:03 sgraband

No, sorry, @sgraband I have no idea what the right thing to do is, here. In general, it's a good idea to keep things as objects instead of encoding them into a string for as long as possible, but not sure how that applies to this problem.

tsmaeder avatar Mar 08 '24 12:03 tsmaeder