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

Recognize new maven, gradle, eclipse project(s) after first init #901

Closed
wants to merge 5 commits into from

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Dec 13, 2018

Fixes #144
Requires redhat-developer/vscode-java#746

Signed-off-by: Snjezana Peco [email protected]

@snjeza snjeza requested review from gorkem and fbricon December 13, 2018 15:53
@@ -251,6 +251,9 @@ public void fileChanged(String uriString, CHANGE_TYPE changeType) {
return;
}
IResource resource = JDTUtils.isFolder(uriString) ? JDTUtils.findFolder(uriString) : JDTUtils.findFile(uriString);
if (resource == null && changeType == CHANGE_TYPE.CREATED) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it should be moved to the if (isBuildFile(..) block, L283

Copy link
Contributor

Choose a reason for hiding this comment

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

so this doesn't work if you want to create a new module within an existing maven structure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it should be moved to the if (isBuildFile(..) block, L283

We will not come to L283 if a resource is null

@@ -302,6 +305,26 @@ public void fileChanged(String uriString, CHANGE_TYPE changeType) {
}
}

private IResource refreshRootFolders(String uriString) {
Copy link
Contributor

@fbricon fbricon Dec 14, 2018

Choose a reason for hiding this comment

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

I think automatic detection is probably not always safe (might break Che's use case, we'd need @tsmaeder, @svor or @tolusha 's feedback on that), or could be unreliable (here it doesn't detect a new pom under a parent project).
So at the very least, we should expose a new import command, users could call explicitly. che-jdt-ls might have something already they could contribute back.
If we do automatic project import, it should be enabled via a preference

@snjeza
Copy link
Contributor Author

snjeza commented Dec 14, 2018

(here it doesn't detect a new pom under a parent project).

See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java#L106

So at the very least, we should expose a new import command, users could call explicitly.

Java: Refresh workspace?

If we do automatic project import, it should be enabled via a preference

'java.import.new.project.enabled', default: false ?

@fbricon
Copy link
Contributor

fbricon commented Dec 15, 2018

(here it doesn't detect a new pom under a parent project).

See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/MavenBuildSupport.java#L106

So at the very least, we should expose a new import command, users could call explicitly.

Java: Refresh workspace?

Java: detect and import Java projects

If we do automatic project import, it should be enabled via a preference

'java.import.new.project.enabled', default: false ?

java.import.newprojects: automatic/interactive/disabled

@snjeza
Copy link
Contributor Author

snjeza commented Dec 15, 2018

@fbricon I have updated the PR.

@fbricon
Copy link
Contributor

fbricon commented Dec 20, 2018

@tsmaeder @tolusha @svor we need your input please

@fbricon
Copy link
Contributor

fbricon commented Dec 21, 2018

@snjeza please rebase against master

@snjeza
Copy link
Contributor Author

snjeza commented Dec 21, 2018

@fbricon I have rebased the PR.

@svor
Copy link
Contributor

svor commented Dec 22, 2018

@fbricon At this moment I can not test it on che side, we still depend on 0.5.0 version of lsp4j. So at first we need to solve eclipse-che/che#12262.

@tsmaeder
Copy link
Contributor

We use a fixed version of jdt.ls in Che 6, so we should not be broken. Che 7 uses vscode-java anyway. So I think Che 6 should not block progress on this.

@snjeza snjeza changed the title Recognize new maven, gradle, eclipse project(s) after first init [WIP] Recognize new maven, gradle, eclipse project(s) after first init Apr 8, 2019
@snjeza snjeza changed the title [WIP] Recognize new maven, gradle, eclipse project(s) after first init Recognize new maven, gradle, eclipse project(s) after first init Jul 9, 2019
@snjeza snjeza removed the in progress label Jul 9, 2019
@snjeza
Copy link
Contributor Author

snjeza commented Jul 9, 2019

I have updated the PR.
@fbricon @tsmaeder @tolusha @svor @l0rd could you, please, test it? You can use https://raw.githubusercontent.com/snjeza/vscode-test/master/java-0.47.0.vsix

I have tested in the following way:

  • build theia
  • add java-0.47.0.vsix to the <theia_root>/plugins directory
  • open an empty workspace
  • cd <workspace_root>
  • git clone [email protected]:spring-projects/spring-petclinic.git

You can also test in VS Code.

@snjeza
Copy link
Contributor Author

snjeza commented Jan 26, 2020

test this please

@@ -119,6 +119,13 @@
CREATED, CHANGED, DELETED
};

//@formatter:off
private static final List<String> buildFiles = Arrays.asList(
Copy link
Contributor

Choose a reason for hiding this comment

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

the list of interesting build files should be provided by each project importer instance, as to minimize coupling with build systems here

*
*/
@RunWith(MockitoJUnitRunner.class)
public class ImportNewProjectsTest extends AbstractProjectsManagerBasedTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

need to check a new build file added to a build directory of an existing project doesn't trigger project import (think test pom.xml processed during a build)

@jdneo
Copy link
Contributor

jdneo commented Mar 11, 2020

@fbricon @snjeza

I noticed that it's mentioned to provide a new command to import the projects. This is exactly what we hope to add in VS Code Java.

May I ask will this command be added in this PR? If not, would you mind me to pick up this work item?

@snjeza
Copy link
Contributor Author

snjeza commented Mar 11, 2020

I noticed that it's mentioned to provide a new command to import the projects. This is exactly what we hope to add in VS Code Java.

@jdneo See redhat-developer/vscode-java#746

@jdneo
Copy link
Contributor

jdneo commented Mar 24, 2020

I'm thinking that do we need to add the configuration(java.import.newprojects) for auto import detection?

IMO, I think just providing the import command to the users will be enough. Since the configuration may confuse the users in the following scenarios:

  • When the configuration file is added in a deeper level (not the direct submodule of the root module), nothing will happen due to we are only detecting one level.
  • When the configuration file is added but empty. For example, after creating a new pom.xml, the user will get a notification: A new file was added. Do you want to import projects?, but there won't be any updates by selecting Now/Always, since the pom.xml is empty so actually the user still needs to invoke the command to import it after the content is completed.

@jdneo
Copy link
Contributor

jdneo commented Apr 1, 2020

How is everything @snjeza 😃

Just would like to ask if you will continue working on this PR? And if you've already planned for other works, would you mind me to take over it?

Thanks.

@snjeza
Copy link
Contributor Author

snjeza commented Apr 1, 2020

would you mind me to take over it?

No, go ahead. I have rebased the PR.

@jdneo
Copy link
Contributor

jdneo commented Apr 11, 2020

@snjeza Oops... I found that I have no permission to update commits into your branch.

@jdneo
Copy link
Contributor

jdneo commented Apr 12, 2020

Thank you @snjeza, I can update now. 😄
I removed the auto-detection logic, since in some cases, we cannot handle it well. But I think we can address the auto-detection thing in the future when we find out some suitable way to do that.

Let's first introduce the import project command to unblock the users. And please feel free to let me know if you have any concerns.

// BTW, the permission of the vscode-client repo is needed as well. 😄

@@ -192,6 +213,8 @@ public void cleanupResources(IProject project) throws CoreException {
File f = new File(cu.getUnderlyingResource().getLocationURI());
if (!f.exists()) {
cu.delete(true, null);
} else {
JDTUtils.resolveCompilationUnit(f.toURI());
Copy link
Contributor

Choose a reason for hiding this comment

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

@snjeza Do you remember why this line is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can check the issue by adding che (https://github.com/eclipse/che) to a workspace.

try {
importProjects(preferenceManager.getPreferences().getRootPaths(), monitor);
} catch (OperationCanceledException e) {
JavaLanguageServerPlugin.logInfo("Initialization has been cancelled.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Importing projects job has been cancelled.

} catch (OperationCanceledException e) {
JavaLanguageServerPlugin.logInfo("Initialization has been cancelled.");
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Initialization failed ", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Importing projects failed

@jdneo
Copy link
Contributor

jdneo commented May 6, 2020

@fbricon, ping...

@jdneo
Copy link
Contributor

jdneo commented May 16, 2020

@fbricon, ping...

@jdneo
Copy link
Contributor

jdneo commented May 17, 2020

test this please

@fbricon
Copy link
Contributor

fbricon commented May 19, 2020

When triggering the import command but there's no more projects to import, this is logged:

[Error - 3:14:39 p.m.] May 19, 2020, 3:14:39 p.m. An internal error occurred during: "Importing projects in workspace...".
Job of type org.eclipse.jdt.ls.core.internal.managers.ProjectsManager$1 returned no status.
java.lang.NullPointerException: Job of type org.eclipse.jdt.ls.core.internal.managers.ProjectsManager$1 returned no status.
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:81)

try {
importProjects(preferenceManager.getPreferences().getRootPaths(), monitor);
} catch (OperationCanceledException e) {
JavaLanguageServerPlugin.logInfo("Importing projects job has been cancelled.");
Copy link
Contributor

Choose a reason for hiding this comment

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

return failed status

importProjects(preferenceManager.getPreferences().getRootPaths(), monitor);
} catch (OperationCanceledException e) {
JavaLanguageServerPlugin.logInfo("Importing projects job has been cancelled.");
} catch (CoreException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

return failed status

} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Importing projects failed.", e);
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

return Status.OK_STATUS

@fbricon
Copy link
Contributor

fbricon commented May 20, 2020

Merged as 6e09b58

Thanks @snjeza and @jdneo!

@fbricon fbricon closed this May 20, 2020
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.

Recognize new maven, gradle, eclipse project(s) after first init
6 participants