最近在使用sonar-runner做代码扫描,
在windows环境运行多模块的扫描ok,但是在linux上sonar-runner扫描多模块报错;
先贴sonar-project.properties配置
#required metadata #projectKey项目的唯一标识,不能重复 sonar.projectKey=testusersonar.projectName=testusersonar.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上怎么也不成功,报错
从报错可以看出,这是在扫描java-module时没有找到/app/mujup/local/testsonar/testsonar/src/main/java路径,但事实是我linux上有这个路径并且是java代码的路径
于是去分析sonar的源码(ProjectReactorBuilder.calss)
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; } }
猜想:
试过把子模块的java-module.sonar.projectBaseDir=src/main/java换成src;src/main均不行
难道linux中认为/app/mujup/local/testsonar/testsonar/src/main/java不是文件夹?应该没有这么挫吧。
改天试试linux判断文件及文件夹,
有人遇到过这种情况吗?