Skip to content

Commit

Permalink
Radon Virtual Env. 추가 Cache 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
switchover committed Apr 15, 2021
1 parent 1c8cc32 commit 6bb80c8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ public void addTempFileToBeDeleted(File tmp) {
public void cleanTempFiles() {
if (!System.getProperty("deleteTempFiles", "true").equalsIgnoreCase("false")) {
for (File toBeDeletedFile : toBeDeletedFiles) {
LOGGER.info("Delete Temporary file : {}", toBeDeletedFile.getAbsolutePath()); // TODO
LOGGER.info("Delete Temporary file : {}", toBeDeletedFile.getAbsolutePath());
FileUtils.deleteQuietly(toBeDeletedFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gson.reflect.TypeToken;
import com.samsungsds.analyst.code.main.CacheUtils;
import com.samsungsds.analyst.code.main.MeasuredResult;
import com.samsungsds.analyst.code.main.Version;
import com.samsungsds.analyst.code.pmd.ComplexityAnalysis;
import com.samsungsds.analyst.code.pmd.ComplexityResult;
import com.samsungsds.analyst.code.python.PythonRuntime;
Expand Down Expand Up @@ -65,18 +66,46 @@ public void addOption(String option, String value) {
public void run(String instanceKey) {
String python = checkPythonVersionAndGetPath();

File tmpDir = saveRadonPackageWheels(instanceKey);
if (haveCachedRadon()) {
File virtualEnvDir = new File(IOAndFileUtils.mkdirCacheDir(), "radon-" + Version.CODE_ANALYST + File.separator + "radon");
LOGGER.info("Cached Radon Virtual Env. used : {}", virtualEnvDir.toString());
String resultJsonPath = runRadon(virtualEnvDir.getAbsolutePath());

String virtualEnvDir = makeVirtualEnv(python, tmpDir);
LOGGER.debug("radon result : {}", resultJsonPath);
processResult(resultJsonPath, instanceKey);
} else {
File tmpDir = saveRadonPackageWheels(instanceKey);

String virtualEnvDir = makeVirtualEnv(python, tmpDir);

installWheelPackages(tmpDir.getPath(), instanceKey);

installRadonPackages(tmpDir.getPath());

String resultJsonPath = runRadon(virtualEnvDir);

LOGGER.debug("radon result : {}", resultJsonPath);
processResult(resultJsonPath, instanceKey);
}
}

installWheelPackages(tmpDir.getPath(), instanceKey);
private boolean haveCachedRadon() {
if (System.getProperty("noCache", "false").equalsIgnoreCase("true")) {
return false;
}

installRadonPackages(tmpDir.getPath());
File cacheDir = IOAndFileUtils.mkdirCacheDir();

String resultJsonPath = runRadon(virtualEnvDir);
File radonExecuteFile;
if (PythonRuntime.IS_MACOS || PythonRuntime.IS_LINUX) {
radonExecuteFile = new File(cacheDir,
"radon-" + Version.CODE_ANALYST + File.separator + "radon" + File.separator + "bin" + File.separator + "radon");
} else {
radonExecuteFile = new File(cacheDir,
"radon-" + Version.CODE_ANALYST + File.separator + "radon" + File.separator + "Scripts" + File.separator + "radon.exe");
}

LOGGER.debug("radon result : {}", resultJsonPath);
processResult(resultJsonPath, instanceKey);
return radonExecuteFile.exists();
}

private String checkPythonVersionAndGetPath() {
Expand Down

0 comments on commit 6bb80c8

Please sign in to comment.