Skip to content

Commit

Permalink
sb3: reinstate infinispan support (#20398)
Browse files Browse the repository at this point in the history
* Revert "disable infinispan at integration tests."

This reverts commit b60e6a7.

* Remove inexistent methods

* add dependency on infinispan-component-annotations

* adjusts to infinispan cache

* disable infinispan tests

* Revert "disable infinispan tests"

This reverts commit 9b9a4c5.

* switch to skip_ci-infinispan bom branch

* adjusts to infinispan

* enable proxyTargetClass

* update build.gradle

* fix prettier

* use revert-1121-skip_ci-infinispan branch

* fix infinispan-spring-boot-starter-embedded dependency

* fixes

* add infinispan bom

* Revert "fixes"

This reverts commit 08ea2458cfb13ed7424f51e31589e30acd1262ad.

* revert bom branch

* revert app configs

* revert proxyTargetClass

* change infinispan to spring-boot3

* modularize gradle cache support.

* fixes

* adjusts

* adjusts

* prettier

* add infinispan TODO
  • Loading branch information
mshima authored Mar 22, 2023
1 parent 0156f5a commit 349b8cc
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 86 deletions.
10 changes: 0 additions & 10 deletions generators/base-application/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,6 @@ export default class BaseApplicationGenerator<
return taskGroup;
}

/**
* Utility method to get typed objects for autocomplete.
*
* @param {import('./tasks.mjs').PostWritingTaskGroup<this, Definition>} taskGroup
* @returns {import('./tasks.mjs').PostWritingTaskGroup<this, Definition>}
*/
asPostWritingTaskGroup(taskGroup) {
return taskGroup;
}

/**
* Utility method to get typed objects for autocomplete.
*/
Expand Down
3 changes: 3 additions & 0 deletions generators/gradle/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default class GradleGenerator extends BaseApplicationGenerator {
async verify({ application }) {
assert.equal(application.buildTool, GRADLE);
},
addSourceNeddles({ source }) {
source.applyFromGradle = script => this.applyFromGradleScript(script);
},
});
}

Expand Down
2 changes: 1 addition & 1 deletion generators/server/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export { serverFiles as files } from './files.mjs';
export type ApplicationDefinition = GenericApplicationDefinition<SpringBootApplication>;

