Resource links for remote apps

Fixed by adding a special case that detects the
special path prefix '/home/vcap/app' and treats
resources in that path the same as classpath
resources.
This commit is contained in:
Kris De Volder
2018-08-17 12:44:32 -07:00
parent d1e960f3fa
commit 2c6dd39a33
5 changed files with 61 additions and 7 deletions

View File

@@ -213,13 +213,10 @@ public abstract class AbstractSpringBootApp implements SpringBootApp {
synchronized(this) {
if (cachedBeansModel == null || !md5.equals(cachedBeansModelMD5)) {
cachedBeansModel = LiveBeansModel.parse(gson.toJson(json));
cachedBeansModelMD5 = md5;
logger.debug("Got {} beans for {}", cachedBeansModel.getBeanNames().size(), this);
}
else {
} else {
logger.debug("Got {} beans for {} - from cache", cachedBeansModel.getBeanNames().size(), this);
}
}

View File

@@ -62,9 +62,10 @@ public class Classpath {
return outputFolder;
}
public void setOutputFolder(String outputFolder) {
public CPE setOutputFolder(String outputFolder) {
Assert.isLegal(outputFolder==null || new File(outputFolder).isAbsolute());
this.outputFolder = outputFolder;
return this;
}
public CPE() {}

View File

@@ -31,6 +31,7 @@ public class SpringResource {
public static final String FILE = "file";
public static final String CLASS_PATH_RESOURCE = "class path resource";
private static final String CF_CLASSPATH_PREFIX = "/home/vcap/app/";
private SourceLinks sourceLinks;
private String type;
@@ -38,7 +39,7 @@ public class SpringResource {
private IJavaProject project;
private static final Pattern BRACKETS = Pattern.compile("\\[[^\\]]*\\]");
private static final String ID_PATTERN = "\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*";
private static final String REGEX_FQCN = ID_PATTERN + "(\\." + ID_PATTERN + ")*";
@@ -49,6 +50,10 @@ public class SpringResource {
if (matcher.find()) {
type = toParse.substring(0, matcher.start()).trim();
path = toParse.substring(matcher.start()+1, matcher.end()-1);
if (type.equals("file") && path.startsWith(CF_CLASSPATH_PREFIX)) {
type = CLASS_PATH_RESOURCE;
path = path.substring(CF_CLASSPATH_PREFIX.length());
}
} else if (Pattern.matches(REGEX_FQCN, toParse)) {
// Resource is fully qualified Java type name
type = CLASS_PATH_RESOURCE;

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 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.boot.java.livehover.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.ide.vscode.boot.java.links.EclipseSourceLinks;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.SpringResource;
import org.springframework.ide.vscode.boot.java.value.test.MockProjects;
import org.springframework.ide.vscode.boot.java.value.test.MockProjects.MockProject;
public class SpringResourceTest {
private MockProjects projects = new MockProjects();
private MockProject project = projects.create("test-project");
private SourceLinks sourceLinks = new EclipseSourceLinks();
@Test public void vcapResourceToMarkdown() throws Exception {
assertEquals(
"[com/github/kdvolder/helloworldservice/Greeter.class]" +
"(http://org.eclipse.ui.intro/execute?command=org.springframework.tooling.boot.ls.OpenJavaType%28fqName%3Dcom.github.kdvolder.helloworldservice.Greeter%2CprojectName%3Dtest-project%29)"
,
toMarkdown("file [/home/vcap/app/com/github/kdvolder/helloworldservice/Greeter.class]")
);
}
private String toMarkdown(String beanResourceString) {
return new SpringResource(sourceLinks, beanResourceString, project).toMarkdown();
}
}

View File

@@ -72,6 +72,7 @@ public class MockProjects {
final private File root;
final private String name;
final private List<File> sourceFolders = new ArrayList<File>();
private File defaultOutputFolder;
final private IClasspath classpath = new IClasspath() {
@@ -84,7 +85,7 @@ public class MockProjects {
public Collection<CPE> getClasspathEntries() throws Exception {
List<CPE> cp = new ArrayList<>();
for (File sf : sourceFolders) {
cp.add(new CPE(Classpath.ENTRY_KIND_SOURCE, sf.getAbsolutePath()));
cp.add(new CPE(Classpath.ENTRY_KIND_SOURCE, sf.getAbsolutePath()).setOutputFolder(defaultOutputFolder.getAbsolutePath()));
}
return cp;
}
@@ -97,6 +98,7 @@ public class MockProjects {
this.root = Files.createTempDir();
createSourceFolder("src/main/java");
createSourceFolder("src/main/resources");
createOutputFolder("target/classes");
projectsByName.put(name, this);
}
synchronized (observer.listeners) {
@@ -110,6 +112,13 @@ public class MockProjects {
return file.toPath().startsWith(root.toPath());
}
private void createOutputFolder(String projectRelativePath) {
Assert.assertNull("Output folder already created", this.defaultOutputFolder);
File outFolder = new File(root, projectRelativePath);
outFolder.mkdirs();
this.defaultOutputFolder = outFolder;
}
public void createSourceFolder(String projectRelativePath) {
File sourceFolder = new File(root, projectRelativePath);
sourceFolder.mkdirs();