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

Fix args parsing on Windows #609

Merged
merged 11 commits into from
Sep 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,29 @@ protected List<String> getBuildArgs() throws MojoExecutionException {

if (buildArgs != null && !buildArgs.isEmpty()) {
for (String buildArg : buildArgs) {
cliArgs.addAll(Arrays.asList(buildArg.split("\\s+")));
if(buildArg.startsWith("\\Q") ||
buildArg.startsWith("-H:ConfigurationFileDirectories")) {
cliArgs.add(buildArg);
continue;
}
String[] args = buildArg.split("\\s+");
int i=0;
while(i < args.length) {
String a =args[i];
if (a.charAt(0) == System.getProperty("user.home").charAt(0)) {
houcine7 marked this conversation as resolved.
Show resolved Hide resolved
StringBuilder path = new StringBuilder(a);
i++;
while( i< args.length && args[i].toLowerCase().charAt(0) <= 'z' &&
houcine7 marked this conversation as resolved.
Show resolved Hide resolved
args[i].toLowerCase().charAt(0) >= 'a') {
path.append(" ").append(args[i]);
i++;
}
cliArgs.add(path.toString());
} else {
cliArgs.add(a);
i++;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ import org.eclipse.jetty.server.handler.ResourceHandler
import spock.lang.Specification
import spock.lang.TempDir

import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.SimpleFileVisitor
import java.nio.file.StandardCopyOption
import java.nio.file.attribute.BasicFileAttributes

abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
@TempDir
Copy link
Collaborator

@dnestoro dnestoro Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you have removed @TempDir annotation and then proceeded with deleting files manually in the cleanup function?

Copy link
Member Author

@houcine7 houcine7 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my local when I work with Tempdir all tests are passing, because windows avoids tempDir path whitespace with a certain encoding (C:\Users\Lahoucine~\AppData\Temp) so no parsing errors will result if I have withespaces in my path.


Path testDirectory

Path testOrigin;
Expand All @@ -71,6 +74,13 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac");

def setup() {
var home_dir = Path.of(System.getProperty("user.home"))
testDirectory = home_dir.resolve("tests")

if (Files.notExists(testDirectory)) {
Files.createDirectory(testDirectory)
}

executor = new IsolatedMavenExecutor(
new File(System.getProperty("java.executable")),
testDirectory.resolve("m2-home").toFile(),
Expand All @@ -79,6 +89,21 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
}

def cleanup() {

//cleanup test directory and all it's sub directories
Files.walkFileTree(testDirectory, new SimpleFileVisitor<Path>() {
@Override
FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});

if (server != null) {
server.stop()
server.destroy()
Expand Down Expand Up @@ -158,7 +183,7 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
var resultingSystemProperties = [
"common.repo.uri": System.getProperty("common.repo.uri"),
"seed.repo.uri": System.getProperty("seed.repo.uri"),
"maven.repo.local": testDirectory.resolve("local-repo").toFile().absolutePath
"maven.repo.local": testDirectory.resolve("local repo").toFile().absolutePath
alvarosanchez marked this conversation as resolved.
Show resolved Hide resolved
]
resultingSystemProperties.putAll(systemProperties)

Expand Down
Loading