Remove obsolete project with classpath file support

This commit is contained in:
Kris De Volder
2018-04-24 13:55:31 -07:00
parent b2985ae4e2
commit 90408661a1
6 changed files with 2 additions and 339 deletions

View File

@@ -1,121 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.maven.java.classpathfile;
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.ide.vscode.commons.java.ClasspathData;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import com.google.common.collect.ImmutableList;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;
/**
* Classpath for a project containing classpath text file
*
* @author Alex Boyko
*
*/
public class FileClasspath implements IClasspath {
//TODO: This is obsolete and no longer used. Should delete and anything taht uses it probably too.
private Path classpathFilePath;
public FileClasspath(Path classpathFilePath) {
this.classpathFilePath = classpathFilePath;
}
@Override
public ImmutableList<CPE> getClasspathEntries() throws Exception {
return ImmutableList.of();
// return ImmutableList.copyOf(Stream.concat(MavenCore.readClassPathFile(classpathFilePath),
// Stream.of(classpathFilePath.getParent().resolve("target/classes"),
// classpathFilePath.getParent().resolve("target/test-classes"))).collect(Collectors.toList()));
}
@Override
public ImmutableList<String> getClasspathResources() {
return ImmutableList.of();
}
@Override
public String getName() {
return classpathFilePath.toFile().getParentFile().getName();
}
@Override
public boolean exists() {
return Files.exists(classpathFilePath);
}
@Override
public IType findType(String fqName) {
//TODO: implement
return null;
}
@Override
public Flux<Tuple2<IType, Double>> fuzzySearchTypes(String searchTerm, Predicate<IType> typeFilter) {
return Flux.empty();
}
@Override
public Flux<Tuple2<String, Double>> fuzzySearchPackages(String searchTerm) {
return Flux.empty();
}
@Override
public Flux<IType> allSubtypesOf(IType type) {
return Flux.empty();
}
@Override
public Path getOutputFolder() {
return null;
}
@Override
public ImmutableList<String> getSourceFolders() {
return ImmutableList.of();
}
@Override
public Optional<File> findClasspathResourceContainer(String fqName) {
return Optional.empty();
}
@Override
public ClasspathData createClasspathData() throws Exception {
return ClasspathData.from(getName(), getClasspathEntries(), getClasspathResources(), getOutputFolder());
}
@Override
public void reindex() {
}
@Override
public Optional<URL> sourceContainer(File classpathResource) {
return Optional.empty();
}
}

View File

@@ -1,85 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.maven.java.classpathfile;
import java.io.File;
import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
/**
* Java project that contains classpath text file
*
* @author Alex Boyko
*
*/
public class JavaProjectWithClasspathFile implements IJavaProject {
private File cpFile;
private FileClasspath classpath;
public JavaProjectWithClasspathFile(File cpFile) {
this.cpFile = cpFile;
this.classpath = new FileClasspath(Paths.get(cpFile.toURI()));
}
@Override
public IClasspath getClasspath() {
return classpath;
}
@Override
public String toString() {
return "JavaProjectWithClasspathFile("+cpFile+")";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cpFile == null) ? 0 : cpFile.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
JavaProjectWithClasspathFile other = (JavaProjectWithClasspathFile) obj;
if (cpFile == null) {
if (other.cpFile != null)
return false;
} else if (!cpFile.equals(other.cpFile))
return false;
return true;
}
CompletableFuture<Boolean> update() {
return CompletableFuture.supplyAsync(() -> doUpdate());
}
private synchronized boolean doUpdate() {
FileClasspath newClasspath = new FileClasspath(Paths.get(cpFile.toURI()));
if (newClasspath.equals(classpath)) {
return false;
} else {
this.classpath = newClasspath;
return true;
}
}
}

View File

