最近在使用sonar-runner作代碼掃描,javascript
在windows環境運行多模塊的掃描ok,可是在linux上sonar-runner掃描多模塊報錯;html
先貼sonar-project.properties配置java
#required metadata #projectKey項目的惟一標識,不能重複 sonar.projectKey=testuser sonar.projectName=testuser sonar.projectVersion=1.0 sonar.sourceEncoding=UTF-8 sonar.modules=java-module,javascript-module,html-module # Java module java-module.sonar.projectName=Java Module java-module.sonar.language=java # .表示projectBaseDir指定的目錄 java-module.sonar.sources=. java-module.sonar.projectBaseDir=src/main/java sonar.binaries=classes # JavaScript module javascript-module.sonar.projectName=JavaScript Module javascript-module.sonar.language=js javascript-module.sonar.sources=js javascript-module.sonar.projectBaseDir=src/main/webapp # Html module html-module.sonar.projectName=Html Module html-module.sonar.language=web html-module.sonar.sources=pages html-module.sonar.projectBaseDir=src/main/webapp
windows環境運行sonar-runner掃描ok,linux
可是linux上怎麼也不成功,報錯web
從報錯能夠看出,這是在掃描java-module時沒有找到/app/mujup/local/testsonar/testsonar/src/main/java路徑,但事實是我linux上有這個路徑而且是java代碼的路徑windows
因而去分析sonar的源碼(ProjectReactorBuilder.calss)app
private void defineChildren(ProjectDefinition parentProject) { Properties parentProps = parentProject.getProperties(); if (parentProps.containsKey("sonar.modules")) //解析子模塊 { String arr$[] = Utils.getListFromProperty(parentProps, "sonar.modules");//得到sonar.modules的元素 int len$ = arr$.length; for (int i$ = 0; i$ < len$; i$++)//循環,java-module,js-module,html-module { String module = arr$[i$]; Properties moduleProps = extractModuleProperties(module, parentProps);//得到每一個子模塊的properties文件 ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, module);//加載子模塊 checkUniquenessOfChildKey(childProject, parentProject); defineChildren(childProject); parentProject.addSubProject(childProject); } } }
private ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) { setProjectKeyAndNameIfNotDefined(moduleProps, moduleId); File baseDir; if (moduleProps.containsKey("sonar.projectBaseDir"))//檢查子模塊的java-module.sonar.projectBaseDir=src/main/java {
//parentProject.getBaseDir()是當前項目的根路徑,這個方法是得到子模塊的絕對路徑
//baseDir是子模塊的絕對路徑,也就是報錯的/app/mujup/local/testsonar/testsonar/src/main/java baseDir = getFileFromPath(moduleProps.getProperty("sonar.projectBaseDir"), parentProject.getBaseDir());
//報錯代碼位置,,這個方法裏判斷baseDir是不是文件夾,明明是文件夾卻返回了異常,百思不得騎姐 setProjectBaseDir(baseDir, moduleProps, moduleId); try { if (!parentProject.getBaseDir().getCanonicalFile().equals(baseDir.getCanonicalFile())) tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId); } catch (IOException e) { throw new IllegalStateException("Error when resolving baseDir", e); } } else if (moduleProps.containsKey("sonar.projectConfigFile")) { baseDir = loadPropsFile(parentProject, moduleProps, moduleId); } else { baseDir = new File(parentProject.getBaseDir(), moduleId); setProjectBaseDir(baseDir, moduleProps, moduleId); tryToFindAndLoadPropsFile(baseDir, moduleProps, moduleId); } checkMandatoryProperties(moduleProps, MANDATORY_PROPERTIES_FOR_CHILD); validateDirectories(moduleProps, baseDir, moduleId); mergeParentProperties(moduleProps, parentProject.getProperties()); prefixProjectKeyWithParentKey(moduleProps, parentProject.getKey()); return defineProject(moduleProps, parentProject); }
private static void setProjectBaseDir(File baseDir, Properties childProps, String moduleId) { if (!baseDir.isDirectory()) {
//報錯--Caused by: java.lang.IllegalStateException: The base directory of the module 'java-module'
//does not exist: /app/mujup/local/testsonar/testsonar/src/main/java throw new IllegalStateException((new StringBuilder()).append("The base directory of the module '").append(moduleId).append("' does not exist: ").append(baseDir.getAbsolutePath()).toString()); } else { childProps.put("sonar.projectBaseDir", baseDir.getAbsolutePath()); return; } }
猜測:webapp
試過把子模塊的java-module.sonar.projectBaseDir=src/main/java換成src;src/main均不行ui
難道linux中認爲/app/mujup/local/testsonar/testsonar/src/main/java不是文件夾?應該沒有這麼挫吧。spa
改天試試linux判斷文件及文件夾,
有人遇到過這種狀況嗎?