Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarqube 6.5 support #23

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Sonarqube plugin for scala analysis

# Set-up
Intended for sonarqube 5.4
Intended for sonarqube 6.5

Download the latest relase into your sonar extentions/downloads folder.
Restart sonarqube either using the update center or manually.
Expand Down
11 changes: 11 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
dependencies:
override:
- wget https://raw.githubusercontent.com/Sagacify/ci-tools/master/run-sonar.sh
- wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-6.5.zip
- unzip sonarqube-6.5.zip
- chmod +x run-sonar.sh
- ./run-sonar.sh check
- ./run-sonar.sh install
- mvn dependency:resolve

compile:
post:
- mvn -DskipTests=true package
- cp target/sonar-scala-plugin-*.jar sonarqube-6.5/extensions/plugins/

# Launch the test into the docker image
test:
override:
- ./sonarqube-6.5/bin/linux-x86-64/sonar.sh start
- mvn scoverage:report
- ./run-sonar.sh run
post:
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
- find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
67 changes: 47 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>31</version>
<version>41</version>
</parent>

<artifactId>sonar-scala-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.0.3-SNAPSHOT</version>
<version>0.1.0-SNAPSHOT</version>

<name>Sonar Scala Plugin</name>
<description>Enables analysis of Scala projects into Sonar.</description>
<url>http://github.com/sagacify/sonar-scala</url>
<inceptionYear>2016</inceptionYear>
<url>http://github.com/sbartram/sonar-scala</url>
<inceptionYear>2017</inceptionYear>

<licenses>
<license>
<name>GNU LGPL 3</name>
<name>GNU LGPL v3</name>
<url>http://www.gnu.org/licenses/lgpl.txt</url>
<distribution>repo</distribution>
</license>
Expand All @@ -40,24 +40,29 @@
</developers>

<scm>
<connection>scm:git:[email protected]:sagacify/sonar-scala.git</connection>
<developerConnection>scm:git:[email protected]:sagacify/sonar-scala.git</developerConnection>
<url>https://github.com/sagacify/sonar-scala</url>
<connection>scm:git:[email protected]:sbartram/sonar-scala.git</connection>
<developerConnection>scm:git:[email protected]:sbartram/sonar-scala.git</developerConnection>
<url>https://github.com/sbartram/sonar-scala</url>
<tag>HEAD</tag>
</scm>

<issueManagement>
<url>https://github.com/sagacify/sonar-scala/issues</url>
<url>https://github.com/sbartram/sonar-scala/issues</url>
</issueManagement>

<properties>
<sonar.version>5.4</sonar.version>
<license.title>SonarQube Scala</license.title>
<license.years>2009-2018</license.years>
<license.owner>SonarSource SA</license.owner>
<license.mailto>mailto:info AT sonarsource DOT com</license.mailto>
<sonar.version>6.5</sonar.version>
<sonar.pluginKey>scala</sonar.pluginKey>
<sonar.pluginName>Scala</sonar.pluginName>
<sonar.pluginClass>com.sagacify.sonar.scala.ScalaPlugin</sonar.pluginClass>

<scala.version>2.11.8</scala.version>
<scala.major.version>2.11</scala.major.version>
<scala.version>${scala.major.version}.8</scala.version>


</properties>

Expand All @@ -77,7 +82,7 @@
<dependency>
<groupId>org.scalariform</groupId>
<artifactId>scalariform_${scala.major.version}</artifactId>
<version>0.1.8</version>
<version>0.2.6</version>
<exclusions>
<exclusion>
<groupId>org.scala-lang</groupId>
Expand All @@ -88,27 +93,27 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>2.6</version>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.major.version}</artifactId>
<version>2.2.6</version>
<version>3.0.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -117,17 +122,30 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.12.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonar.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>

