-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(coverage): move language definition to Java
move language definition to Java file so it can be referenced from other plugins. It didn't work with Scala class (missing Scala runtime on classpath?) Package name is consistent with Sonar convention.
- Loading branch information
Sebastian Chmielewski
committed
Aug 17, 2017
1 parent
9d18153
commit a140f61
Showing
9 changed files
with
137 additions
and
31 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
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,102 @@ | ||
/* | ||
* Sonar Scala Plugin | ||
* Copyright (C) 2016-2016 SonarSource SA | ||
* mailto:contact 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(); | ||
} | ||
|
||
} |
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
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