Skip to content

Commit

Permalink
[kie-issues#754] Use UTF-8 on important places during Quarkus build (a…
Browse files Browse the repository at this point in the history
…pache#5620)

* Use UTF-8 when handling files and file content.

* Fix memory compiler to use UTF-8

* Fix QueryGenerator to use UTF-8.

* Revert selected fixes.
  • Loading branch information
baldimir authored and rgdoliveira committed Dec 13, 2023
1 parent f12f3f6 commit fd4f6eb
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public GeneratedFileType.Category category() {

public String toStringWithContent() {
return "GeneratedFile{" + "path=" + path +
", content='\n" + new String(contents) + "\n'}";
", content='\n" + new String(contents, StandardCharsets.UTF_8) + "\n'}";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Collection;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected static Properties load(File... resourcePaths) {
Properties applicationProperties = new Properties();

for (File resourcePath : resourcePaths) {
try (FileReader fileReader = new FileReader(new File(resourcePath, APPLICATION_PROPERTIES_FILE_NAME))) {
try (FileReader fileReader = new FileReader(new File(resourcePath, APPLICATION_PROPERTIES_FILE_NAME), StandardCharsets.UTF_8)) {
applicationProperties.load(fileReader);
} catch (IOException ioe) {
LOGGER.debug("Unable to load '" + APPLICATION_PROPERTIES_FILE_NAME + "'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static Collection<Resource> fromJarFile(Path jarPath) {
if (resourceType == null) {
continue;
}
InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)), StandardCharsets.UTF_8.name());
resource.setSourcePath(entry.getName());
resource.setResourceType(resourceType);
resources.add(resource);
Expand Down Expand Up @@ -119,7 +120,7 @@ private static Resource toResource(File file) {
if (resourceType == null) {
return null;
}
Resource resource = new FileSystemResource(file);
Resource resource = new FileSystemResource(file, StandardCharsets.UTF_8.name());
resource.setResourceType(resourceType);
return resource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.drools.quarkus.util.deployment;

import java.nio.charset.StandardCharsets;
import io.quarkus.arc.deployment.GeneratedBeanBuildItem;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down Expand Up @@ -174,7 +175,7 @@ private static Map<String, String> getSourceMap(Collection<GeneratedFile> genera
Map<String, String> sourcesMap = new HashMap<>();
for (GeneratedFile javaFile : generatedFiles) {
if (javaFile.category() == GeneratedFileType.Category.SOURCE) {
sourcesMap.put(toClassName(javaFile.relativePath()), new String(javaFile.contents()));
sourcesMap.put(toClassName(javaFile.relativePath()), new String(javaFile.contents(), StandardCharsets.UTF_8));
}
}
return sourcesMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.kie.memorycompiler;

import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -124,7 +125,7 @@ public static Map<String, byte[]> compileNoLoad(Map<String, String> classNameSou
int i = 0;
for (Map.Entry<String, String> entry : classNameSourceMap.entrySet()) {
classNames[i] = toJavaSource( entry.getKey() );
reader.add( classNames[i], entry.getValue().getBytes());
reader.add( classNames[i], entry.getValue().getBytes(StandardCharsets.UTF_8));
i++;
}
JavaConfiguration javaConfiguration = new JavaConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public CompilationResult compile( String[] pResourcePaths,
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavaCompiler compiler = getJavaCompiler();

try (StandardJavaFileManager jFileManager = compiler.getStandardFileManager(diagnostics, null, null)) {
try (StandardJavaFileManager jFileManager = compiler.getStandardFileManager(diagnostics, null, Charset.forName(pSettings.getSourceEncoding()))) {
try {
jFileManager.setLocation( StandardLocation.CLASS_PATH, pSettings.getClasspathLocations() );
jFileManager.setLocation( StandardLocation.CLASS_OUTPUT, Collections.singletonList(new File("target/classes")) );
Expand Down

0 comments on commit fd4f6eb

Please sign in to comment.