Port SpringPropertiesEditorTests

This commit is contained in:
BoykoAlex
2016-10-27 20:22:48 -04:00
parent 608968d86e
commit 28fed6ffcb
24 changed files with 2116 additions and 462 deletions

View File

@@ -1,132 +1,136 @@
package org.springframework.ide.vscode.application.properties.metadata;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
import org.springframework.ide.vscode.commons.java.IClasspath;
public class PropertiesLoader {
private static final String MAIN_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/spring-configuration-metadata.json";
public static final String ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/additional-spring-configuration-metadata.json";
/**
* The default classpath location for config metadata loaded when scanning .jar files on the classpath.
*/
public static final String[] JAR_META_DATA_LOCATIONS = {
MAIN_SPRING_CONFIGURATION_METADATA_JSON
//Not scanning 'additional' metadata because it integrated already in the main data.
};
/**
* The default classpath location for config metadata loaded when scanning project output folders.
*/
public static final String[] PROJECT_META_DATA_LOCATIONS = {
MAIN_SPRING_CONFIGURATION_METADATA_JSON,
ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON
};
private static final Logger LOG = Logger.getLogger(PropertiesLoader.class.getName());
private ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
public ConfigurationMetadataRepository load(IClasspath classPath) {
try {
classPath.getClasspathEntries().forEach(entry -> {
if (entry.toFile().isDirectory()) {
loadFromOutputFolder(entry);
} else {
loadFromJar(entry);
}
});
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to retrieve classpath", e);
}
ConfigurationMetadataRepository repository = builder.build();
return repository;
}
private void loadFromOutputFolder(Path outputFolderPath) {
if (outputFolderPath != null && Files.exists(outputFolderPath)) {
Arrays.stream(PROJECT_META_DATA_LOCATIONS).forEach(mdLoc -> {
loadFromJsonFile(outputFolderPath.resolve(mdLoc));
});
}
}
private void loadFromJsonFile(Path mdf) {
if (Files.exists(mdf)) {
InputStream is = null;
try {
is = Files.newInputStream(mdf);
loadFromInputStream(mdf, is);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error loading file '" + mdf + "'", e);
} finally {
if (is!=null) {
try {
is.close();
} catch (IOException e) {
//ignore
}
}
}
}
}
private void loadFromJar(Path f) {
JarFile jarFile = null;
try {
jarFile = new JarFile(f.toFile());
//jarDump(jarFile);
for (String loc : JAR_META_DATA_LOCATIONS) {
ZipEntry e = jarFile.getEntry(loc);
if (e!=null) {
loadFrom(jarFile, e);
}
}
} catch (Throwable e) {
LOG.log(Level.SEVERE, "Error loading JAR file", e);
} finally {
if (jarFile!=null) {
try {
jarFile.close();
} catch (IOException e) {
}
}
}
}
private void loadFrom(JarFile jarFile, ZipEntry ze) {
InputStream is = null;
try {
is = jarFile.getInputStream(ze);
loadFromInputStream(jarFile.getName()+"["+ze.getName()+"]", is);
} catch (Throwable e) {
LOG.log(Level.SEVERE, "Error loading JAR file", e);
} finally {
if (is!=null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}
private void loadFromInputStream(Object origin, InputStream is) throws IOException {
builder.withJsonResource(origin, is);
}
}
package org.springframework.ide.vscode.application.properties.metadata;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
import org.springframework.ide.vscode.commons.java.IClasspath;
public class PropertiesLoader {
private static final String MAIN_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/spring-configuration-metadata.json";
public static final String ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/additional-spring-configuration-metadata.json";
/**
* The default classpath location for config metadata loaded when scanning .jar files on the classpath.
*/
public static final String[] JAR_META_DATA_LOCATIONS = {
MAIN_SPRING_CONFIGURATION_METADATA_JSON
//Not scanning 'additional' metadata because it integrated already in the main data.
};
/**
* The default classpath location for config metadata loaded when scanning project output folders.
*/
public static final String[] PROJECT_META_DATA_LOCATIONS = {
MAIN_SPRING_CONFIGURATION_METADATA_JSON,
ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON
};
private static final Logger LOG = Logger.getLogger(PropertiesLoader.class.getName());
private ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
public ConfigurationMetadataRepository load(IClasspath classPath) {
try {
classPath.getClasspathEntries().forEach(entry -> {
File fileEntry = entry.toFile();
if (fileEntry.exists()) {
if (fileEntry.isDirectory()) {
loadFromOutputFolder(entry);
} else {
loadFromJar(entry);
}
}
});
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to retrieve classpath", e);
}
ConfigurationMetadataRepository repository = builder.build();
return repository;
}
private void loadFromOutputFolder(Path outputFolderPath) {
if (outputFolderPath != null && Files.exists(outputFolderPath)) {
Arrays.stream(PROJECT_META_DATA_LOCATIONS).forEach(mdLoc -> {
loadFromJsonFile(outputFolderPath.resolve(mdLoc));
});
}
}
private void loadFromJsonFile(Path mdf) {
if (Files.exists(mdf)) {
InputStream is = null;
try {
is = Files.newInputStream(mdf);
loadFromInputStream(mdf, is);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Error loading file '" + mdf + "'", e);
} finally {
if (is!=null) {
try {
is.close();
} catch (IOException e) {
//ignore
}
}
}
}
}
private void loadFromJar(Path f) {
JarFile jarFile = null;
try {
jarFile = new JarFile(f.toFile());
//jarDump(jarFile);
for (String loc : JAR_META_DATA_LOCATIONS) {
ZipEntry e = jarFile.getEntry(loc);
if (e!=null) {
loadFrom(jarFile, e);
}
}
} catch (Throwable e) {
LOG.log(Level.SEVERE, "Error loading JAR file", e);
} finally {
if (jarFile!=null) {
try {
jarFile.close();
} catch (IOException e) {
}
}
}
}
private void loadFrom(JarFile jarFile, ZipEntry ze) {
InputStream is = null;
try {
is = jarFile.getInputStream(ze);
loadFromInputStream(jarFile.getName()+"["+ze.getName()+"]", is);
} catch (Throwable e) {
LOG.log(Level.SEVERE, "Error loading JAR file", e);
} finally {
if (is!=null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}
private void loadFromInputStream(Object origin, InputStream is) throws IOException {
builder.withJsonResource(origin, is);
}
}

View File

@@ -19,9 +19,7 @@ import org.springframework.ide.vscode.application.properties.metadata.PropertyIn
import org.springframework.ide.vscode.application.properties.metadata.SpringPropertiesIndexManager;
import org.springframework.ide.vscode.application.properties.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.application.properties.metadata.util.FuzzyMap;
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
import org.springframework.ide.vscode.commons.maven.java.Projects;
import org.springframework.ide.vscode.commons.maven.java.classpathfile.JavaProjectWithClasspathFile;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
/**
@@ -33,13 +31,14 @@ import org.springframework.ide.vscode.project.harness.ProjectsHarness;
public class PropertiesIndexTest {
private static final String CUSTOM_PROPERTIES_PROJECT = "custom-properties-boot-project";
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
@Test
public void springStandardPropertyPresent_Maven() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
MavenJavaProject mavenProject = Projects
.createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
PropertyInfo propertyInfo = index.get("server.port");
assertNotNull(propertyInfo);
@@ -51,8 +50,7 @@ public class PropertiesIndexTest {
public void customPropertyPresent_Maven() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
MavenJavaProject mavenProject = Projects
.createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
PropertyInfo propertyInfo = index.get("demo.settings.user");
assertNotNull(propertyInfo);
@@ -64,8 +62,7 @@ public class PropertiesIndexTest {
public void propertyNotPresent_Maven() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
MavenJavaProject mavenProject = Projects
.createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
PropertyInfo propertyInfo = index.get("my.server.port");
assertNull(propertyInfo);
@@ -75,8 +72,7 @@ public class PropertiesIndexTest {
public void springStandardPropertyPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
JavaProjectWithClasspathFile classpathFileProject = Projects
.createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
PropertyInfo propertyInfo = index.get("server.port");
assertNotNull(propertyInfo);
@@ -88,8 +84,7 @@ public class PropertiesIndexTest {
public void customPropertyPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
JavaProjectWithClasspathFile classpathFileProject = Projects
.createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
PropertyInfo propertyInfo = index.get("demo.settings.user");
assertNotNull(propertyInfo);
@@ -101,8 +96,7 @@ public class PropertiesIndexTest {
public void propertyNotPresent_ClasspathFile() throws Exception {
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
ValueProviderRegistry.getDefault());
JavaProjectWithClasspathFile classpathFileProject = Projects
.createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT));
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
PropertyInfo propertyInfo = index.get("my.server.port");
assertNull(propertyInfo);

View File

@@ -26,7 +26,6 @@ import org.springframework.ide.vscode.application.properties.metadata.types.Type
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil.EnumCaseMode;
import org.springframework.ide.vscode.application.properties.metadata.types.TypedProperty;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.maven.java.Projects;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
/**
@@ -41,6 +40,7 @@ import org.springframework.ide.vscode.project.harness.ProjectsHarness;
@Ignore
public class TypeUtilTest {
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
private IJavaProject project;
private TypeUtil typeUtil;
@@ -142,7 +142,7 @@ public class TypeUtilTest {
}
private void useProject(String name) throws Exception {
project = Projects.createMavenJavaProject(ProjectsHarness.buildMavenProject(name));;
project = projects.mavenProject(name);;
typeUtil = new TypeUtil(project);
}

View File

@@ -15,7 +15,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
import org.springframework.ide.vscode.commons.maven.java.Projects;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.maven.java.classpathfile.JavaProjectWithClasspathFile;
import org.springframework.ide.vscode.commons.util.FileUtils;
import org.springframework.ide.vscode.commons.util.StringUtil;
@@ -30,7 +30,7 @@ public class JavaProjectWithClasspathFileFinderStrategy implements IJavaProjectF
URI uri = new URI(uriStr);
//TODO: This only work with File uri. Should it work with others too?
File file = new File(uri).getAbsoluteFile();
File cpFile = FileUtils.findFile(file, Projects.CLASSPATH_TXT);
File cpFile = FileUtils.findFile(file, MavenCore.CLASSPATH_TXT);
if (cpFile!=null) {
return new JavaProjectWithClasspathFile(cpFile);
}

View File

@@ -15,8 +15,8 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
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.Projects;
import org.springframework.ide.vscode.commons.util.FileUtils;
import org.springframework.ide.vscode.commons.util.StringUtil;
@@ -36,7 +36,7 @@ public class MavenProjectFinderStrategy implements IJavaProjectFinderStrategy {
URI uri = new URI(uriStr);
//TODO: This only work with File uri. Should it work with others too?
File file = new File(uri).getAbsoluteFile();
File pomFile = FileUtils.findFile(file, Projects.POM_XML);
File pomFile = FileUtils.findFile(file, MavenCore.POM_XML);
if (pomFile!=null) {
return new MavenJavaProject(pomFile);
}

View File

@@ -41,14 +41,6 @@
<version>${project.version}</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>project-test-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -46,6 +46,8 @@ import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
import org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor;
import org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor;
import org.springframework.ide.vscode.commons.util.ExternalCommand;
import org.springframework.ide.vscode.commons.util.ExternalProcess;
/**
* Maven Core functionality
@@ -55,6 +57,9 @@ import org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor;
*/
public class MavenCore {
public static final String CLASSPATH_TXT = "classpath.txt";
public static final String POM_XML = "pom.xml";
private static MavenCore instance = null;
private MavenBridge maven = new MavenBridge();
@@ -79,6 +84,23 @@ public class MavenCore {
Path dir = classPathFilePath.getParent();
return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet());
}
/**
* Builds maven project
*
* @param Path of the project
* @throws Exception
*/
public static void buildMavenProject(Path testProjectPath) throws Exception {
Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win")
? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw");
mvnwPath.toFile().setExecutable(true);
ExternalProcess process = new ExternalProcess(testProjectPath.toFile(),
new ExternalCommand(mvnwPath.toAbsolutePath().toString(), "clean", "package"), true);
if (process.getExitValue() != 0) {
throw new RuntimeException("Failed to build test project");
}
}
/**
* Creates Maven Project descriptor based on the pom file.

View File

@@ -1,66 +1,73 @@
/*******************************************************************************
* Copyright (c) 2016 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;
import java.io.File;
import org.apache.maven.project.MavenProject;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.util.HtmlSnippet;
/**
* Wrapper for Maven Core project
*
* @author Alex Boyko
*
*/
public class MavenJavaProject implements IJavaProject {
private MavenProject mavenProject;
private MavenProjectClasspath classpath;
private MavenCore maven;
public MavenJavaProject(File pom) throws Exception {
this.maven = MavenCore.getInstance();
this.mavenProject = maven.readProject(pom);
this.classpath = new MavenProjectClasspath(mavenProject, maven);
}
@Override
public String getElementName() {
return mavenProject.getName();
}
@Override
public HtmlSnippet getJavaDoc() {
return null;
}
@Override
public boolean exists() {
return mavenProject != null;
}
@Override
public IType findType(String fqName) {
// TODO Auto-generated method stub
return null;
}
@Override
public IClasspath getClasspath() {
return classpath;
}
}
/*******************************************************************************
* Copyright (c) 2016 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;
import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.maven.project.MavenProject;
import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.util.HtmlSnippet;
/**
* Wrapper for Maven Core project
*
* @author Alex Boyko
*
*/
public class MavenJavaProject implements IJavaProject {
private MavenProject mavenProject;
private MavenProjectClasspath classpath;
private MavenCore maven;
public MavenJavaProject(File pom) throws Exception {
this.maven = MavenCore.getInstance();
this.mavenProject = maven.readProject(pom);
this.classpath = new MavenProjectClasspath(mavenProject, maven);
}
@Override
public String getElementName() {
return mavenProject.getName();
}
@Override
public HtmlSnippet getJavaDoc() {
return null;
}
@Override
public boolean exists() {
return mavenProject != null;
}
@Override
public IType findType(String fqName) {
// TODO Auto-generated method stub
return null;
}
@Override
public IClasspath getClasspath() {
return classpath;
}
public Path getOutputFolder() {
return Paths.get(URI.create(mavenProject.getBuild().getOutputDirectory()));
}
}

View File

@@ -1,36 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016 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;
import java.nio.file.Path;
import org.springframework.ide.vscode.commons.maven.java.classpathfile.JavaProjectWithClasspathFile;
/**
* Maven projects methods
*
* @author Alex Boyko
*
*/
public class Projects {
public static final String CLASSPATH_TXT = "classpath.txt";
public static final String POM_XML = "pom.xml";
public static MavenJavaProject createMavenJavaProject(Path projectPath) throws Exception {
return new MavenJavaProject(projectPath.resolve(Projects.POM_XML).toFile());
}
public static JavaProjectWithClasspathFile createJavaProjectWithClasspathFile(Path projectPath) throws Exception {
return new JavaProjectWithClasspathFile(projectPath.resolve(Projects.CLASSPATH_TXT).toFile());
}
}

View File

@@ -19,8 +19,6 @@ import java.util.stream.Collectors;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.springframework.ide.vscode.commons.maven.java.Projects;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
/**
* Tests for comparing maven calculated dependencies with ours
@@ -32,14 +30,15 @@ public class DependencyTreeTest {
@Test
public void mavenTest() throws Exception {
Path testProjectPath = ProjectsHarness.buildMavenProject("empty-boot-project-with-classpath-file");
MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve(Projects.POM_XML).toFile());
Path testProjectPath = Paths.get(DependencyTreeTest.class.getResource("/empty-boot-project-with-classpath-file").toURI());
MavenCore.buildMavenProject(testProjectPath);
MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve(MavenCore.POM_XML).toFile());
Set<Path> calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> {
return Paths.get(artifact.getFile().toURI());
}).collect(Collectors.toSet());;
Set<Path> expectedClasspath = MavenCore.readClassPathFile(testProjectPath.resolve(Projects.CLASSPATH_TXT));
Set<Path> expectedClasspath = MavenCore.readClassPathFile(testProjectPath.resolve(MavenCore.CLASSPATH_TXT));
assertEquals(expectedClasspath, calculatedClassPath);
}

View File

@@ -6,7 +6,10 @@ import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.swing.text.BadLocationException;
@@ -72,6 +75,7 @@ public class Editor {
private int selectionEnd;
private int selectionStart;
private Set<String> ignoredTypes;
public Editor(LanguageServerHarness harness, String contents) throws Exception {
this.harness = harness;
@@ -79,6 +83,7 @@ public class Editor {
this.document = harness.openDocument(harness.createWorkingCopy(state.documentContents));
this.selectionStart = state.selectionStart;
this.selectionEnd = state.selectionEnd;
this.ignoredTypes = new HashSet<>();
}
/**
@@ -96,7 +101,9 @@ public class Editor {
*/
public void assertProblems(String... expectedProblems) throws Exception {
Editor editor = this;
List<Diagnostic> actualProblems = new ArrayList<>(editor.reconcile());
List<Diagnostic> actualProblems = new ArrayList<>(editor.reconcile().stream().filter(d -> {
return !ignoredTypes.contains(d.getCode());
}).collect(Collectors.toList()));
Collections.sort(actualProblems, PROBLEM_COMPARATOR);
String bad = null;
if (actualProblems.size()!=expectedProblems.length) {
@@ -313,6 +320,15 @@ public class Editor {
throw new UnsupportedOperationException("Not implemented yet!");
}
/**
* Verifies an expected textSnippet is contained in the hover text that is
* computed when hovering mouse at position at the end of first occurrence of
* a given string in the editor.
*/
public void assertHoverText(String afterString, String expectSnippet) {
throw new UnsupportedOperationException("Not implemented yet!");
}
public void setSelection(int start, int end) {
Assert.assertTrue(start>=0);
Assert.assertTrue(end>=start);
@@ -366,4 +382,8 @@ public class Editor {
assertEquals(expected, getText());
}
public void ignoreProblem(Object type) {
ignoredTypes.add(type.toString());
}
}

View File

@@ -280,4 +280,10 @@ public class LanguageServerHarness {
assertEquals(expect.toString(), actual.toString());
}
public void assertCompletionDisplayString(String editorContents, String expected) throws Exception {
Editor editor = newEditor(editorContents);
CompletionItem completion = editor.getFirstCompletion();
assertEquals(expected, completion.getLabel());
}
}

View File

@@ -1,20 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>project-test-harness</artifactId>
<name>project-test-harness</name>
<description>Test projects and utilities for test projects. Independent of any tooling projects.</description>
<dependencies>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>project-test-harness</artifactId>
<name>project-test-harness</name>
<description>Test projects and utilities for test projects. Independent of any tooling projects.</description>
<dependencies>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-maven</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -10,41 +10,58 @@
*******************************************************************************/
package org.springframework.ide.vscode.project.harness;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.ide.vscode.commons.util.ExternalCommand;
import org.springframework.ide.vscode.commons.util.ExternalProcess;
import org.springframework.ide.vscode.commons.java.IJavaProject;
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 com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
/**
* Test project harness utilities
* Test projects harness
*
* @author Alex Boyko
*
*/
public class ProjectsHarness {
/**
* Builds maven project
*
* @param name
* @return
* @throws Exception
*/
public static Path buildMavenProject(String name) throws Exception {
Path testProjectPath = Paths.get(ProjectsHarness.class.getResource("/" + name).toURI());
if (!Files.exists(testProjectPath.resolve("classpath.txt"))) {
Path mvnwPath = System.getProperty("os.name").toLowerCase().startsWith("win")
? testProjectPath.resolve("mvnw.cmd") : testProjectPath.resolve("mvnw");
mvnwPath.toFile().setExecutable(true);
ExternalProcess process = new ExternalProcess(testProjectPath.toFile(),
new ExternalCommand(mvnwPath.toAbsolutePath().toString(), "clean", "package"), true);
if (process.getExitValue() != 0) {
throw new RuntimeException("Failed to build test project");
public static final ProjectsHarness INSTANCE = new ProjectsHarness();;
public Cache<String, IJavaProject> cache = CacheBuilder.newBuilder().build();
private enum ProjectType {
MAVEN,
CLASSPATH_TXT
}
private ProjectsHarness() {
}
public IJavaProject project(ProjectType type, String name) throws Exception {
return cache.get(type + "/" + name, () -> {
Path testProjectPath = Paths.get(ProjectsHarness.class.getResource("/" + name).toURI());
switch (type) {
case MAVEN:
return new MavenJavaProject(testProjectPath.resolve(MavenCore.POM_XML).toFile());
case CLASSPATH_TXT:
MavenCore.buildMavenProject(testProjectPath);
return new JavaProjectWithClasspathFile(testProjectPath.resolve(MavenCore.CLASSPATH_TXT).toFile());
default:
throw new IllegalStateException("Bug!!! Missing case");
}
}
return testProjectPath;
});
}
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);
}
}

View File

@@ -0,0 +1,13 @@
package org.springframework.ide.vscode.project.harness;
import static org.junit.Assert.fail;
public class TestAsserts {
public static void assertContains(String needle, String haystack) {
if (haystack==null || !haystack.contains(needle)) {
fail("Not found: "+needle+"\n in \n"+haystack);
}
}
}

View File

@@ -33,5 +33,10 @@
<artifactId>junit</artifactId>
<version>${junit-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>project-test-harness</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,6 +1,5 @@
package org.springframework.ide.vscode.properties.editor.test.harness;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -17,14 +16,21 @@ import org.springframework.ide.vscode.application.properties.metadata.types.Type
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.util.IDocument;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
import org.springframework.ide.vscode.properties.editor.test.harness.PropertyIndexHarness.ItemConfigurer;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
import io.typefox.lsapi.CompletionItem;
public abstract class AbstractPropsEditorTest {
public static final String INTEGER = Integer.class.getName();
public static final String BOOLEAN = Boolean.class.getName();
public static final String STRING = String.class.getName();
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
protected PropertyIndexHarness md;
private LanguageServerHarness harness;
private IJavaProject testProject;
@@ -58,9 +64,8 @@ public abstract class AbstractPropsEditorTest {
md.defaultTestData();
}
public IJavaProject createPredefinedMavenProject(String string) {
notImplemented();
return null;
public MavenJavaProject createPredefinedMavenProject(String name) throws Exception {
return projects.mavenProject(name);
}
public void useProject(IJavaProject p) throws Exception {
@@ -76,6 +81,10 @@ public abstract class AbstractPropsEditorTest {
harness.assertCompletion(textBefore, expectTextAfter);
}
public void assertCompletionDisplayString(String editorContents, String expected) throws Exception {
harness.assertCompletionDisplayString(editorContents, expected);
}
private void notImplemented() {
throw new UnsupportedOperationException("Not yet implemented");
}

View File

@@ -58,12 +58,24 @@
<version>${project.version}</version>
</dependency>
<!-- Test harness -->
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>project-test-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>language-server-test-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>properties-editor-test-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -0,0 +1,78 @@
/*******************************************************************************
* Copyright (c) 2015 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.application.properties.reconcile;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.WARNING;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
/**
* @author Kris De Volder
*/
public enum ApplicationPropertiesProblemType implements ProblemType {
PROP_INVALID_BEAN_NAVIGATION("Accessing a 'bean property' in a type that doesn't have properties (e.g. like String or Integer)"),
PROP_INVALID_INDEXED_NAVIGATION("Accessing a property using [] in a type that doesn't support that"),
PROP_EXPECTED_DOT_OR_LBRACK("Unexpected character found where a '.' or '[' was expected"),
PROP_NO_MATCHING_RBRACK("Found a '[' but no matching ']'"),
PROP_NON_INTEGER_IN_BRACKETS("Use of [..] navigation with non-integer value"),
PROP_VALUE_TYPE_MISMATCH("Expecting a value of a certain type, but value doesn't parse as such"),
PROP_INVALID_BEAN_PROPERTY("Accessing a named property in a type that doesn't provide a property accessor with that name"),
PROP_UNKNOWN_PROPERTY(WARNING, "Property-key not found in any configuration metadata on the project's classpath"),
PROP_DEPRECATED(WARNING, "Property is marked as Deprecated"),
PROP_DUPLICATE_KEY("Multiple assignments to the same property value");
private final ProblemSeverity defaultSeverity;
private String description;
private String label;
private ApplicationPropertiesProblemType(ProblemSeverity defaultSeverity, String description, String label) {
this.description = description;
this.defaultSeverity = defaultSeverity;
this.label = label;
}
private ApplicationPropertiesProblemType(ProblemSeverity defaultSeverity, String description) {
this(defaultSeverity, description, null);
}
private ApplicationPropertiesProblemType(String description) {
this(ERROR, description);
}
public ProblemSeverity getDefaultSeverity() {
return defaultSeverity;
}
public String getLabel() {
if (label==null) {
label = createDefaultLabel();
}
return label;
}
public String getDescription() {
return description;
}
private String createDefaultLabel() {
String label = this.toString().substring(5).toLowerCase().replace('_', ' ');
return Character.toUpperCase(label.charAt(0)) + label.substring(1);
}
@Override
public String getCode() {
return name();
}
}

View File

@@ -1,7 +1,7 @@
package org.springframework.ide.vscode.application.yaml.reconcile;
import static org.springframework.ide.vscode.application.yaml.reconcile.SpringPropertiesProblemType.YAML_DEPRECATED;
import static org.springframework.ide.vscode.application.yaml.reconcile.SpringPropertiesProblemType.YAML_DUPLICATE_KEY;
import static org.springframework.ide.vscode.application.yaml.reconcile.ApplicationYamlProblemType.YAML_DEPRECATED;
import static org.springframework.ide.vscode.application.yaml.reconcile.ApplicationYamlProblemType.YAML_DUPLICATE_KEY;
import static org.springframework.ide.vscode.commons.yaml.ast.NodeUtil.asScalar;
import static org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST.getChildren;
@@ -273,19 +273,19 @@ public class ApplicationYamlASTReconciler implements YamlASTReconciler {
}
private void expectTypeFoundMapping(Type type, MappingNode node) {
expectType(SpringPropertiesProblemType.YAML_EXPECT_TYPE_FOUND_MAPPING, type, node);
expectType(ApplicationYamlProblemType.YAML_EXPECT_TYPE_FOUND_MAPPING, type, node);
}
private void expectTypeFoundSequence(Type type, SequenceNode seq) {
expectType(SpringPropertiesProblemType.YAML_EXPECT_TYPE_FOUND_SEQUENCE, type, seq);
expectType(ApplicationYamlProblemType.YAML_EXPECT_TYPE_FOUND_SEQUENCE, type, seq);
}
private void valueTypeMismatch(Type type, ScalarNode scalar) {
expectType(SpringPropertiesProblemType.YAML_VALUE_TYPE_MISMATCH, type, scalar);
expectType(ApplicationYamlProblemType.YAML_VALUE_TYPE_MISMATCH, type, scalar);
}
private void unkownProperty(Node node, String name, NodeTuple entry) {
SpringPropertyProblem p = problem(SpringPropertiesProblemType.YAML_UNKNOWN_PROPERTY, node, "Unknown property '"+name+"'");
SpringPropertyProblem p = problem(ApplicationYamlProblemType.YAML_UNKNOWN_PROPERTY, node, "Unknown property '"+name+"'");
p.setPropertyName(extendForQuickfix(StringUtil.camelCaseToHyphens(name), entry.getValueNode()));
problems.accept(p);
}
@@ -315,23 +315,23 @@ public class ApplicationYamlASTReconciler implements YamlASTReconciler {
}
private void expectScalar(Node node) {
problems.accept(problem(SpringPropertiesProblemType.YAML_EXPECT_SCALAR, node, "Expecting a 'Scalar' node but got "+describe(node)));
problems.accept(problem(ApplicationYamlProblemType.YAML_EXPECT_SCALAR, node, "Expecting a 'Scalar' node but got "+describe(node)));
}
protected void expectMapping(Node node) {
problems.accept(problem(SpringPropertiesProblemType.YAML_EXPECT_MAPPING, node, "Expecting a 'Mapping' node but got "+describe(node)));
problems.accept(problem(ApplicationYamlProblemType.YAML_EXPECT_MAPPING, node, "Expecting a 'Mapping' node but got "+describe(node)));
}
private void expectBeanPropertyName(Node keyNode, Type type) {
problems.accept(problem(SpringPropertiesProblemType.YAML_EXPECT_BEAN_PROPERTY_NAME, keyNode, "Expecting a bean-property name for object of type '"+typeUtil.niceTypeName(type)+"' "
problems.accept(problem(ApplicationYamlProblemType.YAML_EXPECT_BEAN_PROPERTY_NAME, keyNode, "Expecting a bean-property name for object of type '"+typeUtil.niceTypeName(type)+"' "
+ "but got "+describe(keyNode)));
}
private void unknownBeanProperty(Node keyNode, Type type, String name) {
problems.accept(problem(SpringPropertiesProblemType.YAML_INVALID_BEAN_PROPERTY, keyNode, "Unknown property '"+name+"' for type '"+typeUtil.niceTypeName(type)+"'"));
problems.accept(problem(ApplicationYamlProblemType.YAML_INVALID_BEAN_PROPERTY, keyNode, "Unknown property '"+name+"' for type '"+typeUtil.niceTypeName(type)+"'"));
}
private void expectType(SpringPropertiesProblemType problemType, Type type, Node node) {
private void expectType(ApplicationYamlProblemType problemType, Type type, Node node) {
problems.accept(problem(problemType, node, "Expecting a '"+typeUtil.niceTypeName(type)+"' but got "+describe(node)));
}
@@ -356,7 +356,7 @@ public class ApplicationYamlASTReconciler implements YamlASTReconciler {
return problem;
}
protected SpringPropertyProblem problem(SpringPropertiesProblemType type, Node node, String msg) {
protected SpringPropertyProblem problem(ApplicationYamlProblemType type, Node node, String msg) {
int start = node.getStartMark().getIndex();
int end = node.getEndMark().getIndex();
return SpringPropertyProblem.problem(type, msg, start, end-start);

View File

@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2015 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.application.yaml.reconcile;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.WARNING;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
/**
* @author Kris De Volder
*/
public enum ApplicationYamlProblemType implements ProblemType {
YAML_SYNTAX_ERROR("Error parsing the input using snakeyaml"),
YAML_UNKNOWN_PROPERTY(WARNING, "Property-key not found in the configuration metadata on the project's classpath"),
YAML_VALUE_TYPE_MISMATCH("Expecting a value of a certain type, but value doesn't parse as such"),
YAML_EXPECT_SCALAR("Expecting a 'scalar' value but found something more complex."),
YAML_EXPECT_TYPE_FOUND_SEQUENCE("Found a 'sequence' node where a non 'list-like' type is expected"),
YAML_EXPECT_TYPE_FOUND_MAPPING("Found a 'mapping' node where a type that can't be treated as a 'property map' is expected"),
YAML_EXPECT_MAPPING("Expecting a 'mapping' node but found something else"),
YAML_EXPECT_BEAN_PROPERTY_NAME("Expecting a 'bean property' name but found something more complex"),
YAML_INVALID_BEAN_PROPERTY("Accessing a named property in a type that doesn't provide a property accessor with that name"),
YAML_DEPRECATED(WARNING, "Property is marked as Deprecated"),
YAML_DUPLICATE_KEY("A mapping node contains multiple entries for the same key");
private final ProblemSeverity defaultSeverity;
private String description;
private String label;
private ApplicationYamlProblemType(ProblemSeverity defaultSeverity, String description, String label) {
this.description = description;
this.defaultSeverity = defaultSeverity;
this.label = label;
}
private ApplicationYamlProblemType(ProblemSeverity defaultSeverity, String description) {
this(defaultSeverity, description, null);
}
private ApplicationYamlProblemType(String description) {
this(ERROR, description);
}
public ProblemSeverity getDefaultSeverity() {
return defaultSeverity;
}
public String getLabel() {
if (label==null) {
label = createDefaultLabel();
}
return label;
}
public String getDescription() {
return description;
}
private String createDefaultLabel() {
String label = this.toString().substring(5).toLowerCase().replace('_', ' ');
return Character.toUpperCase(label.charAt(0)) + label.substring(1);
}
@Override
public String getCode() {
return name();
}
}

View File

@@ -1,129 +0,0 @@
/*******************************************************************************
* Copyright (c) 2015 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.application.yaml.reconcile;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.*;
import java.util.ArrayList;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
/**
* @author Kris De Volder
*/
public enum SpringPropertiesProblemType implements ProblemType {
// Naming:
// YAML_* for all problems in .yml files.
// PROP_* for all problems in .properties files.
// All enum values must start with one or the other (or some stuff will break!).
// PROP_INVALID_BEAN_NAVIGATION("Accessing a 'bean property' in a type that doesn't have properties (e.g. like String or Integer)"),
// PROP_INVALID_INDEXED_NAVIGATION("Accessing a property using [] in a type that doesn't support that"),
// PROP_EXPECTED_DOT_OR_LBRACK("Unexpected character found where a '.' or '[' was expected"),
// PROP_NO_MATCHING_RBRACK("Found a '[' but no matching ']'"),
// PROP_NON_INTEGER_IN_BRACKETS("Use of [..] navigation with non-integer value"),
// PROP_VALUE_TYPE_MISMATCH("Expecting a value of a certain type, but value doesn't parse as such"),
// PROP_INVALID_BEAN_PROPERTY("Accessing a named property in a type that doesn't provide a property accessor with that name"),
// PROP_UNKNOWN_PROPERTY(WARNING, "Property-key not found in any configuration metadata on the project's classpath"),
// PROP_DEPRECATED(WARNING, "Property is marked as Deprecated"),
// PROP_DUPLICATE_KEY("Multiple assignments to the same property value"),
YAML_SYNTAX_ERROR("Error parsing the input using snakeyaml"),
YAML_UNKNOWN_PROPERTY(WARNING, "Property-key not found in the configuration metadata on the project's classpath"),
YAML_VALUE_TYPE_MISMATCH("Expecting a value of a certain type, but value doesn't parse as such"),
YAML_EXPECT_SCALAR("Expecting a 'scalar' value but found something more complex."),
YAML_EXPECT_TYPE_FOUND_SEQUENCE("Found a 'sequence' node where a non 'list-like' type is expected"),
YAML_EXPECT_TYPE_FOUND_MAPPING("Found a 'mapping' node where a type that can't be treated as a 'property map' is expected"),
YAML_EXPECT_MAPPING("Expecting a 'mapping' node but found something else"),
YAML_EXPECT_BEAN_PROPERTY_NAME("Expecting a 'bean property' name but found something more complex"),
YAML_INVALID_BEAN_PROPERTY("Accessing a named property in a type that doesn't provide a property accessor with that name"),
YAML_DEPRECATED(WARNING, "Property is marked as Deprecated"),
YAML_DUPLICATE_KEY("A mapping node contains multiple entries for the same key");
private final ProblemSeverity defaultSeverity;
private String description;
private String label;
private SpringPropertiesProblemType(ProblemSeverity defaultSeverity, String description, String label) {
this.description = description;
this.defaultSeverity = defaultSeverity;
this.label = label;
}
private SpringPropertiesProblemType(ProblemSeverity defaultSeverity, String description) {
this(defaultSeverity, description, null);
}
private SpringPropertiesProblemType(String description) {
this(ERROR, description);
}
public ProblemSeverity getDefaultSeverity() {
return defaultSeverity;
}
public static SpringPropertiesProblemType[] forProperties() {
return withPrefix("PROP_");
}
private static SpringPropertiesProblemType[] withPrefix(String prefix) {
SpringPropertiesProblemType[] allValues = values();
ArrayList<SpringPropertiesProblemType> values = new ArrayList<SpringPropertiesProblemType>(allValues.length);
for (SpringPropertiesProblemType v : allValues) {
if (v.toString().startsWith(prefix)) {
values.add(v);
}
}
return values.toArray(new SpringPropertiesProblemType[values.size()]);
}
public String getLabel() {
if (label==null) {
label = createDefaultLabel();
}
return label;
}
public String getDescription() {
return description;
}
private String createDefaultLabel() {
String label = this.toString().substring(5).toLowerCase().replace('_', ' ');
return Character.toUpperCase(label.charAt(0)) + label.substring(1);
}
@Override
public String getCode() {
return name();
}
// TODO: obsolete? We should simply keep the problemtype implementations for yaml / props editor totally separate
// public static final SpringPropertiesProblemType[] FOR_YAML = FOR(EditorType.YAML);
// public static final SpringPropertiesProblemType[] FOR_PROPERTIES = FOR(EditorType.PROP);
// public static SpringPropertiesProblemType[] FOR(EditorType et) {
// return withPrefix(et.getProblemTypePrefix());
// }
// public EditorType getEditorType() {
// String string = this.toString();
// for (EditorType et : EditorType.values()) {
// String prefix = et.getProblemTypePrefix();
// if (string.startsWith(prefix)) {
// return et;
// }
// }
// throw new IllegalStateException("Bug: unknown editor type for "+this);
// }
}

View File

@@ -15,7 +15,7 @@ public class SpringPropertyProblem extends ReconcileProblemImpl {
super(type, msg, offset, len);
}
public static SpringPropertyProblem problem(SpringPropertiesProblemType type, String msg, int offset, int len) {
public static SpringPropertyProblem problem(ApplicationYamlProblemType type, String msg, int offset, int len) {
return new SpringPropertyProblem(type, msg, offset, len);
}