private void initFolders() { final String dexterHome = DexterConfig.getInstance().getDexterHome(); final String tempFolder = dexterHome + DexterUtil.FILE_SEPARATOR + "temp"; DexterUtil.createDirectoryIfNotExist(tempFolder); CPPCHECK_HOME_DIR = dexterHome + DexterUtil.FILE_SEPARATOR + "bin" + DexterUtil.FILE_SEPARATOR + "cppcheck"; if (new File(CPPCHECK_HOME_DIR).exists() == false) { throw new DexterRuntimeException("There is no cppcheck home folder : " + CPPCHECK_HOME_DIR); } }
private void copyCppcheckRunModule() { String dexterHome = DexterConfig.getInstance().getDexterHome(); if (Strings.isNullOrEmpty(dexterHome)) { throw new DexterRuntimeException( "Can't initialize Cppcheck plugin, because the dexter_home is not initialized"); } // copy %DEXTER_HOME%/bin/cppcheck String zipFilePath = dexterHome; String cppcheckPath = ""; if (DexterUtil.getOS() == DexterUtil.OS.WINDOWS) { zipFilePath += "/temp/cppcheck-windows_" + PLUGIN_VERSION + ".zip"; cppcheckPath = "/cppcheck-windows.zip"; } else { // LINUX or MAC if (DexterUtil.getBit() == DexterUtil.BIT._32) { zipFilePath += "/temp/cppcheck-linux_" + PLUGIN_VERSION + "_32.zip"; cppcheckPath = "/cppcheck-linux-32.zip"; } else { zipFilePath += "/temp/cppcheck-linux_" + PLUGIN_VERSION + "_64.zip"; cppcheckPath = "/cppcheck-linux-64.zip"; } } final File file = new File(zipFilePath); if (!file.exists()) { final InputStream is = getClass().getResourceAsStream(cppcheckPath); if (is == null) { throw new DexterRuntimeException("can't find cppcheck.zip file: " + cppcheckPath); } try { FileUtils.copyInputStreamToFile(is, file); DexterUtil.unzip(zipFilePath, CPPCHECK_HOME_DIR); } catch (Exception e) { throw new DexterRuntimeException(e.getMessage(), e); } finally { try { is.close(); } catch (IOException e) { // do nothing } } } }
public void createResultFileFullPath() { assert Strings.isNullOrEmpty(getProjectName()) == false; assert Strings.isNullOrEmpty(getProjectFullPath()) == false; assert Strings.isNullOrEmpty(getSourceFileFullPath()) == false; this.resultFileFullPath = DexterConfig.getInstance().getDexterHome() + "/" + DexterConfig.RESULT_FOLDER_NAME + "/daemon/"; if (sourceFileFullPath.startsWith("\\") || sourceFileFullPath.startsWith("/")) { this.resultFileFullPath += sourceFileFullPath; } else if (sourceFileFullPath.indexOf(":") == 1) { this.resultFileFullPath += sourceFileFullPath.substring(3); } this.resultFileFullPath = DexterUtil.refinePath(this.resultFileFullPath); }
public boolean checkCppcheckPermission() { String dexterHome = DexterConfig.getInstance().getDexterHome(); Process changePermissionProcess = null; StringBuilder changePermissionCmd = new StringBuilder(500); String dexterBin = dexterHome + DexterUtil.FILE_SEPARATOR + "bin"; String cppcheckHome = dexterBin + DexterUtil.FILE_SEPARATOR + "cppcheck"; if (Strings.isNullOrEmpty(dexterBin)) { logger.error( "Can't initialize Cppcheck plugin, because the dexter_home/bin is not initialized"); return false; } if (Strings.isNullOrEmpty(cppcheckHome)) { logger.error("Can't initialize Cppcheck plugin, because the cppcheckHome is not initialized"); return false; } String baseCommand = DexterConfig.EXECUTION_PERMISSION + " "; changePermissionCmd .append(baseCommand) .append(cppcheckHome) .append(DexterUtil.FILE_SEPARATOR) .append("cppcheck"); changePermissionCmd.trimToSize(); try { changePermissionProcess = Runtime.getRuntime().exec(changePermissionCmd.toString()); } catch (IOException e) { throw new DexterRuntimeException( e.getMessage() + " changePermissionCmd: " + changePermissionCmd.toString(), e); } finally { if (changePermissionProcess != null) { changePermissionProcess.destroy(); } } return true; }