forked from stepstone-tech/sonar-coldfusion
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
471a0f0
commit 04bafd0
Showing
13 changed files
with
277 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pipeline { | ||
agent any | ||
agent { | ||
label 'master' | ||
} | ||
stages { | ||
stage('Clean') { | ||
steps { | ||
|
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/main/java/com/stepstone/sonar/plugin/coldfusion/cflint/xml/CountsAttributes.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 @@ | ||
/* | ||
Copyright 2016 StepStone GmbH | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.stepstone.sonar.plugin.coldfusion.cflint.xml; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
import javax.xml.stream.XMLStreamReader; | ||
|
||
public class CountsAttributes extends TagAttribute { | ||
|
||
private Integer totallines; | ||
private Integer totalfiles; | ||
|
||
public CountsAttributes(XMLStreamReader stream) { | ||
this.totallines = getAttributeInteger("totallines", stream); | ||
this.totalfiles = getAttributeInteger("totalfiles", stream); | ||
} | ||
|
||
public Integer getTotalLines() { | ||
return totallines; | ||
} | ||
|
||
public Integer getTotalFiles() { | ||
return totalfiles; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.wellsky; | ||
|
||
import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.sonar.api.Plugin; | ||
import org.sonar.api.SonarQubeSide; | ||
import org.sonar.api.SonarRuntime; | ||
import org.sonar.api.internal.SonarRuntimeImpl; | ||
import org.sonar.api.utils.Version; | ||
|
||
public class ColdfusionPluginTest { | ||
|
||
|
||
private static final Version VERSION_6_5 = Version.create(6, 5); | ||
|
||
@Test | ||
public void testExtensions() { | ||
ColdFusionPlugin plugin = new ColdFusionPlugin(); | ||
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_6_5, SonarQubeSide.SERVER); | ||
Plugin.Context context = new Plugin.Context(runtime); | ||
plugin.define(context); | ||
|
||
Assert.assertEquals(5, context.getExtensions().size()); | ||
} | ||
} |
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,72 @@ | ||
package com.wellsky; | ||
|
||
import com.stepstone.sonar.plugin.coldfusion.ColdFusionPlugin; | ||
import com.stepstone.sonar.plugin.coldfusion.ColdFusionSensor; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.mockito.Mockito; | ||
import org.sonar.api.SonarQubeSide; | ||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | ||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | ||
import org.sonar.api.internal.SonarRuntimeImpl; | ||
import org.sonar.api.internal.apachecommons.codec.Charsets; | ||
import org.sonar.api.measures.CoreMetrics; | ||
import org.sonar.api.measures.FileLinesContext; | ||
import org.sonar.api.measures.FileLinesContextFactory; | ||
import org.sonar.api.profiles.RulesProfile; | ||
import org.sonar.api.utils.Version; | ||
import org.sonar.api.utils.command.CommandExecutor; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ColdfusionSensorTest { | ||
|
||
private RulesProfile rulesProfile = RulesProfile.create(RulesProfile.SONAR_WAY_NAME, ColdFusionPlugin.LANGUAGE_NAME); | ||
|
||
@Rule | ||
public TemporaryFolder tmpFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void testBasicCFMAnalysis() throws IOException { | ||
DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot()); | ||
fileSystem.setEncoding(Charsets.UTF_8); | ||
fileSystem.setWorkDir(tmpFolder.getRoot().toPath()); | ||
|
||
File sourceDir = new File("src/test/resources"); | ||
SensorContextTester context = SensorContextTester.create(sourceDir.toPath()); | ||
context.setFileSystem(fileSystem); | ||
context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER)); | ||
CommandExecutor commandExecutor = CommandExecutor.create(); | ||
String javaHome = System.getProperty("java.home"); | ||
Assert.assertTrue(javaHome!=null && !javaHome.equals("")); | ||
//FIXME get Java on Linux too and check there is java Home set | ||
if(OSValidator.isWindows()) { | ||
context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java.exe"); | ||
} else { | ||
context.settings().appendProperty(ColdFusionPlugin.CFLINT_JAVA, javaHome + "/bin/java"); | ||
} | ||
|
||
context.settings().appendProperty("sonar.sources",sourceDir.getPath()); | ||
// Mock visitor for metrics. | ||
FileLinesContext fileLinesContext = mock(FileLinesContext.class); | ||
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); | ||
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext); | ||
context = Mockito.spy(context); | ||
ColdFusionSensor sensor = new ColdFusionSensor(context.fileSystem(), rulesProfile); | ||
sensor.execute(context); | ||
|
||
assertThat(context.measure(context.module().key(), CoreMetrics.FILES.key()).value()).isEqualTo(2); | ||
|
||
assertThat(context.measure(context.module().key(), CoreMetrics.LINES.key()).value()).isEqualTo(19); | ||
} | ||
|
||
} |
Oops, something went wrong.