// TODO move to ./generator.mts
export type GeneratorDefinition = BaseApplicationGeneratorDefinition<ApplicationDefinition & GenericSourceTypeDefinition>;
export type GeneratorDefinition = BaseApplicationGeneratorDefinition<ApplicationDefinition & GenericSourceTypeDefinition<any>>;
46 changes: 2 additions & 44 deletions generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ dependencies {
if (SPRING_BOOT_VERSION.indexOf('M') > -1 || SPRING_BOOT_VERSION.indexOf('RC') > -1) { _%>
runtimeOnly "org.springframework.boot:spring-boot-properties-migrator"
<%_ } _%>
<%_ if (!cacheProviderNo) { _%>
implementation "org.springframework.boot:spring-boot-starter-cache"
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations"
<%_ if (reactive) { _%>
Expand All @@ -327,30 +324,7 @@ if (SPRING_BOOT_VERSION.indexOf('M') > -1 || SPRING_BOOT_VERSION.indexOf('RC') >
<%_ } _%>
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
<%_ if (cacheProviderHazelcast) { _%>
<%_ if (enableHibernateCache) { _%>
implementation "com.hazelcast:hazelcast-hibernate53:${hazelcastHibernate53Version}"
<%_ } _%>
implementation "com.hazelcast:hazelcast-spring:${hazelcastSpringVersion}"
<%_ } _%>
<%_ if (cacheProviderInfinispan) { _%>
implementation "org.infinispan:infinispan-hibernate-cache-v60"
implementation "org.infinispan:infinispan-spring-boot-starter-embedded"
implementation "org.infinispan:infinispan-core-jakarta"
implementation "org.infinispan:infinispan-jcache"
<%_ } _%>
<%_ if (cacheProviderMemcached) { _%>
implementation "com.google.code.simple-spring-memcached:spring-cache"
implementation "com.google.code.simple-spring-memcached:xmemcached-provider"
implementation "com.googlecode.xmemcached:xmemcached"
<%_ } _%>
<%_ if (cacheProviderRedis) { _%>
implementation "org.redisson:redisson"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
<%_ } _%>
<%_ if (cacheProviderRedis || databaseTypeMongodb || databaseTypeCouchbase || databaseTypeNeo4j || databaseTypeCassandra || searchEngineElasticsearch || messageBrokerKafka || databaseTypeSql) { _%>
<%_ if (databaseTypeMongodb || databaseTypeCouchbase || databaseTypeNeo4j || databaseTypeCassandra || searchEngineElasticsearch || messageBrokerKafka || databaseTypeSql) { _%>
testImplementation "org.testcontainers:junit-jupiter"
testImplementation "org.testcontainers:testcontainers"
<%_ } _%>
Expand Down Expand Up @@ -381,30 +355,14 @@ if (SPRING_BOOT_VERSION.indexOf('M') > -1 || SPRING_BOOT_VERSION.indexOf('RC') >
implementation "eu.michael-simons.neo4j:neo4j-migrations-spring-boot-starter"
testImplementation "org.testcontainers:neo4j"
<%_ } _%>
<%_ if (cacheProviderEhCache || cacheProviderCaffeine || cacheProviderHazelcast || cacheProviderInfinispan || cacheProviderMemcached) { _%>
implementation "javax.cache:cache-api"
<%_ } _%>
<%_ if (databaseTypeCassandra) { _%>
implementation "org.lz4:lz4-java"
testImplementation "org.cassandraunit:cassandra-unit-spring"
testImplementation "org.testcontainers:cassandra"
<%_ } _%>
<%_ if (cacheProviderEhCache) { _%>
implementation "org.ehcache:ehcache"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
<%_ } _%>
<%_ if (cacheProviderCaffeine || (authenticationTypeOauth2 && !cacheProviderInfinispan)) { _%>
<%_ if (authenticationTypeOauth2 && !cacheProviderCaffeine && !cacheProviderInfinispan) { _%>
implementation "com.github.ben-manes.caffeine:caffeine:${caffeineVersion}"
<%_ } _%>
<%_ if (cacheProviderCaffeine) { _%>
implementation "com.github.ben-manes.caffeine:jcache:${caffeineVersion}"
implementation "com.typesafe:config:${typesafeConfigVersion}"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
annotationProcessor "org.hibernate.orm:hibernate-jpamodelgen:${hibernateVersion}"
implementation "org.hibernate.orm:hibernate-core"
Expand Down
19 changes: 17 additions & 2 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<%_ if (cacheProviderInfinispan) { _%>
<!-- TODO rework infinispan-bom dependency once spring-boot 3.0.5 is released -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>14.0.7.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<%_ } _%>
<%_ if (reactive && (prodDatabaseTypeMariadb || prodDatabaseTypeMysql)) { _%>
<!-- TODO drop spring-data-r2dbc is not managing r2dbc-mariadb version -->
<dependency>
Expand Down Expand Up @@ -297,15 +307,20 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-spring-boot-starter-embedded</artifactId>
<artifactId>infinispan-spring-boot3-starter-embedded</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-commons-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-jcache</artifactId>
<artifactId>infinispan-component-annotations</artifactId>
<scope>compile</scope>
</dependency>
<%_ } _%>
<%_ if (cacheProviderMemcached) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<logger name="org.springframework" level="WARN"/>
<logger name="org.springframework.web" level="WARN"/>
<logger name="org.springframework.security" level="WARN"/>
<logger name="org.springframework.boot.autoconfigure.logging" level="INFO"/>
<logger name="org.springframework.cache" level="WARN"/>
<%_ if (reactive) { _%>
<logger name="org.synchronoss" level="WARN"/>
Expand Down
102 changes: 95 additions & 7 deletions generators/spring-cache/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generator - spring-cache caffeine should match files snapshot 1`] = `
exports[`generator - spring-cache caffeine-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache caffeine-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
Expand All @@ -11,18 +25,21 @@ exports[`generator - spring-cache caffeine should match files snapshot 1`] = `
}
`;

exports[`generator - spring-cache ehcache should match files snapshot 1`] = `
exports[`generator - spring-cache ehcache-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache hazelcast should match files snapshot 1`] = `
exports[`generator - spring-cache ehcache-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
Expand All @@ -33,11 +50,39 @@ exports[`generator - spring-cache hazelcast should match files snapshot 1`] = `
}
`;

exports[`generator - spring-cache infinispan should match files snapshot 1`] = `
exports[`generator - spring-cache hazelcast-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache hazelcast-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache infinispan-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
Expand All @@ -47,7 +92,35 @@ exports[`generator - spring-cache infinispan should match files snapshot 1`] = `
}
`;

exports[`generator - spring-cache memcached should match files snapshot 1`] = `
exports[`generator - spring-cache infinispan-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheFactoryConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache memcached-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache memcached-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
Expand All @@ -58,15 +131,30 @@ exports[`generator - spring-cache memcached should match files snapshot 1`] = `
}
`;

exports[`generator - spring-cache no should match files snapshot 1`] = `
exports[`generator - spring-cache redis-gradle should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/config/EmbeddedRedis.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/config/RedisTestContainer.java": {
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/config/RedisTestContainersSpringContextCustomizerFactory.java": {
"stateCleared": "modified",
},
}
`;

exports[`generator - spring-cache redis should match files snapshot 1`] = `
exports[`generator - spring-cache redis-maven should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
Expand Down
11 changes: 4 additions & 7 deletions generators/spring-cache/files.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@ import { WriteFileSection } from '../base/api.mjs';
const files: WriteFileSection<Generator, any> = {
cacheFiles: [
{
condition: data =>
data.cacheProviderEhCache ||
data.cacheProviderCaffeine ||
data.cacheProviderHazelcast ||
data.cacheProviderInfinispan ||
data.cacheProviderMemcached ||
data.cacheProviderRedis,
condition: data => data.buildToolGradle,
templates: ['gradle/cache.gradle'],
},
{
path: `${SERVER_MAIN_SRC_DIR}package/`,
renameTo: moveToJavaPackageSrcDir,
templates: ['config/CacheConfiguration.java'],
Expand Down
10 changes: 8 additions & 2 deletions generators/spring-cache/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_SPRING_CACHE, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs';
import writeTask from './files.mjs';
import cleanupTask from './cleanup.mjs';
import { GeneratorDefinition as SpringBootGeneratorDefinition } from '../server/index.mjs';

export default class SpringCacheGenerator extends BaseApplicationGenerator {
export default class SpringCacheGenerator extends BaseApplicationGenerator<SpringBootGeneratorDefinition> {
async beforeQueue() {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
if (!this.fromBlueprint) {
Expand Down Expand Up @@ -51,13 +52,18 @@ export default class SpringCacheGenerator extends BaseApplicationGenerator {
get postWriting() {
return this.asPostWritingTaskGroup({
addTestSpringFactory({ source, application }) {
if (application.cacheProviderRedis) {
if ((application as any).cacheProviderRedis) {
source.addTestSpringFactory?.({
key: 'org.springframework.test.context.ContextCustomizerFactory',
value: `${application.packageName}.config.RedisTestContainersSpringContextCustomizerFactory`,
});
}
},
applyGradleScript({ source, application }) {
if (application.buildToolGradle) {
source.applyFromGradle?.('gradle/cache');
}
},
});
}

Expand Down
10 changes: 6 additions & 4 deletions generators/spring-cache/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import lodash from 'lodash';
import { basename, dirname } from 'path';
import { fileURLToPath } from 'url';

import { buildServerMatrix, extendMatrix, extendFilteredMatrix, buildSamplesFromMatrix, fromMatrix } from '../../test/support/index.mjs';
import { fromMatrix } from '../../test/support/index.mjs';
import { testBlueprintSupport } from '../../test/support/tests.mjs';
import Generator from './index.mjs';
import { defaultHelpers as helpers, result } from '../../test/support/helpers.mjs';

import { GENERATOR_SPRING_CACHE } from '../generator-list.mjs';
import { cacheTypes } from '../../jdl/jhipster/index.mjs';
import { cacheTypes, buildToolTypes } from '../../jdl/jhipster/index.mjs';

const { snakeCase } = lodash;

Expand All @@ -18,10 +18,12 @@ const __dirname = dirname(__filename);

const generator = basename(__dirname);

const { NO: NO_CACHE_PROVIDER, EHCACHE, CAFFEINE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = cacheTypes;
const { EHCACHE, CAFFEINE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = cacheTypes;
const { MAVEN, GRADLE } = buildToolTypes;

const samples = fromMatrix({
cacheProvider: [NO_CACHE_PROVIDER, EHCACHE, CAFFEINE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS],
cacheProvider: [EHCACHE, CAFFEINE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS],
buildTool: [MAVEN, GRADLE],
});

describe(`generator - ${generator}`, () => {
Expand Down
Loading

0 comments on commit 349b8cc

Please sign in to comment.