Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java/graalvm: polish #27675

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ exports[`generator - github-build-matrix with graalvm should match matrix value
"npm-version": "NPM-VERSION",
"default-environment": "prod",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"jdl-base": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool maven\\n cacheProvider no\\n }\\n}",
"jdl": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool maven\\n graalvmSupport true\\n }\\n}"
},
{
Expand All @@ -586,7 +585,6 @@ exports[`generator - github-build-matrix with graalvm should match matrix value
"npm-version": "NPM-VERSION",
"default-environment": "prod",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"jdl-base": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool maven\\n reactive true\\n cacheProvider no\\n }\\n}",
"jdl": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool maven\\n reactive true\\n graalvmSupport true\\n }\\n}"
},
{
Expand All @@ -598,7 +596,6 @@ exports[`generator - github-build-matrix with graalvm should match matrix value
"npm-version": "NPM-VERSION",
"default-environment": "prod",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"jdl-base": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool gradle\\n cacheProvider no\\n }\\n}",
"jdl": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool gradle\\n graalvmSupport true\\n }\\n}"
},
{
Expand All @@ -610,7 +607,6 @@ exports[`generator - github-build-matrix with graalvm should match matrix value
"npm-version": "NPM-VERSION",
"default-environment": "prod",
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"jdl-base": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool gradle\\n reactive true\\n cacheProvider no\\n }\\n}",
"jdl": "application {\\n config {\\n testFrameworks [cypress]\\n buildTool gradle\\n reactive true\\n graalvmSupport true\\n }\\n}"
}
]
Expand Down
4 changes: 2 additions & 2 deletions .blueprint/github-build-matrix/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export default class extends BaseGenerator {
// Push events requires a base commit for diff. Diff cannot be checked by @~1 if PR was merged with a rebase.
const useChanges = this.eventName === 'pull_request';
const changes = await getGitChanges({ allTrue: !useChanges });
const { base, common, devBlueprint, client, e2e, java, workspaces } = changes;
const { base, common, devBlueprint, client, e2e, graalvm, java, workspaces } = changes;
const hasWorkflowChanges = changes[`${this.workflow}Workflow`];

let matrix: GitHubMatrixRecord = {};
let randomEnvironment = false;
if (this.workflow === 'docker-compose-integration') {
matrix = dockerComposeMatrix;
} else if (this.workflow === 'graalvm') {
if (hasWorkflowChanges || java) {
if (hasWorkflowChanges || java || graalvm) {
matrix = graalvmMatrix;
}
} else if (this.workflow === 'devserver') {
Expand Down
1 change: 0 additions & 1 deletion .blueprint/github-build-matrix/samples/graalvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const graalvmMatrix = Object.fromEntries(
key,
{
'java-version': '21',
'jdl-base': convertOptionsToJDL({ ...value, cacheProvider: 'no' }),
jdl: convertOptionsToJDL({ ...value, graalvmSupport: true }),
},
]),
Expand Down
9 changes: 7 additions & 2 deletions .blueprint/github-build-matrix/support/git-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const getGitChanges = async (options: { allTrue?: boolean } = {}) => {
const git = simpleGit({ baseDir: fileURLToPath(new URL('../../', import.meta.url).href) });
const summary = await git.diffSummary({ '@~1': null });
const files = summary.files.map(({ file }) => file);
hasPatternChanges = (pattern: string) => files.some(file => minimatch(file, pattern, { dot: true }));
hasPatternChanges = (pattern: string, ignore?: string) =>
files.some(file => minimatch(file, pattern, { dot: true }) && (!ignore || !minimatch(file, ignore, { dot: true })));
}

const hasClientWorkflowChanges = (client: 'angular' | 'react' | 'vue') =>
Expand All @@ -29,7 +30,11 @@ export const getGitChanges = async (options: { allTrue?: boolean } = {}) => {
common: hasPatternChanges('generators/{app,common,docker,languages}/**'),
client: hasPatternChanges('generators/{client,init,javascript}/**'),
e2e: hasPatternChanges('generators/cypress/**'),
java: hasPatternChanges('generators/{cucumber,feign-client,gatling,gradle,java,liquibase,maven,server,spring*}/**'),
java: hasPatternChanges(
'generators/{cucumber,feign-client,gatling,gradle,java,liquibase,maven,server,spring*}/**',
'generators/java/generators/graalvm/**',
),
graalvm: hasPatternChanges('generators/java/generators/graalvm/**'),
react: hasPatternChanges('generators/react/**'),
reactWorkflow: hasClientWorkflowChanges('react'),
workspaces: hasPatternChanges('generators/{docker-compose,kubernetes*,workspaces}/**'),
Expand Down
1 change: 1 addition & 0 deletions generators/base/shared-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class SharedData<ApplicationType extends BaseApplication = BaseAp
removeFiles,
customizeRemoveFiles: [],
cleanupFiles: async (cleanup: Record<string, (string | [boolean, ...string[]])[]>) => {
if (!jhipsterOldVersion) return;
await Promise.all(
Object.entries(cleanup).map(async ([version, files]) => {
const stringFiles: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ exports[`generator - java:graalvm with default options should call source snapsh
</metadataRepository>
<imageName>\${native-image-name}</imageName>
<verbose>true</verbose>
<buildArgs>
<buildArg>-Duser.language=en</buildArg>
<buildArg>-H:IncludeLocales=</buildArg>
</buildArgs>
<jvmArgs>
<arg>-Xms4g</arg>
<arg>-Xmx10g</arg>
</jvmArgs>
</configuration>",
Expand Down Expand Up @@ -131,6 +136,17 @@ exports[`generator - java:graalvm with default options should call source snapsh
],
},
],
"addNativeHint": [
{
"advanced": [
"hints.reflection().registerType(sun.misc.Unsafe.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));",
"hints.reflection().registerType(java.util.Locale.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));",
],
"resources": [
"i18n/*",
],
},
],
"editJavaFile": [
[
"src/main/java/com/mycompany/myapp/JhipsterApp.java",
Expand Down Expand Up @@ -170,6 +186,17 @@ exports[`generator - java:graalvm with default options should call source snapsh
"version": "'NATIVE-BUILD-TOOLS-VERSION'",
},
],
"addNativeHint": [
{
"advanced": [
"hints.reflection().registerType(sun.misc.Unsafe.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));",
"hints.reflection().registerType(java.util.Locale.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));",
],
"resources": [
"i18n/*",
],
},
],
"applyFromGradle": [
{
"script": "gradle/native.gradle",
Expand Down
23 changes: 21 additions & 2 deletions generators/java/generators/graalvm/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,17 @@ export default class GraalvmGenerator extends BaseApplicationGenerator {
},

async customizeMaven({ application, source }) {
const { buildToolMaven, reactive, databaseTypeSql, javaDependencies } = application;
const { buildToolMaven, reactive, databaseTypeSql, javaDependencies, nativeLanguageDefinition, languagesDefinition } = application;
if (!buildToolMaven) return;

source.addMavenDefinition!(
mavenDefinition({ reactive, nativeBuildToolsVersion: javaDependencies!.nativeBuildTools!, databaseTypeSql }),
mavenDefinition({
reactive,
nativeBuildToolsVersion: javaDependencies!.nativeBuildTools!,
databaseTypeSql,
userLanguage: nativeLanguageDefinition.languageTag,
languages: languagesDefinition.map(def => def.languageTag),
}),
);
},

Expand Down Expand Up @@ -237,6 +243,19 @@ export default class GraalvmGenerator extends BaseApplicationGenerator {
),
);
},
nativeHints({ source, application }) {
if (!application.backendTypeSpringBoot) return;

source.addNativeHint!({
advanced: [
// Undertow
'hints.reflection().registerType(sun.misc.Unsafe.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));',
// Thymeleaf template
'hints.reflection().registerType(java.util.Locale.class, (hint) -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));',
],
resources: ['i18n/*'],
});
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export const mavenDefinition = ({
reactive,
nativeBuildToolsVersion,
databaseTypeSql,
userLanguage,
languages,
}: {
reactive?: boolean;
nativeBuildToolsVersion?: string;
databaseTypeSql?: boolean;
userLanguage: string;
languages: string[];
}): MavenDefinition => ({
properties: [
{ property: 'repackage.classifier' },
Expand All @@ -29,7 +33,12 @@ export const mavenDefinition = ({
</metadataRepository>
<imageName>\${native-image-name}</imageName>
<verbose>true</verbose>
<buildArgs>
<buildArg>-Duser.language=${userLanguage}</buildArg>
<buildArg>-H:IncludeLocales=${languages.join(',')}</buildArg>
</buildArgs>
<jvmArgs>
<arg>-Xms4g</arg>
<arg>-Xmx10g</arg>
</jvmArgs>
</configuration>`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ graalvmNative {
// languageVersion = JavaLanguageVersion.of(19)
// vendor = JvmVendorSpec.matching("GraalVM Community")
//}
buildArgs.add("-Duser.language=<%- nativeLanguageDefinition.languageTag %>")
buildArgs.add("-H:IncludeLocales=<%- languagesDefinition.map(def => def.languageTag).join(',') %>")
}
binaries.all {
verbose = true
jvmArgs.add('-Xms4g')
jvmArgs.add('-Xmx10g')
}
}
binaries.all {
verbose = true
jvmArgs.add('-Xms4g')
jvmArgs.add('-Xmx10g')
}
}

Expand Down
1 change: 0 additions & 1 deletion generators/liquibase/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator {
// Hints may be dropped if newer version is supported
// https://github.com/oracle/graalvm-reachability-metadata/blob/master/metadata/org.liquibase/liquibase-core/index.json
source.addNativeHint!({
advanced: ['hints.resources().registerPattern("");'],
resources: ['config/liquibase/*'],
declaredConstructors: [
'liquibase.database.LiquibaseTableNamesFactory.class',
Expand Down
Loading