Skip to content

Commit

Permalink
Convert relative config.project_path to absolute path FrontEndART#81
Browse files Browse the repository at this point in the history
  • Loading branch information
fea-devteam committed Jul 21, 2022
1 parent 1af35e9 commit d10d439
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/eu/assuremoss/utils/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public Configuration(String generalFileName, String mapFileName) throws IOExcept
properties = new Properties();
loadConfiguration(generalFileName);
loadConfiguration(mapFileName);

convertRelativePathToAbsolutePath();
}

private void loadConfiguration(String confFileName) throws IOException {
Expand Down Expand Up @@ -83,6 +85,12 @@ private Properties loadPropertiesFromResource(String fileName) throws IOExceptio
return prop;
}

/**
* Prepends the current working directory to all paths specified in the configuration.
*/
private void convertRelativePathToAbsolutePath() {
updatePathToAbsolute(PROJECT_PATH_KEY);
}

public static boolean archiveEnabled(Properties props) {
return Boolean.parseBoolean(props.getProperty(ARCHIVE_ENABLED));
Expand All @@ -99,4 +107,14 @@ public static String patchSavePath(Properties props) {
public static boolean isTestingEnabled() {
return Boolean.parseBoolean(VulnRepairDriver.properties.getProperty(PROJECT_RUN_TESTS));
}

private void updatePathToAbsolute(String key) {
String path = properties.get(key).toString();

if (PathHandler.isAbsolute(path)) {
return;
}

properties.setProperty(key, PathHandler.toAbsolute(path));
}
}
12 changes: 10 additions & 2 deletions src/main/java/eu/assuremoss/utils/PathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ public class PathHandler {
private final String patchUnitTestsCSV = "patch_unit_tests.csv";


public PathHandler(Properties props) {
this.props = props;
}

public static String joinPath(String first, String... args) {
return String.valueOf(Paths.get(first, args));
}

public PathHandler(Properties props) {
this.props = props;
public static String toAbsolute(String path) {
return joinPath(Utils.getWorkingDir(), path);
}

public static boolean isAbsolute(String path) {
return path.startsWith(Utils.getWorkingDir());
}

// Directories
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/eu/assuremoss/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,8 @@ public static String getOsName() {
if (OS_NAME.contains("Linux")) return "Linux";
return OS_NAME;
}

public static String getWorkingDir() {
return System.getProperty("user.dir");
}
}
20 changes: 20 additions & 0 deletions src/test/java/eu/assuremoss/utils/PathHandlerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package eu.assuremoss.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class PathHandlerTest {
String testProjectRelativePath = "test-project";
String testProjectAbsolutePath = PathHandler.joinPath(Utils.getWorkingDir(), testProjectRelativePath);

@Test
void testToAbsolute() {
Assertions.assertEquals(testProjectAbsolutePath, PathHandler.toAbsolute(testProjectRelativePath));
}

@Test
void testIsAbsolute() {
Assertions.assertTrue(PathHandler.isAbsolute(testProjectAbsolutePath));
Assertions.assertFalse(PathHandler.isAbsolute(testProjectRelativePath));
}
}

0 comments on commit d10d439

Please sign in to comment.