diff --git a/vscode-extensions/commons/application-properties-metadata/src/main/java/org/springframework/ide/vscode/application/properties/metadata/MetadataManipulator.java b/vscode-extensions/commons/application-properties-metadata/src/main/java/org/springframework/ide/vscode/application/properties/metadata/MetadataManipulator.java new file mode 100644 index 000000000..bf0408c80 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/main/java/org/springframework/ide/vscode/application/properties/metadata/MetadataManipulator.java @@ -0,0 +1,230 @@ +/******************************************************************************* + * 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.metadata; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.LinkedHashMap; + +import org.springframework.ide.eclipse.org.json.JSONArray; +import org.springframework.ide.eclipse.org.json.JSONObject; + +/** + * Helper class to manipulate data in a file presumed to contain + * spring-boot configuration data. + * + * @author Kris De Volder + * @author Alex Boyko + */ +public class MetadataManipulator { + + private abstract class Content { + public abstract String toString(); + public abstract void addProperty(JSONObject jsonObject) throws Exception; + } + + /** + * Content was parse as JSONObject. + */ + private class ParsedContent extends Content { + + private JSONObject object; + + public ParsedContent(JSONObject o) { + this.object = o; + } + + public String toString() { + return object.toString(indentFactor); + } + + @Override + public void addProperty(JSONObject propertyData) throws Exception { + JSONArray properties = object.getJSONArray("properties"); + properties.put(properties.length(), propertyData); + } + } + + /** + * Content that is 'unparsed' and just a bunch of text. + * Used only as a fallback when data in file can't + * be parsed. + *

+ * This content is manipulated by string manipulation. + * It is less reliable, but can be done even if the + * file data is not parseable. + */ + private class RawContent extends Content { + + private StringBuilder doc; + + public RawContent(String content) { + this.doc = new StringBuilder(content); + } + + @Override + public String toString() { + return doc.toString(); + } + + @Override + public void addProperty(JSONObject propertyData) throws Exception { + int insertAt = findLast(']'); + if (insertAt<0) { + //although we're not looking for much, we didn't find it! + //Funky file contents. Let's just insert something at end of file in a 'best effort' spirit. + insertAt = doc.length(); + } + insert(insertAt, "\n"); + + insert(insertAt, propertyData.toString(indentFactor)); + + int insertComma = findInsertCommaPos(insertAt); + if (insertComma>=0) { + insert(insertComma, ","); + } + } + + /** + * Maybe we need to add a comma in front of the new entry. This + * method finds if/where to stick this comma. + * @throws Exception + */ + private int findInsertCommaPos(int pos) throws Exception { + pos--; + while (pos>=0 && Character.isWhitespace(doc.charAt(pos))) { + pos--; + } + if (pos>=0) { + char c = doc.charAt(pos); + if (c == '}') { + //Add a comma after a '}' + return pos+1; + } + } + return -1; + } + + private int insert(int insertAt, String str) throws Exception { + if (insertAt < doc.length()) { + doc.replace(insertAt, insertAt, str); + } else { + doc.append(str); + } + return insertAt + str.length(); + } + + private int findLast(char toFind) throws Exception { + int pos = doc.length()-1; + while (pos>=0 && doc.charAt(pos)!=toFind) { + pos--; + } + //We got here either because + // - we found char at pos or.. + // - we reached position *before* start of file (i.e. -1) + return pos; + } + + } + + public interface ContentStore { + String getContents() throws Exception; + void setContents(String content) throws Exception; + } + + private static final String INITIAL_CONTENT = + "{\"properties\": [\n" + + "]}"; + + private static final String ENCODING = "UTF8"; + private ContentStore contentStore; + private Content fContent; + private int indentFactor = 2; + + public MetadataManipulator(ContentStore contentStore) { + this.contentStore = contentStore; + } + + public MetadataManipulator(final File file) { + this(new ContentStore() { + + @Override + public String getContents() throws Exception { + return new String(Files.readAllBytes(Paths.get(file.toURI())), ENCODING); + } + + @Override + public void setContents(String content) throws Exception { + Files.write(Paths.get(file.toURI()), content.getBytes(ENCODING)); + } + + }); + } + + private Content getContent() throws Exception { + if (fContent==null) { + fContent = readContent(); + } + return fContent; + } + + private Content readContent() throws Exception { + String content = contentStore.getContents(); + if (content.trim().isEmpty()) { + JSONObject o = initialContent(); + return new ParsedContent(o); + } else { + try { + return new ParsedContent(new JSONObject(content)); + } catch (Exception e) { + //couldn't parse? + return new RawContent(content); + } + } + } + + public void addDefaultInfo(String propertyName) throws Exception { + getContent().addProperty(createDefaultData(propertyName)); + } + + private JSONObject createDefaultData(String propertyName) throws Exception { + JSONObject obj = new JSONObject(new LinkedHashMap()); + obj.put("name", propertyName); + obj.put("type", String.class.getName()); + obj.put("description", "A description for '"+propertyName+"'"); + return obj; + } + + /** + * Generate the initial content (must be generated rather than being a constant to respect newline conventions + * on user's system. + */ + private JSONObject initialContent() throws Exception { + return new JSONObject(INITIAL_CONTENT); + } + + /** + * After manipulating the data, use this to persist changes back to the file. + */ + public void save() throws Exception { + contentStore.setContents(getContent().toString()); + } + + /** + * Determines whether the 'reliable' manipulations can be used (which is the case + * only if the data in the file is valid json). + */ + public boolean isReliable() throws Exception { + return getContent() instanceof ParsedContent; + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/IndexNavigatorTest.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/IndexNavigatorTest.java new file mode 100644 index 000000000..c47c2ea3a --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/IndexNavigatorTest.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2015, 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.boot.properties.metadata; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.springframework.ide.vscode.application.properties.metadata.IndexNavigator; + +/** + * Index Navigation tests. + * + * @author Kris De Volder + * @author Alex Boyko + * + */ +public class IndexNavigatorTest { + + @Test + public void testSimple() throws Exception { + PropertiesMetadataTestData data = new PropertiesMetadataTestData(); + data.defaultTestData(); + + start(data); + assertContinuable(); + + navigate("server"); + assertContinuable(); + + navigate("port"); + assertProperty(); + + navigate("extracrap"); + assertEmpty(); + } + + @Test + public void testPartialName() throws Exception { + PropertiesMetadataTestData data = new PropertiesMetadataTestData(); + data.defaultTestData(); + + start(data); + assertContinuable(); + + navigate("serv"); + // As a plain string 'serv' is a prefix of 'server' + // but it shouldn't be treated as such since it doesn't continue with + // a '.' + assertEmpty(); + } + + @Test + public void testAmbiguous() throws Exception { + PropertiesMetadataTestData data = new PropertiesMetadataTestData(); + data.defaultTestData(); + + data.addPropertyMetadata("foo.bar", "java.lang.String", null, "Foo dot bar"); + data.addPropertyMetadata("foo", "java.lang.String", null, "Just foo"); + data.addPropertyMetadata("fooaaaa", "java.lang.String", null, "Confuse the foo match"); + + start(data); + navigate("foo"); + assertAmbiguous(); + } + + /////////////// test harnes ///////////////////////////////////// + + /** + * Assert that current navigation state is unambiguous and allows + * further navigation. I.e. the current navigation state does not + * represent an exact property match but contains valid sub-properties + */ + public void assertContinuable() { + assertNull(navigator.getExactMatch()); + assertNotNull(navigator.getExtensionCandidate()); + } + + /** + * Assert that current navigation state is unambiguous and represents + * an exact property match. + */ + public void assertProperty() { + assertNotNull(navigator.getExactMatch()); + assertNull(navigator.getExtensionCandidate()); + } + + /** + * Assert that current navigation state is both an exact property match + * (so navigation could end here) and also contains valid subproperties + * (so navigation could continue). + */ + public void assertAmbiguous() { + assertNotNull(navigator.getExactMatch()); + assertNotNull(navigator.getExtensionCandidate()); + } + + /** + * Assert that the current navigation state is neither an exact property + * match nor continuable. + */ + public void assertEmpty() { + assertNull(navigator.getExactMatch()); + assertNull(navigator.getExtensionCandidate()); + } + + /** + * Current navigation state + */ + public IndexNavigator navigator; + + /** + * Reset navigation state to point at the root of the index. + */ + public void start(PropertiesMetadataTestData data) { + navigator = IndexNavigator.with(data.createIndex()); + } + + /** + * Navigate from current navigation 'root' to a sub property + */ + public void navigate(String propName) { + navigator = navigator.selectSubProperty(propName); + } + + + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/MetadataManipulatorTest.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/MetadataManipulatorTest.java new file mode 100644 index 000000000..1f70ca8a3 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/MetadataManipulatorTest.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * 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.boot.properties.metadata; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.springframework.ide.vscode.application.properties.metadata.MetadataManipulator; + +/** + * Tests for Spring Boot Properties Metadata manipulations + * + * @author Kris De Volder + * @author Alex Boyko + * + */ +public class MetadataManipulatorTest { + + public static class MockContent implements MetadataManipulator.ContentStore { + + private String content; + + public MockContent(String intialContent) { + this.content = intialContent; + } + + @Override + public String toString() { + //So tests don't fail on Windoze + return content.replace("\r\n", "\n"); + } + + @Override + public String getContents() throws Exception { + return content; + } + + @Override + public void setContents(String content) throws Exception { + this.content = content; + } + } + + @Test + public void testAddOneElementFromEmpty() throws Exception { + MockContent content = new MockContent(""); + MetadataManipulator md = new MetadataManipulator(content); + + md.addDefaultInfo("test.property"); + md.save(); + + assertEquals( + "{\"properties\": [{\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + "}]}", + //================ + content.toString()); + + md.addDefaultInfo("another.property"); + md.save(); + + assertEquals( + "{\"properties\": [\n" + + " {\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + " },\n" + + " {\n" + + " \"name\": \"another.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'another.property'\"\n" + + " }\n" + + "]}", + //================ + content.toString()); + + assertTrue(md.isReliable()); + + } + + @Test + public void testRawContent() throws Exception { + MockContent content = new MockContent("garbage"); + MetadataManipulator md = new MetadataManipulator(content); + + md.addDefaultInfo("test.property"); + md.save(); + + assertEquals( + "garbage{\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + "}\n", + //================ + content.toString()); + + md.addDefaultInfo("another.property"); + md.save(); + + assertEquals( + "garbage{\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + "},\n" + + "{\n" + + " \"name\": \"another.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'another.property'\"\n" + + "}\n", + //================ + content.toString()); + + assertFalse(md.isReliable()); + } + + @Test + public void testRawContent2() throws Exception { + MockContent content = new MockContent( + //almost correct content, its missing a comma + "{\"properties\": [\n" + + " {\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + " }\n" + //missing comma! + " {\n" + + " \"name\": \"another.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'another.property'\"\n" + + " }\n" + + "]}" + ); + MetadataManipulator md = new MetadataManipulator(content); + + md.addDefaultInfo("foo.bar"); + md.save(); + + assertEquals( + "{\"properties\": [\n" + + " {\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + " }\n" + + " {\n" + + " \"name\": \"another.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'another.property'\"\n" + + " },\n" + + //TODO: The indentation is off... maybe this could be fixed + "{\n" + + " \"name\": \"foo.bar\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'foo.bar'\"\n" + + "}\n" + + "]}", + //================ + content.toString()); + + assertFalse(md.isReliable()); + } + + @Test + public void testDisallowRawContent() throws Exception { + MockContent content; + MetadataManipulator md; + + // empty files can be reliabley manipulated? + content = new MockContent(""); + md = new MetadataManipulator(content); + + md.addDefaultInfo("test.property"); + md.save(); + + assertEquals( + "{\"properties\": [{\n" + + " \"name\": \"test.property\",\n" + + " \"type\": \"java.lang.String\",\n" + + " \"description\": \"A description for 'test.property'\"\n" + + "}]}", + //================ + content.toString()); + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesIndexTest.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesIndexTest.java index a456d4068..1dae0b1bc 100644 --- a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesIndexTest.java +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesIndexTest.java @@ -1,110 +1,110 @@ -/******************************************************************************* - * 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.boot.properties.metadata; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.junit.Test; -import org.springframework.ide.vscode.application.properties.metadata.PropertyInfo; -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.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.project.harness.Projects; - -/** - * Sanity test the boot properties index - * - * @author Alex Boyko - * - */ -public class PropertiesIndexTest { - - private static final String CUSTOM_PROPERTIES_PROJECT = "custom-properties-boot-project"; - - @Test - public void springStandardPropertyPresent_Maven() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - MavenJavaProject mavenProject = new MavenJavaProject( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.POM_XML).toFile()); - FuzzyMap index = indexManager.get(mavenProject); - PropertyInfo propertyInfo = index.get("server.port"); - assertNotNull(propertyInfo); - assertEquals(Integer.class.getName(), propertyInfo.getType()); - assertEquals("port", propertyInfo.getName()); - } - - @Test - public void customPropertyPresent_Maven() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - MavenJavaProject mavenProject = new MavenJavaProject( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.POM_XML).toFile()); - FuzzyMap index = indexManager.get(mavenProject); - PropertyInfo propertyInfo = index.get("demo.settings.user"); - assertNotNull(propertyInfo); - assertEquals(String.class.getName(), propertyInfo.getType()); - assertEquals("user", propertyInfo.getName()); - } - - @Test - public void propertyNotPresent_Maven() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - MavenJavaProject mavenProject = new MavenJavaProject( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.POM_XML).toFile()); - FuzzyMap index = indexManager.get(mavenProject); - PropertyInfo propertyInfo = index.get("my.server.port"); - assertNull(propertyInfo); - } - - @Test - public void springStandardPropertyPresent_ClasspathFile() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - JavaProjectWithClasspathFile classpathFileProject = new JavaProjectWithClasspathFile( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.CLASSPATH_TXT).toFile()); - FuzzyMap index = indexManager.get(classpathFileProject); - PropertyInfo propertyInfo = index.get("server.port"); - assertNotNull(propertyInfo); - assertEquals(Integer.class.getName(), propertyInfo.getType()); - assertEquals("port", propertyInfo.getName()); - } - - @Test - public void customPropertyPresent_ClasspathFile() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - JavaProjectWithClasspathFile classpathFileProject = new JavaProjectWithClasspathFile( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.CLASSPATH_TXT).toFile()); - FuzzyMap index = indexManager.get(classpathFileProject); - PropertyInfo propertyInfo = index.get("demo.settings.user"); - assertNotNull(propertyInfo); - assertEquals(String.class.getName(), propertyInfo.getType()); - assertEquals("user", propertyInfo.getName()); - } - - @Test - public void propertyNotPresent_ClasspathFile() throws Exception { - SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( - ValueProviderRegistry.getDefault()); - JavaProjectWithClasspathFile classpathFileProject = new JavaProjectWithClasspathFile( - Projects.buildMavenProject(CUSTOM_PROPERTIES_PROJECT).resolve(MavenCore.CLASSPATH_TXT).toFile()); - FuzzyMap index = indexManager.get(classpathFileProject); - PropertyInfo propertyInfo = index.get("my.server.port"); - assertNull(propertyInfo); - } -} +/******************************************************************************* + * 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.boot.properties.metadata; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.springframework.ide.vscode.application.properties.metadata.PropertyInfo; +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.project.harness.ProjectsHarness; + +/** + * Sanity test the boot properties index + * + * @author Alex Boyko + * + */ +public class PropertiesIndexTest { + + private static final String CUSTOM_PROPERTIES_PROJECT = "custom-properties-boot-project"; + + @Test + public void springStandardPropertyPresent_Maven() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + MavenJavaProject mavenProject = Projects + .createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(mavenProject); + PropertyInfo propertyInfo = index.get("server.port"); + assertNotNull(propertyInfo); + assertEquals(Integer.class.getName(), propertyInfo.getType()); + assertEquals("port", propertyInfo.getName()); + } + + @Test + public void customPropertyPresent_Maven() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + MavenJavaProject mavenProject = Projects + .createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(mavenProject); + PropertyInfo propertyInfo = index.get("demo.settings.user"); + assertNotNull(propertyInfo); + assertEquals(String.class.getName(), propertyInfo.getType()); + assertEquals("user", propertyInfo.getName()); + } + + @Test + public void propertyNotPresent_Maven() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + MavenJavaProject mavenProject = Projects + .createMavenJavaProject(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(mavenProject); + PropertyInfo propertyInfo = index.get("my.server.port"); + assertNull(propertyInfo); + } + + @Test + public void springStandardPropertyPresent_ClasspathFile() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + JavaProjectWithClasspathFile classpathFileProject = Projects + .createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(classpathFileProject); + PropertyInfo propertyInfo = index.get("server.port"); + assertNotNull(propertyInfo); + assertEquals(Integer.class.getName(), propertyInfo.getType()); + assertEquals("port", propertyInfo.getName()); + } + + @Test + public void customPropertyPresent_ClasspathFile() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + JavaProjectWithClasspathFile classpathFileProject = Projects + .createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(classpathFileProject); + PropertyInfo propertyInfo = index.get("demo.settings.user"); + assertNotNull(propertyInfo); + assertEquals(String.class.getName(), propertyInfo.getType()); + assertEquals("user", propertyInfo.getName()); + } + + @Test + public void propertyNotPresent_ClasspathFile() throws Exception { + SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager( + ValueProviderRegistry.getDefault()); + JavaProjectWithClasspathFile classpathFileProject = Projects + .createJavaProjectWithClasspathFile(ProjectsHarness.buildMavenProject(CUSTOM_PROPERTIES_PROJECT)); + FuzzyMap index = indexManager.get(classpathFileProject); + PropertyInfo propertyInfo = index.get("my.server.port"); + assertNull(propertyInfo); + } +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesMetadataTestData.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesMetadataTestData.java new file mode 100644 index 000000000..5b8285872 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/PropertiesMetadataTestData.java @@ -0,0 +1,514 @@ +/******************************************************************************* + * 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.boot.properties.metadata; + +import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; +import org.springframework.boot.configurationmetadata.ValueHint; +import org.springframework.boot.configurationmetadata.ValueProvider; +import org.springframework.ide.vscode.application.properties.metadata.SpringPropertyIndex; +import org.springframework.ide.vscode.application.properties.metadata.ValueProviderRegistry; +import org.springframework.ide.vscode.commons.java.IClasspath; + +/** + * Boot properties Metadata generated artificially for the tests + * + * @author Alex Boyko + * + */ +public class PropertiesMetadataTestData { + + public class ItemConfigurer { + + private ConfigurationMetadataProperty item; + + public ItemConfigurer(ConfigurationMetadataProperty item) { + this.item = item; + } + + /** + * Add a provider with a single parameter. + * @return + */ + public ItemConfigurer provider(String name, String paramName, Object paramValue) { + ValueProvider provider = new ValueProvider(); + provider.setName(name); + provider.getParameters().put(paramName, paramValue); + item.getHints().getValueProviders().add(provider); + return this; + } + + /** + * Add a value hint. If description contains a '.' the dot is used + * to break description into a short and long description. + * @return + */ + public ItemConfigurer valueHint(Object value, String description) { + ValueHint hint = new ValueHint(); + hint.setValue(value); + if (description!=null) { + int dotPos = description.indexOf('.'); + if (dotPos>=0) { + hint.setShortDescription( description.substring(0, dotPos)); + } + hint.setDescription(description); + } + item.getHints().getValueHints().add(hint); + return this; + } + } + + Map datas = new LinkedHashMap<>(); + + public ItemConfigurer addPropertyMetadata(String id, String type, Object deflt, String description, + String... source + ) { + ConfigurationMetadataProperty item = new ConfigurationMetadataProperty(); + item.setId(id); + item.setDescription(description); + item.setType(type); + item.setDefaultValue(deflt); + datas.put(item.getId(), item); + return new ItemConfigurer(item); + } + + public SpringPropertyIndex createIndex() { + SpringPropertyIndex index = new SpringPropertyIndex(ValueProviderRegistry.getDefault(), new IClasspath() { + @Override + public Collection getClasspathEntries() throws Exception { + return Collections.emptyList(); + } + }); + for (ConfigurationMetadataProperty propertyInfo : datas.values()) { + index.add(propertyInfo); + } + return index; + } + + /** + * Call this method to add some default test data to the Completion engine's index. + * Note that this data is not added automatically, some test may want to use smaller + * test data sets. + */ + public void defaultTestData() { + addPropertyMetadata("banner.charset", "java.nio.charset.Charset", "UTF-8", "Banner file encoding."); + addPropertyMetadata("banner.location", "java.lang.String", "classpath:banner.txt", "Banner file location."); + addPropertyMetadata("debug", "java.lang.Boolean", "false", "Enable debug logs."); + addPropertyMetadata("flyway.check-location", "java.lang.Boolean", "false", "Check that migration scripts location exists."); + addPropertyMetadata("flyway.clean-on-validation-error", "java.lang.Boolean", null, null); + addPropertyMetadata("flyway.enabled", "java.lang.Boolean", "true", "Enable flyway."); + addPropertyMetadata("flyway.encoding", "java.lang.String", null, null); + addPropertyMetadata("flyway.ignore-failed-future-migration", "java.lang.Boolean", null, null); + addPropertyMetadata("flyway.init-description", "java.lang.String", null, null); + addPropertyMetadata("flyway.init-on-migrate", "java.lang.Boolean", null, null); + addPropertyMetadata("flyway.init-sqls", "java.util.List", null, "SQL statements to execute to initialize a connection immediately after obtaining\n it."); + addPropertyMetadata("flyway.init-version", "org.flywaydb.core.api.MigrationVersion", null, null); + addPropertyMetadata("flyway.locations", "java.util.List", null, "Locations of migrations scripts."); + addPropertyMetadata("flyway.out-of-order", "java.lang.Boolean", null, null); + addPropertyMetadata("flyway.password", "java.lang.String", null, "Login password of the database to migrate."); + addPropertyMetadata("flyway.placeholder-prefix", "java.lang.String", null, null); + addPropertyMetadata("flyway.placeholders", "java.util.Map", null, null); + addPropertyMetadata("flyway.placeholder-suffix", "java.lang.String", null, null); + addPropertyMetadata("flyway.schemas", "java.lang.String[]", null, null); + addPropertyMetadata("flyway.sql-migration-prefix", "java.lang.String", null, null); + addPropertyMetadata("flyway.sql-migration-separator", "java.lang.String", null, null); + addPropertyMetadata("flyway.sql-migration-suffix", "java.lang.String", null, null); + addPropertyMetadata("flyway.table", "java.lang.String", null, null); + addPropertyMetadata("flyway.target", "org.flywaydb.core.api.MigrationVersion", null, null); + addPropertyMetadata("flyway.url", "java.lang.String", null, "JDBC url of the database to migrate. If not set, the primary configured data source\n is used."); + addPropertyMetadata("flyway.user", "java.lang.String", null, "Login user of the database to migrate."); + addPropertyMetadata("flyway.validate-on-migrate", "java.lang.Boolean", null, null); + addPropertyMetadata("http.mappers.json-pretty-print", "java.lang.Boolean", null, "Enable json pretty print."); + addPropertyMetadata("http.mappers.json-sort-keys", "java.lang.Boolean", null, "Enable key sorting."); + addPropertyMetadata("liquibase.change-log", "java.lang.String", "classpath:/db/changelog/db.changelog-master.yaml", "Change log configuration path."); + addPropertyMetadata("liquibase.check-change-log-location", "java.lang.Boolean", "true", "Check the change log location exists."); + addPropertyMetadata("liquibase.contexts", "java.lang.String", null, "Comma-separated list of runtime contexts to use."); + addPropertyMetadata("liquibase.default-schema", "java.lang.String", null, "Default database schema."); + addPropertyMetadata("liquibase.drop-first", "java.lang.Boolean", "false", "Drop the database schema first."); + addPropertyMetadata("liquibase.enabled", "java.lang.Boolean", "true", "Enable liquibase support."); + addPropertyMetadata("liquibase.password", "java.lang.String", null, "Login password of the database to migrate."); + addPropertyMetadata("liquibase.url", "java.lang.String", null, "JDBC url of the database to migrate. If not set, the primary configured data source\n is used."); + addPropertyMetadata("liquibase.user", "java.lang.String", null, "Login user of the database to migrate."); + addPropertyMetadata("logging.config", "java.lang.String", null, "Location of the logging configuration file."); + addPropertyMetadata("logging.file", "java.lang.String", null, "Log file name."); + addPropertyMetadata("logging.level", "java.util.Map", null, "Log levels severity mapping. Use 'root' for the root logger."); + addPropertyMetadata("logging.path", "java.lang.String", null, "Location of the log file."); + addPropertyMetadata("multipart.file-size-threshold", "java.lang.String", "0", "Threshold after which files will be written to disk. Values can use the suffixed\n \"MB\" or \"KB\" to indicate a Megabyte or Kilobyte size."); + addPropertyMetadata("multipart.location", "java.lang.String", null, "Intermediate location of uploaded files."); + addPropertyMetadata("multipart.max-file-size", "java.lang.String", "1Mb", "Max file size. Values can use the suffixed \"MB\" or \"KB\" to indicate a Megabyte or\n Kilobyte size."); + addPropertyMetadata("multipart.max-request-size", "java.lang.String", "10Mb", "Max request size. Values can use the suffixed \"MB\" or \"KB\" to indicate a Megabyte\n or Kilobyte size."); + addPropertyMetadata("security.basic.enabled", "java.lang.Boolean", "true", "Enable basic authentication."); + addPropertyMetadata("security.basic.path", "java.lang.String[]", "[Ljava.lang.Object;@7abd0056", "Comma-separated list of paths to secure."); + addPropertyMetadata("security.basic.realm", "java.lang.String", "Spring", "HTTP basic realm name."); + addPropertyMetadata("security.enable-csrf", "java.lang.Boolean", "false", "Enable Cross Site Request Forgery support."); + addPropertyMetadata("security.filter-order", "java.lang.Integer", "0", "Security filter chain order."); + addPropertyMetadata("security.headers.cache", "java.lang.Boolean", "false", "Enable cache control HTTP headers."); + addPropertyMetadata("security.headers.content-type", "java.lang.Boolean", "false", "Enable \"X-Content-Type-Options\" header."); + addPropertyMetadata("security.headers.frame", "java.lang.Boolean", "false", "Enable \"X-Frame-Options\" header."); + addPropertyMetadata("security.headers.hsts", "org.springframework.boot.autoconfigure.security.SecurityProperties$Headers$HSTS", null, "HTTP Strict Transport Security (HSTS) mode (none, domain, all)."); + addPropertyMetadata("security.headers.xss", "java.lang.Boolean", "false", "Enable cross site scripting (XSS) protection."); + addPropertyMetadata("security.ignored", "java.util.List", null, "Comma-separated list of paths to exclude from the default secured paths."); + addPropertyMetadata("security.require-ssl", "java.lang.Boolean", "false", "Enable secure channel for all requests."); + addPropertyMetadata("security.sessions", "org.springframework.security.config.http.SessionCreationPolicy", null, "Session creation policy (always, never, if_required, stateless)."); + addPropertyMetadata("security.user.name", "java.lang.String", "user", "Default user name."); + addPropertyMetadata("security.user.password", "java.lang.String", null, "Password for the default user name."); + addPropertyMetadata("security.user.role", "java.util.List", null, "Granted roles for the default user name."); + addPropertyMetadata("server.address", "java.net.InetAddress", null, "Network address to which the server should bind to."); + addPropertyMetadata("server.context-parameters", "java.util.Map", null, "ServletContext parameters."); + addPropertyMetadata("server.context-path", "java.lang.String", null, "Context path of the application."); + addPropertyMetadata("server.port", "java.lang.Integer", null, "Server HTTP port."); + addPropertyMetadata("server.servlet-path", "java.lang.String", "/", "Path of the main dispatcher servlet."); + addPropertyMetadata("server.session-timeout", "java.lang.Integer", null, "Session timeout in seconds."); + addPropertyMetadata("server.ssl.ciphers", "java.lang.String[]", null, null); + addPropertyMetadata("server.ssl.client-auth", "org.springframework.boot.context.embedded.Ssl$ClientAuth", null, null); + addPropertyMetadata("server.ssl.key-alias", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.key-password", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.key-store", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.key-store-password", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.key-store-provider", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.key-store-type", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.protocol", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.trust-store", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.trust-store-password", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.trust-store-provider", "java.lang.String", null, null); + addPropertyMetadata("server.ssl.trust-store-type", "java.lang.String", null, null); + addPropertyMetadata("server.tomcat.access-log-enabled", "java.lang.Boolean", "false", "Enable access log."); + addPropertyMetadata("server.tomcat.access-log-pattern", "java.lang.String", null, "Format pattern for access logs."); + addPropertyMetadata("server.tomcat.background-processor-delay", "java.lang.Integer", "30", "Delay in seconds between the invocation of backgroundProcess methods."); + addPropertyMetadata("server.tomcat.basedir", "java.io.File", null, "Tomcat base directory. If not specified a temporary directory will be used."); + addPropertyMetadata("server.tomcat.internal-proxies", "java.lang.String", "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|192\\.168\\.\\d{1,3}\\.\\d{1,3}|169\\.254\\.\\d{1,3}\\.\\d{1,3}|127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", "Regular expression that matches proxies that are to be trusted."); + addPropertyMetadata("server.tomcat.max-http-header-size", "java.lang.Integer", "0", "Maximum size in bytes of the HTTP message header."); + addPropertyMetadata("server.tomcat.max-threads", "java.lang.Integer", "0", "Maximum amount of worker threads."); + addPropertyMetadata("server.tomcat.port-header", "java.lang.String", null, "Name of the HTTP header used to override the original port value."); + addPropertyMetadata("server.tomcat.protocol-header", "java.lang.String", null, "Header that holds the incoming protocol, usually named \"X-Forwarded-Proto\".\n Configured as a RemoteIpValve only if remoteIpHeader is also set."); + addPropertyMetadata("server.tomcat.remote-ip-header", "java.lang.String", null, "Name of the http header from which the remote ip is extracted. Configured as a\n RemoteIpValve only if remoteIpHeader is also set."); + addPropertyMetadata("server.tomcat.uri-encoding", "java.lang.String", null, "Character encoding to use to decode the URI."); + addPropertyMetadata("server.undertow.buffer-size", "java.lang.Integer", null, "Size of each buffer in bytes."); + addPropertyMetadata("server.undertow.buffers-per-region", "java.lang.Integer", null, "Number of buffer per region."); + addPropertyMetadata("server.undertow.direct-buffers", "java.lang.Boolean", null, null); + addPropertyMetadata("server.undertow.io-threads", "java.lang.Integer", null, "Number of I/O threads to create for the worker."); + addPropertyMetadata("server.undertow.worker-threads", "java.lang.Integer", null, "Number of worker threads."); + addPropertyMetadata("spring.activemq.broker-url", "java.lang.String", null, "URL of the ActiveMQ broker. Auto-generated by default."); + addPropertyMetadata("spring.activemq.in-memory", "java.lang.Boolean", "true", "Specify if the default broker URL should be in memory. Ignored if an explicit\n broker has been specified."); + addPropertyMetadata("spring.activemq.password", "java.lang.String", null, "Login password of the broker."); + addPropertyMetadata("spring.activemq.pooled", "java.lang.Boolean", "false", "Specify if a PooledConnectionFactory should be created instead of a regular\n ConnectionFactory."); + addPropertyMetadata("spring.activemq.user", "java.lang.String", null, "Login user of the broker."); + addPropertyMetadata("spring.aop.auto", "java.lang.Boolean", "true", "Add @EnableAspectJAutoProxy."); + addPropertyMetadata("spring.aop.proxy-target-class", "java.lang.Boolean", "false", "Whether subclass-based (CGLIB) proxies are to be created (true) as opposed to standard Java interface-based proxies (false)."); + addPropertyMetadata("spring.application.index", "java.lang.Integer", null, "Application index."); + addPropertyMetadata("spring.application.name", "java.lang.String", null, "Application name."); + addPropertyMetadata("spring.batch.initializer.enabled", "java.lang.Boolean", "true", "Create the required batch tables on startup if necessary."); + addPropertyMetadata("spring.batch.job.enabled", "java.lang.Boolean", "true", "Execute all Spring Batch jobs in the context on startup."); + addPropertyMetadata("spring.batch.job.names", "java.lang.String", "", "Comma-separated list of job names to execute on startup. By default, all Jobs\n found in the context are executed."); + addPropertyMetadata("spring.batch.schema", "java.lang.String", "classpath:org/springframework/batch/core/schema-@@platform@@.sql", "Path to the SQL file to use to initialize the database schema."); + addPropertyMetadata("spring.config.location", "java.lang.String", null, "Config file locations."); + addPropertyMetadata("spring.config.name", "java.lang.String", "application", "Config file name."); + addPropertyMetadata("spring.dao.exceptiontranslation.enabled", "java.lang.Boolean", "true", "Enable the PersistenceExceptionTranslationPostProcessor."); + addPropertyMetadata("spring.data.elasticsearch.cluster-name", "java.lang.String", "elasticsearch", "Elasticsearch cluster name."); + addPropertyMetadata("spring.data.elasticsearch.cluster-nodes", "java.lang.String", null, "Comma-separated list of cluster node addresses. If not specified, starts a client\n node."); + addPropertyMetadata("spring.data.elasticsearch.repositories.enabled", "java.lang.Boolean", "true", "Enable Elasticsearch repositories."); + addPropertyMetadata("spring.data.jpa.repositories.enabled", "java.lang.Boolean", "true", "Enable JPA repositories."); + addPropertyMetadata("spring.data.mongodb.authentication-database", "java.lang.String", null, "Authentication database name."); + addPropertyMetadata("spring.data.mongodb.database", "java.lang.String", null, "Database name."); + addPropertyMetadata("spring.data.mongodb.grid-fs-database", "java.lang.String", null, "GridFS database name."); + addPropertyMetadata("spring.data.mongodb.host", "java.lang.String", null, "Mongo server host."); + addPropertyMetadata("spring.data.mongodb.password", "char[]", null, "Login password of the mongo server."); + addPropertyMetadata("spring.data.mongodb.port", "java.lang.Integer", null, "Mongo server port."); + addPropertyMetadata("spring.data.mongodb.repositories.enabled", "java.lang.Boolean", "true", "Enable Mongo repositories."); + addPropertyMetadata("spring.data.mongodb.uri", "java.lang.String", "mongodb://localhost/test", "Mmongo database URI. When set, host and port are ignored."); + addPropertyMetadata("spring.data.mongodb.username", "java.lang.String", null, "Login user of the mongo server."); + addPropertyMetadata("spring.data.rest.base-uri", "java.net.URI", null, null); + addPropertyMetadata("spring.data.rest.default-page-size", "java.lang.Integer", null, null); + addPropertyMetadata("spring.data.rest.limit-param-name", "java.lang.String", null, null); + addPropertyMetadata("spring.data.rest.max-page-size", "java.lang.Integer", null, null); + addPropertyMetadata("spring.data.rest.page-param-name", "java.lang.String", null, null); + addPropertyMetadata("spring.data.rest.return-body-on-create", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.data.rest.return-body-on-update", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.data.rest.sort-param-name", "java.lang.String", null, null); + addPropertyMetadata("spring.data.solr.host", "java.lang.String", "http://127.0.0.1:8983/solr", "Solr host. Ignored if \"zk-host\" is set."); + addPropertyMetadata("spring.data.solr.repositories.enabled", "java.lang.Boolean", "true", "Enable Solr repositories."); + addPropertyMetadata("spring.data.solr.zk-host", "java.lang.String", null, "ZooKeeper host address in the form HOST:PORT."); + addPropertyMetadata("spring.datasource.abandon-when-percentage-full", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.access-to-underlying-connection-allowed", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.alternate-username-allowed", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.auto-commit", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.catalog", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.commit-on-return", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.connection-customizer-class-name", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.connection-init-sql", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.connection-init-sqls", "java.util.Collection", null, null); + addPropertyMetadata("spring.datasource.connection-properties", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.connection-test-query", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.connection-timeout", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.continue-on-error", "java.lang.Boolean", "false", "Do not stop if an error occurs while initializing the database."); + addPropertyMetadata("spring.datasource.data", "java.lang.String", null, "Data (DML) script resource reference."); + addPropertyMetadata("spring.datasource.data-source-class-name", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.data-source", "java.lang.Object", null, null); + addPropertyMetadata("spring.datasource.data-source-j-n-d-i", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.data-source-properties", "java.util.Properties", null, null); + addPropertyMetadata("spring.datasource.db-properties", "java.util.Properties", null, null); + addPropertyMetadata("spring.datasource.default-auto-commit", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.default-catalog", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.default-read-only", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.default-transaction-isolation", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.driver-class-name", "java.lang.String", null, "Fully qualified name of the JDBC driver. Auto-detected based on the URL by default."); + addPropertyMetadata("spring.datasource.fair-queue", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.idle-timeout", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.ignore-exception-on-pre-load", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.initialization-fail-fast", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.initialize", "java.lang.Boolean", "true", "Populate the database using 'data.sql'."); + addPropertyMetadata("spring.datasource.initial-size", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.init-s-q-l", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.isolate-internal-queries", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.jdbc4-connection-test", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.jdbc-interceptors", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.jdbc-url", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.jmx-enabled", "java.lang.Boolean", "false", "Enable JMX support (if provided by the underlying pool)."); + addPropertyMetadata("spring.datasource.jndi-name", "java.lang.String", null, "JNDI location of the datasource. Class, url, username & password are ignored when\n set."); + addPropertyMetadata("spring.datasource.leak-detection-threshold", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.log-abandoned", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.login-timeout", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.log-validation-errors", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.max-active", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.max-age", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.max-idle", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.maximum-pool-size", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.max-lifetime", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.max-open-prepared-statements", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.max-wait", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.metric-registry", "java.lang.Object", null, null); + addPropertyMetadata("spring.datasource.min-evictable-idle-time-millis", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.min-idle", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.minimum-idle", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.name", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.num-tests-per-eviction-run", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.password", "java.lang.String", null, "Login password of the database."); + addPropertyMetadata("spring.datasource.platform", "java.lang.String", "all", "Platform to use in the schema resource (schema-${platform}.sql)."); + addPropertyMetadata("spring.datasource.pool-name", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.pool-prepared-statements", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.propagate-interrupt-state", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.read-only", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.register-mbeans", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.remove-abandoned", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.remove-abandoned-timeout", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.rollback-on-return", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.schema", "java.lang.String", null, "Schema (DDL) script resource reference."); + addPropertyMetadata("spring.datasource.separator", "java.lang.String", ";", "Statement separator in SQL initialization scripts."); + addPropertyMetadata("spring.datasource.sql-script-encoding", "java.lang.String", null, "SQL scripts encoding."); + addPropertyMetadata("spring.datasource.suspect-timeout", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.test-on-borrow", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.test-on-connect", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.test-on-return", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.test-while-idle", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.time-between-eviction-runs-millis", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.transaction-isolation", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.url", "java.lang.String", null, "JDBC url of the database."); + addPropertyMetadata("spring.datasource.use-disposable-connection-facade", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.use-equals", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.use-lock", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.datasource.username", "java.lang.String", null, "Login user of the database."); + addPropertyMetadata("spring.datasource.validation-interval", "java.lang.Long", null, null); + addPropertyMetadata("spring.datasource.validation-query", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.validation-query-timeout", "java.lang.Integer", null, null); + addPropertyMetadata("spring.datasource.validator-class-name", "java.lang.String", null, null); + addPropertyMetadata("spring.datasource.xa.data-source-class-name", "java.lang.String", null, "XA datasource fully qualified name."); + addPropertyMetadata("spring.datasource.xa.properties", "java.util.Map", null, "Properties to pass to the XA data source."); + addPropertyMetadata("spring.freemarker.allow-request-override", "java.lang.Boolean", null, "Set whether HttpServletRequest attributes are allowed to override (hide) controller\n generated model attributes of the same name."); + addPropertyMetadata("spring.freemarker.cache", "java.lang.Boolean", null, "Enable template caching."); + addPropertyMetadata("spring.freemarker.char-set", "java.lang.String", null, null); + addPropertyMetadata("spring.freemarker.charset", "java.lang.String", null, "Template encoding."); + addPropertyMetadata("spring.freemarker.check-template-location", "java.lang.Boolean", null, "Check that the templates location exists."); + addPropertyMetadata("spring.freemarker.content-type", "java.lang.String", null, "Content-Type value."); + addPropertyMetadata("spring.freemarker.enabled", "java.lang.Boolean", null, "Enable MVC view resolution for this technology."); + addPropertyMetadata("spring.freemarker.expose-request-attributes", "java.lang.Boolean", null, "Set whether all request attributes should be added to the model prior to merging\n with the template."); + addPropertyMetadata("spring.freemarker.expose-session-attributes", "java.lang.Boolean", null, "Set whether all HttpSession attributes should be added to the model prior to\n merging with the template."); + addPropertyMetadata("spring.freemarker.expose-spring-macro-helpers", "java.lang.Boolean", null, "Set whether to expose a RequestContext for use by Spring's macro library, under the\n name \"springMacroRequestContext\"."); + addPropertyMetadata("spring.freemarker.prefix", "java.lang.String", null, "Prefix that gets prepended to view names when building a URL."); + addPropertyMetadata("spring.freemarker.request-context-attribute", "java.lang.String", null, "Name of the RequestContext attribute for all views."); + addPropertyMetadata("spring.freemarker.settings", "java.util.Map", null, "Well-known FreeMarker keys which will be passed to FreeMarker's Configuration."); + addPropertyMetadata("spring.freemarker.suffix", "java.lang.String", null, "Suffix that gets appended to view names when building a URL."); + addPropertyMetadata("spring.freemarker.template-loader-path", "java.lang.String[]", new String[] {"snuzzle" ,"buggles"}, "Comma-separated list of template paths."); + addPropertyMetadata("spring.freemarker.view-names", "java.lang.String[]", null, "White list of view names that can be resolved."); + addPropertyMetadata("spring.groovy.template.cache", "java.lang.Boolean", null, "Enable template caching."); + addPropertyMetadata("spring.groovy.template.char-set", "java.lang.String", null, null); + addPropertyMetadata("spring.groovy.template.charset", "java.lang.String", null, "Template encoding."); + addPropertyMetadata("spring.groovy.template.check-template-location", "java.lang.Boolean", null, "Check that the templates location exists."); + addPropertyMetadata("spring.groovy.template.configuration.auto-escape", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.configuration.auto-indent", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.configuration.auto-indent-string", "java.lang.String", null, null); + addPropertyMetadata("spring.groovy.template.configuration.auto-new-line", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.configuration.base-template-class", "java.lang.Class", null, null); + addPropertyMetadata("spring.groovy.template.configuration.cache-templates", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.configuration.declaration-encoding", "java.lang.String", null, null); + addPropertyMetadata("spring.groovy.template.configuration.expand-empty-elements", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.configuration", "java.util.Map", null, "Configuration to pass to TemplateConfiguration."); + addPropertyMetadata("spring.groovy.template.configuration.locale", "java.util.Locale", null, null); + addPropertyMetadata("spring.groovy.template.configuration.new-line-string", "java.lang.String", null, null); + addPropertyMetadata("spring.groovy.template.configuration.resource-loader-path", "java.lang.String", null, null); + addPropertyMetadata("spring.groovy.template.configuration.use-double-quotes", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.groovy.template.content-type", "java.lang.String", null, "Content-Type value."); + addPropertyMetadata("spring.groovy.template.enabled", "java.lang.Boolean", null, "Enable MVC view resolution for this technology."); + addPropertyMetadata("spring.groovy.template.prefix", "java.lang.String", "classpath:/templates/", "Prefix that gets prepended to view names when building a URL."); + addPropertyMetadata("spring.groovy.template.suffix", "java.lang.String", ".tpl", "Suffix that gets appended to view names when building a URL."); + addPropertyMetadata("spring.groovy.template.view-names", "java.lang.String[]", null, "White list of view names that can be resolved."); + addPropertyMetadata("spring.hornetq.embedded.cluster-password", "java.lang.String", null, "Cluster password. Randomly generated on startup by default"); + addPropertyMetadata("spring.hornetq.embedded.data-directory", "java.lang.String", null, "Journal file directory. Not necessary if persistence is turned off."); + addPropertyMetadata("spring.hornetq.embedded.enabled", "java.lang.Boolean", "true", "Enable embedded mode if the HornetQ server APIs are available."); + addPropertyMetadata("spring.hornetq.embedded.persistent", "java.lang.Boolean", "false", "Enable persistent store."); + addPropertyMetadata("spring.hornetq.embedded.queues", "java.lang.String[]", "[Ljava.lang.Object;@2f5ce114", "Comma-separate list of queues to create on startup."); + addPropertyMetadata("spring.hornetq.embedded.server-id", "java.lang.Integer", "0", "Server id. By default, an auto-incremented counter is used."); + addPropertyMetadata("spring.hornetq.embedded.topics", "java.lang.String[]", "[Ljava.lang.Object;@6272137a", "Comma-separate list of topics to create on startup."); + addPropertyMetadata("spring.hornetq.host", "java.lang.String", "localhost", "HornetQ broker host."); + addPropertyMetadata("spring.hornetq.mode", "org.springframework.boot.autoconfigure.jms.hornetq.HornetQMode", null, "HornetQ deployment mode, auto-detected by default. Can be explicitly set to\n \"native\" or \"embedded\"."); + addPropertyMetadata("spring.hornetq.port", "java.lang.Integer", "5445", "HornetQ broker port."); + addPropertyMetadata("spring.http.encoding.charset", "java.nio.charset.Charset", null, "Charset of HTTP requests and responses. Added to the \"Content-Type\" header if not\n set explicitly."); + addPropertyMetadata("spring.http.encoding.enabled", "java.lang.Boolean", "true", "Enable http encoding support."); + addPropertyMetadata("spring.http.encoding.force", "java.lang.Boolean", "true", "Force the encoding to the configured charset on HTTP requests and responses."); + addPropertyMetadata("spring.jackson.date-format", "java.lang.String", null, "Date format string (yyyy-MM-dd HH:mm:ss), or a fully-qualified date format class\n name."); + addPropertyMetadata("spring.jackson.deserialization", "java.util.Map", null, "Jackson on/off features that affect the way Java objects are deserialized."); + addPropertyMetadata("spring.jackson.generator", "java.util.Map", null, "Jackson on/off features for generators."); + addPropertyMetadata("spring.jackson.mapper", "java.util.Map", null, "Jackson general purpose on/off features."); + addPropertyMetadata("spring.jackson.parser", "java.util.Map", null, "Jackson on/off features for parsers."); + addPropertyMetadata("spring.jackson.property-naming-strategy", "java.lang.String", null, "One of the constants on Jackson's PropertyNamingStrategy\n (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES). Can also be a fully-qualified class\n name of a PropertyNamingStrategy subclass."); + addPropertyMetadata("spring.jackson.serialization", "java.util.Map", null, "Jackson on/off features that affect the way Java objects are serialized."); + addPropertyMetadata("spring.jersey.filter.order", "java.lang.Integer", "0", "Jersey filter chain order."); + addPropertyMetadata("spring.jersey.init", "java.util.Map", null, "Init parameters to pass to Jersey."); + addPropertyMetadata("spring.jersey.type", "org.springframework.boot.autoconfigure.jersey.JerseyProperties$Type", null, "Jersey integration type. Can be either \"servlet\" or \"filter\"."); + addPropertyMetadata("spring.jms.jndi-name", "java.lang.String", null, "Connection factory JNDI name. When set, takes precedence to others connection\n factory auto-configurations."); + addPropertyMetadata("spring.jms.pub-sub-domain", "java.lang.Boolean", "false", "Specify if the default destination type is topic."); + addPropertyMetadata("spring.jmx.enabled", "java.lang.Boolean", "true", "Expose management beans to the JMX domain."); + addPropertyMetadata("spring.jpa.database", "org.springframework.orm.jpa.vendor.Database", null, "Target database to operate on, auto-detected by default. Can be alternatively set\n using the \"databasePlatform\" property."); + addPropertyMetadata("spring.jpa.database-platform", "java.lang.String", null, "Name of the target database to operate on, auto-detected by default. Can be\n alternatively set using the \"Database\" enum."); + addPropertyMetadata("spring.jpa.generate-ddl", "java.lang.Boolean", "false", "Initialize the schema on startup."); + addPropertyMetadata("spring.jpa.hibernate.ddl-auto", "java.lang.String", null, "DDL mode (\"none\", \"validate\", \"update\", \"create\", \"create-drop\"). This is\n actually a shortcut for the \"hibernate.hbm2ddl.auto\" property. Default to\n \"create-drop\" when using an embedded database, \"none\" otherwise."); + addPropertyMetadata("spring.jpa.hibernate.naming-strategy", "java.lang.Class", null, "Naming strategy fully qualified name."); + addPropertyMetadata("spring.jpa.open-in-view", "java.lang.Boolean", "true", "Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for the entire processing of the request."); + addPropertyMetadata("spring.jpa.properties", "java.util.Map", null, "Additional native properties to set on the JPA provider."); + addPropertyMetadata("spring.jpa.show-sql", "java.lang.Boolean", "false", "Enable logging of SQL statements."); + addPropertyMetadata("spring.jta.allow-multiple-lrc", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.asynchronous2-pc", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.background-recovery-interval", "java.lang.Integer", null, null); + addPropertyMetadata("spring.jta.background-recovery-interval-seconds", "java.lang.Integer", null, null); + addPropertyMetadata("spring.jta.current-node-only-recovery", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.debug-zero-resource-transaction", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.default-transaction-timeout", "java.lang.Integer", null, null); + addPropertyMetadata("spring.jta.disable-jmx", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.enabled", "java.lang.Boolean", "true", "Enable JTA support."); + addPropertyMetadata("spring.jta.exception-analyzer", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.filter-log-status", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.force-batching-enabled", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.forced-write-enabled", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.graceful-shutdown-interval", "java.lang.Integer", null, null); + addPropertyMetadata("spring.jta.jndi-transaction-synchronization-registry-name", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.jndi-user-transaction-name", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.journal", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.log-dir", "java.lang.String", null, "Transaction logs directory."); + addPropertyMetadata("spring.jta.log-part1-filename", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.log-part2-filename", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.max-log-size-in-mb", "java.lang.Integer", null, null); + addPropertyMetadata("spring.jta.resource-configuration-filename", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.server-id", "java.lang.String", null, null); + addPropertyMetadata("spring.jta.skip-corrupted-logs", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.jta.transaction-manager-id", "java.lang.String", null, "Transaction manager unique identifier."); + addPropertyMetadata("spring.jta.warn-about-zero-resource-transaction", "java.lang.Boolean", null, null); + addPropertyMetadata("spring.mail.default-encoding", "java.lang.String", "UTF-8", "Default MimeMessage encoding."); + addPropertyMetadata("spring.mail.host", "java.lang.String", null, "SMTP server host."); + addPropertyMetadata("spring.mail.password", "java.lang.String", null, "Login password of the SMTP server."); + addPropertyMetadata("spring.mail.port", "java.lang.Integer", null, "SMTP server port."); + addPropertyMetadata("spring.mail.properties", "java.util.Map", null, "Additional JavaMail session properties."); + addPropertyMetadata("spring.mail.username", "java.lang.String", null, "Login user of the SMTP server."); + addPropertyMetadata("spring.main.show-banner", "java.lang.Boolean", "true", "Display the banner when the application runs."); + addPropertyMetadata("spring.main.sources", "java.util.Set", null, "Sources (class name, package name or XML resource location) used to create the ApplicationContext."); + addPropertyMetadata("spring.main.web-environment", "java.lang.Boolean", null, "Run the application in a web environment (auto-detected by default)."); + addPropertyMetadata("spring.mandatory-file-encoding", "java.lang.String", null, "Expected character encoding the application must use."); + addPropertyMetadata("spring.messages.basename", "java.lang.String", "messages", "Comma-separated list of basenames, each following the ResourceBundle convention.\n Essentially a fully-qualified classpath location. If it doesn't contain a package\n qualifier (such as \"org.mypackage\"), it will be resolved from the classpath root."); + addPropertyMetadata("spring.messages.cache-seconds", "java.lang.Integer", "-1", "Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles\n are cached forever."); + addPropertyMetadata("spring.messages.encoding", "java.lang.String", "utf-8", "Message bundles encoding."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.enabled", "java.lang.Boolean", "false", "Enable device view resolver."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.mobile-prefix", "java.lang.String", "mobile/", "Prefix that gets prepended to view names for mobile devices."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.mobile-suffix", "java.lang.String", "", "Suffix that gets appended to view names for mobile devices."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.normal-prefix", "java.lang.String", "", "Prefix that gets prepended to view names for normal devices."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.normal-suffix", "java.lang.String", "", "Suffix that gets appended to view names for normal devices."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.tablet-prefix", "java.lang.String", "tablet/", "Prefix that gets prepended to view names for tablet devices."); + addPropertyMetadata("spring.mobile.devicedelegatingviewresolver.tablet-suffix", "java.lang.String", "", "Suffix that gets appended to view names for tablet devices."); + addPropertyMetadata("spring.mobile.sitepreference.enabled", "java.lang.Boolean", "true", "Enable SitePreferenceHandler."); + addPropertyMetadata("spring.mvc.date-format", "java.lang.String", null, "Date format to use (e.g. dd/MM/yyyy)"); + addPropertyMetadata("spring.mvc.ignore-default-model-on-redirect", "java.lang.Boolean", "true", "If the the content of the \"default\" model should be ignored during redirect\n scenarios."); + addPropertyMetadata("spring.mvc.locale", "java.lang.String", null, "Locale to use."); + addPropertyMetadata("spring.mvc.message-codes-resolver-format", "org.springframework.validation.DefaultMessageCodesResolver$Format", null, "Formatting strategy for message codes (PREFIX_ERROR_CODE, POSTFIX_ERROR_CODE)."); + addPropertyMetadata("spring.profiles.active", "java.lang.String", null, "Comma-separated list of active profiles. Can be overridden by a command line switch."); + addPropertyMetadata("spring.profiles.include", "java.lang.String", null, "Unconditionally activate the specified comma separated profiles."); + addPropertyMetadata("spring.rabbitmq.addresses", "java.lang.String", null, "Comma-separated list of addresses to which the client should connect to."); + addPropertyMetadata("spring.rabbitmq.dynamic", "java.lang.Boolean", "true", "Create an AmqpAdmin bean."); + addPropertyMetadata("spring.rabbitmq.host", "java.lang.String", "localhost", "RabbitMQ host."); + addPropertyMetadata("spring.rabbitmq.password", "java.lang.String", null, "Login to authenticate against the broker."); + addPropertyMetadata("spring.rabbitmq.port", "java.lang.Integer", "5672", "RabbitMQ port."); + addPropertyMetadata("spring.rabbitmq.username", "java.lang.String", null, "Login user to authenticate to the broker."); + addPropertyMetadata("spring.rabbitmq.virtual-host", "java.lang.String", null, "Virtual host to use when connecting to the broker."); + addPropertyMetadata("spring.redis.database", "java.lang.Integer", "0", "Database index used by the connection factory."); + addPropertyMetadata("spring.redis.host", "java.lang.String", "localhost", "Redis server host."); + addPropertyMetadata("spring.redis.password", "java.lang.String", null, "Login password of the redis server."); + addPropertyMetadata("spring.redis.pool.max-active", "java.lang.Integer", "8", "Max number of connections that can be allocated by the pool at a given time.\n Use a negative value for no limit."); + addPropertyMetadata("spring.redis.pool.max-idle", "java.lang.Integer", "8", "Max number of \"idle\" connections in the pool. Use a negative value to indicate\n an unlimited number of idle connections."); + addPropertyMetadata("spring.redis.pool.max-wait", "java.lang.Integer", "-1", "Maximum amount of time (in milliseconds) a connection allocation should block\n before throwing an exception when the pool is exhausted. Use a negative value\n to block indefinitely."); + addPropertyMetadata("spring.redis.pool.min-idle", "java.lang.Integer", "0", "Target for the minimum number of idle connections to maintain in the pool. This\n setting only has an effect if it is positive."); + addPropertyMetadata("spring.redis.port", "java.lang.Integer", "6379", "Redis server port."); + addPropertyMetadata("spring.redis.sentinel.master", "java.lang.String", null, "Name of Redis server."); + addPropertyMetadata("spring.redis.sentinel.nodes", "java.lang.String", null, "Comma-separated list of host:port pairs."); + addPropertyMetadata("spring.resources.add-mappings", "java.lang.Boolean", "true", "Enable default resource handling."); + addPropertyMetadata("spring.resources.cache-period", "java.lang.Integer", null, "Cache period for the resources served by the resource handler, in seconds."); + addPropertyMetadata("spring.social.auto-connection-views", "java.lang.Boolean", "false", "Enable the connection status view for supported providers."); + addPropertyMetadata("spring.social.facebook.app-id", "java.lang.String", null, "Application id."); + addPropertyMetadata("spring.social.facebook.app-secret", "java.lang.String", null, "Application secret."); + addPropertyMetadata("spring.social.linkedin.app-id", "java.lang.String", null, "Application id."); + addPropertyMetadata("spring.social.linkedin.app-secret", "java.lang.String", null, "Application secret."); + addPropertyMetadata("spring.social.twitter.app-id", "java.lang.String", null, "Application id."); + addPropertyMetadata("spring.social.twitter.app-secret", "java.lang.String", null, "Application secret."); + addPropertyMetadata("spring.thymeleaf.cache", "java.lang.Boolean", "true", "Enable template caching."); + addPropertyMetadata("spring.thymeleaf.check-template-location", "java.lang.Boolean", "true", "Check that the templates location exists."); + addPropertyMetadata("spring.thymeleaf.content-type", "java.lang.String", "text/html", "Content-Type value."); + addPropertyMetadata("spring.thymeleaf.enabled", "java.lang.Boolean", "true", "Enable MVC Thymeleaf view resolution."); + addPropertyMetadata("spring.thymeleaf.encoding", "java.lang.String", "UTF-8", "Template encoding."); + addPropertyMetadata("spring.thymeleaf.excluded-view-names", "java.lang.String[]", null, "Comma-separated list of view names that should be excluded from resolution."); + addPropertyMetadata("spring.thymeleaf.mode", "java.lang.String", "HTML5", "Template mode to be applied to templates. See also StandardTemplateModeHandlers."); + addPropertyMetadata("spring.thymeleaf.prefix", "java.lang.String", "classpath:/templates/", "Prefix that gets prepended to view names when building a URL."); + addPropertyMetadata("spring.thymeleaf.suffix", "java.lang.String", ".html", "Suffix that gets appended to view names when building a URL."); + addPropertyMetadata("spring.thymeleaf.view-names", "java.lang.String[]", null, "Comma-separated list of view names that can be resolved."); + addPropertyMetadata("spring.velocity.allow-request-override", "java.lang.Boolean", null, "Set whether HttpServletRequest attributes are allowed to override (hide) controller\n generated model attributes of the same name."); + addPropertyMetadata("spring.velocity.cache", "java.lang.Boolean", null, "Enable template caching."); + addPropertyMetadata("spring.velocity.char-set", "java.lang.String", null, null); + addPropertyMetadata("spring.velocity.charset", "java.lang.String", null, "Template encoding."); + addPropertyMetadata("spring.velocity.check-template-location", "java.lang.Boolean", null, "Check that the templates location exists."); + addPropertyMetadata("spring.velocity.content-type", "java.lang.String", null, "Content-Type value."); + addPropertyMetadata("spring.velocity.date-tool-attribute", "java.lang.String", null, "Name of the DateTool helper object to expose in the Velocity context of the view."); + addPropertyMetadata("spring.velocity.enabled", "java.lang.Boolean", null, "Enable MVC view resolution for this technology."); + addPropertyMetadata("spring.velocity.expose-request-attributes", "java.lang.Boolean", null, "Set whether all request attributes should be added to the model prior to merging\n with the template."); + addPropertyMetadata("spring.velocity.expose-session-attributes", "java.lang.Boolean", null, "Set whether all HttpSession attributes should be added to the model prior to\n merging with the template."); + addPropertyMetadata("spring.velocity.expose-spring-macro-helpers", "java.lang.Boolean", null, "Set whether to expose a RequestContext for use by Spring's macro library, under the\n name \"springMacroRequestContext\"."); + addPropertyMetadata("spring.velocity.number-tool-attribute", "java.lang.String", null, "Name of the NumberTool helper object to expose in the Velocity context of the view."); + addPropertyMetadata("spring.velocity.prefer-file-system-access", "java.lang.Boolean", "true", "Prefer file system access for template loading. File system access enables hot\n detection of template changes."); + addPropertyMetadata("spring.velocity.prefix", "java.lang.String", null, "Prefix that gets prepended to view names when building a URL."); + addPropertyMetadata("spring.velocity.properties", "java.util.Map", null, "Additional velocity properties."); + addPropertyMetadata("spring.velocity.request-context-attribute", "java.lang.String", null, "Name of the RequestContext attribute for all views."); + addPropertyMetadata("spring.velocity.resource-loader-path", "java.lang.String", "classpath:/templates/", "Template path."); + addPropertyMetadata("spring.velocity.suffix", "java.lang.String", null, "Suffix that gets appended to view names when building a URL."); + addPropertyMetadata("spring.velocity.toolbox-config-location", "java.lang.String", null, "Velocity Toolbox config location, for example \"/WEB-INF/toolbox.xml\". Automatically\n loads a Velocity Tools toolbox definition file and expose all defined tools in the\n specified scopes."); + addPropertyMetadata("spring.velocity.view-names", "java.lang.String[]", null, "White list of view names that can be resolved."); + addPropertyMetadata("spring.view.prefix", "java.lang.String", null, "Spring MVC view prefix."); + addPropertyMetadata("spring.view.suffix", "java.lang.String", null, "Spring MVC view suffix."); + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeParserTest.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeParserTest.java new file mode 100644 index 000000000..b968394d2 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeParserTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.boot.properties.metadata; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.springframework.ide.vscode.application.properties.metadata.types.Type; +import org.springframework.ide.vscode.application.properties.metadata.types.TypeParser; + +/** + * Type parser tests + * + * @author Kris De Volder + */ +public class TypeParserTest { + + @Test + public void testNonGeneric() throws Exception { + Type type = TypeParser.parse("java.lang.String"); + assertEquals("java.lang.String", type.getErasure()); + assertFalse(type.isGeneric()); + assertEquals("java.lang.String", type.toString()); + } + + @Test + public void testSimpleGeneric() throws Exception { + Type type = TypeParser.parse("List"); + assertEquals("List", type.getErasure()); + assertTrue(type.isGeneric()); + + Type[] params = type.getParams(); + assertEquals(1, params.length); + type = params[0]; + assertEquals("Foo", type.getErasure()); + assertFalse(type.isGeneric()); + } + + @Test + public void testMultipleParams() throws Exception { + Type type = TypeParser.parse("Map"); + assertEquals("Map", type.getErasure()); + assertTrue(type.isGeneric()); + + Type[] params = type.getParams(); + assertEquals(2, params.length); + + type = params[0]; + assertEquals("Foo", type.getErasure()); + assertFalse(type.isGeneric()); + + type = params[1]; + assertEquals("Bar", type.getErasure()); + assertFalse(type.isGeneric()); + } + + @Test + public void testNestedGenerics() throws Exception { + Type type = TypeParser.parse("Map>"); + assertEquals("Map", type.getErasure()); + assertTrue(type.isGeneric()); + + assertEquals("Map>", type.toString()); + } + + @Test + public void testTypeEquality() throws Exception { + Type type1 = TypeParser.parse("Map>"); + Type type2 = TypeParser.parse("Map>"); + Type type3 = TypeParser.parse("Map>"); + assertEquals(type1, type2); + assertNotEquals(type1, type3); + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeUtilTest.java b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeUtilTest.java new file mode 100644 index 000000000..789370a96 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/java/org/springframework/ide/vscode/boot/properties/metadata/TypeUtilTest.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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.boot.properties.metadata; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Test; +import org.springframework.ide.vscode.application.properties.metadata.types.Type; +import org.springframework.ide.vscode.application.properties.metadata.types.TypeParser; +import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil; +import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtil.BeanPropertyNameMode; +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; + +/** + * Tests for TypeUtil + * + * TODO: {@link IJavaProject#findType(String)} (or IClasspath#findType(String)) needs to be implemented then uncomment the tests! + * + * @author Kris De Volder + * @author Alex Boyko + * + */ +public class TypeUtilTest { + + private IJavaProject project; + private TypeUtil typeUtil; + + private Type getPropertyType(Type type, String propName, EnumCaseMode enumMode, BeanPropertyNameMode beanMode) { + List props = getProperties(type, enumMode, beanMode); + for (TypedProperty prop : props) { + if (prop.getName().equals(propName)) { + return prop.getType(); + } + } + return null; + } + + private List getProperties(Type type, EnumCaseMode enumMode, BeanPropertyNameMode beanMode) { + return typeUtil.getProperties(type, enumMode, beanMode); + } + +// @Test + public void testGetTrickyProperties() throws Exception { + useProject("tricky-getters-boot-1.3.1-app"); + List props = getProperties(TypeParser.parse("demo.TrickyGetters"), EnumCaseMode.LOWER_CASE, BeanPropertyNameMode.HYPHENATED); + List names = props.stream().map(p -> p.getName()).collect(Collectors.toList()); + assertEquals(1, names.size()); + assertEquals("public-property", names.get(0)); + } + +// @Test + public void testGetProperties() throws Exception { + useProject("enums-boot-1.3.2-app"); + assertNotNull(project.findType("demo.Color")); + assertNotNull(project.findType("demo.ColorData")); + + + Type data = TypeParser.parse("demo.ColorData"); + + assertType("java.lang.Double", + getPropertyType(data, "wavelen")); + assertType("java.lang.String", + getPropertyType(data, "name")); + assertType("demo.Color", + getPropertyType(data, "next")); + assertType("demo.ColorData", + getPropertyType(data, "nested")); + assertType("java.util.List", + getPropertyType(data, "tags")); + assertType("java.util.Map", + getPropertyType(data, "mapped-children")); + assertType("java.util.Map", + getPropertyType(data, "color-children")); + + //Also gets aliased as camelCased names? + assertType("java.util.Map", + getPropertyType(data, "colorChildren")); + assertType("java.util.Map", + getPropertyType(data, "mappedChildren")); + + //Gets aliased names only if asked for it? + assertType("java.util.Map", + getPropertyType(data, "mappedChildren", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.CAMEL_CASE)); + assertType(null, + getPropertyType(data, "mappedChildren", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.HYPHENATED)); + assertType(null, + getPropertyType(data, "mapped-children", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.CAMEL_CASE)); + assertType("java.util.Map", + getPropertyType(data, "mapped-children", EnumCaseMode.ORIGNAL, BeanPropertyNameMode.HYPHENATED)); + + } + +// @Test + public void testGetEnumKeyedProperties() throws Exception { + useProject("enums-boot-1.3.2-app"); + Type data = TypeParser.parse("java.util.Map"); + assertType("Something", getPropertyType(data, "red")); + assertType("Something", getPropertyType(data, "green")); + assertType("Something", getPropertyType(data, "blue")); + assertType("Something", getPropertyType(data, "RED")); + assertType("Something", getPropertyType(data, "GREEN")); + assertType("Something", getPropertyType(data, "BLUE")); + assertNull(getPropertyType(data, "not-a-color")); + } + + private Type getPropertyType(Type type, String propName) { + return getPropertyType(type, propName, EnumCaseMode.ALIASED, BeanPropertyNameMode.ALIASED); + } + + private void assertType(String expectedType, Type actualType) { + assertEquals(TypeParser.parse(expectedType), actualType); + } + +// @Test + public void testTypeFromSignature() throws Exception { + useProject("enums-boot-1.3.2-app"); + assertType("java.lang.String", Type.fromSignature("QString;", project.findType("demo.ColorData"))); + assertType("java.lang.String", Type.fromSignature("Ljava.lang.String;", project.findType("demo.ColorData"))); + assertType("java.lang.String[]", Type.fromSignature("[Ljava.lang.String;", project.findType("demo.ColorData"))); + assertType("java.lang.String[]", Type.fromSignature("[QString;", project.findType("demo.ColorData"))); + } + + private void useProject(String name) throws Exception { + project = Projects.createMavenJavaProject(ProjectsHarness.buildMavenProject(name));; + typeUtil = new TypeUtil(project); + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.jar b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 000000000..c6feb8bb6 Binary files /dev/null and b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.jar differ diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.properties b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 000000000..6637cedb2 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/manifest.yml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/manifest.yml new file mode 100644 index 000000000..e69de29bb diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw new file mode 100755 index 000000000..6ecc150ae --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw @@ -0,0 +1,236 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # + # Look for the Apple JDKs first to preserve the existing behaviour, and then look + # for the new JDKs provided by Oracle. + # + if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then + # + # Apple JDKs + # + export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then + # + # Apple JDKs + # + export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then + # + # Oracle JDKs + # + export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then + # + # Apple JDKs + # + export JAVA_HOME=`/usr/libexec/java_home` + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + local basedir=$(pwd) + local wdir=$(pwd) + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + wdir=$(cd "$wdir/.."; pwd) + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@ +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw.cmd b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw.cmd new file mode 100644 index 000000000..8bb827541 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/mvnw.cmd @@ -0,0 +1,146 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %* +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/pom.xml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/pom.xml new file mode 100644 index 000000000..a10fb0a6b --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + org.test + enums-boot-1.3.2-app + 0.0.1-SNAPSHOT + jar + + demo-enum + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.3.2.RELEASE + + + + + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ClothingSize.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ClothingSize.java new file mode 100644 index 000000000..eb02fd757 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ClothingSize.java @@ -0,0 +1,9 @@ +package demo; + +public enum ClothingSize { + EXTRA_SMALL, + SMALL, + MEDIUM, + LARGE, + EXTRA_LARGE +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/Color.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/Color.java new file mode 100644 index 000000000..e5c7aa3ef --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/Color.java @@ -0,0 +1,16 @@ +package demo; + +public enum Color { + /** + * Hot and delicious. + */ + RED, + /** + * A gardener's favourite. + */ + GREEN, + /** + * Cool and refreshing. + */ + BLUE +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ColorData.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ColorData.java new file mode 100644 index 000000000..de21e3894 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/ColorData.java @@ -0,0 +1,90 @@ +package demo; + +import java.util.List; +import java.util.Map; + +public class ColorData { + + /** + * Wavelength of the color in nano meters (JavaDoc from field). + */ + private double wavelen; + private String name; + private Color next; + private ColorData nested; + private List children; + private List tags; + private Map mappedChildren; + private boolean funky; + + /** + * Children of this node organized by color + */ + private Map colorChildren; + + public double getWavelen() { + return wavelen; + } + /** + * Set the Wavelength of the color in nano meters. + */ + public void setWavelen(double wavelen) { + this.wavelen = wavelen; + } + public String getName() { + return name; + } + + /** + * Set the name of the color. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the next color + */ + public Color getNext() { + return next; + } + public void setNext(Color next) { + this.next = next; + } + public List getChildren() { + return children; + } + public void setChildren(List children) { + this.children = children; + } + public ColorData getNested() { + return nested; + } + public void setNested(ColorData nested) { + this.nested = nested; + } + public Map getMappedChildren() { + return mappedChildren; + } + public void setMappedChildren(Map mappedChildren) { + this.mappedChildren = mappedChildren; + } + public Map getColorChildren() { + return colorChildren; + } + public void setColorChildren(Map colorChildren) { + this.colorChildren = colorChildren; + } + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + public boolean isFunky() { + return funky; + } + public void setFunky(boolean funky) { + this.funky = funky; + } +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/DemoEnumApplication.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/DemoEnumApplication.java new file mode 100644 index 000000000..b484e936f --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/DemoEnumApplication.java @@ -0,0 +1,43 @@ +package demo; + +import java.util.Map.Entry; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +@SpringBootApplication +@EnableConfigurationProperties +public class DemoEnumApplication implements CommandLineRunner { + + public static void main(String[] args) { + SpringApplication.run(DemoEnumApplication.class, args); + } + + + @Autowired + FooProperties foo; + + @Override + public void run(String... arg0) throws Exception { + System.out.println("Today I'm feeling... "+foo.getColor()); + + System.out.println("---- name-colors ----"); + for (Entry e : foo.getNameColors().entrySet()) { + System.out.println(e.getKey() +" -> "+ e.getValue()); + } + + System.out.println("---- color-names ----"); + for (Entry e : foo.getColorNames().entrySet()) { + System.out.println(e.getKey() +" -> "+ e.getValue()); + } + + System.out.println("---- list ----"); + for (String string : foo.getList()) { + System.out.println(string); + } + + } +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/FooProperties.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/FooProperties.java new file mode 100644 index 000000000..0177267a5 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/java/demo/FooProperties.java @@ -0,0 +1,70 @@ +package demo; + +import java.util.List; +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties("foo") +public class FooProperties { + + /** + * Pojo + */ + private ColorData data; + + //Enum + private Color color; + + //Map Enum -> Atomic + private Map colorNames; + + //Map Atomic -> Enum + private Map nameColors; + + //Map Enum -> Pojo + private Map colorData; + + //List + private List list; + + public Color getColor() { + return color; + } + public void setColor(Color color) { + this.color = color; + } + + public Map getColorNames() { + return colorNames; + } + public void setColorNames(Map colorNames) { + this.colorNames = colorNames; + } + public Map getNameColors() { + return nameColors; + } + public void setNameColors(Map nameColors) { + this.nameColors = nameColors; + } + public Map getColorData() { + return colorData; + } + public void setColorData(Map colorData) { + this.colorData = colorData; + } + public ColorData getData() { + return data; + } + public void setData(ColorData data) { + this.data = data; + } + public List getList() { + return list; + } + public void setList(List list) { + this.list = list; + } +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application-prod.properties b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application-prod.properties new file mode 100644 index 000000000..54acdceb7 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application-prod.properties @@ -0,0 +1,23 @@ +foo.color-data.RED.wavelen=5.0 +foo.color-data.RED.name=Rood +foo.color-data.RED.next=RED + +foo.color-data.red.next=green + +foo.color-data.red.children[0].mapped-children.jeff.tags=abc,def +foo.color-data.red.colorChildren.green.nested.children[0].name=Yowza + +foo.colorData.red.next=green + +foo.data.wavelen=4.0 + +foo.data.wavelen.crap=3.0 + +foo.color-data.red.wavelen=3.0 + +foo.color-names.red=Red +foo.data.next=red + +foo.color-data.green.children[0].color-children.green.next=green + +foo.color= \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application-prod.yml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application-prod.yml new file mode 100644 index 000000000..e69de29bb diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.properties b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.properties new file mode 100644 index 000000000..efb5188f3 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.properties @@ -0,0 +1,27 @@ +foo.color-data.RED.wavelen=5.0 +foo.color-data.RED.name=Rood +foo.color-data.RED.next=RED + +foo.color-data.red.next=green + +foo.color-data.red.children[0].mapped-children.jeff.tags=abc,def +foo.color-data.red.colorChildren.green.nested.children[0].name=Yowza + +foo.color= + +foo.colorData.red.next=green + +foo.data.wavelen=4.0 + +foo.data.wavelen.crap=3.0 + +foo.color-data.red.wavelen=3.0 + +foo.color-names.red=Red +foo.data.next=red + +foo.color-data.green.children[0].color-children.green.next=green + +server.port=888 + +foo.color-data.green.wavelen= diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.yml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.yml new file mode 100644 index 000000000..3f049a8cc --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/enums-boot-1.3.2-app/src/main/resources/application.yml @@ -0,0 +1,42 @@ +# Demonstrating the new STS Support for +# Spring Boot Configuration files in .yml format +# What you see here will be available in STS 3.7.0 + +# Features: +# 1) content assist completions +# 2) problem markers +# 3) information hovers +# 4) hyperlink to Java code +# AND +# alwo works for user-defined Configurations, including those where properties +# are bound to +# - enums, +# - Pojo (Beans) +# - lists, +# - Maps + +spring: + cloud: + config: + application: + name: foo + index: 777 + activemq: + broker-url: amqp://sdfksdfkjdsf + +flyway: + enabled: false +server: + port: 666 + address: localhost + +foo: + list: + - aaa + - the be + - and c + data: + color-names: + red: Rood + name-colors: + "Rood kleurtje": red \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.jar b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 000000000..c6feb8bb6 Binary files /dev/null and b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.jar differ diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.properties b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 000000000..6637cedb2 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw new file mode 100755 index 000000000..6ecc150ae --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw @@ -0,0 +1,236 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # + # Look for the Apple JDKs first to preserve the existing behaviour, and then look + # for the new JDKs provided by Oracle. + # + if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then + # + # Apple JDKs + # + export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then + # + # Apple JDKs + # + export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then + # + # Oracle JDKs + # + export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home + fi + + if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then + # + # Apple JDKs + # + export JAVA_HOME=`/usr/libexec/java_home` + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + local basedir=$(pwd) + local wdir=$(pwd) + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + wdir=$(cd "$wdir/.."; pwd) + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@ +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw.cmd b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw.cmd new file mode 100644 index 000000000..8bb827541 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/mvnw.cmd @@ -0,0 +1,146 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %* +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/pom.xml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/pom.xml new file mode 100644 index 000000000..732a6acf6 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.test + 0.0.1-SNAPSHOT + jar + + demo + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.3.1.RELEASE + + + + + UTF-8 + demo.DemoApplication + 1.7 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + tricky-getters-boot-1.3.1-app + diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/CamelCaser.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/CamelCaser.java new file mode 100644 index 000000000..3013de912 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/CamelCaser.java @@ -0,0 +1,34 @@ +package demo; + +public class CamelCaser { + + private int theAnswerToEverything; + + private CamelCaser theLeft; + private CamelCaser theRight; + + public int getTheAnswerToEverything() { + return theAnswerToEverything; + } + + public void setTheAnswerToEverything(int theAnswerToEverything) { + this.theAnswerToEverything = theAnswerToEverything; + } + + public CamelCaser getTheLeft() { + return theLeft; + } + + public void setTheLeft(CamelCaser theLeft) { + this.theLeft = theLeft; + } + + public CamelCaser getTheRight() { + return theRight; + } + + public void setTheRight(CamelCaser theRight) { + this.theRight = theRight; + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/DemoApplication.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/DemoApplication.java new file mode 100644 index 000000000..950618750 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/DemoApplication.java @@ -0,0 +1,16 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan +@EnableAutoConfiguration +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/Deprecater.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/Deprecater.java new file mode 100644 index 000000000..30f0ecc08 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/Deprecater.java @@ -0,0 +1,42 @@ +package demo; + +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; + +public class Deprecater { + + private String newName; + @Deprecated private String name; + + private String altName; + + /////////////////// + + + @Deprecated + public String getName() { + return name; + } + + @Deprecated + public void setName(String oldName) { + this.name = oldName; + } + + public String getNewName() { + return newName; + } + + public void setNewName(String newName) { + this.newName = newName; + } + + public void setAltName(String name) { + altName = name; + } + + @DeprecatedConfigurationProperty(reason="No good anymore", replacement="something.else") + public String getAltName() { + return altName; + } + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/TrickyGetters.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/TrickyGetters.java new file mode 100644 index 000000000..e11e331ca --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/java/demo/TrickyGetters.java @@ -0,0 +1,34 @@ +package demo; + +public class TrickyGetters { + + private static String staticProperty; + private String privateProperty; + private String publicProperty; + + private String getPrivateProperty() { + return privateProperty; + } + + private void setPrivateProperty(String privateProperty) { + this.privateProperty = privateProperty; + } + + public static String getStaticProperty() { + return staticProperty; + } + + public static void setStaticProperty(String staticProperty) { + TrickyGetters.staticProperty = staticProperty; + } + + public String getPublicProperty() { + return publicProperty; + } + + public void setPublicProperty(String publicProperty) { + this.publicProperty = publicProperty; + } + + +} diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.properties b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.properties new file mode 100644 index 000000000..80c6377d9 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.properties @@ -0,0 +1 @@ +debug=true \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.yml b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.yml new file mode 100644 index 000000000..80c6377d9 --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/main/resources/application.yml @@ -0,0 +1 @@ +debug=true \ No newline at end of file diff --git a/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/test/java/demo/DemoApplicationTests.java b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/test/java/demo/DemoApplicationTests.java new file mode 100644 index 000000000..1b7f22d5d --- /dev/null +++ b/vscode-extensions/commons/application-properties-metadata/src/test/resources/tricky-getters-boot-1.3.1-app/src/test/java/demo/DemoApplicationTests.java @@ -0,0 +1,18 @@ +package demo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = DemoApplication.class) +@WebAppConfiguration +public class DemoApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/JavaProjectWithClasspathFileFinderStrategy.java b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/JavaProjectWithClasspathFileFinderStrategy.java index af78258a8..ce42cf3a6 100644 --- a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/JavaProjectWithClasspathFileFinderStrategy.java +++ b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/JavaProjectWithClasspathFileFinderStrategy.java @@ -1,44 +1,44 @@ -/******************************************************************************* - * 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.languageserver.java; - -import java.io.File; -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.classpathfile.JavaProjectWithClasspathFile; -import org.springframework.ide.vscode.commons.util.FileUtils; -import org.springframework.ide.vscode.commons.util.StringUtil; - -public class JavaProjectWithClasspathFileFinderStrategy implements IJavaProjectFinderStrategy { - - @Override - public JavaProjectWithClasspathFile find(IDocument d) { - String uriStr = d.getUri(); - if (StringUtil.hasText(uriStr)) { - try { - 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, MavenCore.CLASSPATH_TXT); - if (cpFile!=null) { - return new JavaProjectWithClasspathFile(cpFile); - } - } catch (URISyntaxException | IllegalArgumentException e) { - //garbage data. Ignore it. - } - } - return null; - } - -} +/******************************************************************************* + * 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.languageserver.java; + +import java.io.File; +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.java.classpathfile.JavaProjectWithClasspathFile; +import org.springframework.ide.vscode.commons.util.FileUtils; +import org.springframework.ide.vscode.commons.util.StringUtil; + +public class JavaProjectWithClasspathFileFinderStrategy implements IJavaProjectFinderStrategy { + + @Override + public JavaProjectWithClasspathFile find(IDocument d) { + String uriStr = d.getUri(); + if (StringUtil.hasText(uriStr)) { + try { + 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); + if (cpFile!=null) { + return new JavaProjectWithClasspathFile(cpFile); + } + } catch (URISyntaxException | IllegalArgumentException e) { + //garbage data. Ignore it. + } + } + return null; + } + +} diff --git a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/MavenProjectFinderStrategy.java b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/MavenProjectFinderStrategy.java index 889bc0285..07404bd15 100644 --- a/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/MavenProjectFinderStrategy.java +++ b/vscode-extensions/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/java/MavenProjectFinderStrategy.java @@ -1,52 +1,52 @@ -/******************************************************************************* - * 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.languageserver.java; - -import java.io.File; -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.util.FileUtils; -import org.springframework.ide.vscode.commons.util.StringUtil; - -/** - * Finds Maven Project based - * - * @author Alex Boyko - * - */ -public class MavenProjectFinderStrategy implements IJavaProjectFinderStrategy { - - @Override - public MavenJavaProject find(IDocument d) { - String uriStr = d.getUri(); - if (StringUtil.hasText(uriStr)) { - try { - 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, MavenCore.POM_XML); - if (pomFile!=null) { - return new MavenJavaProject(pomFile); - } - } catch (URISyntaxException | IllegalArgumentException e) { - //garbage data. Ignore it. - } catch (Exception e) { - //TODO: Erroneous Pom file. Ignore it? Log? - } - } - return null; - } - -} +/******************************************************************************* + * 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.languageserver.java; + +import java.io.File; +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.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; + +/** + * Finds Maven Project based + * + * @author Alex Boyko + * + */ +public class MavenProjectFinderStrategy implements IJavaProjectFinderStrategy { + + @Override + public MavenJavaProject find(IDocument d) { + String uriStr = d.getUri(); + if (StringUtil.hasText(uriStr)) { + try { + 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); + if (pomFile!=null) { + return new MavenJavaProject(pomFile); + } + } catch (URISyntaxException | IllegalArgumentException e) { + //garbage data. Ignore it. + } catch (Exception e) { + //TODO: Erroneous Pom file. Ignore it? Log? + } + } + return null; + } + +} diff --git a/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/MavenCore.java b/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/MavenCore.java index 4ad436dd9..66d18752d 100644 --- a/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/MavenCore.java +++ b/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/MavenCore.java @@ -1,198 +1,195 @@ -/******************************************************************************* - * 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; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.model.DependencyManagement; -import org.apache.maven.project.MavenProject; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.ArtifactTypeRegistry; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.collection.DependencyCollectionException; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.repository.LocalRepositoryManager; -import org.eclipse.aether.util.filter.ScopeDependencyFilter; -import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; -import org.eclipse.aether.util.graph.transformer.ConflictResolver; -import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver; -import org.eclipse.aether.util.graph.transformer.JavaScopeSelector; -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; - -/** - * Maven Core functionality - * - * @author Alex Boyko - * - */ -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(); - - public static MavenCore getInstance() { - if (instance == null) { - instance = new MavenCore(); - } - return instance; - } - - /** - * Reads maven classpath text file - * - * @param classPathFilePath - * @return set of classpath entries - * @throws IOException - */ - public static Set readClassPathFile(Path classPathFilePath) throws IOException { - InputStream in = Files.newInputStream(classPathFilePath); - String text = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining()); - Path dir = classPathFilePath.getParent(); - return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet()); - } - - /** - * Creates Maven Project descriptor based on the pom file. - * - * @param pom The pom file - * @return Maven project instance - * @throws MavenException - */ - public MavenProject readProject(File pom) throws MavenException { - return maven.readProject(pom, maven.createExecutionRequest()); - } - - /** - * Taken from M2E same named method from MavenModelManager - * - * @param repositorySystem - * @param repositorySession - * @param mavenProject - * @param scope - * @return - */ - private DependencyNode readDependencyTree(org.eclipse.aether.RepositorySystem repositorySystem, - RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) { - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession); - - ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), - new SimpleOptionalitySelector(), new JavaScopeDeriver()); - session.setDependencyGraphTransformer(transformer); - session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true)); - session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); - - ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); - - CollectRequest request = new CollectRequest(); - request.setRequestContext("project"); //$NON-NLS-1$ - request.setRepositories(mavenProject.getRemoteProjectRepositories()); - - for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) { - request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes)); - } - - DependencyManagement depMngt = mavenProject.getDependencyManagement(); - if (depMngt != null) { - for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) { - request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes)); - } - } - - DependencyNode node; - try { - node = repositorySystem.collectDependencies(session, request).getRoot(); - } catch (DependencyCollectionException ex) { - node = ex.getResult().getRoot(); - } - - Collection scopes = new HashSet(); - Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, - Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST); - if (Artifact.SCOPE_COMPILE.equals(scope)) { - scopes.remove(Artifact.SCOPE_COMPILE); - scopes.remove(Artifact.SCOPE_SYSTEM); - scopes.remove(Artifact.SCOPE_PROVIDED); - } else if (Artifact.SCOPE_RUNTIME.equals(scope)) { - scopes.remove(Artifact.SCOPE_COMPILE); - scopes.remove(Artifact.SCOPE_RUNTIME); - } else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) { - scopes.remove(Artifact.SCOPE_COMPILE); - scopes.remove(Artifact.SCOPE_SYSTEM); - scopes.remove(Artifact.SCOPE_PROVIDED); - scopes.remove(Artifact.SCOPE_RUNTIME); - } else { - scopes.clear(); - } - - CloningDependencyVisitor cloner = new CloningDependencyVisitor(); - node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes))); - node = cloner.getRootNode(); - - return node; - } - - /** - * Calculates dependency graph for a Maven project provided the scope. - * - * @param project Maven Project descriptor - * @param scope Dependency scope - * @return Set of all dependencies including transient ones - * @throws MavenException - */ - public Set resolveDependencies(MavenProject project, String scope) throws MavenException { - Set artifacts = new LinkedHashSet<>(); - - MavenExecutionRequest request = maven.createExecutionRequest(); - DefaultRepositorySystemSession session = maven.createRepositorySession(request); - - DependencyNode graph = readDependencyTree(maven.lookupComponent(org.eclipse.aether.RepositorySystem.class), session, project, scope); - if (graph != null) { - RepositoryUtils.toArtifacts(artifacts, graph.getChildren(), - Collections.singletonList(project.getArtifact().getId()), null); - - // Maven 2.x quirk: an artifact always points at the local repo, - // regardless whether resolved or not - LocalRepositoryManager lrm = session.getLocalRepositoryManager(); - for (Artifact artifact : artifacts) { - if (!artifact.isResolved()) { - String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact)); - artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); - } - } - } - - return artifacts; - } -} +/******************************************************************************* + * 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; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.maven.RepositoryUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.model.DependencyManagement; +import org.apache.maven.project.MavenProject; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.ArtifactTypeRegistry; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.collection.DependencyCollectionException; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.util.filter.ScopeDependencyFilter; +import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; +import org.eclipse.aether.util.graph.transformer.ConflictResolver; +import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver; +import org.eclipse.aether.util.graph.transformer.JavaScopeSelector; +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; + +/** + * Maven Core functionality + * + * @author Alex Boyko + * + */ +public class MavenCore { + + private static MavenCore instance = null; + + private MavenBridge maven = new MavenBridge(); + + public static MavenCore getInstance() { + if (instance == null) { + instance = new MavenCore(); + } + return instance; + } + + /** + * Reads maven classpath text file + * + * @param classPathFilePath + * @return set of classpath entries + * @throws IOException + */ + public static Set readClassPathFile(Path classPathFilePath) throws IOException { + InputStream in = Files.newInputStream(classPathFilePath); + String text = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining()); + Path dir = classPathFilePath.getParent(); + return Arrays.stream(text.split(File.pathSeparator)).map(dir::resolve).collect(Collectors.toSet()); + } + + /** + * Creates Maven Project descriptor based on the pom file. + * + * @param pom The pom file + * @return Maven project instance + * @throws MavenException + */ + public MavenProject readProject(File pom) throws MavenException { + return maven.readProject(pom, maven.createExecutionRequest()); + } + + /** + * Taken from M2E same named method from MavenModelManager + * + * @param repositorySystem + * @param repositorySession + * @param mavenProject + * @param scope + * @return + */ + private DependencyNode readDependencyTree(org.eclipse.aether.RepositorySystem repositorySystem, + RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) { + DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession); + + ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), + new SimpleOptionalitySelector(), new JavaScopeDeriver()); + session.setDependencyGraphTransformer(transformer); + session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true)); + session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); + + ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); + + CollectRequest request = new CollectRequest(); + request.setRequestContext("project"); //$NON-NLS-1$ + request.setRepositories(mavenProject.getRemoteProjectRepositories()); + + for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) { + request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes)); + } + + DependencyManagement depMngt = mavenProject.getDependencyManagement(); + if (depMngt != null) { + for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) { + request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes)); + } + } + + DependencyNode node; + try { + node = repositorySystem.collectDependencies(session, request).getRoot(); + } catch (DependencyCollectionException ex) { + node = ex.getResult().getRoot(); + } + + Collection scopes = new HashSet(); + Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST); + if (Artifact.SCOPE_COMPILE.equals(scope)) { + scopes.remove(Artifact.SCOPE_COMPILE); + scopes.remove(Artifact.SCOPE_SYSTEM); + scopes.remove(Artifact.SCOPE_PROVIDED); + } else if (Artifact.SCOPE_RUNTIME.equals(scope)) { + scopes.remove(Artifact.SCOPE_COMPILE); + scopes.remove(Artifact.SCOPE_RUNTIME); + } else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) { + scopes.remove(Artifact.SCOPE_COMPILE); + scopes.remove(Artifact.SCOPE_SYSTEM); + scopes.remove(Artifact.SCOPE_PROVIDED); + scopes.remove(Artifact.SCOPE_RUNTIME); + } else { + scopes.clear(); + } + + CloningDependencyVisitor cloner = new CloningDependencyVisitor(); + node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes))); + node = cloner.getRootNode(); + + return node; + } + + /** + * Calculates dependency graph for a Maven project provided the scope. + * + * @param project Maven Project descriptor + * @param scope Dependency scope + * @return Set of all dependencies including transient ones + * @throws MavenException + */ + public Set resolveDependencies(MavenProject project, String scope) throws MavenException { + Set artifacts = new LinkedHashSet<>(); + + MavenExecutionRequest request = maven.createExecutionRequest(); + DefaultRepositorySystemSession session = maven.createRepositorySession(request); + + DependencyNode graph = readDependencyTree(maven.lookupComponent(org.eclipse.aether.RepositorySystem.class), session, project, scope); + if (graph != null) { + RepositoryUtils.toArtifacts(artifacts, graph.getChildren(), + Collections.singletonList(project.getArtifact().getId()), null); + + // Maven 2.x quirk: an artifact always points at the local repo, + // regardless whether resolved or not + LocalRepositoryManager lrm = session.getLocalRepositoryManager(); + for (Artifact artifact : artifacts) { + if (!artifact.isResolved()) { + String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact)); + artifact.setFile(new File(lrm.getRepository().getBasedir(), path)); + } + } + } + + return artifacts; + } +} diff --git a/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/Projects.java b/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/Projects.java new file mode 100644 index 000000000..005a7a5ad --- /dev/null +++ b/vscode-extensions/commons/commons-maven/src/main/java/org/springframework/ide/vscode/commons/maven/java/Projects.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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()); + } + +} diff --git a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java index 691f55776..4c5618b0a 100644 --- a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java +++ b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/DependencyTreeTest.java @@ -1,45 +1,46 @@ -package org.springframework.ide.vscode.commons.maven; - -/******************************************************************************* - * 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 - *******************************************************************************/ -import static org.junit.Assert.assertEquals; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.maven.project.MavenProject; -import org.junit.Test; -import org.springframework.ide.vscode.project.harness.Projects; - -/** - * Tests for comparing maven calculated dependencies with ours - * - * @author Alex Boyko - * - */ -public class DependencyTreeTest { - - @Test - public void mavenTest() throws Exception { - Path testProjectPath = Projects.buildMavenProject("empty-boot-project-with-classpath-file"); - - MavenProject project = MavenCore.getInstance().readProject(testProjectPath.resolve(MavenCore.POM_XML).toFile()); - Set calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> { - return Paths.get(artifact.getFile().toURI()); - }).collect(Collectors.toSet());; - - Set expectedClasspath = MavenCore.readClassPathFile(testProjectPath.resolve(MavenCore.CLASSPATH_TXT)); - assertEquals(expectedClasspath, calculatedClassPath); - } - -} +package org.springframework.ide.vscode.commons.maven; + +/******************************************************************************* + * 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 + *******************************************************************************/ +import static org.junit.Assert.assertEquals; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; +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 + * + * @author Alex Boyko + * + */ +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()); + Set calculatedClassPath = MavenCore.getInstance().resolveDependencies(project, null).stream().map(artifact -> { + return Paths.get(artifact.getFile().toURI()); + }).collect(Collectors.toSet());; + + Set expectedClasspath = MavenCore.readClassPathFile(testProjectPath.resolve(Projects.CLASSPATH_TXT)); + assertEquals(expectedClasspath, calculatedClassPath); + } + +} diff --git a/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/MockYamlEditor.java b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/MockYamlEditor.java new file mode 100644 index 000000000..665206a08 --- /dev/null +++ b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/MockYamlEditor.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * 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.yaml.structure; + +import static org.junit.Assert.assertTrue; + +import org.springframework.ide.vscode.commons.languageserver.util.TextDocument; +import org.springframework.ide.vscode.commons.yaml.ast.YamlASTProvider; +import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST; +import org.springframework.ide.vscode.commons.yaml.ast.YamlParser; +import org.springframework.ide.vscode.commons.yaml.structure.YamlDocument; +import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.nodes.Node; +import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode; +import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode; + +/** + * Yaml editor mock for the tests. + * + * @author Alex Boyko + * + */ +class MockYamlEditor { + + private Yaml yaml; + private YamlASTProvider parser; + + private String text; + + public MockYamlEditor(String string) throws Exception { + this.text = string; + this.yaml = new Yaml(); + this.parser = new YamlParser(yaml); + } + + @Override + public String toString() { + return "YamlEditor("+text+")"; + } + + public SRootNode parseStructure() throws Exception { + YamlStructureProvider sp = YamlStructureProvider.DEFAULT; + TextDocument _doc = new TextDocument(null); + _doc.setText(text); + YamlDocument doc = new YamlDocument(_doc, sp); + return sp.getStructure(doc); + } + + public YamlFileAST parse() throws Exception { + TextDocument _doc = new TextDocument(null); + _doc.setText(text); + return parser.getAST(_doc); + } + + public String getRawText() { + return text; + } + + public String getText() { + //No cursor support, not needed for these tests. + return getRawText(); + } + + public int startOf(String snippet) { + int start = text.indexOf(snippet); + assertTrue("Snippet not found in editor '"+snippet+"'", start>=0); + return start; + } + + public int middleOf(String nodeText) { + int start = startOf(nodeText); + if (start>=0) { + return start + nodeText.length()/2; + } + return -1; + } + + public int endOf(String nodeText) { + int start = startOf(nodeText); + if (start>=0) { + return start+nodeText.length(); + } + return -1; + } + + public String textBetween(int start, int end) { + return text.substring(start, end); + } + + public String textUnder(SNode node) throws Exception { + int start = node.getStart(); + int end = node.getTreeEnd(); + return textBetween(start, end); + } + + public String textUnder(Node node) throws Exception { + int start = node.getStartMark().getIndex(); + int end = node.getEndMark().getIndex(); + return textBetween(start, end); + } + +} \ No newline at end of file diff --git a/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlAstTest.java b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlAstTest.java new file mode 100644 index 000000000..0bb156de6 --- /dev/null +++ b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlAstTest.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2015, 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.yaml.structure; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; +import org.springframework.ide.vscode.commons.yaml.ast.NodeRef; +import org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST; +import org.yaml.snakeyaml.nodes.Node; + +/** + * Yaml AST tests + * + * @author Kris De Volder + * @author Alex Boyko + * + */ +public class YamlAstTest { + + /** + * Check that node at given offset exactly covers the expected text + * snippet in the document. + */ + public void assertNodeTextAt(MockYamlEditor input, int offset, String expectText) throws Exception { + YamlFileAST ast = input.parse(); + Node node = ast.findNode(offset); + String actualText = input.textUnder(node); + assertEquals(expectText, actualText); + } + + + @Test + public void testFindNode() throws Exception { + MockYamlEditor input = new MockYamlEditor( + "spring:\n" + + " application:\n" + + " name: foofoo\n" + + " \n" + + "server:\n" + + " port: 8888" + ); + doFindNodeTest(input, "foofoo"); + doFindNodeTest(input, "application"); + doFindNodeTest(input, "spring"); + doFindNodeTest(input, "port"); + doFindNodeTest(input, "server"); + } + + private void doFindNodeTest(MockYamlEditor input, String nodeText) throws Exception { + assertNodeTextAt(input, input.startOf(nodeText), nodeText); + assertNodeTextAt(input, input.endOf(nodeText)-1, nodeText); + assertNodeTextAt(input, input.middleOf(nodeText), nodeText); + } + + public void testFindPath() throws Exception { + MockYamlEditor input = new MockYamlEditor( + "foo:\n" + + " bar:\n" + + " first: foofoo\n" + + " second: barbar\n" + + " third: lalala\n" + + "server:\n" + + " port: 8888" + ); + + assertPath(input, "barbar", + "ROOT[0]@val['foo']@val['bar']@val['second']"); + + assertPath(input, "8888", + "ROOT[0]@val['server']@val['port']"); + } + + @Test + public void testMultiDocsPath() throws Exception { + MockYamlEditor input = new MockYamlEditor( + "theFirst\n" + + "---\n" + + "second\n" + + "...\n" + ); + assertPath(input, "First", + "ROOT[0]" + ); + assertPath(input, "second", + "ROOT[1]" + ); + } + + public void testSequencePath() throws Exception { + MockYamlEditor input = new MockYamlEditor( + "fooList:\n"+ + " - a\n" + + " - b\n" + + " - c\n" + ); + + assertPath(input, "a", + "ROOT[0]@val['fooList'][0]" + ); + assertPath(input, "b", + "ROOT[0]@val['fooList'][1]" + ); + assertPath(input, "c", + "ROOT[0]@val['fooList'][2]" + ); + } + + protected void assertPath(MockYamlEditor input, String nodeText, String expected) throws Exception { + YamlFileAST ast = input.parse(); + String path = pathString(ast.findPath(input.middleOf(nodeText))); + assertEquals(expected, path); + } + + + private String pathString(List> findPath) { + StringBuilder buf = new StringBuilder(); + for (NodeRef n : findPath) { + buf.append(n); + } + return buf.toString(); + } + +} diff --git a/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java index 2288a819e..2b0881287 100644 --- a/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java +++ b/vscode-extensions/commons/commons-yaml/src/test/java/org/springframework/ide/vscode/yaml/structure/YamlStructureParserTest.java @@ -21,12 +21,9 @@ import java.util.ArrayList; import java.util.regex.Pattern; import org.junit.Test; -import org.springframework.ide.vscode.commons.languageserver.util.TextDocument; import org.springframework.ide.vscode.commons.yaml.path.YamlPath; import org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment; -import org.springframework.ide.vscode.commons.yaml.structure.YamlDocument; import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser; -import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider; import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SChildBearingNode; import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SDocNode; import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SKeyNode; @@ -35,56 +32,8 @@ import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser public class YamlStructureParserTest { - static class YamlEditor { - - private String text; - - public YamlEditor(String string) throws Exception { - this.text = string; - } - - @Override - public String toString() { - return "YamlEditor("+text+")"; - } - - public SRootNode parseStructure() throws Exception { - YamlStructureProvider sp = YamlStructureProvider.DEFAULT; - TextDocument _doc = new TextDocument(null); - _doc.setText(text); - YamlDocument doc = new YamlDocument(_doc, sp); - return sp.getStructure(doc); - } - - public String getRawText() { - return text; - } - - public String getText() { - //No cursor support, not needed for these tests. - return getRawText(); - } - - public int startOf(String snippet) { - int start = text.indexOf(snippet); - assertTrue("Snippet not found in editor '"+snippet+"'", start>=0); - return start; - } - - public String textBetween(int start, int end) { - return text.substring(start, end); - } - - public String textUnder(SNode node) throws Exception { - int start = node.getStart(); - int end = node.getTreeEnd(); - return textBetween(start, end); - } - - } - @Test public void testSimple() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "hello:\n"+ " world:\n" + " message\n" @@ -99,7 +48,7 @@ public class YamlStructureParserTest { ); } - public void assertParse(YamlEditor editor, String... expectDumpLines) throws Exception { + public void assertParse(MockYamlEditor editor, String... expectDumpLines) throws Exception { StringBuilder expected = new StringBuilder(); for (String line : expectDumpLines) { expected.append(line); @@ -108,7 +57,7 @@ public class YamlStructureParserTest { assertEquals(expected.toString().trim(), editor.parseStructure().toString().trim()); } - public void assertParseOneDoc(YamlEditor editor, String... expectDumpLines) throws Exception { + public void assertParseOneDoc(MockYamlEditor editor, String... expectDumpLines) throws Exception { StringBuilder expected = new StringBuilder(); for (String line : expectDumpLines) { expected.append(line); @@ -118,7 +67,7 @@ public class YamlStructureParserTest { } @Test public void testComments() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "#A comment\n" + "hello:\n"+ " #Another comment\n" + @@ -137,7 +86,7 @@ public class YamlStructureParserTest { } @Test public void testSiblings() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -172,7 +121,7 @@ public class YamlStructureParserTest { } @Test public void testMultiDocs() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -215,10 +164,10 @@ public class YamlStructureParserTest { @Test public void testSequenceBasic() throws Exception { - YamlEditor editor; + MockYamlEditor editor; //Sequence at root level - editor = new YamlEditor( + editor = new MockYamlEditor( "- foo\n" + "- bar\n" + "- zor" @@ -231,7 +180,7 @@ public class YamlStructureParserTest { ); //Sequences nested in map without indent - editor = new YamlEditor( + editor = new MockYamlEditor( "something:\n" + "- foo\n" + "- bar\n" + @@ -252,7 +201,7 @@ public class YamlStructureParserTest { ); //Sequences nested in map without indent - editor = new YamlEditor( + editor = new MockYamlEditor( "higher:\n" + " something:\n" + " - foo\n" + @@ -275,7 +224,7 @@ public class YamlStructureParserTest { ); //Sequences nested in map with indent - editor = new YamlEditor( + editor = new MockYamlEditor( "something:\n" + " - foo\n" + " - bar\n" + @@ -298,10 +247,10 @@ public class YamlStructureParserTest { } @Test public void testKeyWithADot() throws Exception { - YamlEditor editor; + MockYamlEditor editor; //First try without a '.' - editor = new YamlEditor( + editor = new MockYamlEditor( "logging:\n" + " level:\n" + " somepackage: " @@ -313,7 +262,7 @@ public class YamlStructureParserTest { " KEY(4): somepackage:" ); - editor = new YamlEditor( + editor = new MockYamlEditor( "logging:\n" + " level:\n" + " some.package: " @@ -328,9 +277,9 @@ public class YamlStructureParserTest { } @Test public void testSequenceWithNestedSequence() throws Exception { - YamlEditor editor; + MockYamlEditor editor; - editor = new YamlEditor( + editor = new MockYamlEditor( "- - a\n" + " - b\n" + "- - c\n" + @@ -347,7 +296,7 @@ public class YamlStructureParserTest { " RAW(-1): " ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "- - a\n" + " - b\n" + @@ -365,7 +314,7 @@ public class YamlStructureParserTest { " SEQ(2): - d" ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "- - a\n" + " - b\n" + @@ -386,7 +335,7 @@ public class YamlStructureParserTest { " RAW(-1): " ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "- \n" + " - a\n" + @@ -406,7 +355,7 @@ public class YamlStructureParserTest { " SEQ(2): - d" ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "- - - - a\n" + " - b\n" + @@ -428,7 +377,7 @@ public class YamlStructureParserTest { " RAW(-1): " ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "- - - - a\n" + " - c\n" + @@ -449,10 +398,10 @@ public class YamlStructureParserTest { } @Test public void testSequenceWithNestedMap() throws Exception { - YamlEditor editor; + MockYamlEditor editor; // A map nested in a sequence may start on the same line - editor = new YamlEditor( + editor = new MockYamlEditor( "- foo: is foo\n" + " bar: is bar\n" + " junk\n" + @@ -472,7 +421,7 @@ public class YamlStructureParserTest { ); //A map nested in a sequence may start on a new line - editor = new YamlEditor( + editor = new MockYamlEditor( "-\n"+ //without space " foo: is foo\n" + " bar: is bar\n" + @@ -492,7 +441,7 @@ public class YamlStructureParserTest { " KEY(2): b: bbb" ); - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n" + "-\n"+ //without space " foo: is foo\n" + @@ -516,7 +465,7 @@ public class YamlStructureParserTest { } @Test public void testTraverseSeq() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "foo:\n" + "- - - - a\n" + " - c\n" + @@ -543,9 +492,9 @@ public class YamlStructureParserTest { } @Test public void testFindAndTraverseSeqNode() throws Exception { - YamlEditor editor; + MockYamlEditor editor; - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n"+ "- abc\n" + "- def\n" + @@ -558,7 +507,7 @@ public class YamlStructureParserTest { // nodes are position sensitive make sure that generated positions agree // with traverse interpretation, even in case where it is not so well-defined // how the indices should be interpreted: - editor = new YamlEditor( + editor = new MockYamlEditor( "foo:\n"+ " garbage\n" + " - abc\n" + @@ -573,7 +522,7 @@ public class YamlStructureParserTest { } - private void findAndTraversPathPath(YamlEditor editor, String snippet) throws Exception { + private void findAndTraversPathPath(MockYamlEditor editor, String snippet) throws Exception { SRootNode root = editor.parseStructure(); SNode node = root.find(editor.startOf(snippet)); assertNotNull(node); @@ -584,7 +533,7 @@ public class YamlStructureParserTest { } @Test public void testTraverseSeqKey() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "foo:\n" + "- bar:\n" + " - a\n" + @@ -601,7 +550,7 @@ public class YamlStructureParserTest { } @Test public void testTreeEnd() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -632,7 +581,7 @@ public class YamlStructureParserTest { } @Test public void testTreeEndKeyNodeNoChildren() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " canada:\n" + @@ -651,7 +600,7 @@ public class YamlStructureParserTest { } @Test public void testFind() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -685,7 +634,7 @@ public class YamlStructureParserTest { } @Test public void testFindInMultiDoc() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -723,7 +672,7 @@ public class YamlStructureParserTest { @Test public void testFindInSequence() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "foo:\n" + "- alchemy\n" + "- bistro\n" + @@ -759,7 +708,7 @@ public class YamlStructureParserTest { } @Test public void testGetKey() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -781,7 +730,7 @@ public class YamlStructureParserTest { } @Test public void testIsInValue() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -807,7 +756,7 @@ public class YamlStructureParserTest { assertValueRange(editor, root, "foo:", null); } - private void assertValueRange(YamlEditor editor, SRootNode root, String nodeText, String expectedValue) throws Exception { + private void assertValueRange(MockYamlEditor editor, SRootNode root, String nodeText, String expectedValue) throws Exception { int start = editor.getText().indexOf(nodeText); SKeyNode node = (SKeyNode) root.find(start); int valueRangeStart; @@ -827,7 +776,7 @@ public class YamlStructureParserTest { } @Test public void testTraverse() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "world:\n" + " europe:\n" + " france:\n" + @@ -857,7 +806,7 @@ public class YamlStructureParserTest { } @Test public void testGetFirstRealChild() throws Exception { - YamlEditor editor = new YamlEditor( + MockYamlEditor editor = new MockYamlEditor( "no-children:\n" + "unreal-children:\n" + " #Unreal\n" + @@ -894,7 +843,7 @@ public class YamlStructureParserTest { assertTrue("Doesn't match: '"+string+"'", pat.matcher(string).matches()); } - private void assertFirstRealChild(YamlEditor editor, String testNodeName, String expectedNodeSnippet) throws Exception { + private void assertFirstRealChild(MockYamlEditor editor, String testNodeName, String expectedNodeSnippet) throws Exception { SDocNode doc = getOnlyDocument(editor.parseStructure()); SKeyNode testNode = doc.getChildWithKey(testNodeName); assertNotNull(testNode); @@ -927,7 +876,7 @@ public class YamlStructureParserTest { return new YamlPath(segments); } - private void assertKey(YamlEditor editor, SRootNode root, String nodeText, String expectedKey) throws Exception { + private void assertKey(MockYamlEditor editor, SRootNode root, String nodeText, String expectedKey) throws Exception { int start = editor.getText().indexOf(nodeText); SKeyNode node = (SKeyNode) root.find(start); String key = node.getKey(); @@ -943,7 +892,7 @@ public class YamlStructureParserTest { assertFalse(node.isInKey(endOfKeyRange+1)); } - private void assertFind(YamlEditor editor, SRootNode root, String snippet, int... expectPath) { + private void assertFind(MockYamlEditor editor, SRootNode root, String snippet, int... expectPath) { int start = editor.getRawText().indexOf(snippet); int end = start+snippet.length(); int middle = (start+end) / 2; @@ -955,13 +904,13 @@ public class YamlStructureParserTest { assertEquals(expectNode, root.find(end)); } - private void assertFindStart(YamlEditor editor, SRootNode root, String snippet, int... expectPath) { + private void assertFindStart(MockYamlEditor editor, SRootNode root, String snippet, int... expectPath) { int start = editor.getRawText().indexOf(snippet); SNode expectNode = getNodeAtPath(root, expectPath); assertEquals(expectNode, root.find(start)); } - private void assertTreeText(YamlEditor editor, SNode node, String expected) throws Exception { + private void assertTreeText(MockYamlEditor editor, SNode node, String expected) throws Exception { String actual = editor.textBetween(node.getStart(), node.getTreeEnd()); assertEquals(expected.trim(), actual.trim()); } diff --git a/vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/Projects.java b/vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java similarity index 91% rename from vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/Projects.java rename to vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java index b73f62180..8e8e4c2e5 100644 --- a/vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/Projects.java +++ b/vscode-extensions/commons/project-test-harness/src/main/java/org/springframework/ide/vscode/project/harness/ProjectsHarness.java @@ -1,50 +1,50 @@ -/******************************************************************************* - * 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.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; - -/** - * Test project harness utilities - * - * @author Alex Boyko - * - */ -public class Projects { - - /** - * Builds maven project - * - * @param name - * @return - * @throws Exception - */ - public static Path buildMavenProject(String name) throws Exception { - Path testProjectPath = Paths.get(Projects.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"); - } - } - return testProjectPath; - } - -} +/******************************************************************************* + * 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.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; + +/** + * Test project harness utilities + * + * @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"); + } + } + return testProjectPath; + } + +} diff --git a/vscode-extensions/vscode-application-properties/pom.xml b/vscode-extensions/vscode-application-properties/pom.xml index 41abc8d13..d79c872c1 100644 --- a/vscode-extensions/vscode-application-properties/pom.xml +++ b/vscode-extensions/vscode-application-properties/pom.xml @@ -51,6 +51,12 @@ commons-language-server ${project.version} + + + org.springframework.ide.vscode + application-properties-metadata + ${project.version} + org.springframework.ide.vscode