Add support for values of type java.time.Duration...

So that both application.properties and application.yml

- recognize/treat these as atomic values
- can recognize 'garbage' values during reconcile and give a error.
This commit is contained in:
Kris De Volder
2018-08-21 12:01:37 -07:00
parent 93ec5e6fae
commit 8ef2e19fdf
5 changed files with 90 additions and 11 deletions

View File

@@ -81,6 +81,7 @@
<jersey-2-version>2.10</jersey-2-version>
<lsp4j-version>0.4.0-SNAPSHOT</lsp4j-version>
<cglib-version>3.2.7</cglib-version>
<boot-version>2.0.4.RELEASE</boot-version>
<!-- NOTE: Reactor version must match version used by the CF client -->
<cloudfoundry-client-version>3.8.0.RELEASE</cloudfoundry-client-version>
<reactor-version>3.1.5.RELEASE</reactor-version>

View File

@@ -1,17 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-language-server</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-parent</artifactId>
<version>0.6.0-SNAPSHOT</version>
<relativePath>../commons/pom.xml</relativePath>
</parent>
<properties>
<dependencies.version>${project.version}</dependencies.version>
</properties>
@@ -22,11 +23,11 @@
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<!-- Local modified JSON lib packaged to support order in maps -->
<!-- Local modified JSON lib packaged to support order in maps -->
<groupId>org.springframework.ide.eclipse</groupId>
<artifactId>org.json</artifactId>
<version>1.0</version>
@@ -61,11 +62,13 @@
<artifactId>commons-boot-app-cli</artifactId>
<version>${dependencies.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.13.102.v20180320-1701_BETA_JAVA10</version>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${boot-version}</version>
</dependency>
<!-- <dependency> <groupId>org.eclipse.tycho</groupId> <artifactId>org.eclipse.jdt.core</artifactId>
<version>3.13.102.v20180320-1701_BETA_JAVA10</version> </dependency> -->
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
@@ -132,6 +135,6 @@
</excludes>
</configuration>
</plugin>
</plugins>
</plugins>
</build>
</project>

View File

@@ -17,6 +17,7 @@ import static org.springframework.ide.vscode.commons.util.ArrayUtils.lastElement
import java.net.InetAddress;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -34,6 +35,7 @@ import java.util.stream.Stream;
import javax.inject.Provider;
import org.springframework.boot.convert.DurationStyle;
import org.springframework.ide.vscode.boot.configurationmetadata.Deprecation;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
@@ -58,6 +60,7 @@ import org.springframework.ide.vscode.commons.util.Log;
import org.springframework.ide.vscode.commons.util.MimeTypes;
import org.springframework.ide.vscode.commons.util.Renderables;
import org.springframework.ide.vscode.commons.util.StringUtil;
import org.springframework.ide.vscode.commons.util.ValueParseException;
import org.springframework.ide.vscode.commons.util.ValueParser;
import com.google.common.collect.ImmutableList;
@@ -95,6 +98,7 @@ public class TypeUtil {
private static final Object OBJECT_TYPE_NAME = Object.class.getName();
private static final String STRING_TYPE_NAME = String.class.getName();
private static final String INET_ADDRESS_TYPE_NAME = InetAddress.class.getName();
private static final String DURATION_TYPE_NAME = Duration.class.getName();
private static final String CLASS_TYPE_NAME = Class.class.getName();
public enum BeanPropertyNameMode {
@@ -171,6 +175,7 @@ public class TypeUtil {
"java.lang.Character",
"java.lang.Byte",
INET_ADDRESS_TYPE_NAME,
DURATION_TYPE_NAME,
CLASS_TYPE_NAME,
"java.lang.String[]"
));
@@ -178,6 +183,7 @@ public class TypeUtil {
private static final Set<String> ATOMIC_TYPES = new HashSet<>(PRIMITIVE_TYPE_NAMES.keySet());
static {
ATOMIC_TYPES.add(INET_ADDRESS_TYPE_NAME);
ATOMIC_TYPES.add(DURATION_TYPE_NAME);
ATOMIC_TYPES.add(STRING_TYPE_NAME);
ATOMIC_TYPES.add(CLASS_TYPE_NAME);
}
@@ -239,6 +245,13 @@ public class TypeUtil {
throw new IllegalArgumentException("Value should be 'true' or 'false'");
}
});
VALUE_PARSERS.put(DURATION_TYPE_NAME, (s) -> {
try {
return DurationStyle.detectAndParse(s);
} catch (IllegalArgumentException e) {
throw new ValueParseException(e.getMessage());
}
});
}
public ValueParser getValueParser(Type type) {

View File

@@ -78,6 +78,33 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
editor.assertProblems("problem|extraneous input", "another|mismatched input");
}
@Test public void bug_158348104() throws Exception {
//See: https://www.pivotaltracker.com/story/show/158348104
data("spring.activemq.close-timeout", "java.time.Duration", null, null);
Editor editor;
editor = newEditor("");
editor.assertContextualCompletions("springactcloti",
"spring.activemq.close-timeout=<*>"
);
editor = newEditor(
"spring.activemq.close-timeout=garbage"
);
editor.assertProblems("garbage|not a valid duration");
editor = newEditor(
"spring.activemq.close-timeout: 15s"
);
editor.assertProblems(/*NONE*/);
editor = newEditor(
"spring.activemq.close-timeout: PT10S" //ISO duration format
);
editor.assertProblems(/*NONE*/);
}
@Test public void testServerPortCompletion() throws Exception {
data("server.port", INTEGER, 8080, "Port where server listens for http.");
assertCompletion("ser<*>", "server.port=<*>");

View File

@@ -51,6 +51,41 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
////////////////////////////////////////////////////////////////////////////////////////
@Test public void bug_158348104() throws Exception {
//See: https://www.pivotaltracker.com/story/show/158348104
data("spring.activemq.close-timeout", "java.time.Duration", null, null);
Editor editor;
editor = newEditor("");
editor.assertContextualCompletions("springactcloti",
"spring:\n" +
" activemq:\n" +
" close-timeout: <*>"
);
editor = newEditor(
"spring:\n" +
" activemq:\n" +
" close-timeout: garbage"
);
editor.assertProblems("garbage|not a valid duration");
editor = newEditor(
"spring:\n" +
" activemq:\n" +
" close-timeout: 15s"
);
editor.assertProblems(/*NONE*/);
editor = newEditor(
"spring:\n" +
" activemq:\n" +
" close-timeout: PT10S" //ISO duration format
);
editor.assertProblems(/*NONE*/);
}
@Test public void bug_153144391() throws Exception {
//See: https://www.pivotaltracker.com/story/show/153144391
useProject(createPredefinedMavenProject("empty-boot-1.3.0-app"));