Skip to content

Commit

Permalink
[Build] TEmporary hack fix for accented characters in path
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Oct 18, 2024
1 parent 38ef9dc commit f985465
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 14 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ jobs:
- name: Build JVM OCI image
run: gradle jib -Djib.serialize=true # https://github.com/GoogleContainerTools/jib/issues/4301
env:
LANG: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
Expand All @@ -86,9 +84,6 @@ jobs:
- name: Build Native OCI Image
run: gradle bootBuildImage --publishImage --imagePlatform linux/amd64
env:
LANG: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
NATIVE_IMAGE_OPTIONS: "-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8"
USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
Expand All @@ -97,9 +92,6 @@ jobs:

- name: Setup QEMU for ARM64 OCI Image
uses: docker/setup-qemu-action@v3
env:
LANG: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
with:
platforms: 'all'

Expand All @@ -112,8 +104,6 @@ jobs:
- name: Build Native ARM64 OCI Image
run: gradle bootBuildImage --publishImage --imagePlatform linux/arm64
env:
LANG: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
Expand Down
48 changes: 44 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.google.cloud.tools.jib.api.buildplan.ImageFormat
import net.nemerosa.versioning.VersioningExtension
import org.gradle.kotlin.dsl.add
import org.gradle.kotlin.dsl.from
import org.gradle.kotlin.dsl.invoke
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -66,9 +69,22 @@ configure<IdeaModel> {
}
}

// Required until GraalVM/Paketo builders receive a fix
sourceSets {
main {
java {
srcDir("src/main")
srcDir("src/java.base")
}
kotlin {
srcDir("src/kotlin")
}
}
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(22))
languageVersion.set(JavaLanguageVersion.of(23))
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}
Expand All @@ -80,8 +96,29 @@ tasks.withType<Test> {
tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_22.toString()
targetCompatibility = JavaVersion.VERSION_22.toString()

finalizedBy("copyPatches")
}

/*
* Hack required until
* - https://github.com/paketo-buildpacks/native-image/issues/344
* - https://github.com/oracle/graal/issues/9879
* are fixed.
*
* We're copying over patches to the JDK and forcing them into the native image at build time.
*/
tasks.register<Copy>("copyPatches") {
dependsOn("build")
mustRunAfter("compileJava")

from(layout.buildDirectory.dir("classes/java/main"))
include("**/*.*")
into(layout.buildDirectory.dir("resources/main/java.base"))
}

tasks.register("buildPatchedNativeImage")

tasks.withType<KotlinCompile> {
compilerOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
Expand Down Expand Up @@ -156,7 +193,11 @@ tasks.withType<BootBuildImage> {
docker.publishRegistry.password = System.getenv("GITHUB_TOKEN") ?: "INVALID_PASSWORD"

builder = "paketobuildpacks/builder-jammy-buildpackless-tiny"
buildpacks = listOf("paketobuildpacks/environment-variables", "paketobuildpacks/java-native-image", "paketobuildpacks/health-checker")
buildpacks = listOf(
"paketobuildpacks/environment-variables",
"paketobuildpacks/java-native-image",
"paketobuildpacks/health-checker"
)
imageName = project.extra["native.image.name"] as String
version = project.extra["docker.image.version"] as String
tags = project.extra["native.image.tags"] as List<String>
Expand All @@ -169,11 +210,10 @@ tasks.withType<BootBuildImage> {
"BP_HEALTH_CHECKER_ENABLED" to "true",
"BP_JVM_CDS_ENABLED" to "true",
"BP_JVM_VERSION" to "23",
"BPE_NATIVE_IMAGE_OPTIONS" to "-Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8",
"BPE_LANG" to "en_US.UTF-8",
"BPE_LANGUAGE" to "LANGUAGE=en_US:en",
"BPE_LC_ALL" to "en_US.UTF-8",
"BP_NATIVE_IMAGE_BUILD_ARGUMENTS" to "-march=compatibility -H:+AddAllCharsets -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8"
"BP_NATIVE_IMAGE_BUILD_ARGUMENTS" to "-march=compatibility -H:+AddAllCharsets -J--patch-module=java.base=/workspace/BOOT-INF/classes/java.base"
)
}

Expand Down
110 changes: 110 additions & 0 deletions src/java.base/sun/nio/fs/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package sun.nio.fs;

import java.nio.charset.StandardCharsets;
import java.util.*;
import java.nio.file.*;
import java.nio.charset.Charset;

/**
* Utility methods
* Only change from Adoptium JDK 23 - use UTF-8 as default charset
* Otherwise native images are broken.
* - https://github.com/oracle/graal/issues/9879
* - https://github.com/paketo-buildpacks/native-image/issues/344
*/

class Util {
private Util() { }

private static final Charset jnuEncoding = StandardCharsets.UTF_8;

/**
* Returns {@code Charset} corresponding to the sun.jnu.encoding property
*/
static Charset jnuEncoding() {
return jnuEncoding;
}

/**
* Encodes the given String into a sequence of bytes using the {@code Charset}
* specified by the sun.jnu.encoding property.
*/
static byte[] toBytes(String s) {
return s.getBytes(jnuEncoding);
}

/**
* Constructs a new String by decoding the specified array of bytes using the
* {@code Charset} specified by the sun.jnu.encoding property.
*/
static String toString(byte[] bytes) {
return new String(bytes, jnuEncoding);
}


/**
* Splits a string around the given character. The array returned by this
* method contains each substring that is terminated by the character. Use
* for simple string spilting cases when needing to avoid loading regex.
*/
static String[] split(String s, char c) {
int count = 0;
for (int i=0; i<s.length(); i++) {
if (s.charAt(i) == c)
count++;
}
String[] result = new String[count+1];
int n = 0;
int last = 0;
for (int i=0; i<s.length(); i++) {
if (s.charAt(i) == c) {
result[n++] = s.substring(last, i);
last = i + 1;
}
}
result[n] = s.substring(last, s.length());
return result;
}

/**
* Returns a Set containing the given elements.
*/
@SafeVarargs
static <E> Set<E> newSet(E... elements) {
HashSet<E> set = new HashSet<>();
for (E e: elements) {
set.add(e);
}
return set;
}

/**
* Returns a Set containing all the elements of the given Set plus
* the given elements.
*/
@SafeVarargs
static <E> Set<E> newSet(Set<E> other, E... elements) {
HashSet<E> set = new HashSet<>(other);
for (E e: elements) {
set.add(e);
}
return set;
}

/**
* Returns {@code true} if symbolic links should be followed
*/
static boolean followLinks(LinkOption... options) {
boolean followLinks = true;
for (LinkOption option: options) {
if (option == LinkOption.NOFOLLOW_LINKS) {
followLinks = false;
} else if (option == null) {
throw new NullPointerException();
} else {
throw new AssertionError("Should not get here");
}
}
return followLinks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.ImportRuntimeHints
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.annotation.EnableScheduling
import java.nio.file.Path

@EnableConfigurationProperties
@EnableAsync
Expand Down

0 comments on commit f985465

Please sign in to comment.