@@ -1,37 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016, 2017 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.maven.java.classpathfile;
import java.io.File;
import org.springframework.ide.vscode.commons.languageserver.Sts4LanguageServer;
import org.springframework.ide.vscode.commons.languageserver.java.AbstractFileToProjectCache;
public class JavaProjectWithClasspathFileCache extends AbstractFileToProjectCache<JavaProjectWithClasspathFile> {
public JavaProjectWithClasspathFileCache(Sts4LanguageServer server) {
super(server, false, null);
}
@Override
protected boolean update(JavaProjectWithClasspathFile project) {
project.update();
return true;
}
@Override
protected JavaProjectWithClasspathFile createProject(File cpFile) throws Exception {
return new JavaProjectWithClasspathFile(cpFile);
}
}

View File

@@ -1,50 +0,0 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.maven.java.classpathfile;
import java.io.File;
import java.util.Optional;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.java.FileBasedJavaProjectFinder;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.util.FileUtils;
/**
* Finder for projects with classpath.txt file that contains classpath entries
* For test purposes only.
*
* @author Alex Boyko
*
*/
public class JavaProjectWithClasspathFileFinder extends FileBasedJavaProjectFinder {
private JavaProjectWithClasspathFileCache cache;
public JavaProjectWithClasspathFileFinder(JavaProjectWithClasspathFileCache cache) {
super();
this.cache = cache;
}
@Override
public Optional<IJavaProject> find(File file) {
File cpFile = FileUtils.findFile(file, MavenCore.CLASSPATH_TXT);
if (cpFile!=null) {
return Optional.ofNullable(cache.project(cpFile));
}
return Optional.empty();
}
@Override
protected Optional<IJavaProject> findProjectByName(String name) {
return cache.projectByName(name);
}
}

View File

@@ -14,7 +14,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
@@ -67,38 +66,4 @@ public class PropertiesIndexTest {
PropertyInfo propertyInfo = index.get("my.server.port");
assertNull(propertyInfo);
}
@Test @Ignore //ignore because classpath file is going to disapear and pieces already removed
public void springStandardPropertyPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault(), null);
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
PropertyInfo propertyInfo = index.get("server.port");
assertNotNull(propertyInfo);
assertEquals(Integer.class.getName(), propertyInfo.getType());
assertEquals("port", propertyInfo.getName());
}
@Test @Ignore //ignore because classpath file is going to disapear and pieces already removed
public void customPropertyPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault(), null);
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
PropertyInfo propertyInfo = index.get("demo.settings.user");
assertNotNull(propertyInfo);
assertEquals(String.class.getName(), propertyInfo.getType());
assertEquals("user", propertyInfo.getName());
}
@Test @Ignore //ignore because classpath file is going to disapear and pieces already removed
public void propertyNotPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault(), null);
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
PropertyInfo propertyInfo = index.get("my.server.port");
assertNull(propertyInfo);
}
}

View File

@@ -23,7 +23,6 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.maven.MavenBuilder;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
import org.springframework.ide.vscode.commons.maven.java.classpathfile.JavaProjectWithClasspathFile;
import org.springframework.ide.vscode.commons.util.IOUtil;
import com.google.common.cache.Cache;
@@ -79,8 +78,8 @@ public class ProjectsHarness {
}
private enum ProjectType {
MAVEN,
CLASSPATH_TXT
MAVEN
// GRADLE?
}
private ProjectsHarness() {
@@ -102,9 +101,6 @@ public class ProjectsHarness {
case MAVEN:
MavenBuilder.newBuilder(testProjectPath).clean().pack().javadoc().skipTests().execute();
return new MavenJavaProject(MavenCore.getDefault(), testProjectPath.resolve(MavenCore.POM_XML).toFile());
case CLASSPATH_TXT:
MavenBuilder.newBuilder(testProjectPath).clean().pack().skipTests().execute();
return new JavaProjectWithClasspathFile(testProjectPath.resolve(MavenCore.CLASSPATH_TXT).toFile());
default:
throw new IllegalStateException("Bug!!! Missing case");
}
@@ -133,9 +129,4 @@ public class ProjectsHarness {
public MavenJavaProject mavenProject(String name) throws Exception {
return (MavenJavaProject) project(ProjectType.MAVEN, name);
}
public IJavaProject javaProjectWithClasspathFile(String name) throws Exception {
return project(ProjectType.CLASSPATH_TXT, name);
}
}