Skip to content

Commit

Permalink
Remove Java 7 code
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubois committed Oct 7, 2015
1 parent eb597c1 commit 0acf65c
Show file tree
Hide file tree
Showing 31 changed files with 129 additions and 623 deletions.
33 changes: 5 additions & 28 deletions app/index.js
Expand Up @@ -41,6 +41,7 @@ JhipsterGenerator.prototype.askFor = function askFor() {
console.log(chalk.white.bold(' http://jhipster.github.io\n'));
console.log(chalk.white('Welcome to the JHipster Generator ') + chalk.yellow('v' + packagejs.version + '\n'));
var insight = this.insight();
this.javaVersion = '8'; // Java version is forced to be 1.8. We keep the variable as it might be useful in the future.
var questions = 15; // making questions a variable to avoid updating each question by hand when adding additional options

var prompts = [
Expand Down Expand Up @@ -73,22 +74,6 @@ JhipsterGenerator.prototype.askFor = function askFor() {
message: '(2/' + questions + ') What is your default Java package name?',
default: 'com.mycompany.myapp'
},
{
type: 'list',
name: 'javaVersion',
message: '(3/' + questions + ') Do you want to use Java 8?',
choices: [
{
value: '8',
name: 'Yes (use Java 8)'
},
{
value: '7',
name: 'No (use Java 7 - Warning! Cassandra and ElasticSearch support will not be available)'
}
],
default: 0
},
{
type: 'list',
name: 'authenticationType',
Expand All @@ -111,7 +96,7 @@ JhipsterGenerator.prototype.askFor = function askFor() {
},
{
when: function (response) {
return (!(response.authenticationType == 'oauth2' || response.javaVersion == '7'));
return (response.authenticationType != 'oauth2');
},
type: 'list',
name: 'databaseType',
Expand All @@ -134,7 +119,7 @@ JhipsterGenerator.prototype.askFor = function askFor() {
},
{
when: function (response) {
return (response.authenticationType == 'oauth2' || response.javaVersion == '7');
return (response.authenticationType == 'oauth2');
},
type: 'list',
name: 'databaseType',
Expand Down Expand Up @@ -255,9 +240,6 @@ JhipsterGenerator.prototype.askFor = function askFor() {
default: 1
},
{
when: function (response) {
return (!(response.javaVersion == '7') && response.databaseType == 'sql');
},
type: 'list',
name: 'searchEngine',
message: '(9/' + questions + ') Do you want to use a search engine in your application?',
Expand Down Expand Up @@ -375,7 +357,6 @@ JhipsterGenerator.prototype.askFor = function askFor() {
if (this.useSass == undefined) { // backward compatibility for existing compass users
this.useSass = this.config.get('useCompass');
}
this.javaVersion = this.config.get('javaVersion');
this.buildTool = this.config.get('buildTool');
this.frontendBuilder = this.config.get('frontendBuilder');
this.rememberMeKey = this.config.get('rememberMeKey');
Expand All @@ -394,8 +375,7 @@ JhipsterGenerator.prototype.askFor = function askFor() {
this.searchEngine != null &&
this.useSass != null &&
this.buildTool != null &&
this.frontendBuilder != null &&
this.javaVersion != null) {
this.frontendBuilder != null) {

// Generate key if key does not already exist in config
if (this.rememberMeKey == null) {
Expand Down Expand Up @@ -429,7 +409,6 @@ JhipsterGenerator.prototype.askFor = function askFor() {
this.useSass = props.useSass;
this.buildTool = props.buildTool;
this.frontendBuilder = props.frontendBuilder;
this.javaVersion = props.javaVersion;
this.enableTranslation = props.enableTranslation;
this.rememberMeKey = crypto.randomBytes(20).toString('hex');

Expand Down Expand Up @@ -465,7 +444,6 @@ JhipsterGenerator.prototype.app = function app() {
insight.track('app/useSass', this.useSass);
insight.track('app/buildTool', this.buildTool);
insight.track('app/frontendBuilder', this.frontendBuilder);
insight.track('app/javaVersion', this.javaVersion);
insight.track('app/enableTranslation', this.enableTranslation);

var packageFolder = this.packageName.replace(/\./g, '/');
Expand All @@ -482,7 +460,7 @@ JhipsterGenerator.prototype.app = function app() {
this.slugifiedBaseName = _.slugify(this.baseName);

if (this.prodDatabaseType === 'oracle') { // create a folder for users to place ojdbc jar
this.ojdbcVersion = this.javaVersion == '7' ? '6' : '7';
this.ojdbcVersion = '7';
this.libFolder = 'lib/oracle/ojdbc/' + this.ojdbcVersion + '/';
mkdirp(this.libFolder);
}
Expand Down Expand Up @@ -1145,7 +1123,6 @@ JhipsterGenerator.prototype.app = function app() {
this.config.set('useSass', this.useSass);
this.config.set('buildTool', this.buildTool);
this.config.set('frontendBuilder', this.frontendBuilder);
this.config.set('javaVersion', this.javaVersion);
this.config.set('enableTranslation', this.enableTranslation);
this.config.set('rememberMeKey', this.rememberMeKey);
};
Expand Down
11 changes: 5 additions & 6 deletions app/templates/_build.gradle
Expand Up @@ -40,8 +40,7 @@ apply from: 'sonar.gradle'
<% if (databaseType == 'sql') { %>
apply from: 'liquibase.gradle'<% } %>
apply from: 'gatling.gradle'
<% if (javaVersion == '8') { %>
apply from: 'mapstruct.gradle'<% } %>
apply from: 'mapstruct.gradle'

if (project.hasProperty('prod')) {
apply from: 'profile_prod.gradle'
Expand Down Expand Up @@ -165,9 +164,9 @@ dependencies {
<% if (devDatabaseType == 'mysql' || prodDatabaseType == 'mysql') { %>
compile group: 'mysql', name: 'mysql-connector-java'<% } %><% if (devDatabaseType == 'postgresql' || prodDatabaseType == 'postgresql') { %>
compile group: 'org.postgresql', name: 'postgresql', version: postgresql_version<% } %><% if (devDatabaseType == 'h2Memory') { %>
compile group: 'com.h2database', name: 'h2'<% } %><% if (javaVersion == '8') { %>
compile group: 'fr.ippon.spark.metrics', name: 'metrics-spark-reporter', version: metrics_spark_reporter_version<% } %><% if (javaVersion == '8') { %>
compile group: 'org.mapstruct', name: 'mapstruct-jdk8', version: mapstruct_version<% } %>
compile group: 'com.h2database', name: 'h2'<% } %>
compile group: 'fr.ippon.spark.metrics', name: 'metrics-spark-reporter', version: metrics_spark_reporter_version
compile group: 'org.mapstruct', name: 'mapstruct-jdk8', version: mapstruct_version
testCompile group: 'com.jayway.awaitility', name: 'awaitility', version: awaility_version
testCompile group: 'com.jayway.jsonpath', name: 'json-path'<% if (databaseType == 'cassandra') { %>
testCompile(group: 'org.cassandraunit', name: 'cassandra-unit-spring', version: cassandra_unit_spring_version) {
Expand All @@ -184,7 +183,7 @@ dependencies {
testCompile group: 'io.gatling.highcharts', name: 'gatling-charts-highcharts', version: gatling_version
<% if (devDatabaseType != 'h2Memory') { %>
testCompile group: 'com.h2database', name: 'h2'<% } %><% if (devDatabaseType == 'oracle' || prodDatabaseType == 'oracle') { %>
runtime files('lib/oracle/ojdbc/<% if (javaVersion == '7') { %>6/ojdbc-6<% }else { %>7/ojdbc-7<% } %>.jar')
runtime files('lib/oracle/ojdbc/7/ojdbc-7.jar')
runtime fileTree(dir: 'lib', include: '*.jar')<% } %>
optional group: 'org.springframework.boot', name:'spring-boot-configuration-processor', version: spring_boot_version

Expand Down
4 changes: 1 addition & 3 deletions app/templates/_gradle.properties
@@ -1,8 +1,6 @@
rootProject.name=<%= slugifiedBaseName %>
profile=dev
<% if (javaVersion == '8') { %>
assertj_core_version=3.1.0<% } %><% if (javaVersion == '7') { %>
assertj_core_version=2.1.0<% } %>
assertj_core_version=3.1.0
awaility_version=1.4.0
commons_lang_version=2.6
commons_io_version=2.4<% if (databaseType == 'cassandra') { %>
Expand Down
15 changes: 2 additions & 13 deletions app/templates/_pom.xml
Expand Up @@ -22,12 +22,7 @@

<properties>
<hikaricp.version>2.4.1</hikaricp.version>
<%_ if (javaVersion == '8') { _%>
<assertj-core.version>3.1.0</assertj-core.version>
<%_ } _%>
<%_ if (javaVersion == '7') { _%>
<assertj-core.version>2.1.0</assertj-core.version>
<%_ } _%>
<awaitility.version>1.4.0</awaitility.version>
<commons-io.version>2.4</commons-io.version>
<commons-lang.version>2.6</commons-lang.version>
Expand Down Expand Up @@ -319,7 +314,7 @@
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc</artifactId>
<version><% if (javaVersion == '7') { %>6<% }else { %>7<% } %></version>
<version>7</version>
</dependency>
<%_ } _%>
<dependency>
Expand Down Expand Up @@ -394,13 +389,11 @@
<version>${postgresql.version}</version>
</dependency>
<%_ } _%>
<%_ if (javaVersion == '8') { _%>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<%_ } _%>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
Expand Down Expand Up @@ -537,13 +530,11 @@
</dependency>
<%_ } _%>
<!-- reporting -->
<%_ if (javaVersion == '8') { _%>
<dependency>
<groupId>fr.ippon.spark.metrics</groupId>
<artifactId>metrics-spark-reporter</artifactId>
<version>${metrics-spark-reporter.version}</version>
</dependency>
<%_ } _%>
</dependencies>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
Expand Down Expand Up @@ -637,7 +628,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine><% if (javaVersion == '7') { %>-XX:MaxPermSize=128m <% } %>-Xmx256m ${surefireArgLine}</argLine>
<argLine>-Xmx256m ${surefireArgLine}</argLine>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
</configuration>
Expand Down Expand Up @@ -685,7 +676,6 @@
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar-maven-plugin.version}</version>
</plugin>
<%_ if (javaVersion == '8') { _%>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
Expand Down Expand Up @@ -719,7 +709,6 @@
</dependency>
</dependencies>
</plugin>
<%_ } _%>
<%_ if (databaseType == 'sql') { _%>
<plugin>
<groupId>org.liquibase</groupId>
Expand Down
Expand Up @@ -30,48 +30,25 @@ public void execute(Runnable task, long startTimeout) {
executor.execute(createWrappedRunnable(task), startTimeout);
}

private <T> Callable<T> createCallable(final Callable<T> task) {<% if (javaVersion == '8') { %>
private <T> Callable<T> createCallable(final Callable<T> task) {
return () -> {
try {
return task.call();
} catch (Exception e) {
handle(e);
throw e;
}
};<% } else { %>
return new Callable<T>() {

@Override
public T call() throws Exception {
try {
return task.call();
} catch (Exception e) {
handle(e);
throw e;
}
}
};<% } %>
};
}

private Runnable createWrappedRunnable(final Runnable task) {<% if (javaVersion == '8') { %>
private Runnable createWrappedRunnable(final Runnable task) {
return () -> {
try {
task.run();
} catch (Exception e) {
handle(e);
}
};<% } else { %>
return new Runnable() {

@Override
public void run() {
try {
task.run();
} catch (Exception e) {
handle(e);
}
}
};<% } %>
};
}

protected void handle(Exception e) {
Expand Down
Expand Up @@ -54,11 +54,8 @@ public class CacheConfiguration {
@PreDestroy
public void destroy() {<% if (hibernateCache == 'ehcache') { %>
log.info("Remove Cache Manager metrics");
SortedSet<String> names = metricRegistry.getNames();<% if (javaVersion == '8') { %>
names.forEach(metricRegistry::remove);<% } else { %>
for (String name : names) {
metricRegistry.remove(name);
}<% } %><% } %>
SortedSet<String> names = metricRegistry.getNames();
names.forEach(metricRegistry::remove);<% } %>
log.info("Closing Cache Manager");<% if (hibernateCache == 'ehcache') { %>
cacheManager.shutdown();<% } %><% if (hibernateCache == 'hazelcast' || clusteredHttpSession == 'hazelcast') { %>
Hazelcast.shutdownAll();<% } %>
Expand Down
Expand Up @@ -7,8 +7,8 @@
import com.codahale.metrics.health.HealthCheckRegistry;
import com.codahale.metrics.jvm.*;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;<% if (javaVersion == '8') { %>
import fr.ippon.spark.metrics.SparkReporter;<% } %>
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;
import fr.ippon.spark.metrics.SparkReporter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand Down Expand Up @@ -98,7 +98,7 @@ private void init() {
graphiteReporter.start(1, TimeUnit.MINUTES);
}
}
}<% if (javaVersion == '8') { %>
}

@Configuration
@ConditionalOnClass(SparkReporter.class)
Expand Down Expand Up @@ -126,5 +126,5 @@ private void init() {
sparkReporter.start(1, TimeUnit.MINUTES);
}
}
}<% } %>
}
}
Expand Up @@ -58,10 +58,10 @@ public Docket swaggerSpringfoxDocket(JHipsterProperties jHipsterProperties) {
.genericModelSubstitutes(ResponseEntity.class)
.directModelSubstitute(org.joda.time.LocalDate.class, String.class)
.directModelSubstitute(org.joda.time.LocalDateTime.class, Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, Date.class)<% if (javaVersion == '8') { %>
.directModelSubstitute(org.joda.time.DateTime.class, Date.class)
.directModelSubstitute(java.time.LocalDate.class, String.class)
.directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
.directModelSubstitute(java.time.LocalDateTime.class, Date.class)<% } %>
.directModelSubstitute(java.time.LocalDateTime.class, Date.class)
.select()
.paths(regex(DEFAULT_INCLUDE_PATTERN))
.build();
Expand Down
@@ -1,15 +1,12 @@
package <%=packageName%>.config.metrics;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;<% if (databaseType == 'sql') { %><% if (javaVersion == '7') { %>
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ConnectionCallback;<% } %>
import org.springframework.boot.actuate.health.Health;<% if (databaseType == 'sql') { %>
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;
import java.sql.Connection;<% if (javaVersion == '7') { %>
import java.sql.SQLException;<% } %>
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;<% } %>

Expand Down Expand Up @@ -56,14 +53,7 @@ protected void doHealthCheck(Health.Builder builder) throws Exception {
}

private String getProduct() {
return this.jdbcTemplate.execute(<% if (javaVersion == '8') { %>(Connection connection) -> connection.getMetaData().getDatabaseProductName()<% } else { %>new ConnectionCallback<String>() {
@Override
public String doInConnection(Connection connection) throws SQLException,
DataAccessException {

return connection.getMetaData().getDatabaseProductName();
}
}<% } %>);
return this.jdbcTemplate.execute((Connection connection) -> connection.getMetaData().getDatabaseProductName());
}

protected String detectQuery(String product) {
Expand Down

0 comments on commit 0acf65c

Please sign in to comment.