Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ private static IFile materializeFlexJar(IProject project, AppEngineProjectConfig
return hello;
}

private static IFile materializeFlexSpringBoot(IProject project, AppEngineProjectConfig config,
IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, "Generating code", 10);

IFile hello = createFlexSpringBootJavaSourceFiles(project, config, subMonitor.newChild(20));

boolean isStandardProject = false;
createAppEngineWebXmlOrAppYaml(project, config, isStandardProject, subMonitor.newChild(5));

createFlexSpringBootPomXml(project, config, subMonitor.newChild(5));

return hello;
}

private static IFile createJavaSourceFiles(IProject project, AppEngineProjectConfig config,
boolean isStandardProject, IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 15);
Expand Down Expand Up @@ -176,6 +190,29 @@ private static IFile createFlexJarJavaSourceFiles(IProject project, AppEnginePro
return hello;
}

private static IFile createFlexSpringBootJavaSourceFiles(IProject project,
AppEngineProjectConfig config, IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 10);

String packageName = config.getPackageName();
String packagePath = packageName.replace('.', '/');
IFolder mainPackageFolder = project.getFolder("src/main/java/" + packagePath); //$NON-NLS-1$
IFolder testPackageFolder = project.getFolder("src/test/java/" + packagePath); //$NON-NLS-1$

Map<String, String> properties = new HashMap<>();
properties.put("package", Strings.nullToEmpty(packageName)); //$NON-NLS-1$

IFile hello = createChildFile("HelloAppEngineSpringBoot.java", //$NON-NLS-1$
Templates.HELLO_APPENGINE_SPRING_BOOT_TEMPLATE,
mainPackageFolder, properties, subMonitor.newChild(5));

createChildFile("HelloAppEngineSpringBootIntegrationTest.java", //$NON-NLS-1$
Templates.HELLO_APPENGINE_SPRING_BOOT_INTEGRATION_TEST_TEMPLATE,
testPackageFolder, properties, subMonitor.newChild(5));

return hello;
}

private static void createAppEngineWebXmlOrAppYaml(IProject project,
AppEngineProjectConfig config, boolean isStandardProject, IProgressMonitor monitor)
throws CoreException {
Expand Down Expand Up @@ -271,6 +308,17 @@ private static void createFlexJarPomXml(IProject project, AppEngineProjectConfig
project, properties, monitor);
}

private static void createFlexSpringBootPomXml(IProject project, AppEngineProjectConfig config,
IProgressMonitor monitor) throws CoreException {
Map<String, String> properties = new HashMap<>();
properties.put("projectGroupId", config.getMavenGroupId()); //$NON-NLS-1$
properties.put("projectArtifactId", config.getMavenArtifactId()); //$NON-NLS-1$
properties.put("projectVersion", config.getMavenVersion()); //$NON-NLS-1$

createChildFile("pom.xml", Templates.POM_XML_FLEX_SPRING_BOOT_TEMPLATE, //$NON-NLS-1$
project, properties, monitor);
}

@VisibleForTesting
static IFile createChildFile(String name, String template, IContainer parent,
Map<String, String> values, IProgressMonitor monitor) throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public class Templates {
"HelloAppEngineHandlerTest.java.ftl";
public static final String MOCKHTTPEXCHANGE_TEMPLATE = "MockHttpExchange.java.ftl";

public static final String HELLO_APPENGINE_SPRING_BOOT_TEMPLATE =
"HelloAppEngineSpringBoot.java.ftl";
public static final String HELLO_APPENGINE_SPRING_BOOT_INTEGRATION_TEST_TEMPLATE =
"HelloAppEngineSpringBootIntegrationTest.java.ftl";

public static final String POM_XML_STANDARD_TEMPLATE = "pom.xml.standard.ftl";
public static final String POM_XML_FLEX_TEMPLATE = "pom.xml.flex.ftl";
public static final String POM_XML_FLEX_JAR_TEMPLATE = "pom.xml.flex.jar.ftl";
public static final String POM_XML_FLEX_SPRING_BOOT_TEMPLATE = "pom.xml.flex.spring.boot.ftl";

private static Configuration configuration;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#if package != "">package ${package};

</#if>import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class HelloAppEngineSpringBoot {

@RequestMapping("/")
public String home() {
return "Hello App Engine!";
}

public static void main(String[] args) {
SpringApplication.run(HelloAppEngineSpringBoot.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<#if package != "">package ${package};

</#if>import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class HelloAppEngineSpringBootIntegrationTest {

@Autowired
private TestRestTemplate template;

@Test
public void contextLoads() throws Exception {
}

@Test
public void testRequest() throws Exception {
ResponseEntity<String> responseEntity = template.getForEntity("/", String.class);
assertTrue(responseEntity.toString().contains("Hello App Engine!"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<version>${projectVersion}</version>

<groupId>${projectGroupId}</groupId>
<artifactId>${projectArtifactId}</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to show deprecation?
In general I prefer to keep samples minimal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original and current standard env pom.xml had this, and this is currently in every pom.xml we generate. I'll remove all of them here. Just let me know if you change your mind.

</properties>

<prerequisites>
<maven>3.3.9</maven>
</prerequisites>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.8.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.8.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>
</project>