当前位置: 首页>>代码示例>>Java>>正文


Java Resource类代码示例

本文整理汇总了Java中org.sonar.api.resources.Resource的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Resource类属于org.sonar.api.resources包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addIssue

import org.sonar.api.resources.Resource; //导入依赖的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());
  }
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:19,代码来源:CoverageSensor.java

示例2: testComputeEffectiveKey

import org.sonar.api.resources.Resource; //导入依赖的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)
  );
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:24,代码来源:CoverageUtilsTest.java

示例3: testGetMeasureValue

import org.sonar.api.resources.Resource; //导入依赖的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
  );
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:25,代码来源:DefaultSonarClientTest.java

示例4: decorate

import org.sonar.api.resources.Resource; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void decorate(Resource resource, DecoratorContext context) {
  if (resource.getScope().equals(Scopes.FILE)) {
    Map lineHits = new HashMap<Integer, Integer>();
    context.saveMeasure(CoreMetrics.LINES_TO_COVER, context.getMeasure(CoreMetrics.LINES).getValue());
    context.saveMeasure(CoreMetrics.UNCOVERED_LINES, 0.0);

    for (int i = 1; i <= context.getMeasure(CoreMetrics.LINES).getIntValue(); i++) {
      lineHits.put(i, 1);
    }
    context.saveMeasure(new Measure(CoreMetrics.COVERAGE_LINE_HITS_DATA).setData(KeyValueFormat.format(lineHits)).setPersistenceMode(PersistenceMode.DATABASE));
  }

  for (Metric[] entry : CONV) {

    applyAndSaveMeasure(entry, context, resource);

  }
}
 
开发者ID:Londran,项目名称:sonar-ctc,代码行数:21,代码来源:CtcCoreMetricDecorator.java

示例5: getValidResource

import org.sonar.api.resources.Resource; //导入依赖的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;
  }
 
开发者ID:Londran,项目名称:sonar-ctc,代码行数:22,代码来源:CtcSensor.java

示例6: whenDecorateIsInvokedThenAllViolationsShouldBeProcessed

import org.sonar.api.resources.Resource; //导入依赖的package包/类
@Test
public void whenDecorateIsInvokedThenAllViolationsShouldBeProcessed() {

  int count = 10;

  DecoratorContext context = mock(DecoratorContext.class);
  Resource resource = mock(Resource.class);
  configureProject("Java");

  List<Issue> issues = new ArrayList<Issue>();
  for (int i = 0; i < count; i++) {
    issues.add(createIssue("", DebtProcessorFactory.MISSING_SWITCH_DEFAULT_CHECK_STYLE, ""));
  }

  Issuable issuable = mock(Issuable.class);
  when(issuable.issues()).thenReturn(issues);

  when(perspectivesMock.as(Issuable.class, resource)).thenReturn(issuable);

  decorator.decorate(resource, context);
}
 
开发者ID:cezarcoca,项目名称:sonar-toxicity-chart,代码行数:22,代码来源:ToxicityChartDecoratorTest.java

示例7: pointsAreDisabled

import org.sonar.api.resources.Resource; //导入依赖的package包/类
/**
 * Checks to see if point earning is disabled for this project or globally.
 * @return
 */
private boolean pointsAreDisabled(@SuppressWarnings("rawtypes") Resource resource) {
	boolean disabled = false;
	Property projectProperty = propertyDao.getForResource(PropertyDao.POINTS_DISABLED, project);
	Property globalProperty = propertyDao.getForGlobal(PropertyDao.POINTS_DISABLED);
	if(projectProperty == null) {
		if(globalProperty == null) {
			return false;
		} else {
			disabled = globalProperty.getValue().equals(Boolean.toString(true));
			return disabled;
		}
	} else {
		disabled = projectProperty.getValue().equals(true);
		return disabled;
	}
}
 
开发者ID:CatalystIT,项目名称:sonar-score-plugin,代码行数:21,代码来源:PointsDecorator.java

示例8: setup

import org.sonar.api.resources.Resource; //导入依赖的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);	
}
 
开发者ID:CatalystIT,项目名称:sonar-score-plugin,代码行数:20,代码来源:TrophiesDecoratorTest.java

示例9: setUp

import org.sonar.api.resources.Resource; //导入依赖的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);
}
 
开发者ID:CatalystIT,项目名称:sonar-score-plugin,代码行数:24,代码来源:PointsDecoratorTest.java

示例10: fetchMeasure

