Project build data via classpath listener from JDT
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -18,8 +18,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.ClasspathFileBasedCache;
|
||||
import org.springframework.ide.vscode.commons.java.DelegatingCachedClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IProjectBuild;
|
||||
import org.springframework.ide.vscode.commons.java.LegacyJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
/**
|
||||
@@ -32,24 +34,24 @@ public class GradleJavaProject extends LegacyJavaProject {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GradleJavaProject.class);
|
||||
|
||||
private GradleJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File projectDir, JavadocService javadocService) {
|
||||
super(fileObserver, projectDir.toURI(), projectDataCache, classpath, javadocService);
|
||||
private GradleJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File gradleFile, JavadocService javadocService) {
|
||||
super(fileObserver, gradleFile.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.GRADLE_PROJECT_TYPE, gradleFile.toURI()));
|
||||
}
|
||||
|
||||
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File projectDir, Path projectDataCache, JavadocService javadocService) {
|
||||
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File gradleFile, Path projectDataCache, JavadocService javadocService) {
|
||||
File file = projectDataCache == null
|
||||
? null
|
||||
: projectDataCache.resolve(ClasspathFileBasedCache.CLASSPATH_DATA_CACHE_FILE).toFile();
|
||||
ClasspathFileBasedCache fileBasedCache = new ClasspathFileBasedCache(file);
|
||||
IClasspath classpath = new DelegatingCachedClasspath(
|
||||
() -> new GradleProjectClasspath(gradle, projectDir),
|
||||
() -> new GradleProjectClasspath(gradle, gradleFile.getParentFile()),
|
||||
fileBasedCache
|
||||
);
|
||||
return new GradleJavaProject(fileObserver, projectDataCache, classpath, projectDir, javadocService);
|
||||
return new GradleJavaProject(fileObserver, projectDataCache, classpath, gradleFile, javadocService);
|
||||
}
|
||||
|
||||
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File projectDir, JavadocService javadocService) {
|
||||
GradleJavaProject thiss = create(fileObserver, gradle, projectDir, null, javadocService);
|
||||
public static GradleJavaProject create(FileObserver fileObserver, GradleCore gradle, File gradleFile, JavadocService javadocService) {
|
||||
GradleJavaProject thiss = create(fileObserver, gradle, gradleFile, null, javadocService);
|
||||
if (!thiss.getClasspath().isCached()) {
|
||||
try {
|
||||
thiss.getClasspath().update();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -51,7 +51,7 @@ public class GradleProjectCache extends AbstractFileToProjectCache<GradleJavaPro
|
||||
@Override
|
||||
protected GradleJavaProject createProject(File gradleBuild) throws Exception {
|
||||
File gradleFile = gradleBuild.getParentFile();
|
||||
GradleJavaProject gradleJavaProject = GradleJavaProject.create(getFileObserver(), gradle, gradleFile,
|
||||
GradleJavaProject gradleJavaProject = GradleJavaProject.create(getFileObserver(), gradle, gradleBuild,
|
||||
projectCacheFolder == null ? null : gradleFile.toPath().resolve(projectCacheFolder),
|
||||
javadocService
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -70,7 +70,7 @@ public class GradleProjectTest {
|
||||
}
|
||||
|
||||
private GradleJavaProject getGradleProject(String projectName) throws Exception {
|
||||
Path testProjectPath = Paths.get(GradleProjectTest.class.getResource("/" + projectName).toURI());
|
||||
Path testProjectPath = Paths.get(GradleProjectTest.class.getResource("/" + projectName + "/build.gradle").toURI());
|
||||
return GradleJavaProject.create(fileObserver, GradleCore.getDefault(), testProjectPath.toFile(), (uri, cpe) -> JavaDocProviders.createFor(cpe));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -19,12 +19,14 @@ public abstract class AbstractJavaProject implements IJavaProject, Disposable {
|
||||
|
||||
private final IClasspath classpath;
|
||||
private final URI uri;
|
||||
private final IProjectBuild projectBuild;
|
||||
|
||||
private ClasspathIndex index;
|
||||
|
||||
public AbstractJavaProject(URI uri, IClasspath classpath) {
|
||||
public AbstractJavaProject(URI uri, IClasspath classpath, IProjectBuild projectBuild) {
|
||||
this.uri = uri;
|
||||
this.classpath = classpath;
|
||||
this.projectBuild = projectBuild;
|
||||
}
|
||||
@Override
|
||||
public IClasspath getClasspath() {
|
||||
@@ -67,5 +69,10 @@ public abstract class AbstractJavaProject implements IJavaProject, Disposable {
|
||||
public String toString() {
|
||||
return "JavaProject("+uri+")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IProjectBuild getProjectBuild() {
|
||||
return projectBuild;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -17,6 +17,7 @@ public interface IJavaProject {
|
||||
final static String PROJECT_CACHE_FOLDER = ".sts4-cache";
|
||||
|
||||
IClasspath getClasspath();
|
||||
IProjectBuild getProjectBuild();
|
||||
ClasspathIndex getIndex();
|
||||
URI getLocationUri();
|
||||
boolean exists();
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public interface IProjectBuild {
|
||||
|
||||
String getType();
|
||||
|
||||
URI getBuildFile();
|
||||
|
||||
static IProjectBuild create(String type, URI buildFile) {
|
||||
return new IProjectBuild() {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getBuildFile() {
|
||||
return buildFile;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -23,8 +23,8 @@ public class JavaProject extends AbstractJavaProject {
|
||||
private final FileObserver fileObserver;
|
||||
private final JavadocProviderFactory javadocProviderFactory;
|
||||
|
||||
public JavaProject(FileObserver fileObserver, URI uri, IClasspath classpath, JavadocService javadocService) {
|
||||
super(uri, classpath);
|
||||
public JavaProject(FileObserver fileObserver, URI uri, IClasspath classpath, JavadocService javadocService, IProjectBuild projectBuild) {
|
||||
super(uri, classpath, projectBuild);
|
||||
this.fileObserver = fileObserver;
|
||||
this.javadocProviderFactory = (classpathResource) -> {
|
||||
CPE cpe = IClasspathUtil.findEntryForBinaryRoot(classpath, classpathResource);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2019, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -21,8 +21,8 @@ public class JdtLsJavaProject extends AbstractJavaProject {
|
||||
final private STS4LanguageClient client;
|
||||
final private ProjectObserver projectObserver;
|
||||
|
||||
public JdtLsJavaProject(STS4LanguageClient client, URI uri, IClasspath classpath, ProjectObserver projectObserver) {
|
||||
super(uri, classpath);
|
||||
public JdtLsJavaProject(STS4LanguageClient client, URI uri, IClasspath classpath, ProjectObserver projectObserver, IProjectBuild projectBuild) {
|
||||
super(uri, classpath, projectBuild);
|
||||
this.client = client;
|
||||
this.projectObserver = projectObserver;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -29,8 +29,8 @@ public class LegacyJavaProject extends JavaProject {
|
||||
|
||||
final protected Path projectDataCache;
|
||||
|
||||
public LegacyJavaProject(FileObserver fileObserver, URI loactionUri, Path projectDataCache, IClasspath classpath, JavadocService javadocService) {
|
||||
super(fileObserver, loactionUri, classpath, javadocService);
|
||||
public LegacyJavaProject(FileObserver fileObserver, URI loactionUri, Path projectDataCache, IClasspath classpath, JavadocService javadocService, IProjectBuild projectBuild) {
|
||||
super(fileObserver, loactionUri, classpath, javadocService, projectBuild);
|
||||
this.projectDataCache = projectDataCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.vscode.commons.languageserver.java.ls;
|
||||
|
||||
import org.springframework.ide.vscode.commons.protocol.java.Classpath;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
|
||||
|
||||
public interface ClasspathListener {
|
||||
|
||||
@@ -22,22 +23,23 @@ public interface ClasspathListener {
|
||||
public final String name;
|
||||
public final boolean deleted;
|
||||
public final Classpath classpath;
|
||||
public final ProjectBuild projectBuild;
|
||||
|
||||
public Event(String projectUri, String name, boolean deleted, Classpath classpath) {
|
||||
public Event(String projectUri, String name, boolean deleted, Classpath classpath, ProjectBuild projectBuild) {
|
||||
super();
|
||||
this.projectUri = projectUri;
|
||||
this.name = name;
|
||||
this.deleted = deleted;
|
||||
this.classpath = classpath;
|
||||
this.projectBuild = projectBuild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Event [projectUri=" + projectUri + ", name=" + name + ", deleted=" + deleted + ", classpath="
|
||||
+ classpath + "]";
|
||||
+ classpath + ", projectBuild=" + projectBuild + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018, 2019 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.Classpath;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
|
||||
import org.springframework.ide.vscode.commons.util.AsyncRunner;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -73,7 +74,14 @@ public class ClasspathListenerManager {
|
||||
|
||||
Classpath classpath = gson.fromJson((JsonElement)event.get(3), Classpath.class);
|
||||
log.debug("classpath = {}", classpath);
|
||||
classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath));
|
||||
|
||||
ProjectBuild projectBuild = null;
|
||||
if (event.size() > 4) {
|
||||
projectBuild = gson.fromJson((JsonElement)event.get(4), ProjectBuild.class);
|
||||
log.debug("projectBuild = {}", projectBuild);
|
||||
}
|
||||
|
||||
classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath, projectBuild));
|
||||
}
|
||||
} else {
|
||||
//Still support non-batched events for backwards compatibility with clients
|
||||
@@ -88,7 +96,14 @@ public class ClasspathListenerManager {
|
||||
|
||||
Classpath classpath = gson.fromJson((JsonElement)args.get(3), Classpath.class);
|
||||
log.debug("classpath = {}", classpath);
|
||||
classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath));
|
||||
|
||||
ProjectBuild projectBuild = null;
|
||||
if (args.size() > 4) {
|
||||
projectBuild = gson.fromJson((JsonElement)args.get(4), ProjectBuild.class);
|
||||
log.debug("projectBuild = {}", projectBuild);
|
||||
}
|
||||
|
||||
classpathListener.changed(new ClasspathListener.Event(projectUri, name, deleted, classpath, projectBuild));
|
||||
}
|
||||
return "done";
|
||||
}));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.java;
|
||||
|
||||
public class ProjectBuild {
|
||||
|
||||
public static final String MAVEN_PROJECT_TYPE = "maven";
|
||||
public static final String GRADLE_PROJECT_TYPE = "gradle";
|
||||
|
||||
private String type;
|
||||
|
||||
private String buildFile;
|
||||
|
||||
public ProjectBuild(String type, String buildFile) {
|
||||
this.type = type;
|
||||
this.buildFile = buildFile;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getBuildFile() {
|
||||
return buildFile;
|
||||
}
|
||||
|
||||
public void setBuildFile(String buildFile) {
|
||||
this.buildFile = buildFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProjectBuild [type=" + type + ", buildFile=" + buildFile + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2022 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -18,9 +18,11 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.java.ClasspathFileBasedCache;
|
||||
import org.springframework.ide.vscode.commons.java.DelegatingCachedClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IProjectBuild;
|
||||
import org.springframework.ide.vscode.commons.java.LegacyJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavadocService;
|
||||
import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.ProjectBuild;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
|
||||
/**
|
||||
@@ -36,7 +38,7 @@ public class MavenJavaProject extends LegacyJavaProject {
|
||||
private final File pom;
|
||||
|
||||
private MavenJavaProject(FileObserver fileObserver, Path projectDataCache, IClasspath classpath, File pom, JavadocService javadocService) {
|
||||
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService);
|
||||
super(fileObserver, pom.getParentFile().toURI(), projectDataCache, classpath, javadocService, IProjectBuild.create(ProjectBuild.MAVEN_PROJECT_TYPE, pom.toURI()));
|
||||
this.pom = pom;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user