This is an automated email from the ASF dual-hosted git repository. jamesfredley pushed a commit to branch grails7-initial-neo4jUpdates in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 7f814bb6d349d38a29b3688cd1af0ae7d1638e07 Author: James Fredley <[email protected]> AuthorDate: Thu Oct 2 15:01:17 2025 -0400 Revert "Remove Neo4j GORM support and related tests" This reverts commit d214a06fb2ea7d6b6fcb8fdb0f8e92fea5c3a9cd. --- .../grails/forge/feature/database/Neo4jGorm.java | 71 ++++++++++++++++++++++ .../java/org/grails/forge/options/GormImpl.java | 3 +- .../forge/feature/database/MongoGormSpec.groovy | 9 +++ .../{MongoGormSpec.groovy => Neo4JGormSpec.groovy} | 22 ++++--- 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/grails-forge/grails-forge-core/src/main/java/org/grails/forge/feature/database/Neo4jGorm.java b/grails-forge/grails-forge-core/src/main/java/org/grails/forge/feature/database/Neo4jGorm.java new file mode 100644 index 0000000000..4a2656a7f6 --- /dev/null +++ b/grails-forge/grails-forge-core/src/main/java/org/grails/forge/feature/database/Neo4jGorm.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.database; + +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.feature.Feature; +import org.grails.forge.options.GormImpl; +import org.grails.forge.options.Options; + +import java.util.Map; +import java.util.Set; + +@Singleton +public class Neo4jGorm extends GormOneOfFeature { + + @Override + public String getName() { + return "gorm-neo4j"; + } + + @Override + public String getTitle() { + return "GORM for Neo4j"; + } + + @Override + public String getDescription() { + return "Configure GORM for using Neo4j"; + } + + @Override + public void apply(GeneratorContext generatorContext) { + Map<String, Object> config = generatorContext.getConfiguration(); + applyDefaultGormConfig(config); + config.put("grails.neo4j.type", "embedded"); + config.put("grails.neo4j.location", "build/data/neo4j"); + generatorContext.addDependency(Dependency.builder() + .groupId("org.grails.plugins") + .artifactId("neo4j") + .implementation()); + + generatorContext.addDependency(Dependency.builder() + .groupId("org.neo4j.test") + .artifactId("neo4j-harness") + .testRuntimeOnly()); + } + + @Override + public boolean shouldApply(ApplicationType applicationType, Options options, Set<Feature> selectedFeatures) { + return selectedFeatures.stream().anyMatch(f -> f instanceof Neo4jGorm) || options.getGormImpl() == GormImpl.NEO4J; + } +} diff --git a/grails-forge/grails-forge-core/src/main/java/org/grails/forge/options/GormImpl.java b/grails-forge/grails-forge-core/src/main/java/org/grails/forge/options/GormImpl.java index a216c382ee..6b907297fd 100644 --- a/grails-forge/grails-forge-core/src/main/java/org/grails/forge/options/GormImpl.java +++ b/grails-forge/grails-forge-core/src/main/java/org/grails/forge/options/GormImpl.java @@ -23,7 +23,8 @@ import io.micronaut.core.annotation.NonNull; public enum GormImpl { HIBERNATE("gorm-hibernate5"), - MONGODB("gorm-mongodb"); + MONGODB("gorm-mongodb"), + NEO4J("gorm-neo4j"); public static final GormImpl DEFAULT_OPTION = HIBERNATE; private final String featureName; diff --git a/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy b/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy index c8a0eda408..bc7144bb36 100644 --- a/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy +++ b/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy @@ -43,6 +43,15 @@ class MongoGormSpec extends ApplicationContextSpec implements CommandOutputFixtu features.contains("gorm-mongodb") } + void "test there can only be one of either MongoDB or Neo4j feature"() { + when: + getFeatures(beanContext.getBeansOfType(GormOneOfFeature)*.name) + + then: + def ex = thrown(IllegalArgumentException) + ex.message.contains("There can only be one of the following features selected") + } + void "test dependencies are present for gradle"() { when: String template = new BuildBuilder(beanContext) diff --git a/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy b/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/Neo4JGormSpec.groovy similarity index 66% copy from grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy copy to grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/Neo4JGormSpec.groovy index c8a0eda408..3a8f68931c 100644 --- a/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/MongoGormSpec.groovy +++ b/grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/database/Neo4JGormSpec.groovy @@ -25,40 +25,42 @@ import org.grails.forge.application.generator.GeneratorContext import org.grails.forge.feature.Features import org.grails.forge.fixture.CommandOutputFixture -class MongoGormSpec extends ApplicationContextSpec implements CommandOutputFixture { +class Neo4JGormSpec extends ApplicationContextSpec implements CommandOutputFixture { void "test Mongo gorm features"() { when: - Features features = getFeatures(['gorm-mongodb']) + Features features = getFeatures(['gorm-neo4j']) then: - features.contains("gorm-mongodb") + features.contains("gorm-neo4j") } - void "test Mongo gorm with Embedded MongoDB features "() { + void "test there can only be one of either MongoDB or Neo4j feature"() { when: - Features features = getFeatures(['gorm-mongodb']) + getFeatures(beanContext.getBeansOfType(GormOneOfFeature)*.name) then: - features.contains("gorm-mongodb") + def ex = thrown(IllegalArgumentException) + ex.message.contains("There can only be one of the following features selected") } void "test dependencies are present for gradle"() { when: String template = new BuildBuilder(beanContext) - .features(["gorm-mongodb"]) + .features(["gorm-neo4j"]) .render() then: - template.contains("implementation \"org.apache.grails:grails-data-mongodb\"") + template.contains("implementation \"org.grails.plugins:neo4j\"") } void "test config"() { when: - GeneratorContext ctx = buildGeneratorContext(['gorm-mongodb']) + GeneratorContext ctx = buildGeneratorContext(['gorm-neo4j']) then: - ctx.configuration.containsKey("grails.mongodb.url") + ctx.configuration.containsKey("grails.neo4j.type") + ctx.configuration.containsKey("grails.neo4j.location") }