import org.sonar.api.resources.Resource; //导入依赖的package包/类
private Integer fetchMeasure(SensorContext context, Resource resource, Metric<Integer> metric) {
  Measure<Integer> measure = context.getMeasure(resource, metric);
  if (measure != null) {
    return measure.value();
  }
  LOGGER.warn("Could not retrieve measure of {} for {}", metric.getKey(), resource);
  return null;
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:9,代码来源:CoverageSensor.java

示例11: analyseFile

import org.sonar.api.resources.Resource; //导入依赖的package包/类
private void analyseFile(Project module, SensorContext context, InputFile file) {
  Integer linesToCover = null;
  Integer uncoveredLines = null;

  Resource fileResource = context.getResource(file);
  linesToCover = fetchMeasure(context, fileResource, CoreMetrics.LINES_TO_COVER);
  uncoveredLines = fetchMeasure(context, fileResource, CoreMetrics.UNCOVERED_LINES);

  // get lines_to_cover, uncovered_lines
  if ((linesToCover != null) && (uncoveredLines != null)) {
    Double previousCoverage = sonar.getMeasureValue(module, fileResource, CoreMetrics.LINE_COVERAGE);

    double coverage = calculateCoverage(linesToCover, uncoveredLines);

    coverageProjectStore.updateMeasurements(linesToCover, uncoveredLines);

    if (previousCoverage == null) {
      return;
    }

    // The API returns the coverage rounded.
    // So we can only report anything if the rounded value has changed,
    // otherwise we could report false positives.
    LOGGER.debug("Previous/current file coverage on {}: {} / {}",
        fileResource.getPath(), previousCoverage, coverage);
    if (roundedPercentageGreaterThan(previousCoverage, coverage)) {
      addIssue(file, coverage, previousCoverage);
    }
  }
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:31,代码来源:CoverageSensor.java

示例12: setUp

import org.sonar.api.resources.Resource; //导入依赖的package包/类
@Before
public void setUp() {
  project = new Project("foo:bar");
  settings.setProperty("sonar.scanAllFiles", true);

  when(rp.as(eq(Issuable.class), any(Resource.class))).thenReturn(issuable);
  when(rp.as(eq(Issuable.class), any(InputFile.class))).thenReturn(issuable);
  Issuable.IssueBuilder issueBuilder = mock(Issuable.IssueBuilder.class, Answers.RETURNS_SELF);
  when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:11,代码来源:CoverageSensorTest.java

示例13: mockFileCoverages

import org.sonar.api.resources.Resource; //导入依赖的package包/类
private static void mockFileCoverages(
    SensorContext context, SonarClient client,
    InputFile file, Project module,
    int newLinesToCover, int newUncoveredLines,
    int oldLinesToCover, int oldUncoveredLines
) {
  Resource resource = new org.sonar.api.resources.File(file.relativePath());
  when(context.getResource(eq(file))).thenReturn(resource);

  mockPreviousCoverage(client, module, resource, oldLinesToCover, oldUncoveredLines);
  mockCurrentCoverage(context, resource, newLinesToCover, newUncoveredLines);
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:13,代码来源:CoverageSensorTest.java

示例14: mockPreviousCoverage

import org.sonar.api.resources.Resource; //导入依赖的package包/类
private static void mockPreviousCoverage(
    SonarClient client,
    Project module, Resource resource,
    int linesToCover, int uncoveredLines
) {
  double coverage = CoverageUtils.calculateCoverage(linesToCover, uncoveredLines);
  when(client.getMeasureValue(eq(module), eq(resource), eq(CoreMetrics.LINE_COVERAGE))).thenReturn(
      coverage
  );
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:11,代码来源:CoverageSensorTest.java

示例15: mockCurrentCoverage

import org.sonar.api.resources.Resource; //导入依赖的package包/类
private static void mockCurrentCoverage(
    SensorContext context, Resource resource,
    int linesToCover, int uncoveredLines
) {
  double coverage = CoverageUtils.calculateCoverage(linesToCover, uncoveredLines);
  when(context.getMeasure(eq(resource), eq(CoreMetrics.LINES_TO_COVER)))
      .thenReturn(new Measure<>(CoreMetrics.LINES_TO_COVER, (double) linesToCover));
  when(context.getMeasure(eq(resource), eq(CoreMetrics.UNCOVERED_LINES)))
      .thenReturn(new Measure<>(CoreMetrics.UNCOVERED_LINES, (double) uncoveredLines));
  when(context.getMeasure(eq(resource), eq(CoreMetrics.LINE_COVERAGE)))
      .thenReturn(new Measure<>(CoreMetrics.LINE_COVERAGE, coverage));
}
 
开发者ID:AmadeusITGroup,项目名称:sonar-coverage-evolution,代码行数:13,代码来源:CoverageSensorTest.java


注:本文中的org.sonar.api.resources.Resource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。