mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Migrate initializr-service
to Java
This commit is contained in:
@@ -82,7 +82,7 @@ final class Version implements Serializable, Comparable<Version> {
|
||||
* @return a Version instance for the specified version text
|
||||
* @see {@link VersionParser}
|
||||
*/
|
||||
static safeParse(String text) {
|
||||
static Version safeParse(String text) {
|
||||
try {
|
||||
return parse(text)
|
||||
} catch (InvalidVersionException e) {
|
||||
|
@@ -52,10 +52,6 @@
|
||||
<build>
|
||||
<finalName>initializr-service</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
|
@@ -14,21 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.service
|
||||
package io.spring.initializr.service;
|
||||
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider
|
||||
import io.spring.initializr.web.project.LegacyStsController
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.web.project.LegacyStsController;
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurerSupport
|
||||
import org.springframework.scheduling.annotation.EnableAsync
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
|
||||
import org.springframework.web.servlet.resource.ResourceUrlProvider
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
|
||||
/**
|
||||
* Initializr service application. Enables legacy STS support for older
|
||||
@@ -37,17 +37,17 @@ import org.springframework.web.servlet.resource.ResourceUrlProvider
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SpringBootApplication
|
||||
class InitializrService {
|
||||
public class InitializrService {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(InitializrService, args)
|
||||
SpringApplication.run(InitializrService.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("deprecation")
|
||||
LegacyStsController legacyStsController(InitializrMetadataProvider metadataProvider,
|
||||
ResourceUrlProvider resourceUrlProvider) {
|
||||
new LegacyStsController(metadataProvider, resourceUrlProvider)
|
||||
public LegacyStsController legacyStsController(InitializrMetadataProvider metadataProvider,
|
||||
ResourceUrlProvider resourceUrlProvider) {
|
||||
return new LegacyStsController(metadataProvider, resourceUrlProvider);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -55,13 +55,13 @@ class InitializrService {
|
||||
static class AsyncConfiguration extends AsyncConfigurerSupport {
|
||||
|
||||
@Override
|
||||
Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor()
|
||||
executor.setCorePoolSize(1)
|
||||
executor.setMaxPoolSize(5)
|
||||
executor.setThreadNamePrefix("initializr-")
|
||||
executor.initialize()
|
||||
executor
|
||||
public Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(1);
|
||||
executor.setMaxPoolSize(5);
|
||||
executor.setThreadNamePrefix("initializr-");
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,14 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.service.extension
|
||||
package io.spring.initializr.service.extension;
|
||||
|
||||
import io.spring.initializr.generator.ProjectRequest
|
||||
import io.spring.initializr.generator.ProjectRequestPostProcessorAdapter
|
||||
import io.spring.initializr.metadata.InitializrMetadata
|
||||
import io.spring.initializr.util.Version
|
||||
import io.spring.initializr.generator.ProjectRequest;
|
||||
import io.spring.initializr.generator.ProjectRequestPostProcessorAdapter;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.util.Version;
|
||||
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* As of Spring Boot 2.0, Java8 is mandatory so this extension makes sure that the
|
||||
@@ -32,12 +32,13 @@ import org.springframework.stereotype.Component
|
||||
@Component
|
||||
class SpringBoot2RequestPostProcessor extends ProjectRequestPostProcessorAdapter {
|
||||
|
||||
private static final VERSION_2_0_0_M1 = Version.parse('2.0.0.M1')
|
||||
private static final Version VERSION_2_0_0_M1 = Version.parse("2.0.0.M1");
|
||||
|
||||
@Override
|
||||
void postProcessAfterResolution(ProjectRequest request, InitializrMetadata metadata) {
|
||||
if (VERSION_2_0_0_M1 <= Version.safeParse(request.bootVersion)) {
|
||||
request.javaVersion = '1.8'
|
||||
public void postProcessAfterResolution(ProjectRequest request, InitializrMetadata metadata) {
|
||||
Version requestVersion = Version.safeParse(request.getBootVersion());
|
||||
if (VERSION_2_0_0_M1.compareTo(requestVersion) <= 0) {
|
||||
request.setJavaVersion("1.8");
|
||||
}
|
||||
}
|
||||
|
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.service.extension
|
||||
|
||||
import io.spring.initializr.generator.ProjectGenerator
|
||||
import io.spring.initializr.generator.ProjectRequest
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider
|
||||
import io.spring.initializr.test.generator.GradleBuildAssert
|
||||
import io.spring.initializr.test.generator.PomAssert
|
||||
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.test.context.junit4.SpringJUnit4ClassRunner
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringBoot2RequestPostProcessor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner)
|
||||
@SpringBootTest
|
||||
class SpringBoot2RequestPostProcessorTests {
|
||||
|
||||
@Autowired
|
||||
private ProjectGenerator projectGenerator
|
||||
|
||||
@Autowired
|
||||
private InitializrMetadataProvider metadataProvider
|
||||
|
||||
@Test
|
||||
void java8IsMandatoryMaven() {
|
||||
ProjectRequest request = createProjectRequest('web')
|
||||
request.bootVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
request.javaVersion = '1.7'
|
||||
generateMavenPom(request).hasJavaVersion('1.8')
|
||||
}
|
||||
|
||||
@Test
|
||||
void java8IsMandatoryGradle() {
|
||||
ProjectRequest request = createProjectRequest('data-jpa')
|
||||
request.bootVersion = '2.0.0.M3'
|
||||
request.javaVersion = '1.7'
|
||||
generateGradleBuild(request).hasJavaVersion('1.8')
|
||||
}
|
||||
|
||||
private PomAssert generateMavenPom(ProjectRequest request) {
|
||||
request.type = 'maven-build'
|
||||
def content = new String(projectGenerator.generateMavenPom(request))
|
||||
new PomAssert(content)
|
||||
}
|
||||
|
||||
private GradleBuildAssert generateGradleBuild(ProjectRequest request) {
|
||||
request.type = 'gradle-build'
|
||||
def content = new String(projectGenerator.generateGradleBuild(request))
|
||||
new GradleBuildAssert(content)
|
||||
}
|
||||
|
||||
private ProjectRequest createProjectRequest(String... styles) {
|
||||
def request = new ProjectRequest()
|
||||
request.initialize(metadataProvider.get())
|
||||
request.style.addAll Arrays.asList(styles)
|
||||
request
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.service.extension;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.spring.initializr.generator.ProjectGenerator;
|
||||
import io.spring.initializr.generator.ProjectRequest;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.test.generator.GradleBuildAssert;
|
||||
import io.spring.initializr.test.generator.PomAssert;
|
||||
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.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringBoot2RequestPostProcessor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringBoot2RequestPostProcessorTests {
|
||||
|
||||
@Autowired
|
||||
private ProjectGenerator projectGenerator;
|
||||
|
||||
@Autowired
|
||||
private InitializrMetadataProvider metadataProvider;
|
||||
|
||||
@Test
|
||||
public void java8IsMandatoryMaven() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.setBootVersion("2.0.0.BUILD-SNAPSHOT");
|
||||
request.setJavaVersion("1.7");
|
||||
generateMavenPom(request).hasJavaVersion("1.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void java8IsMandatoryGradle() {
|
||||
ProjectRequest request = createProjectRequest("data-jpa");
|
||||
request.setBootVersion("2.0.0.M3");
|
||||
request.setJavaVersion("1.7");
|
||||
generateGradleBuild(request).hasJavaVersion("1.8");
|
||||
}
|
||||
|
||||
private PomAssert generateMavenPom(ProjectRequest request) {
|
||||
request.setType("maven-build");
|
||||
String content = new String(projectGenerator.generateMavenPom(request));
|
||||
return new PomAssert(content);
|
||||
}
|
||||
|
||||
private GradleBuildAssert generateGradleBuild(ProjectRequest request) {
|
||||
request.setType("gradle-build");
|
||||
String content = new String(projectGenerator.generateGradleBuild(request));
|
||||
return new GradleBuildAssert(content);
|
||||
}
|
||||
|
||||
private ProjectRequest createProjectRequest(String... styles) {
|
||||
ProjectRequest request = new ProjectRequest();
|
||||
request.initialize(metadataProvider.get());
|
||||
request.getStyle().addAll(Arrays.asList(styles));
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user