Skip to content

Commit

Permalink
Merge pull request #9 from elena-lyulina/change-parser-setup
Browse files Browse the repository at this point in the history
added file content check on setting up parser
  • Loading branch information
aniskoff authored Aug 28, 2020
2 parents 4713309 + 4aa353d commit 38f4f41
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.jetbrains.research.transformations.util

import com.github.gumtreediff.gen.Generators
import com.github.gumtreediff.gen.python.PythonTreeGenerator
import com.github.gumtreediff.io.TreeIoUtils
import org.apache.commons.io.FileUtils
import org.jetbrains.research.transformations.util.ParserSetup.checkSetup
import java.io.File
import java.util.logging.Logger

Expand All @@ -22,14 +21,9 @@ object ParserSetup {
*/
private fun putParserToTargetPath(targetPath: String= TARGET_PATH) {

try {
LOG.info("Putting parser into $targetPath")
val pythonparserFile = File(javaClass.getResource("$PARSER_NAME.py").path)
pythonparserFile.copyTo(File(targetPath))

} catch (e: FileAlreadyExistsException) {
LOG.info("Parser file is already in $TARGET_PATH")
}
LOG.info("Putting parser into $targetPath")
val pythonparserFile = File(javaClass.getResource("$PARSER_NAME.py").path)
pythonparserFile.copyTo(File(targetPath), overwrite = true)

}

Expand All @@ -52,8 +46,9 @@ object ParserSetup {
*/
fun checkSetup() {
LOG.info("Checking correctness of a parser setup")
val pythonparserFile = File(javaClass.getResource("$PARSER_NAME.py").path)
val targetFile = File(TARGET_PATH)
if (!targetFile.exists()) {
if (!targetFile.exists() or !FileUtils.contentEquals(pythonparserFile, targetFile)) {
LOG.info("Parser file will be created in $TARGET_PATH")
putParserToTargetPath()
makeFileExecutable(targetFile)
Expand All @@ -69,4 +64,4 @@ object ParserSetup {
val tmpPath = System.getProperty("java.io.tmpdir")
return tmpPath.removeSuffix("/")
}
}
}

0 comments on commit 38f4f41

Please sign in to comment.