@@ -1,7 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- Generated by SonarQube --> | |||
<FindBugsFilter> | |||
<Match> | |||
<Bug pattern="DM_EXIT"/> | |||
</Match> | |||
</FindBugsFilter> |
@@ -1,69 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<BugCollection version="3.0.1" sequence="0" timestamp="1432107278000" analysisTimestamp="1437046750473" release=""> | |||
<Project> | |||
<Jar>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/src/HasFindbugsViolation.java</Jar> | |||
<Jar>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/build/classes/HasFindbugsViolation.class</Jar> | |||
<AuxClasspathEntry>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/build/classes</AuxClasspathEntry> | |||
<AuxClasspathEntry>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/lib/deprecated.jar</AuxClasspathEntry> | |||
<AuxClasspathEntry>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/.sonar/findbugs/annotations.jar</AuxClasspathEntry> | |||
<AuxClasspathEntry>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/.sonar/findbugs/jsr305.jar</AuxClasspathEntry> | |||
<WrkDir>/home/duartem/git/sonar-tests-core/it-sonar-runner/projects/java-bytecode/.sonar</WrkDir> | |||
</Project> | |||
<BugInstance type="DM_EXIT" priority="2" rank="16" abbrev="Dm" category="BAD_PRACTICE" instanceHash="fc6ac81278eca1b0ea92d10f13e0a9e9" instanceOccurrenceNum="0" instanceOccurrenceMax="0" cweid="382"> | |||
<ShortMessage>Method invokes System.exit(...)</ShortMessage> | |||
<LongMessage>HasFindbugsViolation.use() invokes System.exit(...), which shuts down the entire virtual machine</LongMessage> | |||
<Class classname="HasFindbugsViolation" primary="true"> | |||
<SourceLine classname="HasFindbugsViolation" start="1" end="12" sourcefile="HasFindbugsViolation.java" sourcepath="HasFindbugsViolation.java"> | |||
<Message>At HasFindbugsViolation.java:[lines 1-12]</Message> | |||
</SourceLine> | |||
<Message>In class HasFindbugsViolation</Message> | |||
</Class> | |||
<Method classname="HasFindbugsViolation" name="use" signature="()V" isStatic="false" primary="true"> | |||
<SourceLine classname="HasFindbugsViolation" start="6" end="8" startBytecode="0" endBytecode="65" sourcefile="HasFindbugsViolation.java" sourcepath="HasFindbugsViolation.java"/> | |||
<Message>In method HasFindbugsViolation.use()</Message> | |||
</Method> | |||
<SourceLine classname="HasFindbugsViolation" primary="true" start="7" end="7" startBytecode="12" endBytecode="12" sourcefile="HasFindbugsViolation.java" sourcepath="HasFindbugsViolation.java"> | |||
<Message>At HasFindbugsViolation.java:[line 7]</Message> | |||
</SourceLine> | |||
</BugInstance> | |||
<BugCategory category="BAD_PRACTICE"> | |||
<Description>Bad practice</Description> | |||
</BugCategory> | |||
<BugPattern type="DM_EXIT" abbrev="Dm" category="BAD_PRACTICE" cweid="382"> | |||
<ShortDescription>Method invokes System.exit(...)</ShortDescription> | |||
<Details><![CDATA[ | |||
<p> Invoking System.exit shuts down the entire Java virtual machine. This | |||
should only been done when it is appropriate. Such calls make it | |||
hard or impossible for your code to be invoked by other code. | |||
Consider throwing a RuntimeException instead.</p> | |||
]]></Details> | |||
</BugPattern> | |||
<BugCode abbrev="Dm"> | |||
<Description>Dubious method used</Description> | |||
</BugCode> | |||
<Errors errors="0" missingClasses="0"></Errors> | |||
<FindBugsSummary timestamp="Wed, 20 May 2015 09:34:38 +0200" total_classes="1" referenced_classes="13" total_bugs="1" total_size="11" num_packages="1" java_version="1.7.0_79" vm_version="24.79-b02" cpu_seconds="3.30" clock_seconds="1.10" peak_mbytes="227.75" alloc_mbytes="3538.00" gc_seconds="0.02" priority_2="1"> | |||
<FileStats path="HasFindbugsViolation.java" bugCount="1" size="11" bugHash="74a612ed42a469c4b358a80c33515967"/> | |||
<PackageStats package="" total_bugs="1" total_types="1" total_size="11" priority_2="1"> | |||
<ClassStats class="HasFindbugsViolation" sourceFile="HasFindbugsViolation.java" interface="false" size="11" bugs="1" priority_2="1"/> | |||
</PackageStats> | |||
<FindBugsProfile> | |||
<ClassProfile name="edu.umd.cs.findbugs.classfile.engine.ClassInfoAnalysisEngine" totalMilliseconds="224" invocations="320" avgMicrosecondsPerInvocation="700" maxMicrosecondsPerInvocation="17955" standardDeviationMircosecondsPerInvocation="1606"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.detect.FieldItemSummary" totalMilliseconds="67" invocations="13" avgMicrosecondsPerInvocation="5161" maxMicrosecondsPerInvocation="13026" standardDeviationMircosecondsPerInvocation="5212"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.OpcodeStack$JumpInfoFactory" totalMilliseconds="57" invocations="56" avgMicrosecondsPerInvocation="1018" maxMicrosecondsPerInvocation="4755" standardDeviationMircosecondsPerInvocation="939"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.detect.FindNoSideEffectMethods" totalMilliseconds="41" invocations="13" avgMicrosecondsPerInvocation="3202" maxMicrosecondsPerInvocation="12613" standardDeviationMircosecondsPerInvocation="3864"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.util.TopologicalSort" totalMilliseconds="36" invocations="288" avgMicrosecondsPerInvocation="127" maxMicrosecondsPerInvocation="1297" standardDeviationMircosecondsPerInvocation="215"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.classfile.engine.ClassDataAnalysisEngine" totalMilliseconds="34" invocations="321" avgMicrosecondsPerInvocation="105" maxMicrosecondsPerInvocation="458" standardDeviationMircosecondsPerInvocation="52"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.classfile.engine.bcel.MethodGenFactory" totalMilliseconds="28" invocations="3" avgMicrosecondsPerInvocation="9462" maxMicrosecondsPerInvocation="27862" standardDeviationMircosecondsPerInvocation="13010"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.classfile.engine.bcel.JavaClassAnalysisEngine" totalMilliseconds="25" invocations="28" avgMicrosecondsPerInvocation="925" maxMicrosecondsPerInvocation="11951" standardDeviationMircosecondsPerInvocation="2278"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.detect.NoteDirectlyRelevantTypeQualifiers" totalMilliseconds="23" invocations="13" avgMicrosecondsPerInvocation="1779" maxMicrosecondsPerInvocation="5478" standardDeviationMircosecondsPerInvocation="1779"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.detect.FunctionsThatMightBeMistakenForProcedures" totalMilliseconds="22" invocations="13" avgMicrosecondsPerInvocation="1761" maxMicrosecondsPerInvocation="5446" standardDeviationMircosecondsPerInvocation="1973"/> | |||
<ClassProfile name="edu.umd.cs.findbugs.detect.BuildStringPassthruGraph" totalMilliseconds="17" invocations="13" avgMicrosecondsPerInvocation="1358" maxMicrosecondsPerInvocation="3601" standardDeviationMircosecondsPerInvocation="1349"/> | |||
</FindBugsProfile> | |||
</FindBugsSummary> | |||
<ClassFeatures></ClassFeatures> | |||
<History></History> | |||
</BugCollection> |
@@ -0,0 +1,7 @@ | |||
# Note that the format of project key is still groupId:artifactId in order to support test with sonar 2.6. | |||
#sonar.projectKey=java:sample | |||
sonar.projectName=Java Sample, with comma | |||
sonar.projectDescription=This is a Java sample | |||
sonar.projectVersion=1.2.3 | |||
sonar.sources=src |
@@ -0,0 +1,9 @@ | |||
package basic; | |||
public class Hello { | |||
public void hello() { | |||
int i=356; | |||
if (true) i=5658; | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
package basic; | |||
public final class World { | |||
public void world() { | |||
System.out.println("hello world"); | |||
} | |||
} |
@@ -20,7 +20,6 @@ | |||
package com.sonar.runner.it; | |||
import org.junit.Assume; | |||
import org.junit.BeforeClass; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.junit.Rule; | |||
@@ -67,21 +66,21 @@ public class CacheTest extends RunnerTestCase { | |||
@Test | |||
public void testIssuesMode() throws IOException { | |||
Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); | |||
// online, without cache -> should sync | |||
ensureStarted(); | |||
SonarRunner build = createRunner("issues", true); | |||
SonarRunner build = createRunner("issues", true, "java-sample"); | |||
BuildResult result = orchestrator.executeBuild(build, false); | |||
assertThat(result.isSuccess()).isTrue(); | |||
// offline, with cache -> should run from cache | |||
ensureStopped(); | |||
build = createRunner("issues", false); | |||
build = createRunner("issues", false, "java-sample"); | |||
result = orchestrator.executeBuild(build, false); | |||
assertThat(result.isSuccess()).isTrue(); | |||
// offline, without cache -> should fail | |||
build = createRunner("issues", true); | |||
build = createRunner("issues", true, "java-sample"); | |||
try { | |||
result = orchestrator.executeBuild(build); | |||
} catch (BuildFailureException e) { | |||
@@ -89,19 +88,36 @@ public class CacheTest extends RunnerTestCase { | |||
} | |||
} | |||
@Test | |||
public void testNonAssociatedMode() throws IOException { | |||
Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); | |||
// online, without cache -> should sync | |||
ensureStarted(); | |||
SonarRunner build = createRunner("issues", true, "java-sample-non-associated"); | |||
BuildResult result = orchestrator.executeBuild(build, false); | |||
assertThat(result.isSuccess()).isTrue(); | |||
// offline, with cache -> should run from cache | |||
ensureStopped(); | |||
build = createRunner("issues", false, "java-sample-non-associated"); | |||
result = orchestrator.executeBuild(build, false); | |||
assertThat(result.isSuccess()).isTrue(); | |||
} | |||
@Test | |||
public void testPublishModeOffline() throws IOException { | |||
Assume.assumeTrue(orchestrator.getServer().version().isGreaterThanOrEquals("5.2")); | |||
// online (cache not used) | |||
ensureStarted(); | |||
SonarRunner build = createRunner("publish"); | |||
SonarRunner build = createRunner("publish", "java-sample"); | |||
BuildResult result = orchestrator.executeBuild(build, false); | |||
assertThat(result.isSuccess()).isTrue(); | |||
// offline (cache not used) -> should fail | |||
ensureStopped(); | |||
build = createRunner("publish", false); | |||
build = createRunner("publish", false, "java-sample"); | |||
try { | |||
result = orchestrator.executeBuild(build); | |||
} catch (BuildFailureException e) { | |||
@@ -110,16 +126,16 @@ public class CacheTest extends RunnerTestCase { | |||
} | |||
private SonarRunner createRunner(String mode) throws IOException { | |||
return createRunner(mode, false); | |||
private SonarRunner createRunner(String mode, String project) throws IOException { | |||
return createRunner(mode, false, project); | |||
} | |||
private SonarRunner createRunner(String mode, boolean refreshCache) throws IOException { | |||
private SonarRunner createRunner(String mode, boolean refreshCache, String project) throws IOException { | |||
if (refreshCache || currentTemp == null) { | |||
currentTemp = temp.newFolder(); | |||
} | |||
SonarRunner runner = newRunner(new File("projects/java-sample")) | |||
SonarRunner runner = newRunner(new File("projects/" + project)) | |||
.setProperty("sonar.analysis.mode", mode) | |||
.setProperty("sonar.userHome", currentTemp.getAbsolutePath()); | |||
@@ -19,19 +19,27 @@ | |||
*/ | |||
package org.sonar.runner.api; | |||
import org.junit.Rule; | |||
import org.junit.rules.TemporaryFolder; | |||
import java.io.Closeable; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.nio.charset.StandardCharsets; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.util.Properties; | |||
import org.junit.Test; | |||
import org.junit.Test; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
import static org.mockito.Mockito.doThrow; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
public class UtilsTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Test | |||
public void should_join_strings() { | |||
assertThat(Utils.join(new String[] {}, ",")).isEqualTo(""); | |||
@@ -48,6 +56,15 @@ public class UtilsTest { | |||
assertThat(Utils.taskRequiresProject(props)).isTrue(); | |||
} | |||
@Test | |||
public void write_properties() throws IOException { | |||
File f = temp.newFile(); | |||
Properties p = new Properties(); | |||
p.put("key", "value"); | |||
Utils.writeProperties(f, p); | |||
assertThat(Files.readAllLines(f.toPath(), StandardCharsets.UTF_8)).contains("key=value"); | |||
} | |||
@Test | |||
public void task_should_not_require_project() { | |||
Properties props = new Properties(); | |||
@@ -56,7 +73,7 @@ public class UtilsTest { | |||
} | |||
@Test | |||
public void close_quietly() throws IOException { | |||
public void close_quietly_error() throws IOException { | |||
Closeable c = mock(Closeable.class); | |||
doThrow(IOException.class).when(c).close(); | |||
Utils.closeQuietly(c); | |||
@@ -68,6 +85,20 @@ public class UtilsTest { | |||
Utils.closeQuietly(null); | |||
} | |||
@Test | |||
public void close_quietly() throws IOException { | |||
Closeable c = mock(Closeable.class); | |||
Utils.closeQuietly(c); | |||
verify(c).close(); | |||
} | |||
@Test | |||
public void delete_quietly() { | |||
File f = mock(File.class); | |||
doThrow(IOException.class).when(f).toPath(); | |||
Utils.deleteQuietly(f); | |||
} | |||
@Test | |||
public void delete_non_empty_directory() throws IOException { | |||
/*- |