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


Java JsonWriter类代码示例

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


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

示例1: handle

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
@Override
public void handle(final Request request, final Response response) {
	LOGGER.info("Handle issueresolver import request ...");
	final ImportResult importResult = new ImportResult();

	// Read issue data from request
	final Map<IssueKey, IssueData> issues = readIssues(request, importResult);
	LOGGER.info("Read " + importResult.getIssues() + " issues (having " + importResult.getDuplicateKeys()
			+ " duplicate keys)");

	IssueHelper.resolveIssues(request.localConnector(), importResult,
			request.mandatoryParamAsBoolean(PARAM_PREVIEW), request.mandatoryParamAsBoolean(PARAM_SKIP_ASSIGN),
			request.mandatoryParamAsBoolean(PARAM_SKIP_COMMENTS), request.mandatoryParam(PARAM_PROJECT_KEY),
			issues);

	// Sent result
	final JsonWriter responseWriter = response.newJsonWriter();
	importResult.write(responseWriter);
	responseWriter.close();
	LOGGER.debug("Issueresolver import request done");
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:22,代码来源:ImportAction.java

示例2: handle

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
@Override
public void handle(final Request request, final Response response) {
	LOGGER.debug("Handle issueresolver export request");
	response.setHeader("Content-Disposition", "attachment; filename=\"resolved-issues.json\"");

	final JsonWriter responseWriter = response.newJsonWriter();
	writeStart(responseWriter);

	IssueHelper.forEachIssue(request.localConnector(),
			SearchHelper.findIssuesForExport(request.mandatoryParam(PARAM_PROJECT_KEY)), (searchIssuesResponse,
					issue) -> writeIssue(responseWriter, issue, searchIssuesResponse.getComponentsList()));

	writeEnd(responseWriter);
	responseWriter.close();
	LOGGER.debug("Issueresolver export request done");
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:17,代码来源:ExportAction.java

示例3: writeTo

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
void writeTo(HttpServletResponse resp) throws IOException {
  try (ServletOutputStream outputStream = resp.getOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(outputStream, UTF_8);
    JsonWriter json = JsonWriter.of(writer)) {
    json.beginObject();
    json.prop("code", code);
    writePagination(json);
    writeIssues(json);
    writeStore(json);
    writeHighlightings(json);
    writeSymbolRefs(json);
    writeErrors(json);
    json.endObject();
  }
  resp.setStatus(200);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:17,代码来源:ResponseMessage.java

示例4: writeIssues

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writeIssues(JsonWriter json) {
  json.name("issues");
  json.beginArray();
  for (Issue issue : analyzerResult.issues()) {
    json.beginObject();
    json.prop("rule", issue.getRuleKey());
    json.prop("severity", issue.getSeverity());
    json.prop("message", issue.getMessage());
    json.prop("type", issue.getType());

    json.name("textRange")
      .beginObject()
      .prop("startLine", issue.getStartLine())
      .prop("endLine", issue.getEndLine())
      .prop("startOffset", issue.getStartLineOffset())
      .prop("endOffset", issue.getEndLineOffset())
      .endObject();

    json.endObject();
  }
  json.endArray();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:23,代码来源:ResponseMessage.java

示例5: writeSymbolRefs

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writeSymbolRefs(JsonWriter json) {
  json.name("symbolRefs");
  json.beginArray();
  for (Map.Entry<TextRange, Set<TextRange>> entry : analyzerResult.symbolRefs().entrySet()) {
    json.beginObject();

    json.name("symbol").beginObject();
    appendRange(json, entry.getKey());
    json.endObject();

    json.name("locations").beginArray();
    for (TextRange range : entry.getValue()) {
      json.beginObject();
      appendRange(json, range);
      json.endObject();
    }
    json.endArray();

    json.endObject();
  }
  json.endArray();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:23,代码来源:ResponseMessage.java

示例6: writeIssue

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writeIssue(final JsonWriter writer, final Issue issue, List<Component> components) {
	writer.beginObject();

	final IssueKey key = IssueKey.fromIssue(issue, components);
	key.write(writer);

	final IssueData data = IssueData.fromIssue(issue);
	data.write(writer);

	writer.endObject();
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:12,代码来源:ExportAction.java

示例7: handle

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
@Override
public void handle(final Request request, final Response response) {
	LOGGER.info("Handle issueresolver update request ...");
	final ImportResult importResult = new ImportResult();

	// Read issues from project
	final Map<IssueKey, IssueData> issues = new HashMap<>();
	IssueHelper.forEachIssue(request.localConnector(),
			SearchHelper.findIssuesForExport(request.mandatoryParam(PARAM_FROM_PROJECT_KEY)),
			(searchIssuesResponse, issue) -> {
				issues.put(IssueKey.fromIssue(issue, searchIssuesResponse.getComponentsList()),
						IssueData.fromIssue(issue));
				importResult.registerIssue();
			});
	LOGGER.info("Read " + importResult.getIssues() + " issues");

	IssueHelper.resolveIssues(request.localConnector(), importResult,
			request.mandatoryParamAsBoolean(PARAM_PREVIEW), request.mandatoryParamAsBoolean(PARAM_SKIP_ASSIGN),
			request.mandatoryParamAsBoolean(PARAM_SKIP_COMMENTS), request.mandatoryParam(PARAM_PROJECT_KEY),
			issues);

	// Sent result
	final JsonWriter responseWriter = response.newJsonWriter();
	importResult.write(responseWriter);
	responseWriter.close();
	LOGGER.debug("Issueresolver update request done");
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:28,代码来源:UpdateAction.java

示例8: write

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
public void write(final JsonWriter writer) {
	writer.beginObject();
	writer.prop("preview", preview);
	writer.prop("issues", issues);
	writer.prop("duplicateKeys", duplicateKeys);
	writer.prop("matchedIssues", matchedIssues);
	writer.name("matchFailures");
	writer.beginArray();
	writer.values(matchFailures);
	writer.endArray();		
	writer.prop("transitionedIssues", transitionedIssues);
	writer.name("transitionFailures");
	writer.beginArray();
	writer.values(transitionFailures);
	writer.endArray();
	writer.prop("assignedIssues", assignedIssues);
	writer.name("assignFailures");
	writer.beginArray();
	writer.values(assignFailures);
	writer.endArray();
	writer.prop("commentedIssues", commentedIssues);
	writer.name("commentFailures");
	writer.beginArray();
	writer.values(commentFailures);
	writer.endArray();
	writer.endObject();
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:28,代码来源:ImportResult.java

示例9: write

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
/**
 * Write data to export data.
 * 
 * @param writer
 *            json writer
 */
public void write(final JsonWriter writer) {
	writer.prop(NAME_STATUS, status);
	writer.prop(NAME_RESOLUTION, resolution);
	writer.prop(NAME_ASSIGNEE, assignee);

	writer.name(NAME_COMMENTS);
	writer.beginArray();
	writer.values(comments);
	writer.endArray();
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:17,代码来源:IssueData.java

示例10: test

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
@Test
public void test() throws IOException {
	final Issue issue = ReflectionTestUtils.build(Issue.class, "status_", "RESOLVED", "resolution_", "FALSE-POSITIVE",
			"assignee_", "admin", "comments_",
			ReflectionTestUtils.build(Comments.class, "comments_",
					Arrays.asList(ReflectionTestUtils.build(Comment.class, "markdown_", "Comment one"),
							ReflectionTestUtils.build(Comment.class, "markdown_", "Comment two"))));

	final IssueData data = IssueData.fromIssue(issue);
	Assert.assertEquals("RESOLVED", data.getStatus());
	Assert.assertEquals("FALSE-POSITIVE", data.getResolution());
	Assert.assertEquals("admin", data.getAssignee());
	Assert.assertEquals(Arrays.asList("Comment one", "Comment two"), data.getComments());

	final String json;
	try (final StringWriter writer = new StringWriter()) {
		final JsonWriter jsonWriter = JsonWriter.of(writer);
		jsonWriter.beginObject();
		data.write(jsonWriter);
		jsonWriter.endObject();
		jsonWriter.close();

		json = writer.toString();
	}
	Assert.assertEquals("{\"status\":\"RESOLVED\",\"resolution\":\"FALSE-POSITIVE\",\"assignee\":\"admin\",\"comments\":[\"Comment one\",\"Comment two\"]}", json);

	final IssueData readData;
	try (final ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8"));
			final JsonReader reader = new JsonReader(bais)) {
		reader.beginObject();
		readData = IssueData.read(reader);
		reader.endObject();
	}
	
	Assert.assertEquals("RESOLVED", readData.getStatus());
	Assert.assertEquals("FALSE-POSITIVE", readData.getResolution());
	Assert.assertEquals("admin", readData.getAssignee());
	Assert.assertEquals(Arrays.asList("Comment one", "Comment two"), readData.getComments());
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:40,代码来源:IssueDataTest.java

示例11: test

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
@Test
public void test() throws IOException {
	final Issue issue = ReflectionTestUtils.build(Issue.class, "rule_", "test:rule001", "component_",
			"nl.future-edge.sonarqube.plugins:sonar-issueresolver-plugin:src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java",
			"textRange_", ReflectionTestUtils.build(TextRange.class, "startLine_", 13, "startOffset_", 65));
	final Component component = ReflectionTestUtils.build(Component.class, "key_", "nl.future-edge.sonarqube.plugins:sonar-issueresolver-plugin:src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java",
		"longName_", "src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java");
	final List<Component> components = Arrays.asList(component);

	final IssueKey key = IssueKey.fromIssue(issue, components);

	final String json;
	try (final StringWriter writer = new StringWriter()) {
		final JsonWriter jsonWriter = JsonWriter.of(writer);
		jsonWriter.beginObject();
		key.write(jsonWriter);
		jsonWriter.endObject();
		jsonWriter.close();

		json = writer.toString();
	}
	Assert.assertEquals(
			"{\"longName\":\"src/main/java/nl/futureedge/sonar/plugin/issueresolver/issues/IssueKey.java\",\"rule\":\"test:rule001\",\"line\":13}",
			json);

	final IssueKey readKey;
	try (final ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8"));
			final JsonReader reader = new JsonReader(bais)) {
		reader.beginObject();
		readKey = IssueKey.read(reader);
		reader.endObject();
	}

	Assert.assertEquals(key.hashCode(), readKey.hashCode());
	Assert.assertEquals(key, readKey);
	Assert.assertFalse(key.equals(null));
	Assert.assertTrue(key.equals(key));
	Assert.assertFalse(key.equals(new Object()));
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:40,代码来源:IssueKeyTest.java

示例12: writePagination

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writePagination(JsonWriter json) {
  int issueCount = analyzerResult.issues().size();
  json.prop("total", issueCount);
  json.prop("p", 1);
  json.prop("ps", issueCount);
  json.name("paging")
    .beginObject()
    .prop("pageIndex", 1)
    .prop("pageSize", issueCount)
    .prop("total", issueCount)
    .endObject();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:13,代码来源:ResponseMessage.java

示例13: writeStore

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writeStore(JsonWriter json) {
  if (languageVersion != null) {
    json.prop("languageVersion", languageVersion);
  }
  if (storedAs != null) {
    json.prop("storedAs", storedAs);
  }
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:9,代码来源:ResponseMessage.java

示例14: appendRange

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void appendRange(JsonWriter json, TextRange range) {
  TextPointer start = range.start();
  TextPointer end = range.end();
  json.prop("startLine", start.line())
    .prop("endLine", end.line())
    .prop("startOffset", start.lineOffset())
    .prop("endOffset", end.lineOffset());
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:9,代码来源:ResponseMessage.java

示例15: writeHighlightings

import org.sonar.api.utils.text.JsonWriter; //导入依赖的package包/类
private void writeHighlightings(JsonWriter json) {
  json.name("highlightings");
  json.beginArray();
  for (Highlighting highlighting : analyzerResult.highlightings()) {
    json.beginObject()
      .prop("type", highlighting.type().name())
      .prop("cssClass", highlighting.type().cssClass());
    appendRange(json, highlighting.textRange());
    json.endObject();
  }
  json.endArray();
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:13,代码来源:ResponseMessage.java


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