Skip to content

Commit

Permalink
81-relative-path-fix (#98)
Browse files Browse the repository at this point in the history
* Refactor - Extract configuration attributes

* Refactor - Replace temp with Query

* Refactor - Fix ToolFactory path issue

* Refactor - Extract tasks

* Enhance console output with own logger

* Enhance console output, redirect all the current info into the log file with own logger

* Create validation folder, #72

* Enhance console output #45

* Refactor - Parameterize Function

* Refactor - Extract Function

* Minor format changes #45

* Minor format changes #45

* Add support for Gradle #44

* Add support for Ant #83

* Add support for Ant #83

* Find the variable name for some vulnerabilities

* Column info on MS_SHOULD_BE_FINAL and EI_EXPOSE_REP2

* Complete refactor of ColumnInfoParser

* Implement AST method for retrieving column info

* Use JavaParser library for parsing column info (temporary solution)

* Extended JavaParser implementation, find column info for FB_EER/FB_EiER, FB_NNOSP and FB_MSBF

* dynamic column info data passed to OpenStaticAnalyzer and processed properly

* ColumnInfoParser uses anonymous VoidVisitor class to visit nodes, minor code cleanup

* Minor code cleanup

* Insert TODOs

* Refactor - Replace temp with Query, minor changes

* Refactor - SRP: Separate 'column info attach' from VulnerabilityLocation

* Refactor - Clean OpenStaticAnalyzer

* Refactor - Clean OpenStaticAnalyzer

* Create integration test for: extracting column info #6

* Framework repair (#77)

* Refactor - Extract configuration attributes

* Refactor - Replace temp with Query

* Refactor - Fix ToolFactory path issue

* Refactor - Extract tasks

* Enhance console output with own logger

* Enhance console output, redirect all the current info into the log file with own logger

* Create validation folder, #72

* Enhance console output #45

* Refactor - Parameterize Function

* Add support for Gradle #44

* Refactor - Replace temp with Query, minor changes

* Refactor - SRP: Separate 'column info attach' from VulnerabilityLocation

* Refactor - Clean OpenStaticAnalyzer

* Fix NullPointerException in getResultPair()

* Skip build when the generated patch is empty

* Log Vulnerabilities

* Add support for MavenCLI

* Fix failure on not retrieved column info

* Get mapping properties from config

* Log elapsed time

* Disable test case

* Create statistics

* Create statistics

* Fix invalid elapsed time

* Refactor - Simplify OpenStaticAnalyzer

* Extend pairing with variable source path #87

* Trying to fix #88

* Save number of generated/filtered/verified patches

* Upload missing method

* Fix command line argument usage

* Remove copyDependency option from CLI patchers

* Add an option to change the source path of the analysed project

* Separate log files for each build

* Save unit test results for each compiled patch

* Clarify patch name in patch_unit_test.csv

* Separate Vuln_ID and Patch in patch_unit_test.csv

* Updated CodeRepair to 1.0.2

* Updated README.md with working command

* Remove copyDependency option from CLI patchers

* Updated CodeRepair to 1.0.2

* Updated README.md with working command

* Run 'mvn' command using 'cmd /c' on Windows #86

* Unit tests for ColumnInfoParser

* Unit tests for Configuration

* Unit tests for TestInfoExtractor

* Add flag for running unit tests

* Fix different os path issue

* Add unit tests for Statistics #6

* Add unit tests for Statistics #6

* Test deleteIntermediatePatches() #6

* Convert relative config.project_path to absolute path #81

* Update documentation
  • Loading branch information
fea-devteam authored Jul 25, 2022
1 parent 0b9e855 commit ee63d81
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
19 changes: 19 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;
}

/**
* Converts the problematic relative path to absolute path (PROJECT_PATH)
*/
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,15 @@ 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));
}

}
33 changes: 31 additions & 2 deletions src/main/java/eu/assuremoss/utils/PathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,41 @@ public class PathHandler {
private final String logFinish = "log_finish.txt";
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

public String logsDir() {
return joinPath(props.getProperty(RESULTS_PATH_KEY), logsDir);
}

public String buildDir() {
return joinPath(props.getProperty(RESULTS_PATH_KEY), logsDir, buildLogsDir);
}

public String generatedPatches() {
return joinPath(props.getProperty(RESULTS_PATH_KEY), patchesDir);
}

// Files

public String vulnFound() {
return joinPath(props.getProperty(RESULTS_PATH_KEY), logsDir, vulnFound);
}

// 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 @@ -257,4 +257,8 @@ public static String getOsName() {
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 ee63d81

Please sign in to comment.