import org.sonar.xoo.scm.XooBlameCommand; | import org.sonar.xoo.scm.XooBlameCommand; | ||||
import org.sonar.xoo.scm.XooIgnoreCommand; | import org.sonar.xoo.scm.XooIgnoreCommand; | ||||
import org.sonar.xoo.scm.XooScmProvider; | import org.sonar.xoo.scm.XooScmProvider; | ||||
import org.sonar.xoo.test.CoveragePerTestSensor; | |||||
import org.sonar.xoo.test.TestExecutionSensor; | |||||
/** | /** | ||||
* Plugin entry-point, as declared in pom.xml. | * Plugin entry-point, as declared in pom.xml. | ||||
// Analysis errors | // Analysis errors | ||||
AnalysisErrorSensor.class, | AnalysisErrorSensor.class, | ||||
// Tests | |||||
TestExecutionSensor.class, | |||||
CoveragePerTestSensor.class, | |||||
// Other | // Other | ||||
XooProjectBuilder.class, | XooProjectBuilder.class, | ||||
XooPostJob.class, | XooPostJob.class, |
import org.sonar.api.batch.sensor.Sensor; | import org.sonar.api.batch.sensor.Sensor; | ||||
import org.sonar.api.batch.sensor.SensorContext; | import org.sonar.api.batch.sensor.SensorContext; | ||||
import org.sonar.api.batch.sensor.SensorDescriptor; | import org.sonar.api.batch.sensor.SensorDescriptor; | ||||
import org.sonar.api.batch.sensor.coverage.CoverageType; | |||||
import org.sonar.api.batch.sensor.coverage.NewCoverage; | import org.sonar.api.batch.sensor.coverage.NewCoverage; | ||||
import org.sonar.api.utils.log.Logger; | import org.sonar.api.utils.log.Logger; | ||||
import org.sonar.api.utils.log.Loggers; | import org.sonar.api.utils.log.Loggers; | ||||
try { | try { | ||||
List<String> lines = FileUtils.readLines(coverageFile, context.fileSystem().encoding().name()); | List<String> lines = FileUtils.readLines(coverageFile, context.fileSystem().encoding().name()); | ||||
NewCoverage coverageBuilder = context.newCoverage() | NewCoverage coverageBuilder = context.newCoverage() | ||||
.onFile(inputFile) | |||||
.ofType(getCoverageType()); | |||||
.onFile(inputFile); | |||||
int lineNumber = 0; | int lineNumber = 0; | ||||
for (String line : lines) { | for (String line : lines) { | ||||
lineNumber++; | lineNumber++; | ||||
protected abstract String getCoverageExtension(); | protected abstract String getCoverageExtension(); | ||||
protected abstract CoverageType getCoverageType(); | |||||
@Override | @Override | ||||
public void describe(SensorDescriptor descriptor) { | public void describe(SensorDescriptor descriptor) { | ||||
descriptor | descriptor |
*/ | */ | ||||
package org.sonar.xoo.coverage; | package org.sonar.xoo.coverage; | ||||
import org.sonar.api.batch.sensor.coverage.CoverageType; | |||||
/** | /** | ||||
* Parse files *.xoo.itcoverage | * Parse files *.xoo.itcoverage | ||||
*/ | */ | ||||
return ".itcoverage"; | return ".itcoverage"; | ||||
} | } | ||||
@Override | |||||
protected CoverageType getCoverageType() { | |||||
return CoverageType.IT; | |||||
} | |||||
@Override | @Override | ||||
protected String getSensorName() { | protected String getSensorName() { | ||||
return "Xoo IT Coverage Sensor"; | return "Xoo IT Coverage Sensor"; |
*/ | */ | ||||
package org.sonar.xoo.coverage; | package org.sonar.xoo.coverage; | ||||
import org.sonar.api.batch.sensor.coverage.CoverageType; | |||||
/** | /** | ||||
* Parse files *.xoo.overallcoverage | * Parse files *.xoo.overallcoverage | ||||
*/ | */ | ||||
return ".overallcoverage"; | return ".overallcoverage"; | ||||
} | } | ||||
@Override | |||||
protected CoverageType getCoverageType() { | |||||
return CoverageType.OVERALL; | |||||
} | |||||
@Override | @Override | ||||
protected String getSensorName() { | protected String getSensorName() { | ||||
return "Xoo Overall Coverage Sensor"; | return "Xoo Overall Coverage Sensor"; |
*/ | */ | ||||
package org.sonar.xoo.coverage; | package org.sonar.xoo.coverage; | ||||
import org.sonar.api.batch.sensor.coverage.CoverageType; | |||||
/** | /** | ||||
* Parse files *.xoo.coverage | * Parse files *.xoo.coverage | ||||
*/ | */ | ||||
return ".coverage"; | return ".coverage"; | ||||
} | } | ||||
@Override | |||||
protected CoverageType getCoverageType() { | |||||
return CoverageType.UNIT; | |||||
} | |||||
@Override | @Override | ||||
protected String getSensorName() { | protected String getSensorName() { | ||||
return "Xoo UT Coverage Sensor"; | return "Xoo UT Coverage Sensor"; |
*/ | */ | ||||
package org.sonar.xoo.extensions; | package org.sonar.xoo.extensions; | ||||
import com.google.common.collect.Iterables; | |||||
import org.sonar.api.batch.postjob.PostJob; | import org.sonar.api.batch.postjob.PostJob; | ||||
import org.sonar.api.batch.postjob.PostJobContext; | import org.sonar.api.batch.postjob.PostJobContext; | ||||
import org.sonar.api.batch.postjob.PostJobDescriptor; | import org.sonar.api.batch.postjob.PostJobDescriptor; | ||||
public void describe(PostJobDescriptor descriptor) { | public void describe(PostJobDescriptor descriptor) { | ||||
descriptor.name("Xoo Post Job") | descriptor.name("Xoo Post Job") | ||||
.requireProperty("sonar.xoo.enablePostJob"); | .requireProperty("sonar.xoo.enablePostJob"); | ||||
} | } | ||||
@Override | @Override | ||||
public void execute(PostJobContext context) { | public void execute(PostJobContext context) { | ||||
LOG.info("Resolved issues: " + Iterables.size(context.resolvedIssues())); | |||||
LOG.info("Open issues: " + Iterables.size(context.issues())); | |||||
LOG.info("Running Xoo PostJob"); | |||||
} | } | ||||
} | } |
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import javax.annotation.Nullable; | |||||
import org.apache.commons.io.FileUtils; | import org.apache.commons.io.FileUtils; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
Iterator<String> split = Splitter.on(",").split(line).iterator(); | Iterator<String> split = Splitter.on(",").split(line).iterator(); | ||||
String[] symbolOffsets = split.next().split(":"); | String[] symbolOffsets = split.next().split(":"); | ||||
if (symbolOffsets.length == 2) { | |||||
int startOffset = parseInt(symbolOffsets[0]); | |||||
int endOffset = parseInt(symbolOffsets[1]); | |||||
NewSymbol s = symbolTable.newSymbol(startOffset, endOffset); | |||||
parseReferences(s, split, endOffset - startOffset); | |||||
} else if (symbolOffsets.length == 4) { | |||||
if (symbolOffsets.length == 4) { | |||||
int startLine = parseInt(symbolOffsets[0]); | int startLine = parseInt(symbolOffsets[0]); | ||||
int startLineOffset = parseInt(symbolOffsets[1]); | int startLineOffset = parseInt(symbolOffsets[1]); | ||||
int endLine = parseInt(symbolOffsets[2]); | int endLine = parseInt(symbolOffsets[2]); | ||||
int endLineOffset = parseInt(symbolOffsets[3]); | int endLineOffset = parseInt(symbolOffsets[3]); | ||||
NewSymbol s = symbolTable.newSymbol(startLine, startLineOffset, endLine, endLineOffset); | NewSymbol s = symbolTable.newSymbol(startLine, startLineOffset, endLine, endLineOffset); | ||||
parseReferences(s, split, null); | |||||
parseReferences(s, split); | |||||
} else { | } else { | ||||
throw new IllegalStateException("Illegal number of elements separated by ':'. " + | throw new IllegalStateException("Illegal number of elements separated by ':'. " + | ||||
"Must either be startOffset:endOffset (offset in whole file) or startLine:startLineOffset:endLine:endLineOffset"); | |||||
"Must be startLine:startLineOffset:endLine:endLineOffset"); | |||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e); | throw new IllegalStateException("Error processing line " + lineNumber + " of file " + symbolFile.getAbsolutePath(), e); | ||||
} | } | ||||
} | } | ||||
private static void parseReferences(NewSymbol s, Iterator<String> split, @Nullable Integer defaultLen) { | |||||
private static void parseReferences(NewSymbol s, Iterator<String> split) { | |||||
while (split.hasNext()) { | while (split.hasNext()) { | ||||
addReference(s, split.next(), defaultLen); | |||||
addReference(s, split.next()); | |||||
} | } | ||||
} | } | ||||
private static void addReference(NewSymbol s, String str, @Nullable Integer defaultLen) { | |||||
if (str.contains(":")) { | |||||
String[] split = str.split(":"); | |||||
if (split.length == 2) { | |||||
int startOffset = parseInt(split[0]); | |||||
int endOffset = parseInt(split[1]); | |||||
s.newReference(startOffset, endOffset); | |||||
} else if (split.length == 4) { | |||||
int startLine = parseInt(split[0]); | |||||
int startLineOffset = parseInt(split[1]); | |||||
int endLine = parseInt(split[2]); | |||||
int endLineOffset = parseInt(split[3]); | |||||
s.newReference(startLine, startLineOffset, endLine, endLineOffset); | |||||
} else { | |||||
throw new IllegalStateException("Illegal number of elements separated by ':'"); | |||||
} | |||||
} else if (defaultLen == null) { | |||||
throw new IllegalStateException("Mix of new and old format. Use startLine:startLineOffset:endLine:endLineOffset for references too"); | |||||
private static void addReference(NewSymbol s, String str) { | |||||
String[] split = str.split(":"); | |||||
if (split.length == 4) { | |||||
int startLine = parseInt(split[0]); | |||||
int startLineOffset = parseInt(split[1]); | |||||
int endLine = parseInt(split[2]); | |||||
int endLineOffset = parseInt(split[3]); | |||||
s.newReference(startLine, startLineOffset, endLine, endLineOffset); | |||||
} else { | } else { | ||||
int startOffset = parseInt(str); | |||||
s.newReference(startOffset, startOffset + defaultLen); | |||||
throw new IllegalStateException("Illegal number of elements separated by ':'"); | |||||
} | } | ||||
} | } | ||||
private static void processLine(File highlightingFile, int lineNumber, NewHighlighting highlighting, String line) { | private static void processLine(File highlightingFile, int lineNumber, NewHighlighting highlighting, String line) { | ||||
try { | try { | ||||
String[] split = line.split(":"); | String[] split = line.split(":"); | ||||
if (split.length == 3) { | |||||
int startOffset = parseInt(split[0]); | |||||
int endOffset = parseInt(split[1]); | |||||
highlighting.highlight(startOffset, endOffset, TypeOfText.forCssClass(split[2])); | |||||
} else if (split.length == 5) { | |||||
if (split.length == 5) { | |||||
int startLine = parseInt(split[0]); | int startLine = parseInt(split[0]); | ||||
int startLineOffset = parseInt(split[1]); | int startLineOffset = parseInt(split[1]); | ||||
int endLine = parseInt(split[2]); | int endLine = parseInt(split[2]); | ||||
highlighting.highlight(startLine, startLineOffset, endLine, endLineOffset, TypeOfText.forCssClass(split[4])); | highlighting.highlight(startLine, startLineOffset, endLine, endLineOffset, TypeOfText.forCssClass(split[4])); | ||||
} else { | } else { | ||||
throw new IllegalStateException("Illegal number of elements separated by ':'. " + | throw new IllegalStateException("Illegal number of elements separated by ':'. " + | ||||
"Must either be startOffset:endOffset:class (offset in whole file) or startLine:startLineOffset:endLine:endLineOffset:class"); | |||||
"Must be startLine:startLineOffset:endLine:endLineOffset:class"); | |||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + highlightingFile.getAbsolutePath(), e); | throw new IllegalStateException("Error processing line " + lineNumber + " of file " + highlightingFile.getAbsolutePath(), e); |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.xoo.Xoo2; | import org.sonar.xoo.Xoo2; | ||||
public class Xoo2BasicProfile extends ProfileDefinition { | |||||
public class Xoo2BasicProfile implements BuiltInQualityProfilesDefinition { | |||||
@Override | @Override | ||||
public RulesProfile createProfile(ValidationMessages messages) { | |||||
RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY); | |||||
profile.setDefaultProfile(true); | |||||
// so UGLY | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); | |||||
return profile; | |||||
public void define(Context context) { | |||||
NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Basic", Xoo2.KEY); | |||||
qProfile.setDefault(true); | |||||
qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY); | |||||
qProfile.done(); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.xoo.Xoo2; | import org.sonar.xoo.Xoo2; | ||||
public class Xoo2SonarWayProfile extends ProfileDefinition { | |||||
public class Xoo2SonarWayProfile implements BuiltInQualityProfilesDefinition { | |||||
@Override | @Override | ||||
public RulesProfile createProfile(ValidationMessages messages) { | |||||
RulesProfile profile = RulesProfile.create("Sonar way", Xoo2.KEY); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.MINOR); | |||||
return profile; | |||||
public void define(Context context) { | |||||
NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Sonar way", Xoo2.KEY); | |||||
qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY); | |||||
qProfile.activateRule(XooRulesDefinition.XOO2_REPOSITORY, OneIssuePerLineSensor.RULE_KEY); | |||||
qProfile.done(); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.xoo.Xoo; | import org.sonar.xoo.Xoo; | ||||
public class XooBasicProfile extends ProfileDefinition { | |||||
public class XooBasicProfile implements BuiltInQualityProfilesDefinition { | |||||
@Override | @Override | ||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
final RulesProfile profile = RulesProfile.create("Basic", Xoo.KEY); | |||||
profile.setDefaultProfile(true); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); | |||||
return profile; | |||||
public void define(Context context) { | |||||
NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Basic", Xoo.KEY); | |||||
qProfile.setDefault(true); | |||||
qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY); | |||||
qProfile.done(); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.xoo.Xoo; | import org.sonar.xoo.Xoo; | ||||
public class XooEmptyProfile extends ProfileDefinition { | |||||
public class XooEmptyProfile implements BuiltInQualityProfilesDefinition { | |||||
@Override | @Override | ||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
return RulesProfile.create("empty", Xoo.KEY); | |||||
public void define(Context context) { | |||||
context.createBuiltInQualityProfile("empty", Xoo.KEY) | |||||
.done(); | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.xoo.rule; | package org.sonar.xoo.rule; | ||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.rule.Severity; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.xoo.Xoo; | import org.sonar.xoo.Xoo; | ||||
public class XooSonarWayProfile extends ProfileDefinition { | |||||
public class XooSonarWayProfile implements BuiltInQualityProfilesDefinition { | |||||
@Override | @Override | ||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
final RulesProfile profile = RulesProfile.create("Sonar way", Xoo.KEY); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY), RulePriority.INFO); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY), RulePriority.CRITICAL); | |||||
profile.activateRule(Rule.create(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY), RulePriority.CRITICAL); | |||||
return profile; | |||||
public void define(Context context) { | |||||
NewBuiltInQualityProfile qProfile = context.createBuiltInQualityProfile("Sonar way", Xoo.KEY); | |||||
qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HasTagSensor.RULE_KEY).overrideSeverity(Severity.MAJOR); | |||||
qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerLineSensor.RULE_KEY).overrideSeverity(Severity.INFO); | |||||
qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, OneIssuePerFileSensor.RULE_KEY).overrideSeverity(Severity.CRITICAL); | |||||
qProfile.activateRule(XooRulesDefinition.XOO_REPOSITORY, HotspotSensor.RULE_KEY).overrideSeverity(Severity.CRITICAL); | |||||
qProfile.done(); | |||||
} | } | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.xoo.test; | |||||
import com.google.common.base.Splitter; | |||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.util.ArrayList; | |||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
import org.apache.commons.io.FileUtils; | |||||
import org.apache.commons.lang.StringUtils; | |||||
import org.sonar.api.batch.DependsUpon; | |||||
import org.sonar.api.batch.fs.FilePredicates; | |||||
import org.sonar.api.batch.fs.FileSystem; | |||||
import org.sonar.api.batch.fs.InputFile; | |||||
import org.sonar.api.batch.fs.InputFile.Type; | |||||
import org.sonar.api.batch.sensor.Sensor; | |||||
import org.sonar.api.batch.sensor.SensorContext; | |||||
import org.sonar.api.batch.sensor.SensorDescriptor; | |||||
import org.sonar.api.component.ResourcePerspectives; | |||||
import org.sonar.api.test.MutableTestCase; | |||||
import org.sonar.api.test.MutableTestPlan; | |||||
import org.sonar.api.test.MutableTestable; | |||||
import org.sonar.api.utils.log.Logger; | |||||
import org.sonar.api.utils.log.Loggers; | |||||
import org.sonar.xoo.Xoo; | |||||
/** | |||||
* Parse files *.xoo.testcoverage | |||||
*/ | |||||
@DependsUpon("test-exec") | |||||
public class CoveragePerTestSensor implements Sensor { | |||||
private static final Logger LOG = Loggers.get(CoveragePerTestSensor.class); | |||||
private static final String TEST_EXTENSION = ".testcoverage"; | |||||
private final FileSystem fs; | |||||
private final ResourcePerspectives perspectives; | |||||
public CoveragePerTestSensor(FileSystem fileSystem, ResourcePerspectives perspectives) { | |||||
this.fs = fileSystem; | |||||
this.perspectives = perspectives; | |||||
} | |||||
private void processTestFile(InputFile inputFile, SensorContext context) { | |||||
File testExecutionFile = new File(inputFile.file().getParentFile(), inputFile.file().getName() + TEST_EXTENSION); | |||||
if (testExecutionFile.exists()) { | |||||
LOG.debug("Processing " + testExecutionFile.getAbsolutePath()); | |||||
try { | |||||
List<String> lines = FileUtils.readLines(testExecutionFile, fs.encoding().name()); | |||||
int lineNumber = 0; | |||||
MutableTestPlan testPlan = perspectives.as(MutableTestPlan.class, inputFile); | |||||
for (String line : lines) { | |||||
lineNumber++; | |||||
if (StringUtils.isBlank(line)) { | |||||
continue; | |||||
} | |||||
if (line.startsWith("#")) { | |||||
continue; | |||||
} | |||||
try { | |||||
Iterator<String> split = Splitter.on(";").split(line).iterator(); | |||||
String name = split.next(); | |||||
while (split.hasNext()) { | |||||
String coveredBlockStr = split.next(); | |||||
Iterator<String> splitCoveredBlock = Splitter.on(",").split(coveredBlockStr).iterator(); | |||||
String componentPath = splitCoveredBlock.next(); | |||||
InputFile coveredFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(componentPath)); | |||||
MutableTestable testable = perspectives.as(MutableTestable.class, coveredFile); | |||||
List<Integer> coveredLines = new ArrayList<>(); | |||||
while (splitCoveredBlock.hasNext()) { | |||||
coveredLines.add(Integer.parseInt(splitCoveredBlock.next())); | |||||
} | |||||
for (MutableTestCase testCase : testPlan.testCasesByName(name)) { | |||||
testCase.setCoverageBlock(testable, coveredLines); | |||||
} | |||||
} | |||||
} catch (Exception e) { | |||||
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + testExecutionFile.getAbsolutePath(), e); | |||||
} | |||||
} | |||||
} catch (IOException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public void describe(SensorDescriptor descriptor) { | |||||
descriptor | |||||
.name("Xoo Coverage Per Test Sensor") | |||||
.onlyOnLanguages(Xoo.KEY); | |||||
} | |||||
@Override | |||||
public void execute(SensorContext context) { | |||||
FilePredicates p = context.fileSystem().predicates(); | |||||
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) { | |||||
processTestFile(file, context); | |||||
} | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.xoo.test; | |||||
import com.google.common.base.Splitter; | |||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.util.Iterator; | |||||
import java.util.List; | |||||
import org.apache.commons.io.FileUtils; | |||||
import org.apache.commons.lang.StringUtils; | |||||
import org.sonar.api.batch.DependedUpon; | |||||
import org.sonar.api.batch.fs.FilePredicates; | |||||
import org.sonar.api.batch.fs.FileSystem; | |||||
import org.sonar.api.batch.fs.InputFile; | |||||
import org.sonar.api.batch.fs.InputFile.Type; | |||||
import org.sonar.api.batch.sensor.Sensor; | |||||
import org.sonar.api.batch.sensor.SensorContext; | |||||
import org.sonar.api.batch.sensor.SensorDescriptor; | |||||
import org.sonar.api.component.ResourcePerspectives; | |||||
import org.sonar.api.test.MutableTestCase; | |||||
import org.sonar.api.test.MutableTestPlan; | |||||
import org.sonar.api.test.TestCase; | |||||
import org.sonar.api.utils.log.Logger; | |||||
import org.sonar.api.utils.log.Loggers; | |||||
import org.sonar.xoo.Xoo; | |||||
/** | |||||
* Parse files *.xoo.test | |||||
*/ | |||||
@DependedUpon("test-exec") | |||||
public class TestExecutionSensor implements Sensor { | |||||
private static final Logger LOG = Loggers.get(TestExecutionSensor.class); | |||||
private static final String TEST_EXTENSION = ".test"; | |||||
private final FileSystem fs; | |||||
private final ResourcePerspectives perspectives; | |||||
public TestExecutionSensor(FileSystem fileSystem, ResourcePerspectives perspectives) { | |||||
this.fs = fileSystem; | |||||
this.perspectives = perspectives; | |||||
} | |||||
private void processTestFile(InputFile inputFile, SensorContext context) { | |||||
File testExecutionFile = new File(inputFile.file().getParentFile(), inputFile.file().getName() + TEST_EXTENSION); | |||||
if (testExecutionFile.exists()) { | |||||
LOG.debug("Processing " + testExecutionFile.getAbsolutePath()); | |||||
try { | |||||
List<String> lines = FileUtils.readLines(testExecutionFile, fs.encoding().name()); | |||||
int lineNumber = 0; | |||||
MutableTestPlan testPlan = perspectives.as(MutableTestPlan.class, inputFile); | |||||
for (String line : lines) { | |||||
lineNumber++; | |||||
if (StringUtils.isBlank(line)) { | |||||
continue; | |||||
} | |||||
if (line.startsWith("#")) { | |||||
continue; | |||||
} | |||||
try { | |||||
Iterator<String> split = Splitter.on(":").split(line).iterator(); | |||||
String name = split.next(); | |||||
String durationStr = split.next(); | |||||
Long duration = StringUtils.isNotBlank(durationStr) ? Long.parseLong(durationStr) : null; | |||||
String msg = split.next(); | |||||
String stack = split.next(); | |||||
String status = split.next(); | |||||
String type = split.next(); | |||||
MutableTestCase testCase = testPlan.addTestCase(name); | |||||
testCase.setDurationInMs(duration); | |||||
testCase.setMessage(msg); | |||||
testCase.setStackTrace(stack); | |||||
testCase.setStatus(TestCase.Status.valueOf(status)); | |||||
testCase.setType(type); | |||||
} catch (Exception e) { | |||||
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + testExecutionFile.getAbsolutePath(), e); | |||||
} | |||||
} | |||||
} catch (IOException e) { | |||||
throw new RuntimeException(e); | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public void describe(SensorDescriptor descriptor) { | |||||
descriptor | |||||
.name("Xoo Test Execution Sensor") | |||||
.onlyOnLanguages(Xoo.KEY); | |||||
} | |||||
@Override | |||||
public void execute(SensorContext context) { | |||||
FilePredicates p = context.fileSystem().predicates(); | |||||
for (InputFile file : context.fileSystem().inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.TEST)))) { | |||||
processTestFile(file, context); | |||||
} | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
package org.sonar.xoo.test; | |||||
import javax.annotation.ParametersAreNonnullByDefault; |
*/ | */ | ||||
package org.sonar.xoo.extensions; | package org.sonar.xoo.extensions; | ||||
import java.util.Arrays; | |||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.api.batch.postjob.PostJobContext; | import org.sonar.api.batch.postjob.PostJobContext; | ||||
import org.sonar.api.utils.log.LogTester; | |||||
import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; | import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; | ||||
import org.sonar.api.utils.log.LogTester; | |||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.mockito.Mockito.mock; | import static org.mockito.Mockito.mock; | ||||
import static org.mockito.Mockito.when; | |||||
public class XooPostJobTest { | public class XooPostJobTest { | ||||
public void increaseCoverage() { | public void increaseCoverage() { | ||||
new XooPostJob().describe(new DefaultPostJobDescriptor()); | new XooPostJob().describe(new DefaultPostJobDescriptor()); | ||||
PostJobContext context = mock(PostJobContext.class); | PostJobContext context = mock(PostJobContext.class); | ||||
when(context.issues()).thenReturn(Arrays.asList()); | |||||
when(context.resolvedIssues()).thenReturn(Arrays.asList()); | |||||
new XooPostJob().execute(context); | new XooPostJob().execute(context); | ||||
assertThat(logTester.logs()).contains("Resolved issues: 0", "Open issues: 0"); | |||||
assertThat(logTester.logs()).contains("Running Xoo PostJob"); | |||||
} | } | ||||
} | } |
@Test | @Test | ||||
public void testExecution() throws IOException { | public void testExecution() throws IOException { | ||||
File symbol = new File(baseDir, "src/foo.xoo.symbol"); | File symbol = new File(baseDir, "src/foo.xoo.symbol"); | ||||
FileUtils.write(symbol, "1:4,7\n12:15,23:33\n\n#comment"); | |||||
FileUtils.write(symbol, "1:1:1:4,1:7:1:10\n1:11:1:13,1:14:1:33\n\n#comment"); | |||||
InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") | InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") | ||||
.initMetadata("xoo file with some source code and length over 33") | .initMetadata("xoo file with some source code and length over 33") | ||||
.setLanguage(Xoo.KEY) | .setLanguage(Xoo.KEY) | ||||
assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2)) | assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 2)) | ||||
.containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1, 10))); | .containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 7), new DefaultTextPointer(1, 10))); | ||||
assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 13)) | |||||
.containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 23), new DefaultTextPointer(1, 33))); | |||||
assertThat(context.referencesForSymbolAt("foo:src/foo.xoo", 1, 12)) | |||||
.containsOnly(new DefaultTextRange(new DefaultTextPointer(1, 14), new DefaultTextPointer(1, 33))); | |||||
} | } | ||||
} | } |
@Test | @Test | ||||
public void testExecution() throws IOException { | public void testExecution() throws IOException { | ||||
File symbol = new File(baseDir, "src/foo.xoo.highlighting"); | File symbol = new File(baseDir, "src/foo.xoo.highlighting"); | ||||
FileUtils.write(symbol, "1:4:k\n12:15:cd\n\n#comment"); | |||||
FileUtils.write(symbol, "1:1:1:4:k\n2:7:2:10:cd\n\n#comment"); | |||||
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") | DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo") | ||||
.setLanguage("xoo") | .setLanguage("xoo") | ||||
.setModuleBaseDir(baseDir.toPath()) | .setModuleBaseDir(baseDir.toPath()) |
import org.junit.rules.TemporaryFolder; | import org.junit.rules.TemporaryFolder; | ||||
import org.sonar.api.SonarEdition; | import org.sonar.api.SonarEdition; | ||||
import org.sonar.api.SonarQubeSide; | import org.sonar.api.SonarQubeSide; | ||||
import org.sonar.api.batch.rule.Severity; | |||||
import org.sonar.api.batch.sensor.issue.Issue; | |||||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | import org.sonar.api.batch.fs.internal.DefaultInputFile; | ||||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | ||||
import org.sonar.api.batch.rule.Severity; | |||||
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; | import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; | ||||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | import org.sonar.api.batch.sensor.internal.SensorContextTester; | ||||
import org.sonar.api.batch.sensor.issue.Issue; | |||||
import org.sonar.api.config.internal.MapSettings; | |||||
import org.sonar.api.internal.SonarRuntimeImpl; | import org.sonar.api.internal.SonarRuntimeImpl; | ||||
import org.sonar.api.utils.Version; | import org.sonar.api.utils.Version; | ||||
import org.sonar.xoo.Xoo; | import org.sonar.xoo.Xoo; | ||||
SensorContextTester context = SensorContextTester.create(temp.newFolder()); | SensorContextTester context = SensorContextTester.create(temp.newFolder()); | ||||
context.fileSystem().add(inputFile); | context.fileSystem().add(inputFile); | ||||
context.settings().setProperty(OneIssuePerLineSensor.FORCE_SEVERITY_PROPERTY, "MINOR"); | |||||
context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.FORCE_SEVERITY_PROPERTY, "MINOR")); | |||||
sensor.execute(context); | sensor.execute(context); | ||||
SensorContextTester context = SensorContextTester.create(temp.newFolder()); | SensorContextTester context = SensorContextTester.create(temp.newFolder()); | ||||
context.fileSystem().add(inputFile); | context.fileSystem().add(inputFile); | ||||
context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2"); | |||||
context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2")); | |||||
sensor.execute(context); | sensor.execute(context); | ||||
SensorContextTester context = SensorContextTester.create(temp.newFolder()); | SensorContextTester context = SensorContextTester.create(temp.newFolder()); | ||||
context.fileSystem().add(inputFile); | context.fileSystem().add(inputFile); | ||||
context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2"); | |||||
context.setSettings(new MapSettings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2")); | |||||
context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); | context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); | ||||
sensor.execute(context); | sensor.execute(context); |
.put(HighlightingType.ANNOTATION, "a") | .put(HighlightingType.ANNOTATION, "a") | ||||
.put(HighlightingType.CONSTANT, "c") | .put(HighlightingType.CONSTANT, "c") | ||||
.put(HighlightingType.COMMENT, "cd") | .put(HighlightingType.COMMENT, "cd") | ||||
.put(HighlightingType.CPP_DOC, "cppd") | |||||
.put(HighlightingType.STRUCTURED_COMMENT, "j") | .put(HighlightingType.STRUCTURED_COMMENT, "j") | ||||
.put(HighlightingType.KEYWORD, "k") | .put(HighlightingType.KEYWORD, "k") | ||||
.put(HighlightingType.KEYWORD_LIGHT, "h") | .put(HighlightingType.KEYWORD_LIGHT, "h") |
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.ANNOTATION; | import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.ANNOTATION; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.COMMENT; | import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.COMMENT; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.CONSTANT; | import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.CONSTANT; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.CPP_DOC; | |||||
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.HIGHLIGHTING_STRING; | import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.HIGHLIGHTING_STRING; | ||||
import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.KEYWORD; | import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.KEYWORD; | ||||
public void supports_highlighting_over_multiple_lines_including_an_empty_one() { | public void supports_highlighting_over_multiple_lines_including_an_empty_one() { | ||||
List<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingList = new ArrayList<>(); | List<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingList = new ArrayList<>(); | ||||
addHighlighting(syntaxHighlightingList, 1, 0, 1, 7, KEYWORD); // package | addHighlighting(syntaxHighlightingList, 1, 0, 1, 7, KEYWORD); // package | ||||
addHighlighting(syntaxHighlightingList, 2, 0, 4, 6, CPP_DOC); // comment over 3 lines | |||||
addHighlighting(syntaxHighlightingList, 2, 0, 4, 6, COMMENT); // comment over 3 lines | |||||
addHighlighting(syntaxHighlightingList, 5, 0, 5, 6, KEYWORD); // public | addHighlighting(syntaxHighlightingList, 5, 0, 5, 6, KEYWORD); // public | ||||
addHighlighting(syntaxHighlightingList, 5, 7, 5, 12, KEYWORD); // class | addHighlighting(syntaxHighlightingList, 5, 7, 5, 12, KEYWORD); // class | ||||
HighlightingLineReader highlightingLineReader = new HighlightingLineReader(FILE, syntaxHighlightingList.iterator(), new RangeOffsetConverter()); | HighlightingLineReader highlightingLineReader = new HighlightingLineReader(FILE, syntaxHighlightingList.iterator(), new RangeOffsetConverter()); | ||||
.extracting("highlighting") | .extracting("highlighting") | ||||
.containsExactly( | .containsExactly( | ||||
"0,7,k", | "0,7,k", | ||||
"0,2,cppd", | |||||
"0,2,cd", | |||||
"", | "", | ||||
"0,6,cppd", | |||||
"0,6,cd", | |||||
"0,6,k;7,12,k", | "0,6,k;7,12,k", | ||||
""); | ""); | ||||
} | } |
import org.sonar.api.config.EmailSettings; | import org.sonar.api.config.EmailSettings; | ||||
import org.sonar.api.internal.MetadataLoader; | import org.sonar.api.internal.MetadataLoader; | ||||
import org.sonar.api.internal.SonarRuntimeImpl; | import org.sonar.api.internal.SonarRuntimeImpl; | ||||
import org.sonar.api.profiles.AnnotationProfileParser; | |||||
import org.sonar.api.profiles.XMLProfileParser; | import org.sonar.api.profiles.XMLProfileParser; | ||||
import org.sonar.api.profiles.XMLProfileSerializer; | import org.sonar.api.profiles.XMLProfileSerializer; | ||||
import org.sonar.api.resources.Languages; | import org.sonar.api.resources.Languages; | ||||
import org.sonar.server.log.ServerLogging; | import org.sonar.server.log.ServerLogging; | ||||
import org.sonar.server.measure.index.ProjectMeasuresIndexer; | import org.sonar.server.measure.index.ProjectMeasuresIndexer; | ||||
import org.sonar.server.metric.CoreCustomMetrics; | import org.sonar.server.metric.CoreCustomMetrics; | ||||
import org.sonar.server.metric.DefaultMetricFinder; | |||||
import org.sonar.server.metric.MetricFinder; | |||||
import org.sonar.server.metric.UnanalyzedLanguageMetrics; | import org.sonar.server.metric.UnanalyzedLanguageMetrics; | ||||
import org.sonar.server.notification.DefaultNotificationManager; | import org.sonar.server.notification.DefaultNotificationManager; | ||||
import org.sonar.server.notification.NotificationService; | import org.sonar.server.notification.NotificationService; | ||||
ActiveRuleIndexer.class, | ActiveRuleIndexer.class, | ||||
XMLProfileParser.class, | XMLProfileParser.class, | ||||
XMLProfileSerializer.class, | XMLProfileSerializer.class, | ||||
AnnotationProfileParser.class, | |||||
BuiltInQualityProfileAnnotationLoader.class, | BuiltInQualityProfileAnnotationLoader.class, | ||||
Rules.QProfiles.class, | Rules.QProfiles.class, | ||||
// measure | // measure | ||||
CoreCustomMetrics.class, | CoreCustomMetrics.class, | ||||
DefaultMetricFinder.class, | |||||
MetricFinder.class, | |||||
UnanalyzedLanguageMetrics.class, | UnanalyzedLanguageMetrics.class, | ||||
UserIndexer.class, | UserIndexer.class, |
import java.util.List; | import java.util.List; | ||||
import javax.annotation.Nonnull; | import javax.annotation.Nonnull; | ||||
import org.sonar.api.measures.Metric; | import org.sonar.api.measures.Metric; | ||||
import org.sonar.api.measures.MetricFinder; | |||||
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
import org.sonar.db.metric.MetricDto; | import org.sonar.db.metric.MetricDto; | ||||
import static com.google.common.collect.FluentIterable.from; | import static com.google.common.collect.FluentIterable.from; | ||||
public class DefaultMetricFinder implements MetricFinder { | |||||
public class MetricFinder { | |||||
private final DbClient dbClient; | private final DbClient dbClient; | ||||
public DefaultMetricFinder(DbClient dbClient) { | |||||
public MetricFinder(DbClient dbClient) { | |||||
this.dbClient = dbClient; | this.dbClient = dbClient; | ||||
} | } | ||||
@Override | |||||
public Metric findByUuid(String uuid) { | public Metric findByUuid(String uuid) { | ||||
try (DbSession session = dbClient.openSession(false)) { | try (DbSession session = dbClient.openSession(false)) { | ||||
MetricDto dto = dbClient.metricDao().selectByUuid(session, uuid); | MetricDto dto = dbClient.metricDao().selectByUuid(session, uuid); | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public Metric findByKey(String key) { | public Metric findByKey(String key) { | ||||
try (DbSession session = dbClient.openSession(false)) { | try (DbSession session = dbClient.openSession(false)) { | ||||
MetricDto dto = dbClient.metricDao().selectByKey(session, key); | MetricDto dto = dbClient.metricDao().selectByKey(session, key); | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public Collection<Metric> findAll(List<String> metricKeys) { | public Collection<Metric> findAll(List<String> metricKeys) { | ||||
try (DbSession session = dbClient.openSession(false)) { | try (DbSession session = dbClient.openSession(false)) { | ||||
List<MetricDto> dtos = dbClient.metricDao().selectByKeys(session, metricKeys); | List<MetricDto> dtos = dbClient.metricDao().selectByKeys(session, metricKeys); | ||||
} | } | ||||
} | } | ||||
@Override | |||||
public Collection<Metric> findAll() { | public Collection<Metric> findAll() { | ||||
try (DbSession session = dbClient.openSession(false)) { | try (DbSession session = dbClient.openSession(false)) { | ||||
List<MetricDto> dtos = dbClient.metricDao().selectEnabled(session); | List<MetricDto> dtos = dbClient.metricDao().selectEnabled(session); |
return new Date(state.getStartedAt()); | return new Date(state.getStartedAt()); | ||||
} | } | ||||
@Override | |||||
public File getRootDir() { | |||||
return fs.getHomeDir(); | |||||
} | |||||
@Override | @Override | ||||
public String getContextPath() { | public String getContextPath() { | ||||
return urlSettings.getContextPath(); | return urlSettings.getContextPath(); | ||||
return urlSettings.getBaseUrl(); | return urlSettings.getBaseUrl(); | ||||
} | } | ||||
@Override | |||||
public boolean isDev() { | |||||
return false; | |||||
} | |||||
@Override | @Override | ||||
public boolean isSecured() { | public boolean isSecured() { | ||||
return urlSettings.isSecured(); | return urlSettings.isSecured(); | ||||
} | } | ||||
@Override | |||||
public String getURL() { | |||||
return urlSettings.getBaseUrl(); | |||||
} | |||||
} | } |
import com.google.common.collect.ListMultimap; | import com.google.common.collect.ListMultimap; | ||||
import java.lang.annotation.Annotation; | import java.lang.annotation.Annotation; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.Map; | |||||
import java.util.Set; | import java.util.Set; | ||||
import org.sonar.api.ExtensionProvider; | |||||
import org.sonar.api.Plugin; | import org.sonar.api.Plugin; | ||||
import org.sonar.api.SonarRuntime; | import org.sonar.api.SonarRuntime; | ||||
import org.sonar.api.config.Configuration; | import org.sonar.api.config.Configuration; | ||||
import static java.lang.String.format; | import static java.lang.String.format; | ||||
import static java.util.Objects.requireNonNull; | import static java.util.Objects.requireNonNull; | ||||
import static org.sonar.core.extension.ExtensionProviderSupport.isExtensionProvider; | |||||
/** | /** | ||||
* Loads the plugins server extensions and injects them to DI container | * Loads the plugins server extensions and injects them to DI container | ||||
.build(); | .build(); | ||||
plugin.define(context); | plugin.define(context); | ||||
for (Object extension : context.getExtensions()) { | for (Object extension : context.getExtensions()) { | ||||
if (installExtension(container, pluginInfo, extension, true) != null) { | |||||
if (installExtension(container, pluginInfo, extension) != null) { | |||||
installedExtensionsByPlugin.put(pluginInfo, extension); | installedExtensionsByPlugin.put(pluginInfo, extension); | ||||
} else { | } else { | ||||
container.declareExtension(pluginInfo, extension); | container.declareExtension(pluginInfo, extension); | ||||
throw new IllegalStateException(format("Fail to load plugin %s [%s]", pluginInfo.getName(), pluginInfo.getKey()), e); | throw new IllegalStateException(format("Fail to load plugin %s [%s]", pluginInfo.getName(), pluginInfo.getKey()), e); | ||||
} | } | ||||
} | } | ||||
for (Map.Entry<PluginInfo, Object> entry : installedExtensionsByPlugin.entries()) { | |||||
PluginInfo pluginInfo = entry.getKey(); | |||||
try { | |||||
Object extension = entry.getValue(); | |||||
if (isExtensionProvider(extension)) { | |||||
ExtensionProvider provider = (ExtensionProvider) container.getComponentByKey(extension); | |||||
installProvider(container, pluginInfo, provider); | |||||
} | |||||
} catch (Throwable e) { | |||||
// catch Throwable because we want to catch Error too (IncompatibleClassChangeError, ...) | |||||
throw new IllegalStateException(format("Fail to load plugin %s [%s]", pluginInfo.getName(), pluginInfo.getKey()), e); | |||||
} | |||||
} | |||||
} | } | ||||
private void installProvider(ComponentContainer container, PluginInfo pluginInfo, ExtensionProvider provider) { | |||||
Object obj = provider.provide(); | |||||
if (obj != null) { | |||||
if (obj instanceof Iterable) { | |||||
for (Object ext : (Iterable) obj) { | |||||
installExtension(container, pluginInfo, ext, false); | |||||
} | |||||
} else { | |||||
installExtension(container, pluginInfo, obj, false); | |||||
} | |||||
} | |||||
} | |||||
private Object installExtension(ComponentContainer container, PluginInfo pluginInfo, Object extension, boolean acceptProvider) { | |||||
private Object installExtension(ComponentContainer container, PluginInfo pluginInfo, Object extension) { | |||||
for (Class<? extends Annotation> supportedAnnotationType : supportedAnnotationTypes) { | for (Class<? extends Annotation> supportedAnnotationType : supportedAnnotationTypes) { | ||||
if (AnnotationUtils.getAnnotation(extension, supportedAnnotationType) != null) { | if (AnnotationUtils.getAnnotation(extension, supportedAnnotationType) != null) { | ||||
if (!acceptProvider && isExtensionProvider(extension)) { | |||||
throw new IllegalStateException("ExtensionProvider can not include providers itself: " + extension); | |||||
} | |||||
container.addExtension(pluginInfo, extension); | container.addExtension(pluginInfo, extension); | ||||
return extension; | return extension; | ||||
} | } |
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.sonar.db.metric.MetricTesting.newMetricDto; | import static org.sonar.db.metric.MetricTesting.newMetricDto; | ||||
public class DefaultMetricFinderTest { | |||||
public class MetricFinderTest { | |||||
@Rule | @Rule | ||||
public DbTester db = DbTester.create(System2.INSTANCE); | public DbTester db = DbTester.create(System2.INSTANCE); | ||||
private DefaultMetricFinder underTest = new DefaultMetricFinder(db.getDbClient()); | |||||
private final MetricFinder underTest = new MetricFinder(db.getDbClient()); | |||||
@Test | @Test | ||||
public void findAll_enabled() { | public void findAll_enabled() { | ||||
assertThat(underTest.findByUuid(firstMetric.getUuid())).extracting(Metric::getKey).isEqualTo(firstMetric.getKey()); | assertThat(underTest.findByUuid(firstMetric.getUuid())).extracting(Metric::getKey).isEqualTo(firstMetric.getKey()); | ||||
} | } | ||||
@Test | |||||
public void findById_filters_out_disabled() { | |||||
MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setEnabled(false)); | |||||
db.commit(); | |||||
assertThat(underTest.findByUuid(secondMetric.getUuid())).isNull(); | |||||
} | |||||
@Test | |||||
public void findById_doesnt_find_anything() { | |||||
MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
db.commit(); | |||||
assertThat(underTest.findByUuid("non existing")).isNull(); | |||||
} | |||||
@Test | @Test | ||||
public void findByKey() { | public void findByKey() { | ||||
MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | ||||
assertThat(underTest.findByKey(secondMetric.getKey())).extracting(Metric::getKey).isEqualTo(secondMetric.getKey()); | assertThat(underTest.findByKey(secondMetric.getKey())).extracting(Metric::getKey).isEqualTo(secondMetric.getKey()); | ||||
} | } | ||||
@Test | |||||
public void findByKey_filters_out_disabled() { | |||||
MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setEnabled(false)); | |||||
db.commit(); | |||||
assertThat(underTest.findByKey(secondMetric.getKey())).isNull(); | |||||
} | |||||
@Test | |||||
public void findByKey_doesnt_find_anything() { | |||||
MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); | |||||
db.commit(); | |||||
assertThat(underTest.findByKey("doesnt exist")).isNull(); | |||||
} | |||||
} | } |
@Rule | @Rule | ||||
public TemporaryFolder temp = new TemporaryFolder(); | public TemporaryFolder temp = new TemporaryFolder(); | ||||
@Test | |||||
public void isDev_always_returns_false() { | |||||
assertThat(underTest.isDev()).isFalse(); | |||||
} | |||||
@Test | @Test | ||||
public void test_url_information() { | public void test_url_information() { | ||||
when(urlSettings.getContextPath()).thenReturn("/foo"); | when(urlSettings.getContextPath()).thenReturn("/foo"); | ||||
when(urlSettings.isSecured()).thenReturn(false); | when(urlSettings.isSecured()).thenReturn(false); | ||||
assertThat(underTest.getContextPath()).isEqualTo("/foo"); | assertThat(underTest.getContextPath()).isEqualTo("/foo"); | ||||
assertThat(underTest.getURL()).isEqualTo("http://localhost:9000/foo"); | |||||
assertThat(underTest.getPublicRootUrl()).isEqualTo("http://localhost:9000/foo"); | assertThat(underTest.getPublicRootUrl()).isEqualTo("http://localhost:9000/foo"); | ||||
assertThat(underTest.isDev()).isFalse(); | |||||
assertThat(underTest.isSecured()).isFalse(); | assertThat(underTest.isSecured()).isFalse(); | ||||
} | } | ||||
public void test_file_system_information() throws IOException { | public void test_file_system_information() throws IOException { | ||||
File home = temp.newFolder(); | File home = temp.newFolder(); | ||||
when(fs.getHomeDir()).thenReturn(home); | when(fs.getHomeDir()).thenReturn(home); | ||||
assertThat(underTest.getRootDir()).isEqualTo(home); | |||||
} | } | ||||
@Test | @Test |
return null; | return null; | ||||
} | } | ||||
@Override | |||||
public File getRootDir() { | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public String getContextPath() { | public String getContextPath() { | ||||
return null; | return null; | ||||
return null; | return null; | ||||
} | } | ||||
@Override | |||||
public boolean isDev() { | |||||
return false; | |||||
} | |||||
@Override | @Override | ||||
public boolean isSecured() { | public boolean isSecured() { | ||||
return false; | return false; | ||||
} | } | ||||
@Override | |||||
public String getURL() { | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public String getPermanentServerId() { | public String getPermanentServerId() { | ||||
return null; | return null; |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.server.qualityprofile; | |||||
import com.google.common.collect.ImmutableList; | |||||
import java.util.List; | |||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rules.ActiveRuleParam; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.api.utils.log.Logger; | |||||
import org.sonar.api.utils.log.Loggers; | |||||
import org.sonar.api.utils.log.Profiler; | |||||
import static java.lang.String.format; | |||||
/** | |||||
* Bridge between deprecated {@link ProfileDefinition} API and new {@link BuiltInQualityProfilesDefinition} | |||||
*/ | |||||
public class BuiltInQProfileDefinitionsBridge implements BuiltInQualityProfilesDefinition { | |||||
private static final Logger LOGGER = Loggers.get(BuiltInQProfileDefinitionsBridge.class); | |||||
private final List<ProfileDefinition> definitions; | |||||
/** | |||||
* Requires for pico container when no {@link ProfileDefinition} is defined at all | |||||
*/ | |||||
public BuiltInQProfileDefinitionsBridge() { | |||||
this(new ProfileDefinition[0]); | |||||
} | |||||
public BuiltInQProfileDefinitionsBridge(ProfileDefinition... definitions) { | |||||
this.definitions = ImmutableList.copyOf(definitions); | |||||
} | |||||
@Override | |||||
public void define(Context context) { | |||||
Profiler profiler = Profiler.create(Loggers.get(getClass())); | |||||
for (ProfileDefinition definition : definitions) { | |||||
profiler.start(); | |||||
ValidationMessages validation = ValidationMessages.create(); | |||||
RulesProfile profile = definition.createProfile(validation); | |||||
validation.log(LOGGER); | |||||
if (profile == null) { | |||||
profiler.stopDebug(format("Loaded definition %s that return no profile", definition)); | |||||
} else { | |||||
if (!validation.hasErrors()) { | |||||
define(context, profile); | |||||
} | |||||
profiler.stopDebug(format("Loaded deprecated profile definition %s for language %s", profile.getName(), profile.getLanguage())); | |||||
} | |||||
} | |||||
} | |||||
private static void define(Context context, RulesProfile profile) { | |||||
NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage()) | |||||
.setDefault(profile.getDefaultProfile()); | |||||
for (org.sonar.api.rules.ActiveRule ar : profile.getActiveRules()) { | |||||
NewBuiltInActiveRule newActiveRule = newQp.activateRule(ar.getRepositoryKey(), ar.getRuleKey()); | |||||
RulePriority overriddenSeverity = ar.getOverriddenSeverity(); | |||||
if (overriddenSeverity != null) { | |||||
newActiveRule.overrideSeverity(overriddenSeverity.name()); | |||||
} | |||||
for (ActiveRuleParam param : ar.getActiveRuleParams()) { | |||||
newActiveRule.overrideParam(param.getKey(), param.getValue()); | |||||
} | |||||
} | |||||
newQp.done(); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.server.qualityprofile; | |||||
import java.util.Arrays; | |||||
import org.junit.Test; | |||||
import org.sonar.api.profiles.ProfileDefinition; | |||||
import org.sonar.api.profiles.RulesProfile; | |||||
import org.sonar.api.rule.RuleKey; | |||||
import org.sonar.api.rule.Severity; | |||||
import org.sonar.api.rules.ActiveRule; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RuleParam; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInActiveRule; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import static org.assertj.core.api.Assertions.assertThat; | |||||
import static org.assertj.core.groups.Tuple.tuple; | |||||
public class BuiltInQProfileDefinitionsBridgeTest { | |||||
@Test | |||||
public void noProfileDefinitions() { | |||||
BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(); | |||||
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); | |||||
bridge.define(context); | |||||
assertThat(context.profilesByLanguageAndName()).isEmpty(); | |||||
} | |||||
@Test | |||||
public void bridgeProfileDefinitions() { | |||||
BuiltInQProfileDefinitionsBridge bridge = new BuiltInQProfileDefinitionsBridge(new Profile1(), new NullProfile(), new ProfileWithError()); | |||||
BuiltInQualityProfilesDefinition.Context context = new BuiltInQualityProfilesDefinition.Context(); | |||||
bridge.define(context); | |||||
assertThat(context.profilesByLanguageAndName()).hasSize(1); | |||||
assertThat(context.profilesByLanguageAndName().get("xoo")).hasSize(1); | |||||
BuiltInQualityProfile profile1 = context.profile("xoo", "Profile 1"); | |||||
assertThat(profile1).isNotNull(); | |||||
assertThat(profile1.rules()).hasSize(3); | |||||
BuiltInActiveRule defaultSeverity = profile1.rule(RuleKey.of("repo1", "defaultSeverity")); | |||||
assertThat(defaultSeverity).isNotNull(); | |||||
assertThat(defaultSeverity.overriddenSeverity()).isNull(); | |||||
assertThat(defaultSeverity.overriddenParams()).isEmpty(); | |||||
assertThat(profile1.rule(RuleKey.of("repo1", "overrideSeverity")).overriddenSeverity()).isEqualTo(Severity.CRITICAL); | |||||
assertThat(profile1.rule(RuleKey.of("repo1", "overrideParam")).overriddenParams()) | |||||
.extracting(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue).containsOnly(tuple("param", "value")); | |||||
} | |||||
private static class Profile1 extends ProfileDefinition { | |||||
@Override | |||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
RulesProfile profile1 = RulesProfile.create("Profile 1", "xoo"); | |||||
profile1.activateRule(Rule.create("repo1", "defaultSeverity"), null); | |||||
profile1.activateRule(Rule.create("repo1", "overrideSeverity"), RulePriority.CRITICAL); | |||||
Rule ruleWithParam = Rule.create("repo1", "overrideParam"); | |||||
ruleWithParam.setParams(Arrays.asList(new RuleParam(ruleWithParam, "param", "", ""))); | |||||
ActiveRule arWithParam = profile1.activateRule(ruleWithParam, null); | |||||
arWithParam.setParameter("param", "value"); | |||||
return profile1; | |||||
} | |||||
} | |||||
private static class NullProfile extends ProfileDefinition { | |||||
@Override | |||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
return null; | |||||
} | |||||
} | |||||
private static class ProfileWithError extends ProfileDefinition { | |||||
@Override | |||||
public RulesProfile createProfile(ValidationMessages validation) { | |||||
validation.addErrorText("Foo"); | |||||
return RulesProfile.create("Profile with errors", "xoo"); | |||||
} | |||||
} | |||||
} |
Profiler profiler = Profiler.create(LOG).startInfo("Register rules"); | Profiler profiler = Profiler.create(LOG).startInfo("Register rules"); | ||||
try (DbSession dbSession = dbClient.openSession(false)) { | try (DbSession dbSession = dbClient.openSession(false)) { | ||||
RulesDefinition.Context ruleDefinitionContext = defLoader.load(); | RulesDefinition.Context ruleDefinitionContext = defLoader.load(); | ||||
List<RulesDefinition.ExtendedRepository> repositories = getRepositories(ruleDefinitionContext); | |||||
List<RulesDefinition.Repository> repositories = ruleDefinitionContext.repositories(); | |||||
RegisterRulesContext registerRulesContext = createRegisterRulesContext(dbSession); | RegisterRulesContext registerRulesContext = createRegisterRulesContext(dbSession); | ||||
verifyRuleKeyConsistency(repositories, registerRulesContext); | verifyRuleKeyConsistency(repositories, registerRulesContext); | ||||
} | } | ||||
} | } | ||||
private static List<RulesDefinition.ExtendedRepository> getRepositories(RulesDefinition.Context context) { | |||||
List<RulesDefinition.ExtendedRepository> repositories = new ArrayList<>(context.repositories()); | |||||
for (RulesDefinition.ExtendedRepository extendedRepoDef : context.extendedRepositories()) { | |||||
if (context.repository(extendedRepoDef.key()) == null) { | |||||
LOG.warn(format("Extension is ignored, repository %s does not exist", extendedRepoDef.key())); | |||||
} else { | |||||
repositories.add(extendedRepoDef); | |||||
} | |||||
} | |||||
return repositories; | |||||
} | |||||
private RegisterRulesContext createRegisterRulesContext(DbSession dbSession) { | private RegisterRulesContext createRegisterRulesContext(DbSession dbSession) { | ||||
Map<RuleKey, RuleDefinitionDto> allRules = dbClient.ruleDao().selectAllDefinitions(dbSession).stream() | Map<RuleKey, RuleDefinitionDto> allRules = dbClient.ruleDao().selectAllDefinitions(dbSession).stream() | ||||
.collect(uniqueIndex(RuleDefinitionDto::getKey)); | .collect(uniqueIndex(RuleDefinitionDto::getKey)); | ||||
* If an extended repository do not exists anymore, then related active rules will be removed. | * If an extended repository do not exists anymore, then related active rules will be removed. | ||||
*/ | */ | ||||
private List<ActiveRuleChange> removeActiveRulesOnStillExistingRepositories(DbSession dbSession, RegisterRulesContext recorder, | private List<ActiveRuleChange> removeActiveRulesOnStillExistingRepositories(DbSession dbSession, RegisterRulesContext recorder, | ||||
List<RulesDefinition.ExtendedRepository> context) { | |||||
List<RulesDefinition.Repository> context) { | |||||
List<String> repositoryKeys = context.stream() | List<String> repositoryKeys = context.stream() | ||||
.map(RulesDefinition.ExtendedRepository::key) | .map(RulesDefinition.ExtendedRepository::key) | ||||
.collect(MoreCollectors.toList(context.size())); | .collect(MoreCollectors.toList(context.size())); | ||||
dbClient.ruleDao().update(session, rule); | dbClient.ruleDao().update(session, rule); | ||||
} | } | ||||
private static void verifyRuleKeyConsistency(List<RulesDefinition.ExtendedRepository> repositories, RegisterRulesContext registerRulesContext) { | |||||
private static void verifyRuleKeyConsistency(List<RulesDefinition.Repository> repositories, RegisterRulesContext registerRulesContext) { | |||||
List<RulesDefinition.Rule> definedRules = repositories.stream() | List<RulesDefinition.Rule> definedRules = repositories.stream() | ||||
.flatMap(r -> r.rules().stream()) | .flatMap(r -> r.rules().stream()) | ||||
.collect(toList()); | .collect(toList()); |
static class FbContribRepository implements RulesDefinition { | static class FbContribRepository implements RulesDefinition { | ||||
@Override | @Override | ||||
public void define(Context context) { | public void define(Context context) { | ||||
NewExtendedRepository repo = context.extendRepository("findbugs", "java"); | |||||
NewExtendedRepository repo = context.createRepository("findbugs", "java"); | |||||
repo.createRule("rule2") | repo.createRule("rule2") | ||||
.setName("Rule Two") | .setName("Rule Two") | ||||
.setHtmlDescription("Description of Rule Two"); | .setHtmlDescription("Description of Rule Two"); |
*/ | */ | ||||
package org.sonar.server.telemetry; | package org.sonar.server.telemetry; | ||||
import java.io.File; | |||||
import java.util.Date; | import java.util.Date; | ||||
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import org.sonar.api.platform.Server; | import org.sonar.api.platform.Server; | ||||
return null; | return null; | ||||
} | } | ||||
@Override | |||||
public File getRootDir() { | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public String getContextPath() { | public String getContextPath() { | ||||
return null; | return null; | ||||
return null; | return null; | ||||
} | } | ||||
@Override | |||||
public boolean isDev() { | |||||
return false; | |||||
} | |||||
@Override | @Override | ||||
public boolean isSecured() { | public boolean isSecured() { | ||||
return false; | return false; | ||||
} | } | ||||
@Override | |||||
public String getURL() { | |||||
return null; | |||||
} | |||||
} | } |
import java.util.Collection; | import java.util.Collection; | ||||
import org.sonar.api.measures.Metric; | import org.sonar.api.measures.Metric; | ||||
import org.sonar.api.measures.Metric.ValueType; | import org.sonar.api.measures.Metric.ValueType; | ||||
import org.sonar.api.measures.MetricFinder; | |||||
import org.sonar.api.server.ws.Request; | import org.sonar.api.server.ws.Request; | ||||
import org.sonar.api.server.ws.Response; | import org.sonar.api.server.ws.Response; | ||||
import org.sonar.api.server.ws.WebService; | import org.sonar.api.server.ws.WebService; | ||||
import org.sonar.api.utils.text.JsonWriter; | import org.sonar.api.utils.text.JsonWriter; | ||||
import org.sonar.server.metric.MetricFinder; | |||||
public class UserMetricsAction implements MetricsWsAction { | public class UserMetricsAction implements MetricsWsAction { | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.api.measures.Metric; | import org.sonar.api.measures.Metric; | ||||
import org.sonar.api.measures.Metric.ValueType; | import org.sonar.api.measures.Metric.ValueType; | ||||
import org.sonar.api.measures.MetricFinder; | |||||
import org.sonar.server.metric.MetricFinder; | |||||
import org.sonar.server.ws.WsActionTester; | import org.sonar.server.ws.WsActionTester; | ||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; |
*/ | */ | ||||
package org.sonar.server.platform.ws; | package org.sonar.server.platform.ws; | ||||
import java.io.File; | |||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); | ||||
} | } | ||||
@Override | |||||
public File getRootDir() { | |||||
throw new UnsupportedOperationException(); | |||||
} | |||||
@Override | @Override | ||||
public String getContextPath() { | public String getContextPath() { | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); | ||||
} | } | ||||
@Override | |||||
public boolean isDev() { | |||||
throw new UnsupportedOperationException(); | |||||
} | |||||
@Override | @Override | ||||
public boolean isSecured() { | public boolean isSecured() { | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); | ||||
} | } | ||||
@Override | |||||
public String getURL() { | |||||
throw new UnsupportedOperationException(); | |||||
} | |||||
@Override | @Override | ||||
public String getPermanentServerId() { | public String getPermanentServerId() { | ||||
throw new UnsupportedOperationException(); | throw new UnsupportedOperationException(); |
import org.sonar.alm.client.github.GithubApplicationHttpClientImpl; | import org.sonar.alm.client.github.GithubApplicationHttpClientImpl; | ||||
import org.sonar.alm.client.github.security.GithubAppSecurityImpl; | import org.sonar.alm.client.github.security.GithubAppSecurityImpl; | ||||
import org.sonar.alm.client.gitlab.GitlabHttpClient; | import org.sonar.alm.client.gitlab.GitlabHttpClient; | ||||
import org.sonar.api.profiles.AnnotationProfileParser; | |||||
import org.sonar.api.profiles.XMLProfileParser; | import org.sonar.api.profiles.XMLProfileParser; | ||||
import org.sonar.api.profiles.XMLProfileSerializer; | import org.sonar.api.profiles.XMLProfileSerializer; | ||||
import org.sonar.api.resources.Languages; | import org.sonar.api.resources.Languages; | ||||
import org.sonar.server.measure.live.LiveMeasureModule; | import org.sonar.server.measure.live.LiveMeasureModule; | ||||
import org.sonar.server.measure.ws.MeasuresWsModule; | import org.sonar.server.measure.ws.MeasuresWsModule; | ||||
import org.sonar.server.metric.CoreCustomMetrics; | import org.sonar.server.metric.CoreCustomMetrics; | ||||
import org.sonar.server.metric.DefaultMetricFinder; | |||||
import org.sonar.server.metric.MetricFinder; | |||||
import org.sonar.server.metric.UnanalyzedLanguageMetrics; | import org.sonar.server.metric.UnanalyzedLanguageMetrics; | ||||
import org.sonar.server.metric.ws.MetricsWsModule; | import org.sonar.server.metric.ws.MetricsWsModule; | ||||
import org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsModule; | import org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsModule; | ||||
import org.sonar.server.qualitygate.ws.QualityGateWsModule; | import org.sonar.server.qualitygate.ws.QualityGateWsModule; | ||||
import org.sonar.server.qualityprofile.BuiltInQPChangeNotificationHandler; | import org.sonar.server.qualityprofile.BuiltInQPChangeNotificationHandler; | ||||
import org.sonar.server.qualityprofile.BuiltInQPChangeNotificationTemplate; | import org.sonar.server.qualityprofile.BuiltInQPChangeNotificationTemplate; | ||||
import org.sonar.server.qualityprofile.BuiltInQProfileDefinitionsBridge; | |||||
import org.sonar.server.qualityprofile.BuiltInQProfileRepositoryImpl; | import org.sonar.server.qualityprofile.BuiltInQProfileRepositoryImpl; | ||||
import org.sonar.server.qualityprofile.QProfileBackuperImpl; | import org.sonar.server.qualityprofile.QProfileBackuperImpl; | ||||
import org.sonar.server.qualityprofile.QProfileComparison; | import org.sonar.server.qualityprofile.QProfileComparison; | ||||
UpdateCenterModule.class, | UpdateCenterModule.class, | ||||
// quality profile | // quality profile | ||||
BuiltInQProfileDefinitionsBridge.class, | |||||
BuiltInQProfileRepositoryImpl.class, | BuiltInQProfileRepositoryImpl.class, | ||||
ActiveRuleIndexer.class, | ActiveRuleIndexer.class, | ||||
XMLProfileParser.class, | XMLProfileParser.class, | ||||
XMLProfileSerializer.class, | XMLProfileSerializer.class, | ||||
AnnotationProfileParser.class, | |||||
QProfileComparison.class, | QProfileComparison.class, | ||||
QProfileTreeImpl.class, | QProfileTreeImpl.class, | ||||
QProfileRulesImpl.class, | QProfileRulesImpl.class, | ||||
MeasuresWsModule.class, | MeasuresWsModule.class, | ||||
CustomMeasuresWsModule.class, | CustomMeasuresWsModule.class, | ||||
CoreCustomMetrics.class, | CoreCustomMetrics.class, | ||||
DefaultMetricFinder.class, | |||||
MetricFinder.class, | |||||
UnanalyzedLanguageMetrics.class, | UnanalyzedLanguageMetrics.class, | ||||
QualityGateModule.class, | QualityGateModule.class, |
.name(PROPERTY_RULE_KEY_PATTERN) | .name(PROPERTY_RULE_KEY_PATTERN) | ||||
.description("Pattern to match rules which should be ignored.") | .description("Pattern to match rules which should be ignored.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build(), | .build(), | ||||
PropertyFieldDefinition.build(RESOURCE_KEY) | PropertyFieldDefinition.build(RESOURCE_KEY) | ||||
.name(PROPERTY_FILE_PATH_PATTERN) | .name(PROPERTY_FILE_PATH_PATTERN) | ||||
.description("Pattern to match files which should be ignored.") | .description("Pattern to match files which should be ignored.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build() | .build() | ||||
) | ) | ||||
.build(), | .build(), | ||||
.name("Regular Expression for Start of Block") | .name("Regular Expression for Start of Block") | ||||
.description("If this regular expression is found in a file, then following lines are ignored until end of block.") | .description("If this regular expression is found in a file, then following lines are ignored until end of block.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build(), | .build(), | ||||
PropertyFieldDefinition.build(END_BLOCK_REGEXP) | PropertyFieldDefinition.build(END_BLOCK_REGEXP) | ||||
.name("Regular Expression for End of Block") | .name("Regular Expression for End of Block") | ||||
.description("If specified, this regular expression is used to determine the end of code blocks to ignore. If not, then block ends at the end of file.") | .description("If specified, this regular expression is used to determine the end of code blocks to ignore. If not, then block ends at the end of file.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build() | .build() | ||||
) | ) | ||||
.build(), | .build(), | ||||
.name("Regular Expression") | .name("Regular Expression") | ||||
.description("If this regular expression is found in a file, then the whole file is ignored.") | .description("If this regular expression is found in a file, then the whole file is ignored.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build() | .build() | ||||
) | ) | ||||
.build(), | .build(), | ||||
.name(PROPERTY_RULE_KEY_PATTERN) | .name(PROPERTY_RULE_KEY_PATTERN) | ||||
.description("Pattern used to match rules which should be restricted.") | .description("Pattern used to match rules which should be restricted.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build(), | .build(), | ||||
PropertyFieldDefinition.build(RESOURCE_KEY) | PropertyFieldDefinition.build(RESOURCE_KEY) | ||||
.name(PROPERTY_FILE_PATH_PATTERN) | .name(PROPERTY_FILE_PATH_PATTERN) | ||||
.description("Pattern used to match files to which the rules should be restricted.") | .description("Pattern used to match files to which the rules should be restricted.") | ||||
.type(PropertyType.STRING) | .type(PropertyType.STRING) | ||||
.indicativeSize(LARGE_SIZE) | |||||
.build() | .build() | ||||
) | ) | ||||
.build() | .build() | ||||
); | |||||
); | |||||
} | } | ||||
} | } |
package org.sonar.core.extension; | package org.sonar.core.extension; | ||||
import java.lang.annotation.Annotation; | import java.lang.annotation.Annotation; | ||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.List; | |||||
import java.util.Optional; | import java.util.Optional; | ||||
import java.util.function.Predicate; | import java.util.function.Predicate; | ||||
import org.sonar.api.ExtensionProvider; | |||||
import org.sonar.api.SonarRuntime; | import org.sonar.api.SonarRuntime; | ||||
import org.sonar.api.config.Configuration; | import org.sonar.api.config.Configuration; | ||||
import org.sonar.api.config.internal.MapSettings; | import org.sonar.api.config.internal.MapSettings; | ||||
private void install(ComponentContainer container, Predicate<Object> extensionFilter, Predicate<Object> additionalSideFilter, CoreExtension coreExtension) { | private void install(ComponentContainer container, Predicate<Object> extensionFilter, Predicate<Object> additionalSideFilter, CoreExtension coreExtension) { | ||||
String coreExtensionName = coreExtension.getName(); | String coreExtensionName = coreExtension.getName(); | ||||
try { | try { | ||||
List<Object> providerKeys = addDeclaredExtensions(container, extensionFilter, additionalSideFilter, coreExtension); | |||||
addProvidedExtensions(container, additionalSideFilter, coreExtensionName, providerKeys); | |||||
addDeclaredExtensions(container, extensionFilter, additionalSideFilter, coreExtension); | |||||
LOG.debug("Installed core extension: " + coreExtensionName); | LOG.debug("Installed core extension: " + coreExtensionName); | ||||
coreExtensionRepository.installed(coreExtension); | coreExtensionRepository.installed(coreExtension); | ||||
} | } | ||||
} | } | ||||
private List<Object> addDeclaredExtensions(ComponentContainer container, Predicate<Object> extensionFilter, | |||||
private void addDeclaredExtensions(ComponentContainer container, Predicate<Object> extensionFilter, | |||||
Predicate<Object> additionalSideFilter, CoreExtension coreExtension) { | Predicate<Object> additionalSideFilter, CoreExtension coreExtension) { | ||||
ContextImpl context = new ContextImpl(container, extensionFilter, additionalSideFilter, coreExtension.getName()); | ContextImpl context = new ContextImpl(container, extensionFilter, additionalSideFilter, coreExtension.getName()); | ||||
coreExtension.load(context); | coreExtension.load(context); | ||||
return context.getProviders(); | |||||
} | |||||
private void addProvidedExtensions(ComponentContainer container, Predicate<Object> additionalSideFilter, | |||||
String extensionCategory, List<Object> providerKeys) { | |||||
providerKeys.stream() | |||||
.map(providerKey -> (ExtensionProvider) container.getComponentByKey(providerKey)) | |||||
.forEach(provider -> addFromProvider(container, additionalSideFilter, extensionCategory, provider)); | |||||
} | |||||
private void addFromProvider(ComponentContainer container, Predicate<Object> additionalSideFilter, | |||||
String extensionCategory, ExtensionProvider provider) { | |||||
Object obj = provider.provide(); | |||||
if (obj != null) { | |||||
if (obj instanceof Iterable) { | |||||
for (Object ext : (Iterable) obj) { | |||||
addSupportedExtension(container, additionalSideFilter, extensionCategory, ext); | |||||
} | |||||
} else { | |||||
addSupportedExtension(container, additionalSideFilter, extensionCategory, obj); | |||||
} | |||||
} | |||||
} | } | ||||
private <T> boolean addSupportedExtension(ComponentContainer container, Predicate<Object> additionalSideFilter, | private <T> boolean addSupportedExtension(ComponentContainer container, Predicate<Object> additionalSideFilter, | ||||
private final Predicate<Object> extensionFilter; | private final Predicate<Object> extensionFilter; | ||||
private final Predicate<Object> additionalSideFilter; | private final Predicate<Object> additionalSideFilter; | ||||
private final String extensionCategory; | private final String extensionCategory; | ||||
private final List<Object> providers = new ArrayList<>(); | |||||
public ContextImpl(ComponentContainer container, Predicate<Object> extensionFilter, | public ContextImpl(ComponentContainer container, Predicate<Object> extensionFilter, | ||||
Predicate<Object> additionalSideFilter, String extensionCategory) { | Predicate<Object> additionalSideFilter, String extensionCategory) { | ||||
if (!addSupportedExtension(container, additionalSideFilter, extensionCategory, component)) { | if (!addSupportedExtension(container, additionalSideFilter, extensionCategory, component)) { | ||||
container.declareExtension(extensionCategory, component); | container.declareExtension(extensionCategory, component); | ||||
} else if (ExtensionProviderSupport.isExtensionProvider(component)) { | |||||
providers.add(component); | |||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
components.forEach(this::addExtension); | components.forEach(this::addExtension); | ||||
return this; | return this; | ||||
} | } | ||||
public List<Object> getProviders() { | |||||
return providers; | |||||
} | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package org.sonar.core.extension; | package org.sonar.core.extension; | ||||
import org.sonar.api.ExtensionProvider; | |||||
public final class ExtensionProviderSupport { | public final class ExtensionProviderSupport { | ||||
private ExtensionProviderSupport() { | private ExtensionProviderSupport() { | ||||
// prevents implementation | // prevents implementation | ||||
} | } | ||||
public static boolean isExtensionProvider(Object extension) { | |||||
return isType(extension, ExtensionProvider.class) || extension instanceof ExtensionProvider; | |||||
} | |||||
private static boolean isType(Object extension, Class extensionClass) { | private static boolean isType(Object extension, Class extensionClass) { | ||||
Class clazz = extension instanceof Class ? (Class) extension : extension.getClass(); | Class clazz = extension instanceof Class ? (Class) extension : extension.getClass(); | ||||
return extensionClass.isAssignableFrom(clazz); | return extensionClass.isAssignableFrom(clazz); |
import org.mockito.InOrder; | import org.mockito.InOrder; | ||||
import org.mockito.Mockito; | import org.mockito.Mockito; | ||||
import org.picocontainer.ComponentAdapter; | import org.picocontainer.ComponentAdapter; | ||||
import org.sonar.api.ExtensionProvider; | |||||
import org.sonar.api.Property; | import org.sonar.api.Property; | ||||
import org.sonar.api.SonarRuntime; | import org.sonar.api.SonarRuntime; | ||||
import org.sonar.api.config.Configuration; | import org.sonar.api.config.Configuration; | ||||
assertPropertyDefinitions(container, coreExtension, propertyDefinitionNoCategory, propertyDefinitionWithCategory); | assertPropertyDefinitions(container, coreExtension, propertyDefinitionNoCategory, propertyDefinitionWithCategory); | ||||
} | } | ||||
@Test | |||||
@UseDataProvider("allMethodsToAddExtension") | |||||
public void install_adds_providers_to_container_and_install_extensions_they_provide_when_annotated_with_expected_annotation( | |||||
BiConsumer<CoreExtension.Context, Collection<Object>> extensionAdder) { | |||||
List<Object> extensions = ImmutableList.of(WestSideProvider.class, PartiallyWestSideProvider.class, EastSideProvider.class); | |||||
CoreExtension coreExtension = newCoreExtension(context -> extensionAdder.accept(context, extensions)); | |||||
when(coreExtensionRepository.loadedCoreExtensions()).thenReturn(Stream.of(coreExtension)); | |||||
ComponentContainer container = new ComponentContainer(); | |||||
underTest.install(container, noExtensionFilter(), noAdditionalSideFilter()); | |||||
assertAddedExtensions(container, WestSideProvider.class, WestSideProvided.class, PartiallyWestSideProvider.class); | |||||
assertPropertyDefinitions(container); | |||||
} | |||||
@DataProvider | @DataProvider | ||||
public static Object[][] allMethodsToAddExtension() { | public static Object[][] allMethodsToAddExtension() { | ||||
BiConsumer<CoreExtension.Context, Collection<Object>> addExtension = (context, objects) -> objects.forEach(context::addExtension); | BiConsumer<CoreExtension.Context, Collection<Object>> addExtension = (context, objects) -> objects.forEach(context::addExtension); | ||||
} | } | ||||
@WestSide | |||||
public static class WestSideProvider extends ExtensionProvider { | |||||
@Override | |||||
public Object provide() { | |||||
return WestSideProvided.class; | |||||
} | |||||
} | |||||
@WestSide | |||||
public static class WestSideProvided { | |||||
} | |||||
@WestSide | |||||
public static class PartiallyWestSideProvider extends ExtensionProvider { | |||||
@Override | |||||
public Object provide() { | |||||
return NotWestSideProvided.class; | |||||
} | |||||
} | |||||
public static class NotWestSideProvided { | |||||
} | |||||
@EastSide | |||||
public static class EastSideProvider extends ExtensionProvider { | |||||
@Override | |||||
public Object provide() { | |||||
throw new IllegalStateException("EastSideProvider#provide should not be called"); | |||||
} | |||||
} | |||||
@Property(key = "westKey", name = "westName") | @Property(key = "westKey", name = "westName") | ||||
@WestSide | @WestSide | ||||
public static class WestSidePropertyDefinition { | public static class WestSidePropertyDefinition { |
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | import org.sonar.api.batch.fs.internal.DefaultInputFile; | ||||
import org.sonar.api.batch.sensor.coverage.CoverageType; | |||||
import org.sonar.api.batch.sensor.coverage.NewCoverage; | import org.sonar.api.batch.sensor.coverage.NewCoverage; | ||||
import org.sonar.api.batch.sensor.internal.DefaultStorable; | import org.sonar.api.batch.sensor.internal.DefaultStorable; | ||||
import org.sonar.api.batch.sensor.internal.SensorStorage; | import org.sonar.api.batch.sensor.internal.SensorStorage; | ||||
public class DefaultCoverage extends DefaultStorable implements NewCoverage { | public class DefaultCoverage extends DefaultStorable implements NewCoverage { | ||||
private InputFile inputFile; | private InputFile inputFile; | ||||
private CoverageType type; | |||||
private int totalCoveredLines = 0; | private int totalCoveredLines = 0; | ||||
private int totalConditions = 0; | private int totalConditions = 0; | ||||
private int totalCoveredConditions = 0; | private int totalCoveredConditions = 0; | ||||
return inputFile; | return inputFile; | ||||
} | } | ||||
@Override | |||||
public NewCoverage ofType(CoverageType type) { | |||||
this.type = requireNonNull(type, "type can't be null"); | |||||
return this; | |||||
} | |||||
public CoverageType type() { | |||||
return type; | |||||
} | |||||
@Override | @Override | ||||
public NewCoverage lineHits(int line, int hits) { | public NewCoverage lineHits(int line, int hits) { | ||||
validateFile(); | validateFile(); |
return inputFile; | return inputFile; | ||||
} | } | ||||
@Override | |||||
public DefaultHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText) { | |||||
checkInputFileNotNull(); | |||||
TextRange newRange; | |||||
try { | |||||
newRange = inputFile.newRange(startOffset, endOffset); | |||||
} catch (Exception e) { | |||||
throw new IllegalArgumentException("Unable to highlight file " + inputFile, e); | |||||
} | |||||
return highlight(newRange, typeOfText); | |||||
} | |||||
@Override | @Override | ||||
public DefaultHighlighting highlight(int startLine, int startLineOffset, int endLine, int endLineOffset, TypeOfText typeOfText) { | public DefaultHighlighting highlight(int startLine, int startLineOffset, int endLine, int endLineOffset, TypeOfText typeOfText) { | ||||
checkInputFileNotNull(); | checkInputFileNotNull(); |
return this; | return this; | ||||
} | } | ||||
@Override | |||||
public DefaultSensorDescriptor requireProperty(String... propertyKey) { | |||||
return requireProperties(propertyKey); | |||||
} | |||||
@Override | |||||
public DefaultSensorDescriptor requireProperties(String... propertyKeys) { | |||||
this.configurationPredicate = config -> Arrays.stream(propertyKeys).allMatch(config::hasKey); | |||||
return this; | |||||
} | |||||
@Override | @Override | ||||
public SensorDescriptor global() { | public SensorDescriptor global() { | ||||
this.global = true; | this.global = true; |
return newSymbol(declarationRange); | return newSymbol(declarationRange); | ||||
} | } | ||||
@Override | |||||
public NewSymbol newSymbol(int startOffset, int endOffset) { | |||||
checkInputFileNotNull(); | |||||
TextRange declarationRange; | |||||
try { | |||||
declarationRange = inputFile.newRange(startOffset, endOffset); | |||||
} catch (Exception e) { | |||||
throw new IllegalArgumentException("Unable to create symbol on file " + inputFile, e); | |||||
} | |||||
return newSymbol(declarationRange); | |||||
} | |||||
@Override | @Override | ||||
public NewSymbol newSymbol(TextRange range) { | public NewSymbol newSymbol(TextRange range) { | ||||
checkInputFileNotNull(); | checkInputFileNotNull(); | ||||
this.references = references; | this.references = references; | ||||
} | } | ||||
@Override | |||||
public NewSymbol newReference(int startOffset, int endOffset) { | |||||
TextRange referenceRange; | |||||
try { | |||||
referenceRange = inputFile.newRange(startOffset, endOffset); | |||||
} catch (Exception e) { | |||||
throw new IllegalArgumentException("Unable to create symbol reference on file " + inputFile, e); | |||||
} | |||||
return newReference(referenceRange); | |||||
} | |||||
@Override | @Override | ||||
public NewSymbol newReference(int startLine, int startLineOffset, int endLine, int endLineOffset) { | public NewSymbol newReference(int startLine, int startLineOffset, int endLine, int endLineOffset) { | ||||
TextRange referenceRange; | TextRange referenceRange; |
import org.sonar.api.server.rule.internal.DefaultNewRepository; | import org.sonar.api.server.rule.internal.DefaultNewRepository; | ||||
import org.sonar.api.server.rule.internal.DefaultRepository; | import org.sonar.api.server.rule.internal.DefaultRepository; | ||||
import static java.util.Collections.emptyList; | |||||
import static java.util.Collections.unmodifiableList; | import static java.util.Collections.unmodifiableList; | ||||
import static org.sonar.api.utils.Preconditions.checkState; | import static org.sonar.api.utils.Preconditions.checkState; | ||||
return new DefaultNewRepository(this, RuleKey.EXTERNAL_RULE_REPO_PREFIX + engineId, language, true); | return new DefaultNewRepository(this, RuleKey.EXTERNAL_RULE_REPO_PREFIX + engineId, language, true); | ||||
} | } | ||||
@Override | |||||
@Deprecated | |||||
public RulesDefinition.NewRepository extendRepository(String key, String language) { | |||||
return createRepository(key, language); | |||||
} | |||||
@Override | @Override | ||||
@CheckForNull | @CheckForNull | ||||
public RulesDefinition.Repository repository(String key) { | public RulesDefinition.Repository repository(String key) { | ||||
return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); | return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); | ||||
} | } | ||||
@Override | |||||
@Deprecated | |||||
public List<RulesDefinition.ExtendedRepository> extendedRepositories(String repositoryKey) { | |||||
return emptyList(); | |||||
} | |||||
@Override | |||||
@Deprecated | |||||
public List<RulesDefinition.ExtendedRepository> extendedRepositories() { | |||||
return emptyList(); | |||||
} | |||||
public void registerRepository(DefaultNewRepository newRepository) { | public void registerRepository(DefaultNewRepository newRepository) { | ||||
RulesDefinition.Repository existing = repositoriesByKey.get(newRepository.key()); | RulesDefinition.Repository existing = repositoriesByKey.get(newRepository.key()); | ||||
if (existing != null) { | if (existing != null) { |
import org.sonar.api.batch.sensor.internal.SensorStorage; | import org.sonar.api.batch.sensor.internal.SensorStorage; | ||||
import static org.sonar.api.batch.sensor.highlighting.TypeOfText.COMMENT; | import static org.sonar.api.batch.sensor.highlighting.TypeOfText.COMMENT; | ||||
import static org.sonar.api.batch.sensor.highlighting.TypeOfText.CPP_DOC; | |||||
import static org.sonar.api.batch.sensor.highlighting.TypeOfText.KEYWORD; | import static org.sonar.api.batch.sensor.highlighting.TypeOfText.KEYWORD; | ||||
public class DefaultHighlightingTest { | public class DefaultHighlightingTest { | ||||
DefaultHighlighting highlightingDataBuilder = new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | DefaultHighlighting highlightingDataBuilder = new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | ||||
.onFile(INPUT_FILE) | .onFile(INPUT_FILE) | ||||
.highlight(0, 10, COMMENT) | |||||
.highlight(1, 0, 1, 10, COMMENT) | |||||
.highlight(1, 10, 1, 12, KEYWORD) | .highlight(1, 10, 1, 12, KEYWORD) | ||||
.highlight(24, 38, KEYWORD) | |||||
.highlight(42, 50, KEYWORD) | |||||
.highlight(24, 65, CPP_DOC) | |||||
.highlight(12, 20, COMMENT); | |||||
.highlight(1, 24, 1, 38, KEYWORD) | |||||
.highlight(1, 42, 2, 0, KEYWORD) | |||||
.highlight(1, 24, 2, 15, COMMENT) | |||||
.highlight(1, 12, 1, 20, COMMENT); | |||||
highlightingDataBuilder.save(); | highlightingDataBuilder.save(); | ||||
rangeOf(1, 24, 2, 15), | rangeOf(1, 24, 2, 15), | ||||
rangeOf(1, 24, 1, 38), | rangeOf(1, 24, 1, 38), | ||||
rangeOf(1, 42, 2, 0)); | rangeOf(1, 42, 2, 0)); | ||||
Assertions.assertThat(highlightingRules).extracting("textType").containsExactly(COMMENT, KEYWORD, COMMENT, CPP_DOC, KEYWORD, KEYWORD); | |||||
Assertions.assertThat(highlightingRules).extracting("textType").containsExactly(COMMENT, KEYWORD, COMMENT, COMMENT, KEYWORD, KEYWORD); | |||||
} | } | ||||
@Test | @Test | ||||
public void should_support_overlapping() { | public void should_support_overlapping() { | ||||
new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | ||||
.onFile(INPUT_FILE) | .onFile(INPUT_FILE) | ||||
.highlight(0, 15, KEYWORD) | |||||
.highlight(8, 12, CPP_DOC) | |||||
.highlight(1, 0, 1, 15, KEYWORD) | |||||
.highlight(1, 8, 1, 12, COMMENT) | |||||
.save(); | .save(); | ||||
} | } | ||||
new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | ||||
.onFile(INPUT_FILE) | .onFile(INPUT_FILE) | ||||
.highlight(10, 10, KEYWORD) | |||||
.highlight(1, 10, 1, 10, KEYWORD) | |||||
.save(); | .save(); | ||||
} | } | ||||
new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | new DefaultHighlighting(Mockito.mock(SensorStorage.class)) | ||||
.onFile(INPUT_FILE) | .onFile(INPUT_FILE) | ||||
.highlight(0, 10, KEYWORD) | |||||
.highlight(8, 15, KEYWORD) | |||||
.highlight(1, 0, 1, 10, KEYWORD) | |||||
.highlight(1, 8, 1, 15, KEYWORD) | |||||
.save(); | .save(); | ||||
} | } | ||||
.name("Foo") | .name("Foo") | ||||
.onlyOnLanguage("java") | .onlyOnLanguage("java") | ||||
.onlyOnFileType(InputFile.Type.MAIN) | .onlyOnFileType(InputFile.Type.MAIN) | ||||
.requireProperty("sonar.foo.reportPath", "sonar.foo.reportPath2") | |||||
.onlyWhenConfiguration(c -> c.hasKey("sonar.foo.reportPath2") && c.hasKey("sonar.foo.reportPath")) | |||||
.createIssuesForRuleRepository("squid-java"); | .createIssuesForRuleRepository("squid-java"); | ||||
assertThat(descriptor.name()).isEqualTo("Foo"); | assertThat(descriptor.name()).isEqualTo("Foo"); |
tester.newHighlighting() | tester.newHighlighting() | ||||
.onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()) | .onFile(new TestInputFileBuilder("foo", "src/Foo.java").initMetadata("annot dsf fds foo bar").build()) | ||||
.highlight(1, 0, 1, 5, TypeOfText.ANNOTATION) | .highlight(1, 0, 1, 5, TypeOfText.ANNOTATION) | ||||
.highlight(8, 10, TypeOfText.CONSTANT) | |||||
.highlight(9, 10, TypeOfText.COMMENT) | |||||
.highlight(1, 8, 1, 10, TypeOfText.CONSTANT) | |||||
.highlight(1, 9, 1, 10, TypeOfText.COMMENT) | |||||
.save(); | .save(); | ||||
assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 3)).containsExactly(TypeOfText.ANNOTATION); | assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 3)).containsExactly(TypeOfText.ANNOTATION); | ||||
assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 9)).containsExactly(TypeOfText.CONSTANT, TypeOfText.COMMENT); | assertThat(tester.highlightingTypeAt("foo:src/Foo.java", 1, 9)).containsExactly(TypeOfText.CONSTANT, TypeOfText.COMMENT); | ||||
symbolTable | symbolTable | ||||
.newSymbol(1, 1, 1, 5) | .newSymbol(1, 1, 1, 5) | ||||
.newReference(6, 9) | |||||
.newReference(1, 10, 1, 13); | .newReference(1, 10, 1, 13); | ||||
symbolTable.save(); | symbolTable.save(); | ||||
assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull(); | assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 0)).isNull(); | ||||
assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 8)).isEmpty(); | assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 8)).isEmpty(); | ||||
assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)).extracting("start.line", "start.lineOffset", "end.line", "end.lineOffset").containsExactly(tuple(1, 6, 1, 9), | |||||
tuple(1, 10, 1, 13)); | |||||
assertThat(tester.referencesForSymbolAt("foo:src/Foo.java", 1, 3)) | |||||
.extracting("start.line", "start.lineOffset", "end.line", "end.lineOffset") | |||||
.containsExactly(tuple(1, 10, 1, 13)); | |||||
} | } | ||||
@Test(expected = UnsupportedOperationException.class) | @Test(expected = UnsupportedOperationException.class) |
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.sonar.api.batch.fs.InputFile; | import org.sonar.api.batch.fs.InputFile; | ||||
import org.sonar.api.batch.fs.TextRange; | import org.sonar.api.batch.fs.TextRange; | ||||
import org.sonar.api.batch.sensor.internal.SensorStorage; | |||||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | ||||
import org.sonar.api.batch.sensor.internal.SensorStorage; | |||||
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.mockito.Mockito.mock; | import static org.mockito.Mockito.mock; | ||||
DefaultSymbolTable symbolTableBuilder = new DefaultSymbolTable(mock(SensorStorage.class)) | DefaultSymbolTable symbolTableBuilder = new DefaultSymbolTable(mock(SensorStorage.class)) | ||||
.onFile(INPUT_FILE); | .onFile(INPUT_FILE); | ||||
symbolTableBuilder | symbolTableBuilder | ||||
.newSymbol(0, 10) | |||||
.newReference(12, 15) | |||||
.newReference(2, 10, 2, 15); | |||||
.newSymbol(1, 0, 1, 10) | |||||
.newReference(2, 10, 2, 15) | |||||
.newReference(1, 16, 1, 20); | |||||
symbolTableBuilder.newSymbol(1, 12, 1, 15).newReference(52, 55); | |||||
symbolTableBuilder | |||||
.newSymbol(1, 12, 1, 15) | |||||
.newReference(2, 1, 2, 5); | |||||
symbolTableBuilder.save(); | symbolTableBuilder.save(); | ||||
/** | /** | ||||
* This property defines the SonarQubeServer base url, such as <i>http://yourhost.yourdomain/sonar</i>. | * This property defines the SonarQubeServer base url, such as <i>http://yourhost.yourdomain/sonar</i>. | ||||
* When this property is not set, the base url of the SonarQube server is provided by {@link Server#getURL()}. | |||||
* When this property is not set, the base url of the SonarQube server is provided by {@link Server#getPublicRootUrl()}. | |||||
* | * | ||||
* @since 2.10 | * @since 2.10 | ||||
*/ | */ |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api; | |||||
import org.sonar.api.ce.ComputeEngineSide; | |||||
import org.sonar.api.server.ServerSide; | |||||
/** | |||||
* Factory of extensions. It allows to dynamically create extensions depending upon runtime context. One use-case is | |||||
* to create one rule repository by language. | |||||
* | |||||
* <p>Notes : | |||||
* <ul> | |||||
* <li>the provider is declared in Plugin.getExtensions()</li> | |||||
* <li>the provider must also add annotation {@link ServerSide}, {@link ComputeEngineSide} and/or {@link BatchSide}</li> | |||||
* <li>the provider can accept dependencies (parameters) in its constructors.</li> | |||||
* <li>the method provide() is executed once by the platform</li> | |||||
* <li>the method provide() must return an object, a class or an Iterable of objects. <strong>Arrays are excluded</strong>.</li> | |||||
* </ul> | |||||
* | |||||
* | |||||
* <p>Example: | |||||
* <pre> | |||||
* {@code | |||||
* {@literal @}ServerSide | |||||
* public class RuleRepositoryProvider extends ExtensionProvider { | |||||
* private Language[] languages; | |||||
* | |||||
* public RuleRepositoryProvider(Language[] languages) { | |||||
* this.languages = languages; | |||||
* } | |||||
* | |||||
* public List<RuleRepository> provide() { | |||||
* List<RuleRepository> result = new ArrayList<RuleRepository>(); | |||||
* for(Language language: languages) { | |||||
* result.add(new RuleRepository(..., language, ...)); | |||||
* } | |||||
* return result; | |||||
* } | |||||
* } | |||||
* } | |||||
* </pre> | |||||
* | |||||
* | |||||
* @since 2.3 | |||||
* @deprecated since 6.0 should no more be used | |||||
*/ | |||||
@Deprecated | |||||
@ExtensionPoint | |||||
public abstract class ExtensionProvider { | |||||
public abstract Object provide(); | |||||
} |
*/ | */ | ||||
String description() default ""; | String description() default ""; | ||||
/** | |||||
* Indicative size of the field value in characters. This size is not validated, it is merely used by the GUI | |||||
* to size the different input fields of a property set. | |||||
* | |||||
* @deprecated since 6.1, as it was only used for UI. | |||||
*/ | |||||
@Deprecated | |||||
int indicativeSize() default 20; | |||||
PropertyType type() default PropertyType.STRING; | PropertyType type() default PropertyType.STRING; | ||||
/** | /** |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.batch; | |||||
import org.sonarsource.api.sonarlint.SonarLintSide; | |||||
/** | |||||
* Use this component to find the current running mode. | |||||
* @since 5.1 | |||||
* @deprecated since 7.3 preview mode deprecated since 6.6 | |||||
*/ | |||||
@ScannerSide | |||||
@SonarLintSide | |||||
@Deprecated | |||||
public interface AnalysisMode { | |||||
boolean isPreview(); | |||||
/** | |||||
* @since 5.2 | |||||
*/ | |||||
boolean isIssues(); | |||||
boolean isPublish(); | |||||
} |
*/ | */ | ||||
package org.sonar.api.batch.postjob; | package org.sonar.api.batch.postjob; | ||||
import org.sonar.api.batch.AnalysisMode; | |||||
import org.sonar.api.batch.postjob.issue.PostJobIssue; | |||||
import org.sonar.api.config.Configuration; | import org.sonar.api.config.Configuration; | ||||
/** | /** | ||||
* @since 6.5 | * @since 6.5 | ||||
*/ | */ | ||||
Configuration config(); | Configuration config(); | ||||
/** | |||||
* @deprecated since 7.3 preview mode deprecated since 6.6 | |||||
*/ | |||||
@Deprecated | |||||
AnalysisMode analysisMode(); | |||||
// ----------- Only available in preview mode -------------- | |||||
/** | |||||
* All the unresolved issues of the project, including the issues reported by end-users. Only available in preview/issues mode. | |||||
* @throw {@link UnsupportedOperationException} if not in preview/issues mode. To test the mode you can use {@link #analysisMode()}. | |||||
* @deprecated since 7.3 the preview/issues mode is deprecated since 6.7 | |||||
*/ | |||||
@Deprecated | |||||
Iterable<PostJobIssue> issues(); | |||||
/** | |||||
* All the issues of this project that have been marked as resolved during this scan. Only available in preview/issues mode. | |||||
* @throw {@link UnsupportedOperationException} if not in preview mode. To test the mode you can use {@link #analysisMode()}. | |||||
* @deprecated since 7.3 the preview/issues mode is deprecated since 6.7 | |||||
*/ | |||||
@Deprecated | |||||
Iterable<PostJobIssue> resolvedIssues(); | |||||
} | } |
return addAnnotatedChecks((Iterable) Arrays.asList(checkClassesOrObjects)); | return addAnnotatedChecks((Iterable) Arrays.asList(checkClassesOrObjects)); | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.2 use {@link #addAnnotatedChecks(Iterable)} | |||||
*/ | |||||
@Deprecated | |||||
public Checks<C> addAnnotatedChecks(Collection checkClassesOrObjects) { | |||||
return addAnnotatedChecks((Iterable) checkClassesOrObjects); | |||||
} | |||||
public Checks<C> addAnnotatedChecks(Iterable checkClassesOrObjects) { | public Checks<C> addAnnotatedChecks(Iterable checkClassesOrObjects) { | ||||
Map<String, Object> checksByEngineKey = new HashMap<>(); | Map<String, Object> checksByEngineKey = new HashMap<>(); | ||||
for (Object checkClassesOrObject : checkClassesOrObjects) { | for (Object checkClassesOrObject : checkClassesOrObjects) { |
*/ | */ | ||||
@Deprecated | @Deprecated | ||||
Settings settings(); | Settings settings(); | ||||
/** | /** | ||||
* Get settings of the project. | * Get settings of the project. | ||||
* @since 6.5 | * @since 6.5 |
*/ | */ | ||||
SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys); | SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys); | ||||
/** | |||||
* Property this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when | |||||
* property is not set. | |||||
* @deprecated since 6.5 use {@link #onlyWhenConfiguration(Predicate)} | |||||
*/ | |||||
@Deprecated | |||||
SensorDescriptor requireProperty(String... propertyKey); | |||||
/** | |||||
* List properties this {@link Sensor} depends on. Used by the platform to skip execution of the {@link Sensor} when | |||||
* property is not set. | |||||
* @deprecated since 6.5 use {@link #onlyWhenConfiguration(Predicate)} | |||||
*/ | |||||
@Deprecated | |||||
SensorDescriptor requireProperties(String... propertyKeys); | |||||
/** | /** | ||||
* This sensor should be executed at the project level, instead of per-module. | * This sensor should be executed at the project level, instead of per-module. | ||||
* @since 6.4 | * @since 6.4 |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.batch.sensor.coverage; | |||||
/** | |||||
* Different coverage categories. | |||||
* @since 5.2 | |||||
* | |||||
* @deprecated since 6.2 SonarQube merge all coverage reports and don't keep track of different test category | |||||
*/ | |||||
@Deprecated | |||||
public enum CoverageType { | |||||
UNIT, | |||||
IT, | |||||
OVERALL | |||||
} |
*/ | */ | ||||
NewCoverage onFile(InputFile inputFile); | NewCoverage onFile(InputFile inputFile); | ||||
/** | |||||
* @deprecated since 6.2 SonarQube merge all coverage reports and don't keep track of different test category | |||||
*/ | |||||
@Deprecated | |||||
NewCoverage ofType(CoverageType type); | |||||
/** | /** | ||||
* Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines. | * Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines. | ||||
* @param line Line number (starts at 1). | * @param line Line number (starts at 1). |
*/ | */ | ||||
NewHighlighting onFile(InputFile inputFile); | NewHighlighting onFile(InputFile inputFile); | ||||
/** | |||||
* Call this method to indicate the type of text in a range. | |||||
* @param startOffset Starting position in file for this type of text. Beginning of a file starts with offset '0'. | |||||
* @param endOffset End position in file for this type of text. | |||||
* @param typeOfText see {@link TypeOfText} values. | |||||
* @deprecated since 5.6 Only supported to ease migration from old API. Please prefer other {@code highlight()} methods. | |||||
*/ | |||||
@Deprecated | |||||
NewHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText); | |||||
/** | /** | ||||
* Call this method to indicate the type of text in a range. | * Call this method to indicate the type of text in a range. | ||||
* @param range Range of text to highlight. See for example {@link InputFile#newRange(int, int, int, int)}. | * @param range Range of text to highlight. See for example {@link InputFile#newRange(int, int, int, int)}. |
ANNOTATION("a"), | ANNOTATION("a"), | ||||
CONSTANT("c"), | CONSTANT("c"), | ||||
COMMENT("cd"), | COMMENT("cd"), | ||||
/** | |||||
* @deprecated use {@link #COMMENT} | |||||
*/ | |||||
@Deprecated | |||||
CPP_DOC("cppd"), | |||||
/** | /** | ||||
* For example Javadoc | * For example Javadoc | ||||
*/ | */ |
* @since 5.6 | * @since 5.6 | ||||
*/ | */ | ||||
public interface NewSymbol { | public interface NewSymbol { | ||||
/** | |||||
* Register a new symbol reference. | |||||
* @param startOffset Starting position in file for the declaration of this symbol. Beginning of a file starts with offset '0'. | |||||
* @param endOffset End position in file for this symbol declaration. | |||||
* @deprecated since 6.1 Only supported to ease migration from old API. Please prefer other {@code newReference()} methods. | |||||
*/ | |||||
@Deprecated | |||||
NewSymbol newReference(int startOffset, int endOffset); | |||||
/** | /** | ||||
* Register a new symbol. | * Register a new symbol. | ||||
* @param range Range of text for the symbol declaration. See for example {@link InputFile#newRange(int, int, int, int)}. | * @param range Range of text for the symbol declaration. See for example {@link InputFile#newRange(int, int, int, int)}. |
*/ | */ | ||||
NewSymbolTable onFile(InputFile inputFile); | NewSymbolTable onFile(InputFile inputFile); | ||||
/** | |||||
* Register a new symbol declaration. | |||||
* @param startOffset Starting position in file for the declaration of this symbol. Beginning of a file starts with offset '0'. | |||||
* @param endOffset End position in file for this symbol declaration. | |||||
* @deprecated since 5.6 Only supported to ease migration from old API. Please prefer {@link #newSymbol(int, int, int, int)}. | |||||
*/ | |||||
@Deprecated | |||||
NewSymbol newSymbol(int startOffset, int endOffset); | |||||
/** | /** | ||||
* Register a new symbol declaration. | * Register a new symbol declaration. | ||||
* @param range Range of text for the symbol declaration. See for example {@link InputFile#newRange(int, int, int, int)}. | * @param range Range of text for the symbol declaration. See for example {@link InputFile#newRange(int, int, int, int)}. |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.component; | |||||
/** | |||||
* @deprecated since 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public interface Perspective { | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.component; | |||||
import javax.annotation.CheckForNull; | |||||
import org.sonar.api.batch.fs.InputFile; | |||||
import org.sonar.api.batch.fs.InputPath; | |||||
import org.sonar.api.batch.sensor.SensorContext; | |||||
/** | |||||
* @since 3.5 | |||||
* @deprecated since 5.6 all features are available on {@link SensorContext} | |||||
*/ | |||||
@Deprecated | |||||
public interface ResourcePerspectives { | |||||
/** | |||||
* Allow to create perspective from {@link InputPath}. In particular from {@link InputFile}. | |||||
* | |||||
* @since 4.5.2 | |||||
*/ | |||||
@CheckForNull <P extends Perspective> P as(Class<P> perspectiveClass, InputPath inputPath); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
package org.sonar.api.component; | |||||
import javax.annotation.ParametersAreNonnullByDefault; |
import java.util.function.Function; | import java.util.function.Function; | ||||
import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||
import java.util.regex.PatternSyntaxException; | import java.util.regex.PatternSyntaxException; | ||||
import java.util.stream.Stream; | |||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.apache.commons.lang.math.NumberUtils; | import org.apache.commons.lang.math.NumberUtils; | ||||
import org.sonarsource.api.sonarlint.SonarLintSide; | import org.sonarsource.api.sonarlint.SonarLintSide; | ||||
import static java.util.Arrays.asList; | import static java.util.Arrays.asList; | ||||
import static java.util.Arrays.stream; | |||||
import static java.util.Collections.unmodifiableSet; | import static java.util.Collections.unmodifiableSet; | ||||
import static java.util.Objects.requireNonNull; | import static java.util.Objects.requireNonNull; | ||||
import static org.apache.commons.lang.StringUtils.isBlank; | import static org.apache.commons.lang.StringUtils.isBlank; | ||||
private List<String> qualifiers; | private List<String> qualifiers; | ||||
private boolean global; | private boolean global; | ||||
private boolean multiValues; | private boolean multiValues; | ||||
private String propertySetKey; | |||||
private String deprecatedKey; | private String deprecatedKey; | ||||
private List<PropertyFieldDefinition> fields; | private List<PropertyFieldDefinition> fields; | ||||
/** | /** | ||||
this.type = builder.type; | this.type = builder.type; | ||||
this.options = builder.options; | this.options = builder.options; | ||||
this.multiValues = builder.multiValues; | this.multiValues = builder.multiValues; | ||||
this.propertySetKey = builder.propertySetKey; | |||||
this.fields = builder.fields; | this.fields = builder.fields; | ||||
this.deprecatedKey = builder.deprecatedKey; | this.deprecatedKey = builder.deprecatedKey; | ||||
this.qualifiers = builder.onQualifiers; | this.qualifiers = builder.onQualifiers; | ||||
.type(annotation.type()) | .type(annotation.type()) | ||||
.options(asList(annotation.options())) | .options(asList(annotation.options())) | ||||
.multiValues(annotation.multiValues()) | .multiValues(annotation.multiValues()) | ||||
.propertySetKey(annotation.propertySetKey()) | |||||
.fields(PropertyFieldDefinition.create(annotation.fields())) | .fields(PropertyFieldDefinition.create(annotation.fields())) | ||||
.deprecatedKey(annotation.deprecatedKey()); | .deprecatedKey(annotation.deprecatedKey()); | ||||
List<String> qualifiers = new ArrayList<>(); | List<String> qualifiers = new ArrayList<>(); | ||||
return multiValues; | return multiValues; | ||||
} | } | ||||
/** | |||||
* @deprecated since 6.1, as it was not used and too complex to maintain. | |||||
*/ | |||||
@Deprecated | |||||
public String propertySetKey() { | |||||
return propertySetKey; | |||||
} | |||||
public List<PropertyFieldDefinition> fields() { | public List<PropertyFieldDefinition> fields() { | ||||
return fields; | return fields; | ||||
} | } | ||||
@Override | @Override | ||||
public String toString() { | public String toString() { | ||||
if (isEmpty(propertySetKey)) { | |||||
return key; | |||||
} | |||||
return new StringBuilder().append(propertySetKey).append('|').append(key).toString(); | |||||
return key; | |||||
} | } | ||||
public static final class Result { | public static final class Result { | ||||
private PropertyType type = PropertyType.STRING; | private PropertyType type = PropertyType.STRING; | ||||
private List<String> options = new ArrayList<>(); | private List<String> options = new ArrayList<>(); | ||||
private boolean multiValues = false; | private boolean multiValues = false; | ||||
private String propertySetKey = ""; | |||||
private List<PropertyFieldDefinition> fields = new ArrayList<>(); | private List<PropertyFieldDefinition> fields = new ArrayList<>(); | ||||
private String deprecatedKey = ""; | private String deprecatedKey = ""; | ||||
private boolean hidden = false; | private boolean hidden = false; | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* @deprecated since 6.1, as it was not used and too complex to maintain. | |||||
*/ | |||||
@Deprecated | |||||
public Builder propertySetKey(String propertySetKey) { | |||||
this.propertySetKey = propertySetKey; | |||||
return this; | |||||
} | |||||
public Builder fields(PropertyFieldDefinition first, PropertyFieldDefinition... rest) { | public Builder fields(PropertyFieldDefinition first, PropertyFieldDefinition... rest) { | ||||
this.fields.add(first); | this.fields.add(first); | ||||
this.fields.addAll(asList(rest)); | this.fields.addAll(asList(rest)); |
private final String key; | private final String key; | ||||
private final String name; | private final String name; | ||||
private final String description; | private final String description; | ||||
private final int indicativeSize; | |||||
private final PropertyType type; | private final PropertyType type; | ||||
private final List<String> options; | private final List<String> options; | ||||
this.key = builder.key; | this.key = builder.key; | ||||
this.name = builder.name; | this.name = builder.name; | ||||
this.description = builder.description; | this.description = builder.description; | ||||
this.indicativeSize = builder.indicativeSize; | |||||
this.type = builder.type; | this.type = builder.type; | ||||
this.options = builder.options; | this.options = builder.options; | ||||
} | } | ||||
definitions.add(PropertyFieldDefinition.build(field.key()) | definitions.add(PropertyFieldDefinition.build(field.key()) | ||||
.name(field.name()) | .name(field.name()) | ||||
.description(field.description()) | .description(field.description()) | ||||
.indicativeSize(field.indicativeSize()) | |||||
.type(field.type()) | .type(field.type()) | ||||
.options(field.options()) | .options(field.options()) | ||||
.build()); | .build()); | ||||
return description; | return description; | ||||
} | } | ||||
/** | |||||
* @deprecated since 6.1, as it was only used for UI. | |||||
*/ | |||||
@Deprecated | |||||
public int indicativeSize() { | |||||
return indicativeSize; | |||||
} | |||||
public PropertyType type() { | public PropertyType type() { | ||||
return type; | return type; | ||||
} | } | ||||
private String key; | private String key; | ||||
private String name; | private String name; | ||||
private String description; | private String description; | ||||
private int indicativeSize; | |||||
private PropertyType type; | private PropertyType type; | ||||
private List<String> options; | private List<String> options; | ||||
this.key = key; | this.key = key; | ||||
this.name = ""; | this.name = ""; | ||||
this.description = ""; | this.description = ""; | ||||
this.indicativeSize = 20; | |||||
this.type = PropertyType.STRING; | this.type = PropertyType.STRING; | ||||
this.options = new ArrayList<>(); | this.options = new ArrayList<>(); | ||||
} | } | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* @deprecated since 6.1, as it was only used for UI. | |||||
*/ | |||||
@Deprecated | |||||
public Builder indicativeSize(int indicativeSize) { | |||||
this.indicativeSize = indicativeSize; | |||||
return this; | |||||
} | |||||
public Builder type(PropertyType type) { | public Builder type(PropertyType type) { | ||||
this.type = type; | this.type = type; | ||||
return this; | return this; |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.measures; | |||||
import java.util.Collection; | |||||
import java.util.List; | |||||
import javax.annotation.CheckForNull; | |||||
import org.sonar.api.scanner.ScannerSide; | |||||
import org.sonar.api.ce.ComputeEngineSide; | |||||
import org.sonar.api.server.ServerSide; | |||||
/** | |||||
* @since 2.5 | |||||
* @deprecated since 5.1 use {@link org.sonar.api.batch.measure.MetricFinder} on scanner side. | |||||
*/ | |||||
@Deprecated | |||||
@ScannerSide | |||||
@ServerSide | |||||
@ComputeEngineSide | |||||
public interface MetricFinder { | |||||
@CheckForNull | |||||
Metric findByUuid(String uuid); | |||||
@CheckForNull | |||||
Metric findByKey(String key); | |||||
Collection<Metric> findAll(List<String> metricKeys); | |||||
Collection<Metric> findAll(); | |||||
} |
*/ | */ | ||||
public abstract Date getStartedAt(); | public abstract Date getStartedAt(); | ||||
/** | |||||
* @deprecated in 6.0. Replaced by {@link ServerFileSystem#getHomeDir()} | |||||
* @return an existing directory in server and CE environments, {@code null} in scanner. | |||||
*/ | |||||
@Deprecated | |||||
public abstract File getRootDir(); | |||||
/** | /** | ||||
* Context path of web server. Value is blank {@code ""} by default. When defined by | * Context path of web server. Value is blank {@code ""} by default. When defined by | ||||
* the property {@code sonar.web.context} of conf/sonar.properties, then value starts but does | * the property {@code sonar.web.context} of conf/sonar.properties, then value starts but does | ||||
*/ | */ | ||||
public abstract String getPublicRootUrl(); | public abstract String getPublicRootUrl(); | ||||
/** | |||||
* Before version 6.6, the dev mode is enabled when the property {@code sonar.web.dev} is {@code true}. | |||||
* Since 6.6, {@code false} is always returned. | |||||
* @deprecated in 6.6 | |||||
* @since 5.4 | |||||
*/ | |||||
@Deprecated | |||||
public abstract boolean isDev(); | |||||
/** | /** | ||||
* Return whether or not the {#getPublicRootUrl} is started with https. | * Return whether or not the {#getPublicRootUrl} is started with https. | ||||
* | * | ||||
*/ | */ | ||||
@Deprecated | @Deprecated | ||||
public abstract boolean isSecured(); | public abstract boolean isSecured(); | ||||
/** | |||||
* @return the server URL | |||||
* @since since 2.4 on batch side only, since 5.6 on both batch side and server side (WebServer and Compute Engine) | |||||
* @deprecated since 6.5, please use {@link #getPublicRootUrl()} instead | |||||
*/ | |||||
@Deprecated | |||||
public abstract String getURL(); | |||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.profiles; | |||||
import java.util.Collection; | |||||
import org.apache.commons.lang.StringUtils; | |||||
import org.sonar.api.ce.ComputeEngineSide; | |||||
import org.sonar.api.rules.Rule; | |||||
import org.sonar.api.rules.RuleAnnotationUtils; | |||||
import org.sonar.api.rules.RuleFinder; | |||||
import org.sonar.api.rules.RulePriority; | |||||
import org.sonar.api.server.ServerSide; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfileAnnotationLoader; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
import org.sonar.check.BelongsToProfile; | |||||
/** | |||||
* @since 2.3 | |||||
* @deprecated since 6.6 use {@link BuiltInQualityProfileAnnotationLoader} | |||||
*/ | |||||
@ServerSide | |||||
@ComputeEngineSide | |||||
@Deprecated | |||||
public final class AnnotationProfileParser { | |||||
private final RuleFinder ruleFinder; | |||||
public AnnotationProfileParser(RuleFinder ruleFinder) { | |||||
this.ruleFinder = ruleFinder; | |||||
} | |||||
public RulesProfile parse(String repositoryKey, String profileName, String language, Collection<Class> annotatedClasses, ValidationMessages messages) { | |||||
RulesProfile profile = RulesProfile.create(profileName, language); | |||||
for (Class<?> aClass : annotatedClasses) { | |||||
BelongsToProfile belongsToProfile = aClass.getAnnotation(BelongsToProfile.class); | |||||
addRule(aClass, belongsToProfile, profile, repositoryKey, messages); | |||||
} | |||||
return profile; | |||||
} | |||||
private void addRule(Class aClass, BelongsToProfile annotation, RulesProfile profile, String repositoryKey, ValidationMessages messages) { | |||||
if ((annotation != null) && StringUtils.equals(annotation.title(), profile.getName())) { | |||||
String ruleKey = RuleAnnotationUtils.getRuleKey(aClass); | |||||
Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey); | |||||
if (rule == null) { | |||||
messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + ruleKey + "]"); | |||||
} else { | |||||
RulePriority priority = null; | |||||
if (annotation.priority() != null) { | |||||
priority = RulePriority.fromCheckPriority(annotation.priority()); | |||||
} | |||||
profile.activateRule(rule, priority); | |||||
} | |||||
} | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.profiles; | |||||
import org.sonar.api.ExtensionPoint; | |||||
import org.sonar.api.server.ServerSide; | |||||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||||
import org.sonar.api.utils.ValidationMessages; | |||||
/** | |||||
* Define a profile which is automatically registered during sonar startup. | |||||
* The components <code>AnnotationProfileParser</code> and <code>XMLProfileParser</code> can be used to help implementing the method create(). | |||||
* | |||||
* @since 2.3 | |||||
* @deprecated since 6.6 use {@link BuiltInQualityProfilesDefinition} | |||||
*/ | |||||
@ServerSide | |||||
@ExtensionPoint | |||||
@Deprecated | |||||
public abstract class ProfileDefinition { | |||||
public abstract RulesProfile createProfile(ValidationMessages validation); | |||||
} |
* This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric thresholds too. | * This class is badly named. It should be "QualityProfile". Indeed it does not relate only to rules but to metric thresholds too. | ||||
*/ | */ | ||||
public class RulesProfile implements Cloneable { | public class RulesProfile implements Cloneable { | ||||
/** | |||||
* Name of the default profile "Sonar Way" | |||||
* @deprecated in 4.2. Use your own constant. | |||||
*/ | |||||
@Deprecated | |||||
public static final String SONAR_WAY_NAME = "Sonar way"; | |||||
/** | |||||
* Name of the default java profile "Sonar way with Findbugs" | |||||
* @deprecated in 4.2. Use your own constant. | |||||
*/ | |||||
@Deprecated | |||||
public static final String SONAR_WAY_FINDBUGS_NAME = "Sonar way with Findbugs"; | |||||
/** | |||||
* Name of the default java profile "Sun checks" | |||||
* @deprecated in 4.2. Use your own constant. | |||||
*/ | |||||
@Deprecated | |||||
public static final String SUN_CONVENTIONS_NAME = "Sun checks"; | |||||
private String name; | private String name; | ||||
private Boolean defaultProfile = Boolean.FALSE; | private Boolean defaultProfile = Boolean.FALSE; | ||||
private String language; | private String language; | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Does nothing. | |||||
* | |||||
* @return {@code null} | |||||
* @deprecated in 6.5 | |||||
*/ | |||||
@Deprecated | |||||
@CheckForNull | |||||
public String getParentName() { | |||||
return null; | |||||
} | |||||
/** | |||||
* Does nothing. | |||||
* | |||||
* @deprecated in 6.5 | |||||
*/ | |||||
@Deprecated | |||||
public void setParentName(String parentName) { | |||||
// does nothing | |||||
} | |||||
/** | /** | ||||
* Note: disabled rules are excluded. | * Note: disabled rules are excluded. | ||||
* | * |
package org.sonar.api.rules; | package org.sonar.api.rules; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
import javax.annotation.CheckForNull; | |||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.apache.commons.lang.StringUtils; | import org.apache.commons.lang.StringUtils; | ||||
import org.apache.commons.lang.builder.ToStringBuilder; | import org.apache.commons.lang.builder.ToStringBuilder; | ||||
this.severity = severity; | this.severity = severity; | ||||
} | } | ||||
/** | |||||
* @deprecated since 2.5 use {@link #getSeverity()} instead. See http://jira.sonarsource.com/browse/SONAR-1829 | |||||
*/ | |||||
@Deprecated | |||||
public RulePriority getPriority() { | |||||
return severity; | |||||
} | |||||
/** | |||||
* @deprecated since 2.5 use {@link #setSeverity(RulePriority)} instead. See http://jira.sonarsource.com/browse/SONAR-1829 | |||||
*/ | |||||
@Deprecated | |||||
public void setPriority(RulePriority priority) { | |||||
this.severity = priority; | |||||
} | |||||
public RulesProfile getRulesProfile() { | public RulesProfile getRulesProfile() { | ||||
return rulesProfile; | return rulesProfile; | ||||
} | } | ||||
return rule.getKey(); | return rule.getKey(); | ||||
} | } | ||||
/** | |||||
* @since 4.2 | |||||
* @deprecated in 4.4. Feature dropped. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getNoteData() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.2 | |||||
* @deprecated in 4.4. Feature dropped. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getNoteUserLogin() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.2 | |||||
* @deprecated in 4.4. Feature dropped. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public Date getNoteCreatedAt() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.2 | |||||
* @deprecated in 4.4. Feature dropped. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public Date getNoteUpdatedAt() { | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public boolean equals(Object o) { | public boolean equals(Object o) { | ||||
if (this == o) { | if (this == o) { |
return this; | return this; | ||||
} | } | ||||
/** | |||||
* For internal use only. | |||||
* | |||||
* @since 4.3 | |||||
* @deprecated since 4.4, use {@link #getCharacteristicKey()} | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public Integer getCharacteristicId() { | |||||
return null; | |||||
} | |||||
/** | |||||
* For internal use only. | |||||
* | |||||
* @since 4.3 | |||||
* @deprecated since 4.4, use {@link #setCharacteristicKey(String)} | |||||
*/ | |||||
@Deprecated | |||||
public Rule setCharacteristicId(@Nullable Integer characteristicId) { | |||||
return this; | |||||
} | |||||
/** | |||||
* For internal use only. | |||||
* | |||||
* @since 4.3 | |||||
* @deprecated since 4.4, use {@link #getDefaultCharacteristicKey()} | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public Integer getDefaultCharacteristicId() { | |||||
return null; | |||||
} | |||||
/** | |||||
* For internal use only. | |||||
* | |||||
* @since 4.3 | |||||
* @deprecated since 4.4, use {@link #setDefaultCharacteristicKey(String)} | |||||
*/ | |||||
@Deprecated | |||||
public Rule setDefaultCharacteristicId(@Nullable Integer defaultCharacteristicId) { | |||||
return this; | |||||
} | |||||
@Override | @Override | ||||
public boolean equals(Object obj) { | public boolean equals(Object obj) { | ||||
if (!(obj instanceof Rule)) { | if (!(obj instanceof Rule)) { | ||||
return RuleKey.of(getRepositoryKey(), getKey()); | return RuleKey.of(getRepositoryKey(), getKey()); | ||||
} | } | ||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getDefaultCharacteristicKey() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@Deprecated | |||||
public Rule setDefaultCharacteristicKey(@Nullable String defaultCharacteristicKey) { | |||||
return this; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getDefaultSubCharacteristicKey() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@Deprecated | |||||
public Rule setDefaultSubCharacteristicKey(@Nullable String defaultSubCharacteristicKey) { | |||||
return this; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getCharacteristicKey() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@Deprecated | |||||
public Rule setCharacteristicKey(@Nullable String characteristicKey) { | |||||
return this; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String getSubCharacteristicKey() { | |||||
return null; | |||||
} | |||||
/** | |||||
* @since 4.4 | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
*/ | |||||
@Deprecated | |||||
public Rule setSubCharacteristicKey(@Nullable String subCharacteristicKey) { | |||||
return this; | |||||
} | |||||
} | } |
package org.sonar.api.security; | package org.sonar.api.security; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import javax.annotation.CheckForNull; | |||||
import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
/** | /** | ||||
*/ | */ | ||||
public abstract class ExternalGroupsProvider { | public abstract class ExternalGroupsProvider { | ||||
/** | |||||
* @return list of groups associated with specified user, or null if such user doesn't exist | |||||
* @throws RuntimeException in case of unexpected error such as connection failure | |||||
* @deprecated replaced by {@link #doGetGroups(org.sonar.api.security.ExternalGroupsProvider.Context)} since v. 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public Collection<String> doGetGroups(String username) { | |||||
return null; | |||||
} | |||||
/** | /** | ||||
* Override this method in order to load user group information. | * Override this method in order to load user group information. | ||||
* | * | ||||
* @throws RuntimeException in case of unexpected error such as connection failure | * @throws RuntimeException in case of unexpected error such as connection failure | ||||
* @since 5.2 | * @since 5.2 | ||||
*/ | */ | ||||
@CheckForNull | |||||
public Collection<String> doGetGroups(Context context) { | public Collection<String> doGetGroups(Context context) { | ||||
return doGetGroups(context.getUsername()); | |||||
return null; | |||||
} | } | ||||
public static final class Context { | public static final class Context { |
* @since 2.14 | * @since 2.14 | ||||
*/ | */ | ||||
public abstract class ExternalUsersProvider { | public abstract class ExternalUsersProvider { | ||||
/** | |||||
* This method is overridden by old versions of plugins such as LDAP 1.1. It should not be overridden anymore. | |||||
* | |||||
* @param username the username | |||||
* @return details for specified user, or null if such user doesn't exist | |||||
* @throws RuntimeException in case of unexpected error such as connection failure | |||||
* @deprecated replaced by {@link #doGetUserDetails(org.sonar.api.security.ExternalUsersProvider.Context)} since v. 3.1 | |||||
*/ | |||||
@Deprecated | |||||
public UserDetails doGetUserDetails(@Nullable String username) { | |||||
return null; | |||||
} | |||||
/** | /** | ||||
* Override this method in order load user information. | * Override this method in order load user information. | ||||
* | * | ||||
* @since 3.1 | * @since 3.1 | ||||
*/ | */ | ||||
public UserDetails doGetUserDetails(Context context) { | public UserDetails doGetUserDetails(Context context) { | ||||
return doGetUserDetails(context.getUsername()); | |||||
return null; | |||||
} | } | ||||
public static final class Context { | public static final class Context { |
this.usesBaseEffort = usesBaseEffort; | this.usesBaseEffort = usesBaseEffort; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #usesGapMultiplier()} | |||||
*/ | |||||
@Deprecated | |||||
public boolean usesCoefficient() { | |||||
return usesGapMultiplier(); | |||||
} | |||||
/** | /** | ||||
* @since 5.5 | * @since 5.5 | ||||
*/ | */ | ||||
return usesGapMultiplier; | return usesGapMultiplier; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #usesBaseEffort()} | |||||
*/ | |||||
@Deprecated | |||||
public boolean usesOffset() { | |||||
return usesBaseEffort(); | |||||
} | |||||
/** | /** | ||||
* @since 5.5 | * @since 5.5 | ||||
*/ | */ | ||||
*/ | */ | ||||
Type type(); | Type type(); | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #gapMultiplier()} | |||||
*/ | |||||
@Deprecated | |||||
@CheckForNull | |||||
String coefficient(); | |||||
/** | /** | ||||
* Non-null value on {@link Type#LINEAR} and {@link Type#LINEAR_OFFSET} functions, else {@code null}. | * Non-null value on {@link Type#LINEAR} and {@link Type#LINEAR_OFFSET} functions, else {@code null}. | ||||
* | * | ||||
@CheckForNull | @CheckForNull | ||||
String gapMultiplier(); | String gapMultiplier(); | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #baseEffort()} | |||||
*/ | |||||
@Deprecated | |||||
@CheckForNull | |||||
String offset(); | |||||
/** | /** | ||||
* Non-null value on {@link Type#LINEAR_OFFSET} and {@link Type#CONSTANT_ISSUE} functions, else {@code null}. | * Non-null value on {@link Type#LINEAR_OFFSET} and {@link Type#CONSTANT_ISSUE} functions, else {@code null}. | ||||
* | * |
return type; | return type; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #gapMultiplier} | |||||
*/ | |||||
@Override | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String coefficient() { | |||||
return gapMultiplier(); | |||||
} | |||||
@Override | @Override | ||||
@CheckForNull | @CheckForNull | ||||
public String gapMultiplier() { | public String gapMultiplier() { | ||||
return gapMultiplier; | return gapMultiplier; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #baseEffort} | |||||
*/ | |||||
@Override | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String offset() { | |||||
return baseEffort(); | |||||
} | |||||
@Override | @Override | ||||
public String baseEffort() { | public String baseEffort() { | ||||
return baseEffort; | return baseEffort; |
import org.sonar.api.server.rule.internal.DefaultRepository; | import org.sonar.api.server.rule.internal.DefaultRepository; | ||||
import org.sonarsource.api.sonarlint.SonarLintSide; | import org.sonarsource.api.sonarlint.SonarLintSide; | ||||
import static java.util.Collections.emptyList; | |||||
import static java.util.Collections.unmodifiableList; | import static java.util.Collections.unmodifiableList; | ||||
import static org.sonar.api.utils.Preconditions.checkState; | import static org.sonar.api.utils.Preconditions.checkState; | ||||
@SonarLintSide | @SonarLintSide | ||||
@ExtensionPoint | @ExtensionPoint | ||||
public interface RulesDefinition { | public interface RulesDefinition { | ||||
/** | |||||
* Default sub-characteristics of technical debt model. See http://www.sqale.org | |||||
* | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. | |||||
* See https://jira.sonarsource.com/browse/MMF-184 | |||||
*/ | |||||
@Deprecated | |||||
final class SubCharacteristics { | |||||
/** | |||||
* Related to characteristic REUSABILITY | |||||
*/ | |||||
public static final String MODULARITY = "MODULARITY"; | |||||
/** | |||||
* Related to characteristic REUSABILITY | |||||
*/ | |||||
public static final String TRANSPORTABILITY = "TRANSPORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String COMPILER_RELATED_PORTABILITY = "COMPILER_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String HARDWARE_RELATED_PORTABILITY = "HARDWARE_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String LANGUAGE_RELATED_PORTABILITY = "LANGUAGE_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String OS_RELATED_PORTABILITY = "OS_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String SOFTWARE_RELATED_PORTABILITY = "SOFTWARE_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String TIME_ZONE_RELATED_PORTABILITY = "TIME_ZONE_RELATED_PORTABILITY"; | |||||
/** | |||||
* Related to characteristic MAINTAINABILITY | |||||
*/ | |||||
public static final String READABILITY = "READABILITY"; | |||||
/** | |||||
* Related to characteristic MAINTAINABILITY | |||||
*/ | |||||
public static final String UNDERSTANDABILITY = "UNDERSTANDABILITY"; | |||||
/** | |||||
* Related to characteristic SECURITY | |||||
*/ | |||||
public static final String API_ABUSE = "API_ABUSE"; | |||||
/** | |||||
* Related to characteristic SECURITY | |||||
*/ | |||||
public static final String ERRORS = "ERRORS"; | |||||
/** | |||||
* Related to characteristic SECURITY | |||||
*/ | |||||
public static final String INPUT_VALIDATION_AND_REPRESENTATION = "INPUT_VALIDATION_AND_REPRESENTATION"; | |||||
/** | |||||
* Related to characteristic SECURITY | |||||
*/ | |||||
public static final String SECURITY_FEATURES = "SECURITY_FEATURES"; | |||||
/** | |||||
* Related to characteristic EFFICIENCY | |||||
*/ | |||||
public static final String CPU_EFFICIENCY = "CPU_EFFICIENCY"; | |||||
/** | |||||
* Related to characteristic EFFICIENCY | |||||
*/ | |||||
public static final String MEMORY_EFFICIENCY = "MEMORY_EFFICIENCY"; | |||||
/** | |||||
* Related to characteristic EFFICIENCY | |||||
*/ | |||||
public static final String NETWORK_USE = "NETWORK_USE"; | |||||
/** | |||||
* Related to characteristic CHANGEABILITY | |||||
*/ | |||||
public static final String ARCHITECTURE_CHANGEABILITY = "ARCHITECTURE_CHANGEABILITY"; | |||||
/** | |||||
* Related to characteristic CHANGEABILITY | |||||
*/ | |||||
public static final String DATA_CHANGEABILITY = "DATA_CHANGEABILITY"; | |||||
/** | |||||
* Related to characteristic CHANGEABILITY | |||||
*/ | |||||
public static final String LOGIC_CHANGEABILITY = "LOGIC_CHANGEABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String ARCHITECTURE_RELIABILITY = "ARCHITECTURE_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String DATA_RELIABILITY = "DATA_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String EXCEPTION_HANDLING = "EXCEPTION_HANDLING"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String FAULT_TOLERANCE = "FAULT_TOLERANCE"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String INSTRUCTION_RELIABILITY = "INSTRUCTION_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String LOGIC_RELIABILITY = "LOGIC_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String RESOURCE_RELIABILITY = "RESOURCE_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String SYNCHRONIZATION_RELIABILITY = "SYNCHRONIZATION_RELIABILITY"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String UNIT_TESTS = "UNIT_TESTS"; | |||||
/** | |||||
* Related to characteristic TESTABILITY | |||||
*/ | |||||
public static final String INTEGRATION_TESTABILITY = "INTEGRATION_TESTABILITY"; | |||||
/** | |||||
* Related to characteristic TESTABILITY | |||||
*/ | |||||
public static final String UNIT_TESTABILITY = "UNIT_TESTABILITY"; | |||||
/** | |||||
* Related to characteristic ACCESSIBILITY | |||||
*/ | |||||
public static final String USABILITY_ACCESSIBILITY = "USABILITY_ACCESSIBILITY"; | |||||
/** | |||||
* Related to characteristic ACCESSIBILITY | |||||
*/ | |||||
public static final String USABILITY_COMPLIANCE = "USABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic ACCESSIBILITY | |||||
*/ | |||||
public static final String USABILITY_EASE_OF_USE = "USABILITY_EASE_OF_USE"; | |||||
/** | |||||
* Related to characteristic REUSABILITY | |||||
*/ | |||||
public static final String REUSABILITY_COMPLIANCE = "REUSABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic PORTABILITY | |||||
*/ | |||||
public static final String PORTABILITY_COMPLIANCE = "PORTABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic MAINTAINABILITY | |||||
*/ | |||||
public static final String MAINTAINABILITY_COMPLIANCE = "MAINTAINABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic SECURITY | |||||
*/ | |||||
public static final String SECURITY_COMPLIANCE = "SECURITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic EFFICIENCY | |||||
*/ | |||||
public static final String EFFICIENCY_COMPLIANCE = "EFFICIENCY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic CHANGEABILITY | |||||
*/ | |||||
public static final String CHANGEABILITY_COMPLIANCE = "CHANGEABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic RELIABILITY | |||||
*/ | |||||
public static final String RELIABILITY_COMPLIANCE = "RELIABILITY_COMPLIANCE"; | |||||
/** | |||||
* Related to characteristic TESTABILITY | |||||
*/ | |||||
public static final String TESTABILITY_COMPLIANCE = "TESTABILITY_COMPLIANCE"; | |||||
private SubCharacteristics() { | |||||
// only constants | |||||
} | |||||
} | |||||
/** | /** | ||||
* This implementation will be removed as soon as analyzers stop instantiating it. | * This implementation will be removed as soon as analyzers stop instantiating it. | ||||
* Use RulesDefinitionContext in sonar-plugin-api-impl. | * Use RulesDefinitionContext in sonar-plugin-api-impl. | ||||
return new DefaultNewRepository(this, RuleKey.EXTERNAL_RULE_REPO_PREFIX + engineId, language, true); | return new DefaultNewRepository(this, RuleKey.EXTERNAL_RULE_REPO_PREFIX + engineId, language, true); | ||||
} | } | ||||
@Override | |||||
@Deprecated | |||||
public RulesDefinition.NewRepository extendRepository(String key, String language) { | |||||
return createRepository(key, language); | |||||
} | |||||
@Override | @Override | ||||
@CheckForNull | @CheckForNull | ||||
public RulesDefinition.Repository repository(String key) { | public RulesDefinition.Repository repository(String key) { | ||||
return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); | return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); | ||||
} | } | ||||
@Override | |||||
@Deprecated | |||||
public List<RulesDefinition.ExtendedRepository> extendedRepositories(String repositoryKey) { | |||||
return emptyList(); | |||||
} | |||||
@Override | |||||
@Deprecated | |||||
public List<RulesDefinition.ExtendedRepository> extendedRepositories() { | |||||
return emptyList(); | |||||
} | |||||
public void registerRepository(DefaultNewRepository newRepository) { | public void registerRepository(DefaultNewRepository newRepository) { | ||||
RulesDefinition.Repository existing = repositoriesByKey.get(newRepository.key()); | RulesDefinition.Repository existing = repositoriesByKey.get(newRepository.key()); | ||||
if (existing != null) { | if (existing != null) { | ||||
*/ | */ | ||||
public abstract NewRepository createExternalRepository(String engineId, String language); | public abstract NewRepository createExternalRepository(String engineId, String language); | ||||
/** | |||||
* @deprecated since 5.2. Simply use {@link #createRepository(String, String)} | |||||
*/ | |||||
@Deprecated | |||||
public abstract NewRepository extendRepository(String key, String language); | |||||
@CheckForNull | @CheckForNull | ||||
public abstract Repository repository(String key); | public abstract Repository repository(String key); | ||||
public abstract List<Repository> repositories(); | public abstract List<Repository> repositories(); | ||||
/** | |||||
* @deprecated returns empty list since 5.2. Concept of "extended repository" was misleading and not valuable. Simply declare | |||||
* repositories and use {@link #repositories()}. See http://jira.sonarsource.com/browse/SONAR-6709 | |||||
*/ | |||||
@Deprecated | |||||
public abstract List<ExtendedRepository> extendedRepositories(String repositoryKey); | |||||
/** | |||||
* @deprecated returns empty list since 5.2. Concept of "extended repository" was misleading and not valuable. Simply declare | |||||
* repositories and use {@link #repositories()}. See http://jira.sonarsource.com/browse/SONAR-6709 | |||||
*/ | |||||
@Deprecated | |||||
public abstract List<ExtendedRepository> extendedRepositories(); | |||||
public abstract void setCurrentPluginKey(@Nullable String pluginKey); | public abstract void setCurrentPluginKey(@Nullable String pluginKey); | ||||
} | } | ||||
*/ | */ | ||||
public abstract NewRule setStatus(RuleStatus status); | public abstract NewRule setStatus(RuleStatus status); | ||||
/** | |||||
* SQALE sub-characteristic. See http://www.sqale.org | |||||
* | |||||
* @see org.sonar.api.server.rule.RulesDefinition.SubCharacteristics for constant values | |||||
* @see #setType(RuleType) | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. This method does nothing. | |||||
* See https://jira.sonarsource.com/browse/MMF-184 | |||||
*/ | |||||
@Deprecated | |||||
public abstract NewRule setDebtSubCharacteristic(@Nullable String s); | |||||
/** | /** | ||||
* Factory of {@link org.sonar.api.server.debt.DebtRemediationFunction} | * Factory of {@link org.sonar.api.server.debt.DebtRemediationFunction} | ||||
*/ | */ | ||||
*/ | */ | ||||
public abstract NewRule setDebtRemediationFunction(@Nullable DebtRemediationFunction fn); | public abstract NewRule setDebtRemediationFunction(@Nullable DebtRemediationFunction fn); | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #setGapDescription(String)} | |||||
*/ | |||||
@Deprecated | |||||
public abstract NewRule setEffortToFixDescription(@Nullable String s); | |||||
/** | /** | ||||
* For rules that use LINEAR or LINEAR_OFFSET remediation functions, the meaning | * For rules that use LINEAR or LINEAR_OFFSET remediation functions, the meaning | ||||
* of the function parameter (= "gap") must be set. This description | * of the function parameter (= "gap") must be set. This description | ||||
public abstract RuleStatus status(); | public abstract RuleStatus status(); | ||||
/** | |||||
* @see #type() | |||||
* @deprecated in 5.5. SQALE Quality Model is replaced by SonarQube Quality Model. {@code null} is | |||||
* always returned. See https://jira.sonarsource.com/browse/MMF-184 | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public abstract String debtSubCharacteristic(); | |||||
@CheckForNull | @CheckForNull | ||||
public abstract DebtRemediationFunction debtRemediationFunction(); | public abstract DebtRemediationFunction debtRemediationFunction(); | ||||
/** | |||||
* @deprecated since 5.5, replaced by {@link #gapDescription()} | |||||
*/ | |||||
@Deprecated | |||||
@CheckForNull | |||||
public abstract String effortToFixDescription(); | |||||
@CheckForNull | @CheckForNull | ||||
public abstract String gapDescription(); | public abstract String gapDescription(); | ||||
* | * | ||||
* <!-- Quality Model - type of debt remediation function --> | * <!-- Quality Model - type of debt remediation function --> | ||||
* <!-- See enum {@link org.sonar.api.server.debt.DebtRemediationFunction.Type} for supported values --> | * <!-- See enum {@link org.sonar.api.server.debt.DebtRemediationFunction.Type} for supported values --> | ||||
* <!-- It was previously named 'debtRemediationFunction' which is still supported but deprecated since 5.5 --> | |||||
* <!-- It was previously named 'debtRemediationFunction'. --> | |||||
* <!-- Since 5.5 --> | * <!-- Since 5.5 --> | ||||
* <remediationFunction>LINEAR_OFFSET</remediationFunction> | * <remediationFunction>LINEAR_OFFSET</remediationFunction> | ||||
* | * | ||||
* <!-- Quality Model - raw description of the "gap", used for some types of remediation functions. --> | * <!-- Quality Model - raw description of the "gap", used for some types of remediation functions. --> | ||||
* <!-- See {@link org.sonar.api.server.rule.RulesDefinition.NewRule#setGapDescription(String)} --> | * <!-- See {@link org.sonar.api.server.rule.RulesDefinition.NewRule#setGapDescription(String)} --> | ||||
* <!-- It was previously named 'effortToFixDescription' which is still supported but deprecated since 5.5 --> | |||||
* <!-- It was previously named 'effortToFixDescription'. --> | |||||
* <!-- Since 5.5 --> | * <!-- Since 5.5 --> | ||||
* <gapDescription>Effort to test one uncovered condition</gapFixDescription> | * <gapDescription>Effort to test one uncovered condition</gapFixDescription> | ||||
* | * | ||||
* <!-- Quality Model - gap multiplier of debt remediation function. Must be defined only for some function types. --> | * <!-- Quality Model - gap multiplier of debt remediation function. Must be defined only for some function types. --> | ||||
* <!-- See {@link org.sonar.api.server.rule.RulesDefinition.DebtRemediationFunctions} --> | * <!-- See {@link org.sonar.api.server.rule.RulesDefinition.DebtRemediationFunctions} --> | ||||
* <!-- It was previously named 'debtRemediationFunctionCoefficient' which is still supported but deprecated since 5.5 --> | |||||
* <!-- It was previously named 'debtRemediationFunctionCoefficient'. --> | |||||
* <!-- Since 5.5 --> | * <!-- Since 5.5 --> | ||||
* <remediationFunctionGapMultiplier>10min</remediationFunctionGapMultiplier> | * <remediationFunctionGapMultiplier>10min</remediationFunctionGapMultiplier> | ||||
* | * | ||||
* <!-- Quality Model - base effort of debt remediation function. Must be defined only for some function types. --> | * <!-- Quality Model - base effort of debt remediation function. Must be defined only for some function types. --> | ||||
* <!-- See {@link org.sonar.api.server.rule.RulesDefinition.DebtRemediationFunctions} --> | * <!-- See {@link org.sonar.api.server.rule.RulesDefinition.DebtRemediationFunctions} --> | ||||
* <!-- It was previously named 'debtRemediationFunctionOffset' which is still supported but deprecated since 5.5 --> | |||||
* <!-- It was previously named 'debtRemediationFunctionOffset'. --> | |||||
* <!-- Since 5.5 --> | * <!-- Since 5.5 --> | ||||
* <remediationFunctionBaseEffort>2min</remediationFunctionBaseEffort> | * <remediationFunctionBaseEffort>2min</remediationFunctionBaseEffort> | ||||
* | * |
return this; | return this; | ||||
} | } | ||||
@Override | |||||
public DefaultNewRule setDebtSubCharacteristic(@Nullable String s) { | |||||
return this; | |||||
} | |||||
@Override | @Override | ||||
public RulesDefinition.DebtRemediationFunctions debtRemediationFunctions() { | public RulesDefinition.DebtRemediationFunctions debtRemediationFunctions() { | ||||
return functions; | return functions; | ||||
return this; | return this; | ||||
} | } | ||||
@Deprecated | |||||
@Override | |||||
public DefaultNewRule setEffortToFixDescription(@Nullable String s) { | |||||
return setGapDescription(s); | |||||
} | |||||
@Override | @Override | ||||
public DefaultNewRule setGapDescription(@Nullable String s) { | public DefaultNewRule setGapDescription(@Nullable String s) { | ||||
this.gapDescription = s; | this.gapDescription = s; |
return status; | return status; | ||||
} | } | ||||
@CheckForNull | |||||
@Deprecated | |||||
@Override | |||||
public String debtSubCharacteristic() { | |||||
return null; | |||||
} | |||||
@CheckForNull | @CheckForNull | ||||
@Override | @Override | ||||
public DebtRemediationFunction debtRemediationFunction() { | public DebtRemediationFunction debtRemediationFunction() { | ||||
return debtRemediationFunction; | return debtRemediationFunction; | ||||
} | } | ||||
@Deprecated | |||||
@CheckForNull | |||||
@Override | |||||
public String effortToFixDescription() { | |||||
return gapDescription(); | |||||
} | |||||
@CheckForNull | @CheckForNull | ||||
@Override | @Override | ||||
public String gapDescription() { | public String gapDescription() { |
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.apache.commons.lang.StringUtils; | |||||
import org.sonar.api.utils.DateUtils; | import org.sonar.api.utils.DateUtils; | ||||
import static java.lang.String.format; | import static java.lang.String.format; | ||||
return part; | return part; | ||||
} | } | ||||
/** | |||||
* @deprecated to be dropped in 4.4. Default values are declared in ws metadata | |||||
*/ | |||||
@CheckForNull | |||||
@Deprecated | |||||
public String param(String key, @CheckForNull String defaultValue) { | |||||
return StringUtils.defaultString(param(key), defaultValue); | |||||
} | |||||
/** | |||||
* @deprecated to be dropped in 4.4. Default values must be declared in {@link org.sonar.api.server.ws.WebService} then | |||||
* this method can be replaced by {@link #mandatoryParamAsBoolean(String)}. | |||||
*/ | |||||
@Deprecated | |||||
public boolean paramAsBoolean(String key, boolean defaultValue) { | |||||
String value = param(key); | |||||
return value == null ? defaultValue : parseBoolean(key, value); | |||||
} | |||||
/** | |||||
* @deprecated to be dropped in 4.4. Default values must be declared in {@link org.sonar.api.server.ws.WebService} then | |||||
* this method can be replaced by {@link #mandatoryParamAsInt(String)}. | |||||
*/ | |||||
@Deprecated | |||||
public int paramAsInt(String key, int defaultValue) { | |||||
String s = param(key); | |||||
return s == null ? defaultValue : parseInt(key, s); | |||||
} | |||||
/** | |||||
* @deprecated to be dropped in 4.4. Default values must be declared in {@link org.sonar.api.server.ws.WebService} then | |||||
* this method can be replaced by {@link #mandatoryParamAsLong(String)}. | |||||
*/ | |||||
@Deprecated | |||||
public long paramAsLong(String key, long defaultValue) { | |||||
String s = param(key); | |||||
return s == null ? defaultValue : parseLong(key, s); | |||||
} | |||||
@CheckForNull | @CheckForNull | ||||
public Boolean paramAsBoolean(String key) { | public Boolean paramAsBoolean(String key) { | ||||
String value = param(key); | String value = param(key); |
return this; | return this; | ||||
} | } | ||||
/** | |||||
* @see #setDeprecatedKey(String, String) | |||||
* @since 5.0 | |||||
* @deprecated since 6.4 | |||||
*/ | |||||
@Deprecated | |||||
public NewParam setDeprecatedKey(@Nullable String s) { | |||||
this.deprecatedKey = s; | |||||
return this; | |||||
} | |||||
/** | /** | ||||
* @param deprecatedSince Version when the old key was replaced/deprecated. Ex: 5.6 | * @param deprecatedSince Version when the old key was replaced/deprecated. Ex: 5.6 | ||||
* @see Param#deprecatedKey() | * @see Param#deprecatedKey() |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.task; | |||||
import org.sonar.api.batch.ScannerSide; | |||||
import org.sonar.api.batch.InstantiationStrategy; | |||||
/** | |||||
* All the classes implementing this interface can be injected in public constructors of {@link TaskExtension}. | |||||
* | |||||
* @since 3.6 | |||||
* @deprecated since 5.1. Use {@link ScannerSide} and {@link InstantiationStrategy#PER_TASK} | |||||
*/ | |||||
@Deprecated | |||||
@ScannerSide | |||||
@InstantiationStrategy(InstantiationStrategy.PER_TASK) | |||||
public interface TaskComponent { | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.task; | |||||
import org.sonar.api.batch.ScannerSide; | |||||
import org.sonar.api.batch.InstantiationStrategy; | |||||
/** | |||||
* Task extension point | |||||
* | |||||
* @since 3.6 | |||||
* @deprecated since 5.1. Not used. | |||||
*/ | |||||
@Deprecated | |||||
@ScannerSide | |||||
@InstantiationStrategy(InstantiationStrategy.PER_TASK) | |||||
public interface TaskExtension { | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
import java.util.List; | |||||
/** | |||||
* @deprecated since 5.6. Feature will be removed without any alternatives. | |||||
*/ | |||||
@Deprecated | |||||
public interface CoverageBlock { | |||||
TestCase testCase(); | |||||
Testable testable(); | |||||
List<Integer> lines(); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
import java.util.List; | |||||
import javax.annotation.Nullable; | |||||
import org.sonar.api.batch.fs.InputFile; | |||||
/** | |||||
* @deprecated since 5.6. Feature will be removed without any alternatives. | |||||
*/ | |||||
@Deprecated | |||||
public interface MutableTestCase extends TestCase { | |||||
MutableTestCase setStatus(@Nullable Status s); | |||||
MutableTestCase setDurationInMs(@Nullable Long l); | |||||
MutableTestCase setMessage(@Nullable String s); | |||||
MutableTestCase setStackTrace(@Nullable String s); | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
MutableTestCase setType(@Nullable String s); | |||||
/** | |||||
* @deprecated since 5.2. Use {@link #setCoverageBlock(InputFile, List)} | |||||
*/ | |||||
@Deprecated | |||||
MutableTestCase setCoverageBlock(Testable testable, List<Integer> lines); | |||||
MutableTestCase setCoverageBlock(InputFile mainFile, List<Integer> lines); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
/** | |||||
* @deprecated since 5.6. Feature will be removed without any alternatives. | |||||
*/ | |||||
@Deprecated | |||||
public interface MutableTestPlan extends TestPlan<MutableTestCase> { | |||||
/** | |||||
* Add a {@link TestCase} to this test file. | |||||
* Note that a same physical test (for example in Java a single method annotated with @Test) | |||||
* can be executed several times (parameterized tests, different test suites, ...). As a result it is perfectly valid to register several | |||||
* tests with the same name. Anyway in this situation the coverage per test will be merged for all tests with the same name. | |||||
* @param name | |||||
* @return | |||||
*/ | |||||
MutableTestCase addTestCase(String name); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
/** | |||||
* @deprecated since 5.6. Feature will be removed without any alternatives. | |||||
*/ | |||||
@Deprecated | |||||
public interface MutableTestable extends Testable { | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
import java.util.Locale; | |||||
import javax.annotation.CheckForNull; | |||||
import javax.annotation.Nullable; | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
public interface TestCase { | |||||
enum Status { | |||||
OK, FAILURE, ERROR, SKIPPED; | |||||
public static Status of(@Nullable String s) { | |||||
return s == null ? null : valueOf(s.toUpperCase(Locale.ENGLISH)); | |||||
} | |||||
} | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
String TYPE_UNIT = "UNIT"; | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
String TYPE_INTEGRATION = "INTEGRATION"; | |||||
/** | |||||
* Duration in milliseconds | |||||
*/ | |||||
@CheckForNull | |||||
Long durationInMs(); | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
String type(); | |||||
Status status(); | |||||
String name(); | |||||
@CheckForNull | |||||
String message(); | |||||
@CheckForNull | |||||
String stackTrace(); | |||||
TestPlan testPlan(); | |||||
boolean doesCover(); | |||||
int countCoveredLines(); | |||||
Iterable<CoverageBlock> coverageBlocks(); | |||||
@CheckForNull | |||||
CoverageBlock coverageBlock(Testable testable); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
import org.sonar.api.component.Perspective; | |||||
/** | |||||
* @deprecated since 5.2 not used | |||||
*/ | |||||
@Deprecated | |||||
public interface TestPlan<T extends TestCase> extends Perspective { | |||||
Iterable<T> testCases(); | |||||
Iterable<T> testCasesByName(String name); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import java.util.SortedSet; | |||||
import org.sonar.api.component.Perspective; | |||||
/** | |||||
* @deprecated since 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public interface Testable extends Perspective { | |||||
List<TestCase> testCases(); | |||||
TestCase testCaseByName(String key); | |||||
int countTestCasesOfLine(Integer line); | |||||
Map<Integer, Integer> testCasesByLines(); | |||||
List<TestCase> testCasesOfLine(int line); | |||||
SortedSet<Integer> testedLines(); | |||||
CoverageBlock coverageBlock(TestCase testCase); | |||||
Iterable<CoverageBlock> coverageBlocks(); | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test.exception; | |||||
/** | |||||
* @deprecated since 5.6 feature will be removed soon | |||||
*/ | |||||
@Deprecated | |||||
public class CoverageAlreadyExistsException extends TestException { | |||||
public CoverageAlreadyExistsException(String message) { | |||||
super(message); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test.exception; | |||||
/** | |||||
* @deprecated since 5.6 feature will be removed soon | |||||
*/ | |||||
@Deprecated | |||||
public class IllegalDurationException extends TestException { | |||||
public IllegalDurationException(String message) { | |||||
super(message); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2021 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.api.test.exception; | |||||
/** | |||||
* @deprecated since 5.6 feature will be removed soon | |||||
*/ | |||||
@Deprecated | |||||
public class TestException extends RuntimeException { | |||||
public TestException(String message) { | |||||
super(message); | |||||
} | |||||
public TestException(String message, Throwable cause) { | |||||
super(message, cause); | |||||
} | |||||
} |