Skip to content

Commit

Permalink
#240 - archetype fix with initial springboot archetype
Browse files Browse the repository at this point in the history
  • Loading branch information
tavoda committed Mar 6, 2021
1 parent 3034a46 commit b48c5ab
Show file tree
Hide file tree
Showing 23 changed files with 418 additions and 128 deletions.
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<spring-security-version>5.4.2</spring-security-version>
<spring-integration-version>5.4.2</spring-integration-version>
<spring-data-jpa-version>2.4.3</spring-data-jpa-version>
<spring-boot-version>2.4.2</spring-boot-version>
<spring-boot-version>2.4.3</spring-boot-version>

<aspectj-version>1.9.6</aspectj-version>
<slf4j-version>1.7.30</slf4j-version>
Expand Down Expand Up @@ -325,7 +325,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.0.0-M5</version>
<configuration>
<argLine>-Xms32m -Xmx1024m</argLine>
<!-- Adjusting TZ, travis run in UTC '-Duser.timezone=UTC' -->
Expand Down Expand Up @@ -460,6 +460,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<ignoreEOLStyle>true</ignoreEOLStyle>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
12 changes: 6 additions & 6 deletions sculptor-examples/fulltextsearch-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -214,12 +220,6 @@
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>6.0.1.GA</version>
<exclusions>
<exclusion>
<groupId>org.joda</groupId>
<artifactId>joda-money</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
1 change: 0 additions & 1 deletion sculptor-framework/sculptor-framework-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ generate.consumer=true
generate.resource=true
generate.restWeb=true
generate.restWeb.config=true
generate.restWeb.config.springboot=false
generate.restWeb.jsp=true
generate.spring=true
generate.hibernate=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public List<String> projectNature() {
String value = getProperty("project.nature");
String[] operations = value.split(",");
trim(operations);
return new ArrayList<String>(Arrays.asList(operations));
return Arrays.asList(operations);
}

private void trim(String[] strings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ class RestWebConfigTmpl {

def String config(Application it) {
'''
«webXml(it)»
«restServletXml(it)»
«contextTmpl.contextXml(it)»
«IF getBooleanProperty("generate.restWeb.config.springboot")»
«springBootConfig(it)»
«ELSE»
«webXml(it)»
«restServletXml(it)»
«contextTmpl.contextXml(it)»
«ENDIF»
'''
}

Expand Down Expand Up @@ -211,4 +215,152 @@ def String restServletXml(Application it) {
)
}

def String springBootConfig(Application it) {
'''
«springBootAppConfig(it)»
«springBootAppProperties(it)»
«springBootBackendConfig(it)»
«springBootWebConfig(it)»
'''
}

def String springBootAppConfig(Application it) {
fileOutput(basePackage + "/Application.java", OutputSlot.TO_SRC, '''
«javaHeader()»
package «basePackage»;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class
})
public class Application {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder().sources(Application.class).profiles("web").run(args);
}
}
'''
)
}

def String springBootAppProperties(Application it) {
fileOutput("/application.properties", OutputSlot.TO_RESOURCES, '''
# LOGGING
logging.level.org.springframework.web=INFO
# SPRING MVC
# Allow Thymeleaf templates to be reloaded at dev time
spring.thymeleaf.cache=false
# Use Sculptor banner from sculptor-framework-main
spring.banner.location=classpath:/sculptor-banner.txt
# EMBEDDED WEB CONTAINER CONFIGURATION
# Set the error path
server.error.path=/error
'''
)
}

def String springBootBackendConfig(Application it) {
fileOutput(javaFileName(basePackage + ".config.BackendConfig"), OutputSlot.TO_SRC, '''
«javaHeader()»
package «basePackage».config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Profile;
@Profile("!test")
@Configuration
@ImportResource("classpath:applicationContext.xml")
public class BackendConfig {
}
'''
)
}

def String springBootWebConfig(Application it) {
fileOutput(javaFileName(basePackage + ".config.WebConfig"), OutputSlot.TO_SRC, '''
«javaHeader()»
package «basePackage».config;
/// Sculptor code formatter imports ///
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.sculptor.framework.context.ServiceContextServletFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.http.MediaType;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import org.springframework.web.servlet.view.xml.MappingJackson2XmlView;
/* We have to disable this configuration during backend tests */
@Profile("web")
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public View xmlView() {
return new MappingJackson2XmlView();
}
@Bean
public View jsonView() {
return new MappingJackson2JsonView();
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.TEXT_HTML)
.mediaType("html", MediaType.TEXT_HTML).mediaType("xml", MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON);
}
@Bean
public ContentNegotiatingViewResolver viewResolver(ContentNegotiationManager manager) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);
resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
resolver.setDefaultViews(Arrays.asList(new View[] { xmlView(), jsonView() }));
return resolver;
}
@Bean
public FilterRegistrationBean<ServiceContextServletFilter> serviceContextFilterRegistration() {
FilterRegistrationBean<ServiceContextServletFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new ServiceContextServletFilter());
Map<String, String> initParams = new HashMap<String, String>(1);
initParams.put("ServiceContextFactoryImplementationClassName",
"org.sculptor.framework.context.ServletContainerServiceContextFactory");
registration.setInitParameters(initParams);
registration.addUrlPatterns("/rest/*");
registration.setOrder(Ordered.LOWEST_PRECEDENCE);
return registration;
}
}
'''
)
}

}
1 change: 1 addition & 0 deletions sculptor-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>sculptor-maven-archetype</module>
<module>sculptor-maven-archetype-web</module>
<module>sculptor-maven-archetype-ear</module>
<module>sculptor-maven-archetype-springboot</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<fileSets>
<fileSet filtered="true">
<directory></directory>
<directory>/</directory>
<includes>
<include>pom.xml</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<fileSets>
<fileSet filtered="true">
<directory></directory>
<directory>/</directory>
<includes>
<include>pom.xml</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>

<java-version>1.7</java-version>
<java-version>1.8</java-version>
<maven.compiler.source>${java-version}</maven.compiler.source>
<maven.compiler.target>${java-version}</maven.compiler.target>

<sculptor-version>${project.version}</sculptor-version>
<jboss-javaee6-version>${jboss-javaee6-version}</jboss-javaee6-version>
<hibernate-validator-version>${hibernate-validator-version}</hibernate-validator-version>
<hibernate-validator-version>${hibernate-validator-version}</hibernate-validator-version>
<ehcache-version>${ehcache-version}</ehcache-version>
<tomcat-jasper-el>${tomcat-jasper-el}</tomcat-jasper-el>
<slf4j-version>${slf4j-version}</slf4j-version>
<logback-version>${logback-version}</logback-version>
<spring-version>${spring-version}</spring-version>
<aspectj-version>${aspectj-version}</aspectj-version>
<joda-time-version>${joda-time-version}</joda-time-version>
<jackson-version>${jackson-version}</jackson-version>
<xstream-version>${xstream-version}</xstream-version>

<junit-version>${junit-version}</junit-version>
<hamcrest-version>2.2</hamcrest-version>
#if( $mongodb != "true" && $mongodb != "y" && $mongodb != "yes")
<hsqldb-version>${hsqldb-version}</hsqldb-version>
#end
Expand Down Expand Up @@ -82,13 +86,25 @@
</dependencies>
</dependencyManagement>
#end

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>\${junit-version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>

0 comments on commit b48c5ab

Please sign in to comment.