<dependency>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle_${scala.major.version}</artifactId>
<version>0.8.0</version>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.scala-lang</groupId>
Expand All @@ -142,16 +160,20 @@
<version>${sonar.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<sourceDirectory>src/main/scala</sourceDirectory>

<plugins>

<plugin>
<groupId>org.scoverage</groupId>
<artifactId>scoverage-maven-plugin</artifactId>
<version>1.1.1</version>
</plugin>
<version>1.3.0</version>
</plugin>

<!-- disable surefire -->
<plugin>
Expand All @@ -161,6 +183,7 @@
<skipTests>true</skipTests>
</configuration>
</plugin>

<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
Expand All @@ -180,11 +203,12 @@
</execution>
</executions>
</plugin>

<!-- enable scala-maven -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<version>3.3.1</version>
<executions>
<execution>
<goals>
Expand All @@ -194,6 +218,9 @@
</execution>
</executions>
</plugin>

</plugins>

</build>

</project>
101 changes: 101 additions & 0 deletions src/main/java/org/sonar/plugins/scala/Scala.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* SonarQube Scala
* Copyright (C) 2009-2018 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.scala;

import org.sonar.api.config.Settings;
import org.sonar.api.resources.AbstractLanguage;

import scalariform.lexer.ScalaLexer;
import scalariform.lexer.Token;

import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
* This language cover JavaServer Pages (Scala).
*/
public class Scala extends AbstractLanguage {

/**
* Scala key
*/
public static final String KEY = "scala";

/**
* Scala language name
*/
public static final String NAME = "Scala";


/**
* Key of the file suffix parameter
*/
public static final String FILE_SUFFIXES_KEY = "sonar.scala.file.suffixes";

/**
* Default Java files knows suffixes
*/
public static final String DEFAULT_FILE_SUFFIXES = ".scala";

/**
* Settings of the plugin.
*/
private final Settings settings;

/**
* Default constructor
*/
public Scala(Settings settings) {
super(KEY, NAME);
this.settings = settings;
}

/**
* {@inheritDoc}
*
* @see org.sonar.api.resources.AbstractLanguage#getFileSuffixes()
*/
@Override
public String[] getFileSuffixes() {
String[] suffixes = filterEmptyStrings(settings.getStringArray(FILE_SUFFIXES_KEY));
if (suffixes.length == 0) {
suffixes = StringUtils.split(DEFAULT_FILE_SUFFIXES, ",");
}
return suffixes;
}

private static String[] filterEmptyStrings(String[] stringArray) {
List<String> nonEmptyStrings = Lists.newArrayList();
for (String string : stringArray) {
if (StringUtils.isNotBlank(string.trim())) {
nonEmptyStrings.add(string.trim());
}
}
return nonEmptyStrings.toArray(new String[nonEmptyStrings.size()]);
}


public static scala.collection.immutable.List<Token> tokenize(String sourceCode, String scalaVersion) {
return ScalaLexer.createRawLexer(sourceCode, false, scalaVersion).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ class XmlScoverageReportConstructingParser(source: Source, pathSanitizer: PathSa
val childNodes = children.map(_.toStatementCoverage)

childNodes match {
case Nil => coverage.get
case Nil => coverage match {
case None => FileStatementCoverage("Nothing", 0, 0, List.empty[CoveredStatement])
case _ => coverage.get
}
case _ => DirectoryStatementCoverage(name, childNodes)
}
}
Expand Down Expand Up @@ -224,4 +227,4 @@ class XmlScoverageReportConstructingParser(source: Source, pathSanitizer: PathSa

private def coveredStatements(statements: Iterable[CoveredStatement]) =
statements.count(_.hitCount > 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class ScalastyleRunner(rp: RulesProfile) {
val messages = new ScalastyleChecker[FileSpec]().checkFiles(config, fileSpecs)

// only errors and exceptions are of interest
messages.collect { _ match {
messages.collect {
case e: StyleError[_] => e
case ex: StyleException[_] => ex
}}
}

}

Expand Down
20 changes: 14 additions & 6 deletions src/main/scala/com/sagacify/sonar/scala/Measures.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.sagacify.sonar.scala

import scala.annotation.tailrec

import scalariform.lexer.ScalaLexer
import scalariform.lexer.Token
import scalariform.lexer.Tokens.LINE_COMMENT
import scalariform.lexer.Tokens.MULTILINE_COMMENT
import scalariform.lexer.Tokens.XML_COMMENT
import scalariform.lexer.Tokens.WS
import scalariform.lexer.Tokens.EOF
import scalariform.lexer.Tokens._

object Measures {
def count_classes(tokens: List[Token]): Int = {
var count = 0
tokens.foreach(token => if (token.tokenType == CLASS || token.tokenType == OBJECT) count += 1)

count
}

final def count_methods(tokens: List[Token]): Int = {
var count = 0
tokens.foreach(token => if (token.tokenType == DEF) count += 1)

count
}

/* applied on raw source code */

Expand Down
Loading