本文整理汇总了Java中org.sonar.api.resources.Project类的典型用法代码示例。如果您正苦于以下问题:Java Project类的具体用法?Java Project怎么用?Java Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Project类属于org.sonar.api.resources包,在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addIssue
import org.sonar.api.resources.Project; //导入依赖的package包/类
private void addIssue(Project project, double coverage, double previousCoverage) {
Issuable issuable = perspectives.as(Issuable.class, (Resource) project);
if (issuable == null) {
LOGGER.warn("Could not get a perspective of Issuable to create an issue for {}, skipping",
project);
return;
}
Optional<RuleKey> ruleKey = CoverageRule.decreasingOverallLineCoverageRule(fileSystem);
if (ruleKey.isPresent()) {
LOGGER.debug("RuleKey: {}", ruleKey.get());
addIssue(issuable,
formatIssueMessage("the project", coverage, previousCoverage),
ruleKey.get());
} else {
LOGGER.warn("Could not determine the RuleKey for the project {}", project.getEffectiveKey());
}
}
示例2: shouldExecuteOnProject
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Override
public boolean shouldExecuteOnProject(Project project) {
// We only execute when run in preview mode
// I don't know how we should behave during a normal scan
if (!CoverageRule.shouldExecute(activeRules)) {
return false;
}
if (!config.scanAllFiles()) {
LOGGER.warn(
"Not scanning all files, coverage features will be unreliable and will be disabled");
return false;
}
return true;
}
示例3: testComputeEffectiveKey
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Test
public void testComputeEffectiveKey() {
Project module = new Project("foo:bar");
assertEquals(
"foo:bar",
computeEffectiveKey(new Project("foo:bar"), module)
);
assertEquals(
"baz",
computeEffectiveKey(new Project("baz"), module)
);
Resource r = File.create("xyz");
assertEquals(
"foo:bar:xyz",
computeEffectiveKey(r, module)
);
r.setEffectiveKey("quux");
assertEquals(
"quux",
computeEffectiveKey(r, module)
);
}
示例4: testGetMeasureValue
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Test
public void testGetMeasureValue() throws Exception {
String url = "http://localhost:" + httpServer.port() + "/";
String username = "foo";
String password = "bar";
SonarClient client = new DefaultSonarClient(url, username, password);
Project project = new Project("MY_PROJECT");
Resource file = new File("ElementImpl.java");
file.setKey("ElementImpl.java");
httpServer.stubFor(
get("/api/measures/component?componentKey=MY_PROJECT%3AElementImpl.java&metricKeys=line_coverage")
.withBasicAuth(username, password)
.willReturn(
aResponse()
.withBody(readJsonResource("componentMeasure.json").toJson().getBytes())
)
);
assertEquals(
25.0,
client.getMeasureValue(project, file, CoreMetrics.LINE_COVERAGE),
0.001
);
}
示例5: executeOn
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Override
public void executeOn(Project project, SensorContext context) {
if (!settings.getBoolean(DISABLED)) {
String room = settings.getString(ROOM);
String token = settings.getString(TOKEN);
if (isBlank(room) || isBlank(token)) {
LOGGER.warn("No Room or token information available. No notification is send");
return;
}
String postUrl = String.format(settings.getString(URL_TEMPLATE), room, token);
HipChatHttpClient hipChatHttpClient = new HipChatHttpClient(postUrl);
HipChatMessageBuilder messageBuilder = new SonarHipChatMessageBuilder(project, settings, projectIssues);
hipChatHttpClient.sendPreNotification(settings.getString(PRE_MESSAGE), messageBuilder);
hipChatHttpClient.sendStatusNotification(messageBuilder);
}
}
示例6: analyse
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Override
public void analyse(Project project, SensorContext sensorContext) {
// configure the lexer
final PageLexer lexer = new PageLexer();
// configure page scanner and the visitors
final HtmlAstScanner scanner = setupScanner();
for (java.io.File file : fileSystem.files(FileQuery.onSource().onLanguage(TanaguruConstants.LANGUAGE_KEY))) {
File resource = File.fromIOFile(file, project);
WebSourceCode sourceCode = new WebSourceCode(file, resource);
FileReader reader = null;
try {
reader = new FileReader(file);
List<Node> nodeList = lexer.parse(reader);
scanner.scan(nodeList, sourceCode, fileSystem.sourceCharset());
saveMetrics(sensorContext, sourceCode);
saveLineLevelMeasures(resource, sourceCode);
} catch (Exception e) {
LOG.error("Can not analyze file " + file.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(reader);
}
}
}
示例7: execute
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Override
public void execute(Project project) {
logger.info("Launching FC Code Review analysis...");
logger.info(BWCodeReviewPlugin.FC_CODE_REVIEW_RESULTS_RELATIVE_PATH + "=" + relativePath);
logger.info("Project path=" + fs.baseDir().getAbsolutePath());
File xmlCodeReview = getXMLCodeReviewResult();
if (xmlCodeReview != null && xmlCodeReview.exists()) {
logger.info("Code Review XML result=" + xmlCodeReview.getAbsolutePath());
reviewResult = loadReviewResult(xmlCodeReview);
if (reviewResult == null) {
logger.info("Code Review XML result=" + xmlCodeReview.getAbsolutePath());
} else {
//next step
logger.info(reviewResult.getDuration().toString());
}
} else {
logger.info("The Code Review XML result for this BW project was not found. Skipping.");
}
}
示例8: analyse
import org.sonar.api.resources.Project; //导入依赖的package包/类
public void analyse(Project project, SensorContext sensorContext) {
if (CodeReviewInitialize.reviewResult == null || CodeReviewInitialize.reviewResult.getProjectBasedir() == null) return;
logger.debug("Project basedir : " + CodeReviewInitialize.reviewResult.getProjectBasedir());
File projectBasedir = new File(CodeReviewInitialize.reviewResult.getProjectBasedir());
for (RuleType rule : CodeReviewInitialize.reviewResult.getRule()) {
if (rule.getResult().size() > 0) {
logger.debug("Found one non conformity : " + rule.getRule().getKey());
RuleKey ruleKey = RuleKey.of("FCCodeReviewRepository", rule.getRule().getKey());
for (Result result : rule.getResult()) {
File resourceToFind = new File(projectBasedir.getAbsolutePath() + result.getResource());
InputFile resource = fs.inputFile(fs.predicates().hasPath(projectBasedir.getAbsolutePath() + result.getResource()));
if (resource != null) {
logger.debug("Resource found : " + resourceToFind.getAbsolutePath());
Issuable issuable = perspectives.as(Issuable.class, resource);
issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).line(1).build());
} else {
logger.debug("Resource not found : " + resourceToFind.getAbsolutePath());
}
}
}
}
}
示例9: shouldExecuteOnProject
import org.sonar.api.resources.Project; //导入依赖的package包/类
@Test
public void shouldExecuteOnProject() {
Settings settings = mock(Settings.class);
RulesProfile profile = mock(RulesProfile.class);
DefaultFileSystem fileSystem = new DefaultFileSystem();
ResourcePerspectives perspectives = mock(ResourcePerspectives.class);
Project project = mock(Project.class);
ReSharperSensor sensor = new ReSharperSensor(
new ReSharperConfiguration("lang", "foo-resharper", "fooReportkey"),
settings, profile, fileSystem, perspectives);
assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
fileSystem.add(new DefaultInputFile("").setAbsolutePath("").setLanguage("foo"));
when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.<ActiveRule>of());
assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
fileSystem.add(new DefaultInputFile("").setAbsolutePath("").setLanguage("lang"));
when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.of(mock(ActiveRule.class)));
assertThat(sensor.shouldExecuteOnProject(project)).isTrue();
when(profile.getActiveRulesByRepository("foo-resharper")).thenReturn(ImmutableList.<ActiveRule>of());
assertThat(sensor.shouldExecuteOnProject(project)).isFalse();
}
示例10: getValidResource
import org.sonar.api.resources.Project; //导入依赖的package包/类
private Resource getValidResource(Project module, SensorContext context, CtcMeasure measure) {
Resource resource;
java.io.File file = measure.getSOURCE();
if (file == null) {
resource = module;
} else if (!file.exists()) {
resource = null;
} else {
LOG.debug("FileName: {}", measure.getSOURCE());
resource = File.fromIOFile(measure.getSOURCE(), module);
resource = context.getResource(resource);
if (resource == null) {
LOG.error("File not mapped to resource!");
}
}
return resource;
}
示例11: analyse
import org.sonar.api.resources.Project; //导入依赖的package包/类
public void analyse(Project project, SensorContext context) {
this.project = project;
this.context = context;
Collection<SquidAstVisitor<LexerlessGrammar>> squidChecks = annotationCheckFactory.getChecks();
List<SquidAstVisitor<LexerlessGrammar>> visitors = Lists.newArrayList(squidChecks);
//TODO: enable
visitors.add(new FileLinesVisitor(project, fileLinesContextFactory));
this.scanner = PlSQLAstScanner.create(createConfiguration(project), visitors.toArray(new SquidAstVisitor[visitors.size()]));
scanner.scanFiles(InputFileUtils.toFiles(project.getFileSystem().mainFiles(PlSQL.KEY)));
Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
save(squidSourceFiles);
}
示例12: setup
import org.sonar.api.resources.Project; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup(){
mockSession = mock(DatabaseSession.class);
mockSetting = mock(Settings.class);
mockContext = mock(DecoratorContext.class);
mockContext2 = mock(DecoratorContext.class);
project = new Project("Project test");
project.setId(1);
resource = mock(Resource.class);
when(resource.getQualifier()).thenReturn(
"NOT_" + Qualifiers.UNIT_TEST_FILE);
when(resource.getScope()).thenReturn("PRJ");
trophiesDecorator = new TrophiesDecorator(mockSession, project, mockSetting);
utsResource = mock(Resource.class);
when(utsResource.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
}
示例13: setUp
import org.sonar.api.resources.Project; //导入依赖的package包/类
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
project = new Project("test");
session = mock(DatabaseSession.class);
settings = mock(Settings.class);
scoreDecorator = new PointsDecorator(session, project, settings);
mockContext = mock(DecoratorContext.class);
mockContext2 = mock(DecoratorContext.class);
ncloc = mock(Measure.class);
classes = mock(Measure.class);
rulesCompliance = mock(Measure.class);
api = mock(Measure.class);
coverage = mock(Measure.class);
tangle = mock(Measure.class);
resource = mock(Resource.class);
when(resource.getQualifier()).thenReturn(
"NOT_" + Qualifiers.UNIT_TEST_FILE);
utsResource = mock(Resource.class);
when(utsResource.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
}
示例14: analyse
import org.sonar.api.resources.Project; //导入依赖的package包/类
public void analyse(final Project project, final SensorContext sensorContext) {
LOGGER.info("SpringSensor analyse start");
springChecks = SpringRulesRepository.createChecks(profile);
LOGGER.info("SpringSensor analyse checks.size(): " + springChecks.size());
for (InputFile inputfile : SpringPlugin.getFiles(project)) {
try {
org.sonar.api.resources.File resource = SpringProjectFileSystem.fromIOFile(inputfile, project);
if(resource != null && resource.getName().endsWith(".xml")) {
checkXmlFile(project, sensorContext, resource);
} else if(resource != null && resource.getName().endsWith(".java")) {
checkJavaFile();
}
} catch (Exception e) {
LOGGER.error("SpringSensor analyse exception", e);
}
}
LOGGER.info("SpringSensor analyse end");
}
示例15: shouldKeep
import org.sonar.api.resources.Project; //导入依赖的package包/类
private static boolean shouldKeep(Class type, Object extension, @Nullable Project project) {
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type)
|| (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class)));
if (keep && project != null && ClassUtils.isAssignable(extension.getClass(), CheckProject.class)) {
keep = ((CheckProject) extension).shouldExecuteOnProject(project);
}
return keep;
}