-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from lequal/dev
Merge Dev to Master
- Loading branch information
Showing
10 changed files
with
2,737 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/fr/cnes/sonar/plugins/icode/converter/AnalysisConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fr.cnes.sonar.plugins.icode.converter; | ||
|
||
import com.thoughtworks.xstream.converters.ConverterLookup; | ||
import com.thoughtworks.xstream.converters.UnmarshallingContext; | ||
import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter; | ||
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; | ||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | ||
import com.thoughtworks.xstream.mapper.Mapper; | ||
import fr.cnes.sonar.plugins.icode.model.AnalysisRule; | ||
import fr.cnes.sonar.plugins.icode.model.Result; | ||
|
||
public class AnalysisConverter extends ToAttributedValueConverter { | ||
|
||
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup) { | ||
super(type, mapper, reflectionProvider, lookup); | ||
} | ||
|
||
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup, String valueFieldName) { | ||
super(type, mapper, reflectionProvider, lookup, valueFieldName); | ||
} | ||
|
||
public AnalysisConverter(Class type, Mapper mapper, ReflectionProvider reflectionProvider, ConverterLookup lookup, String valueFieldName, Class valueDefinedIn) { | ||
super(type, mapper, reflectionProvider, lookup, valueFieldName, valueDefinedIn); | ||
} | ||
|
||
@Override | ||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { | ||
Object r = super.unmarshal(reader, unmarshallingContext); | ||
if (r.getClass() == AnalysisRule.class) { | ||
Result result = new Result(); | ||
reader.moveDown(); | ||
result.setFileName(reader.getAttribute("fileName")); | ||
result.setResultLine(reader.getAttribute("resultLine")); | ||
result.setResultTypePlace(reader.getAttribute("resultTypePlace")); | ||
result.setResultValue(reader.getAttribute("resultValue")); | ||
if(reader.hasMoreChildren()) { | ||
reader.moveDown(); | ||
result.setResultMessage(reader.getValue()); | ||
reader.moveUp(); | ||
} | ||
reader.moveUp(); | ||
((AnalysisRule) r).setResult(result); | ||
} | ||
return r; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/fr/cnes/sonar/plugins/icode/ParseResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fr.cnes.sonar.plugins.icode; | ||
|
||
import fr.cnes.sonar.plugins.icode.model.AnalysisProject; | ||
import fr.cnes.sonar.plugins.icode.model.XmlHandler; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
|
||
public class ParseResultTest { | ||
@Test | ||
public void parseIcodeOutputTest() { | ||
InputStream icodeOutput = getClass().getResourceAsStream("/result.res"); | ||
AnalysisProject analysisProject = (AnalysisProject) XmlHandler.unmarshal(icodeOutput, AnalysisProject.class); | ||
|
||
|
||
Assert.assertNotNull(analysisProject); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0)); | ||
|
||
// Try to get Analysis informations | ||
Assert.assertNotNull(analysisProject.getAnalysisInformations().getAuthor()); | ||
|
||
// Try to get files informations | ||
Assert.assertEquals(7, analysisProject.getAnalysisFiles().size()); | ||
Assert.assertNotNull(analysisProject.getAnalysisFiles().get(0).getFileName()); | ||
Assert.assertNotNull(analysisProject.getAnalysisFiles().get(0).getLanguage()); | ||
|
||
// Try to get rules analyzed | ||
Assert.assertEquals(574, analysisProject.getAnalysisRules().size()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getResult()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getAnalysisRuleId()); | ||
|
||
// Try to get results | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getResult().getResultTypePlace()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(58).getResult().getResultMessage()); | ||
Assert.assertNull(analysisProject.getAnalysisRules().get(0).getResult().getResultMessage()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getResult().getFileName()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getResult().getResultValue()); | ||
Assert.assertNotNull(analysisProject.getAnalysisRules().get(0).getResult().getResultLine()); | ||
} | ||
} |
Oops, something went wrong.