Skip to content

Commit

Permalink
Resolves mojohaus#931: Fixing problems with encoding in UseDepVersion…
Browse files Browse the repository at this point in the history
… and PomHelper (mojohaus#932)

Co-authored-by: Slawomir Jaranowski <s.jaranowski@gmail.com>
  • Loading branch information
andrzejj0 and slawekjaranowski authored May 14, 2023
1 parent 746c750 commit bdf6b1c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,7 @@ private static List<ModelNode> getRawModelTree(ModelNode rootNode, Log logger, X
.map(pomFile -> {
try {
ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader(
new StringBuilder(new String(Files.readAllBytes(pomFile))),
inputFactory,
pomFile.toString());
readXmlFile(pomFile.toFile()), inputFactory, pomFile.toString());
return new ModelNode(rootNode, getRawModel(pom), pom);
} catch (IOException e) {
throw new UncheckedIOException("Could not open " + pomFile, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-dep-version
invoker.mavenOpts = -Dfile.encoding=latin1 -Dincludes=localhost -DdepVersion=1.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test-group</groupId>
<artifactId>test-artifact</artifactId>
<version>DEVELOP-SNAPSHOT</version>

<description>Wörter mit Umlauten</description>
<!-- Vorläufige Container für Tests -->

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import groovy.xml.XmlSlurper

def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
assert project.dependencies.dependency.version == '1.0.1'
assert project.description == 'Wörter mit Umlauten'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-dep-version
invoker.mavenOpts = -Dfile.encoding=latin1 -Dincludes=localhost -DdepVersion=1.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test-group</groupId>
<artifactId>test-artifact</artifactId>
<version>DEVELOP-SNAPSHOT</version>

<description>Wörter mit Umlauten</description>
<!-- Vorläufige Container für Tests -->

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import groovy.xml.XmlSlurper

def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
assert project.dependencies.dependency.version == '1.0.1'
assert project.description == 'Wörter mit Umlauten'
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -136,10 +135,10 @@ protected void update(ModifiedPomXMLEventReader pom)
public void execute() throws MojoExecutionException, MojoFailureException {
validateInput();
List<ModelNode> rawModels;

try {
ModifiedPomXMLEventReader pomReader = newModifiedPomXER(
new StringBuilder(
new String(Files.readAllBytes(getProject().getFile().toPath()))),
PomHelper.readXmlFile(getProject().getFile()),
getProject().getFile().toPath().toString());
ModelNode rootNode = new ModelNode(PomHelper.getRawModel(pomReader), pomReader);
rawModels = PomHelper.getRawModelTree(rootNode, getLog());
Expand Down

0 comments on commit bdf6b1c

Please sign in to comment.