Skip to content

Commit

Permalink
Merge branch '7.0.x' into merge-6.2.x-into-7.0.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	grails-forge-core/src/main/resources/pom.xml
#	grails-forge-core/src/test/groovy/org/grails/forge/build/gradle/GradleSpec.groovy
#	grails-forge-core/src/test/groovy/org/grails/forge/feature/grails/GrailsGradlePluginSpec.groovy
  • Loading branch information
jamesfredley committed Oct 10, 2024
2 parents ed9e747 + af2bdfc commit 0d2b508
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 48 deletions.
2 changes: 1 addition & 1 deletion config/spotless.license.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-$YEAR original authors
* Copyright $YEAR original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,12 @@

public interface ConfigurationFeature extends OneOfFeature {

String ENVIRONMENTS_KEY = "environments";
String DEV_ENVIRONMENT_KEY = "development";
String TEST_ENVIRONMENT_KEY = "test";
String PROD_ENVIRONMENT_KEY = "production";
String PROPERTIES_KEY = "properties";

@Override
default Class<?> getFeatureClass() {
return ConfigurationFeature.class;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,13 @@
import java.util.Map;
import java.util.Optional;

import static org.grails.forge.feature.config.ConfigurationFeature.DEV_ENVIRONMENT_KEY;
import static org.grails.forge.feature.config.ConfigurationFeature.TEST_ENVIRONMENT_KEY;
import static org.grails.forge.feature.config.ConfigurationFeature.PROD_ENVIRONMENT_KEY;
import static org.grails.forge.feature.config.ConfigurationFeature.ENVIRONMENTS_KEY;
import static org.grails.forge.feature.config.ConfigurationFeature.PROPERTIES_KEY;
import static org.grails.forge.feature.database.HibernateGorm.PREFIX;

/**
* A feature that configures a datasource with a driver
*/
Expand All @@ -33,14 +40,45 @@ public interface DatabaseDriverConfigurationFeature extends Feature {

String getPasswordKey();

String getDbCreateKey();

default void applyDefaultConfig(DatabaseDriverFeature dbFeature, Map<String, Object> config) {
Optional.ofNullable(dbFeature.getJdbcUrl()).ifPresent(url -> config.put(getUrlKey(), url));
Optional.ofNullable(dbFeature.getDriverClass()).ifPresent(driver -> config.put(getDriverKey(), driver));
Optional.ofNullable(dbFeature.getDefaultUser()).ifPresent(user -> config.put(getUsernameKey(), user));
Optional.ofNullable(dbFeature.getDefaultPassword()).ifPresent(pass -> config.put(getPasswordKey(), pass));

config.put(ENVIRONMENTS_KEY + "." + DEV_ENVIRONMENT_KEY + "." + getDbCreateKey(), "create-drop");
Optional.ofNullable(dbFeature.getJdbcDevUrl()).ifPresent(url -> config.put(ENVIRONMENTS_KEY + "." + DEV_ENVIRONMENT_KEY + "." + getUrlKey(), url));
config.put(ENVIRONMENTS_KEY + "." + TEST_ENVIRONMENT_KEY + "." + getDbCreateKey(), "update");
Optional.ofNullable(dbFeature.getJdbcTestUrl()).ifPresent(url -> config.put(ENVIRONMENTS_KEY + "." + TEST_ENVIRONMENT_KEY + "." + getUrlKey(), url));
config.put(ENVIRONMENTS_KEY + "." + PROD_ENVIRONMENT_KEY + "." + getDbCreateKey(), "none");
Optional.ofNullable(dbFeature.getJdbcProdUrl()).ifPresent(url -> config.put(ENVIRONMENTS_KEY + "." + PROD_ENVIRONMENT_KEY + "." + getUrlKey(), url));

addProductionDataSourceProperties(config, "jmxEnabled", true);
addProductionDataSourceProperties(config, "initialSize", 5);
addProductionDataSourceProperties(config, "maxActive", 50);
addProductionDataSourceProperties(config, "minIdle", 5);
addProductionDataSourceProperties(config, "maxIdle", 25);
addProductionDataSourceProperties(config, "maxWait", 10000);
addProductionDataSourceProperties(config, "maxAge", 600000);
addProductionDataSourceProperties(config, "timeBetweenEvictionRunsMillis", 5000);
addProductionDataSourceProperties(config, "minEvictableIdleTimeMillis", 60000);
addProductionDataSourceProperties(config, "validationQuery", "SELECT 1");
addProductionDataSourceProperties(config, "validationQueryTimeout", 3);
addProductionDataSourceProperties(config, "validationInterval", 15000);
addProductionDataSourceProperties(config, "testOnBorrow", true);
addProductionDataSourceProperties(config, "testWhileIdle", true);
addProductionDataSourceProperties(config, "testOnReturn", false);
addProductionDataSourceProperties(config, "jdbcInterceptors", "ConnectionState");
addProductionDataSourceProperties(config, "defaultTransactionIsolation", 2);

final Map<String, Object> additionalConfig = dbFeature.getAdditionalConfig();
if (!additionalConfig.isEmpty()) {
config.putAll(additionalConfig);
}
}

default void addProductionDataSourceProperties(Map<String, Object> config, String key, Object value) {
config.put(ENVIRONMENTS_KEY + "." + PROD_ENVIRONMENT_KEY + "." + PREFIX + PROPERTIES_KEY + "." + key, value);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,7 +65,16 @@ public String getCategory() {

public abstract boolean embedded();

public abstract String getJdbcUrl();
@Deprecated(since = "6.2.2", forRemoval = true)
public String getJdbcUrl() {
return getJdbcProdUrl();
}

public abstract String getJdbcDevUrl();

public abstract String getJdbcTestUrl();

public abstract String getJdbcProdUrl();

public abstract String getDriverClass();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,10 +40,20 @@ public String getDescription() {
}

@Override
public String getJdbcUrl() {
public String getJdbcDevUrl() {
return "jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE";
}

@Override
public String getJdbcTestUrl() {
return "jdbc:h2:mem:testDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE";
}

@Override
public String getJdbcProdUrl() {
return "jdbc:h2:./prodDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE";
}

@Override
public String getDriverClass() {
return "org.h2.Driver";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,11 +32,12 @@
@Singleton
public class HibernateGorm extends GormFeature implements DatabaseDriverConfigurationFeature {

private static final String PREFIX = "dataSource.";
static final String PREFIX = "dataSource.";
private static final String URL_KEY = PREFIX + "url";
private static final String DRIVER_KEY = PREFIX + "driverClassName";
private static final String USERNAME_KEY = PREFIX + "username";
private static final String PASSWORD_KEY = PREFIX + "password";
private static final String DB_CREATE_KEY = PREFIX + "dbCreate";

private final DatabaseDriverFeature defaultDbFeature;

Expand Down Expand Up @@ -74,7 +75,6 @@ public void apply(GeneratorContext generatorContext) {
applyDefaultGormConfig(config);
config.put("dataSource.pooled", true);
config.put("dataSource.jmxExport", true);
config.put("dataSource.dbCreate", "update");
config.put("hibernate.cache.queries", false);
config.put("hibernate.cache.use_second_level_cache", false);
config.put("hibernate.cache.use_query_cache", false);
Expand Down Expand Up @@ -113,6 +113,11 @@ public String getPasswordKey() {
return PASSWORD_KEY;
}

@Override
public String getDbCreateKey() {
return DB_CREATE_KEY;
}

@Override
public boolean shouldApply(ApplicationType applicationType, Options options, Set<Feature> selectedFeatures) {
return selectedFeatures.stream().anyMatch(f -> f instanceof HibernateGorm) || options.getGormImpl() == GormImpl.HIBERNATE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,8 +44,18 @@ public String getDescription() {
}

@Override
public String getJdbcUrl() {
return "jdbc:mysql://localhost:3306/db";
public String getJdbcDevUrl() {
return "jdbc:mysql://localhost:3306/devDb";
}

@Override
public String getJdbcTestUrl() {
return "jdbc:mysql://localhost:3306/testDb";
}

@Override
public String getJdbcProdUrl() {
return "jdbc:mysql://localhost:3306/prodDb";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,17 @@ public String getDescription() {
}

@Override
public String getJdbcUrl() {
public String getJdbcDevUrl() {
return "jdbc:postgresql://localhost:5432/devDb";
}

@Override
public String getJdbcTestUrl() {
return "jdbc:postgresql://localhost:5432/testDb";
}

@Override
public String getJdbcProdUrl() {
// postgres docker image uses default db name and username of postgres so we use the same
return "jdbc:postgresql://localhost:5432/postgres";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,8 +44,18 @@ public String getDescription() {
}

@Override
public String getJdbcUrl() {
return "jdbc:sqlserver://localhost:1433;databaseName=tempdb";
public String getJdbcDevUrl() {
return "jdbc:sqlserver://localhost:1433;databaseName=devDb";
}

@Override
public String getJdbcTestUrl() {
return "jdbc:sqlserver://localhost:1433;databaseName=testDb";
}

@Override
public String getJdbcProdUrl() {
return "jdbc:sqlserver://localhost:1433;databaseName=prodDb";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2024 original 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
*
* https://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 org.grails.forge.feature.grailsProfiles;

import jakarta.inject.Singleton;
import org.grails.forge.application.ApplicationType;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.build.dependencies.Dependency;
import org.grails.forge.build.dependencies.Scope;
import org.grails.forge.feature.Category;
import org.grails.forge.feature.DefaultFeature;
import org.grails.forge.feature.Feature;
import org.grails.forge.options.Options;

import java.util.Map;
import java.util.Set;

@Singleton
public class GrailsProfiles implements DefaultFeature {
@Override
public boolean shouldApply(ApplicationType applicationType, Options options, Set<Feature> selectedFeatures) {
return true;
}

@Override
public String getName() {
return "grails-profiles";
}

@Override
public boolean isVisible() {
return false;
}

@Override
public boolean supports(ApplicationType applicationType) {
return true;
}

@Override
public void apply(GeneratorContext generatorContext) {


final Map<String, Object> config = generatorContext.getConfiguration();
// Required by profile commands when package is not set
config.put("grails.codegen.defaultPackage", generatorContext.getProject().getPackageName());

ApplicationType applicationType = generatorContext.getApplicationType();

generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.profiles")
.artifactId(applicationType.getName().replace("_", "-"))
.scope(Scope.PROFILE));
}

@Override
public String getCategory() {
return Category.CONFIGURATION;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2024 original authors
* Copyright 2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,8 +19,6 @@
import org.grails.forge.application.ApplicationType;
import org.grails.forge.application.OperatingSystem;
import org.grails.forge.application.generator.GeneratorContext;
import org.grails.forge.build.dependencies.Dependency;
import org.grails.forge.build.dependencies.Scope;
import org.grails.forge.template.BinaryTemplate;

@Singleton
Expand Down Expand Up @@ -55,13 +53,6 @@ public void apply(GeneratorContext generatorContext) {
generatorContext.addTemplate("grailsWrapperJar", new BinaryTemplate("grails-wrapper.jar", classLoader.getResource("grails-wrapper/grails-wrapper.jar")));
generatorContext.addTemplate("grailsWrapper", new BinaryTemplate("grailsw", classLoader.getResource("grails-wrapper/grailsw"), true));
generatorContext.addTemplate("grailsWrapperBat", new BinaryTemplate("grailsw.bat", classLoader.getResource("grails-wrapper/grailsw.bat"), false));

ApplicationType applicationType = generatorContext.getApplicationType();

generatorContext.addDependency(Dependency.builder()
.groupId("org.grails.profiles")
.artifactId(applicationType.getName())
.scope(Scope.PROFILE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"includes": [
{"pattern":"assets/.*$"},
{"pattern":"gradle/.*$"},
{"pattern":"grails-wrapper/.*$"},
{"pattern":"gsp/.*$"},
{"pattern":"i18n/.*$"},
{"pattern":".gitkeep"},
Expand Down
Loading

0 comments on commit 0d2b508

Please sign in to comment.