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

Escape backslashes on Windows in repositories/flatDir/dirs #303

Merged
merged 1 commit into from
Jun 23, 2021
Merged
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
30 changes: 22 additions & 8 deletions cli/src/test/java/org/jboss/gm/cli/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.SystemUtils;
import org.gradle.api.logging.LogLevel;
import org.jboss.gm.analyzer.alignment.AlignmentPlugin;
import org.jboss.gm.common.model.ManipulationModel;
Expand Down Expand Up @@ -48,6 +50,14 @@ public class MainTest {
@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();

private String escapeBackslashes(String dir) {
if (SystemUtils.IS_OS_WINDOWS) {
return FilenameUtils.normalize(dir, true).replace("/", "\\\\\\\\");
}

return dir;
}

@Test
public void testGradleNotFound() throws IOException {
Main m = new Main();
Expand Down Expand Up @@ -160,12 +170,14 @@ public void testInvokeAlignment() throws Exception {
final File initFile = tempDir.newFile();
String init = FileUtils.readFileToString(new File(root, "/analyzer/build/resources/main/analyzer-init.gradle"),
Charset.defaultCharset());
final String dir1 = escapeBackslashes(
new File(AlignmentPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent());
final String dir2 = escapeBackslashes(
new File(ManipulationModel.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent());
init = init.replaceFirst("(mavenCentral[(][)])", "$1" +
"\n flatDir {\n dirs '" +
new File(AlignmentPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent() +
"\n flatDir {\n dirs '" + dir1 +
"'\n }\n" +
"\n flatDir {\n dirs '" +
new File(ManipulationModel.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent() +
"\n flatDir {\n dirs '" + dir2 +
"'\n }\n");
System.out.println("Writing to " + initFile + ":" + init);
FileUtils.writeStringToFile(initFile, init, Charset.defaultCharset());
Expand Down Expand Up @@ -207,14 +219,16 @@ public void testInvokeAlignmentFails() throws Exception {
// This hack-fest is because the development version is not in Maven Central so it won't be resolvable
// This adds the compiled libraries as flat dir repositories.
final File initFile = tempDir.newFile();
final String dir1 = escapeBackslashes(
new File(AlignmentPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent());
final String dir2 = escapeBackslashes(
new File(ManipulationModel.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent());
String init = FileUtils.readFileToString(new File(root, "/analyzer/build/resources/main/analyzer-init.gradle"),
Charset.defaultCharset());
init = init.replaceFirst("(mavenCentral[(][)])", "$1" +
"\n flatDir {\n dirs '" +
new File(AlignmentPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent() +
"\n flatDir {\n dirs '" + dir1 +
"'\n }\n" +
"\n flatDir {\n dirs '" +
new File(ManipulationModel.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent() +
"\n flatDir {\n dirs '" + dir2 +
"'\n }\n");
System.out.println("Writing to " + initFile + ":" + init);
FileUtils.writeStringToFile(initFile, init, Charset.defaultCharset());
Expand Down