Skip to content

Commit 1a140ff

Browse files
committed
Show .net core not supported message
1 parent 370a5f1 commit 1a140ff

5 files changed

Lines changed: 45 additions & 18 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.sonarsource.dotnet</groupId>
66
<artifactId>sonar-fxcop-plugin</artifactId>
77
<packaging>sonar-plugin</packaging>
8-
<version>1.4_SNAPSHOT</version>
8+
<version>1.4_BETA2</version>
99

1010
<name>SonarQube FxCop Plugin</name>
1111
<description>Enables scanning of C#/VB.NET source files with FxCop</description>

src/main/java/org/sonar/plugins/fxcop/CSharpProjectInfo.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,30 @@ public class CSharpProjectInfo {
3333
performOnNetCore();
3434
checkAllRequiredValuesFound();
3535
}
36+
37+
public boolean IsDotNetCore(){
38+
if (targetFramework==null)return false;
39+
return targetFramework.toLowerCase().contains("netcoreapp");
40+
}
3641

3742
private void performOnNetCore() {
3843
//Net core project files contain only non default settings, so set defaults if not set
3944
if (targetFramework!=null && targetFramework.startsWith("netcoreapp")){
4045
if (paths.isEmpty()) {
4146
paths.add(convertPath("bin\\Debug\\netcoreapp2.0"));
4247
paths.add(convertPath("bin\\Release\\netcoreapp2.0"));
48+
paths.add(convertPath("bin\\Debug\\netcoreapp2.1"));
49+
paths.add(convertPath("bin\\Release\\netcoreapp2.1"));
50+
LOG.debug("Set Outputpath to default");
4351
}
4452
if (type == null){
4553
type = "Library";
54+
LOG.debug("Set OutputType to default (Library)");
4655
}
4756
if (name == null) {
4857
File projectFile = new File(project);
4958
name = projectFile.getName().replace(".csproj", "");
59+
LOG.debug("Set AssemblyName to default ("+name+")");
5060
}
5161
}
5262

@@ -76,18 +86,23 @@ private void scanProjectFile() throws IOException {
7686
Matcher m = patternType.matcher(currentLine);
7787
if (m.find()) {
7888
type = (m.group(1));
89+
LOG.debug("Found OutputType ("+type+")");
7990
}
8091
m = patternName.matcher(currentLine);
8192
if (m.find()) {
8293
name = (m.group(1));
94+
LOG.debug("Found AssemblyName ("+name+")");
8395
}
8496
m = patternPath.matcher(currentLine);
8597
if (m.find()) {
86-
paths.add(convertPath(m.group(1)));
98+
String path = convertPath(m.group(1));
99+
paths.add(path);
100+
LOG.debug("Found OutputPath ("+path+")");
87101
}
88102
m = patternTargetFramework.matcher(currentLine);
89103
if (m.find()) {
90-
targetFramework = m.group(1);
104+
targetFramework = m.group(1);
105+
LOG.debug("Found TargetFramework ("+targetFramework+")");
91106
}
92107
}
93108
} finally {

src/main/java/org/sonar/plugins/fxcop/FxCopProjectGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ private String[] getTargetFiles(File slnFileObj) {
6262

6363
private void addProjectAssemblyIfExists(List<String> targetFileList, String project) throws IOException {
6464
try {
65-
targetFileList.add(getDllPathFromCsProj(project));
65+
String proj = getDllPathFromCsProj(project);
66+
if (proj != null) targetFileList.add(proj);
6667
} catch (IllegalArgumentException iae){
6768
LOG.warn("Ignore '"+project+"' due to parsing error.");
6869
}
@@ -76,6 +77,10 @@ public String getDllPathFromCsProj(String project) throws IOException {
7677
//Pattern.matches("<OutputType>(\\w+)</OutputType>", input)
7778

7879
CSharpProjectInfo projectInfo = new CSharpProjectInfo(project);
80+
if (projectInfo.IsDotNetCore()) {
81+
LOG.warn(".net core is not supported by FxCop - project " + project + " ignored.");
82+
return null;
83+
}
7984
return projectInfo.getDllPathFromExistingBinary();
8085

8186
}

src/main/java/org/sonar/plugins/fxcop/FxCopSensor.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,7 @@ private String getSlnNameByProperty(SensorContext context, File baseDir) {
201201
private File executeFxCop(FxCopRulesetWriter writer, FxCopExecutor executor, SensorContext context, Settings settings) {
202202
File reportFile;
203203
String workDirPath = context.fileSystem().workDir().getAbsolutePath();
204-
String projectName = settings.getString("sonar.projectName");
205-
if (projectName!=null){
206-
//workDirPath = workDirPath.replaceAll(projectName, "");
207-
LOG.info("Project name: " + projectName);
208-
File workDir = new File(workDirPath);
209-
if (!workDir.exists()){
210-
workDir.mkdirs();
211-
}
212-
}
204+
workDirPath = TrimWorkdir(settings, workDirPath);
213205

214206
File rulesetFile = new File(workDirPath, "fxcop-sonarqube.ruleset");
215207
writer.write(enabledRuleConfigKeys(context.activeRules()), rulesetFile);
@@ -229,6 +221,20 @@ private File executeFxCop(FxCopRulesetWriter writer, FxCopExecutor executor, Sen
229221
return reportFile;
230222
}
231223

224+
private String TrimWorkdir(Settings settings, String workDirPath) {
225+
String projectKey = settings.getString("sonar.projectKey");
226+
if (projectKey!=null && !projectKey.isEmpty() /*&& projectKey.matches("[a-zA-Z0-9_-]:[a-zA-Z0-9_-]:[a-zA-Z0-9_-]")*/){
227+
workDirPath = workDirPath.replace(projectKey.replace(":", ""), projectKey.substring(projectKey.indexOf(':')));
228+
LOG.info("Project key: " + projectKey);
229+
LOG.info("Work Dir: " + workDirPath);
230+
File workDir = new File(workDirPath);
231+
if (!workDir.exists()){
232+
workDir.mkdirs();
233+
}
234+
}
235+
return workDirPath;
236+
}
237+
232238
private void parseReportFile(FxCopReportParser parser, SensorContext context, File reportFile) {
233239
int count = 0;
234240
for (FxCopIssue issue : parser.parse(reportFile)) {

src/test/java/org/sonar/plugins/fxcop/FxCopProjectGeneratorTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testGenerate() throws IOException {
8282

8383
}
8484

85-
@Test
85+
@Test(expected = IllegalArgumentException.class)
8686
public void testGenerateCore() throws IOException {
8787
FxCopProjectGenerator gen = new FxCopProjectGenerator();
8888

@@ -92,8 +92,8 @@ public void testGenerateCore() throws IOException {
9292
assertThat(Files.exists(Paths.get(binFile.getAbsolutePath()))).isTrue();
9393

9494
String resultFileName = gen.generate(TEST_CORE_SLN);
95-
96-
assertThat(resultFileName).isNotEmpty();
95+
//No .net Core support in the moment
96+
//assertThat(resultFileName).isNotEmpty();
9797

9898

9999
}
@@ -200,11 +200,12 @@ public void testCoreCsprojDllDebugScan() throws IOException {
200200

201201
String file = gen.getDllPathFromCsProj(TEST_CORE_CSPROJ_DLL);
202202

203-
assertThat(file).isNotNull();
203+
assertThat(file).isNull();
204+
/* No .Net Core support in the moment
204205
assertThat(file).isNotEmpty();
205206
assertThat(file).endsWith("TestLibCore.dll");
206207
assertThat(file).doesNotContain("/../");
207-
assertThat(file).doesNotContain("\\..\\");
208+
assertThat(file).doesNotContain("\\..\\");*/
208209
}
209210

210211
@Test

0 commit comments

Comments
 (0)