jetbrains.buildServer.serverSide.artifacts.BuildArtifact Java Examples

The following examples show how to use jetbrains.buildServer.serverSide.artifacts.BuildArtifact. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloadSymbolsController.java    From teamcity-symbol-server with Apache License 2.0 6 votes vote down vote up
@Nullable
private BuildArtifact findArtifact(@NotNull BuildMetadataEntry entry) {
  final Map<String,String> metadata = entry.getMetadata();
  final String storedArtifactPath = metadata.get(BuildSymbolsIndexProvider.ARTIFACT_PATH_KEY);
  if(storedArtifactPath == null){
    LOG.debug(String.format("Metadata stored for guid '%s' is invalid.", entry.getKey()));
    return null;
  }

  final long buildId = entry.getBuildId();
  final SBuild build = myServer.findBuildInstanceById(buildId);
  if(build == null){
    LOG.debug(String.format("Build not found by id %d.", buildId));
    return null;
  }
  final BuildArtifact buildArtifact = build.getArtifacts(BuildArtifactsViewMode.VIEW_ALL_WITH_ARCHIVES_CONTENT).getArtifact(storedArtifactPath);
  if(buildArtifact == null){
    LOG.debug(String.format("Artifact not found by path %s for build with id %d.", storedArtifactPath, buildId));
  }
  return buildArtifact;
}
 
Example #2
Source File: BuildSummaryLinkExtension.java    From TeamCity.SonarQubePlugin with Apache License 2.0 6 votes vote down vote up
@Override
public void fillModel(@NotNull final Map<String, Object> model,
                      @NotNull final HttpServletRequest request) {
    final SBuild build = BuildDataExtensionUtil.retrieveBuild(request, myServer);
    if (build == null) {
        return;
    }

    final BuildArtifact artifact = build.getArtifacts(BuildArtifactsViewMode.VIEW_HIDDEN_ONLY).getArtifact(Constants.SONAR_SERVER_URL_ARTIF_LOCATION_FULL);
    if (artifact == null) {
        model.put("sonar_noArtifact", Boolean.TRUE);
        return;
    }

    if (artifact.getSize() > ABSOLUTE_FILESIZE_THRESHOLD) {
        model.put("sonar_bigUrlFile", artifact.getSize());
    } else {
        try {
            model.put("sonar_url", readUrl(artifact));
        } catch (IOException e) {
            model.put("sonar_IOException", e);
        }
    }
    super.fillModel(model, request);
}
 
Example #3
Source File: AllureReportBuildSummaryExtension.java    From allure-teamcity with Apache License 2.0 6 votes vote down vote up
@Override
public void fillModel(@NotNull final Map<String, Object> model, @NotNull final HttpServletRequest request) {
    final SBuild build = BuildDataExtensionUtil.retrieveBuild(request, server);
    if (Objects.isNull(build)) {
        return;
    }
    final BuildArtifact artifact = build.getArtifacts(BuildArtifactsViewMode.VIEW_HIDDEN_ONLY)
            .getArtifact(AllureConstants.ALLURE_ARTIFACT_SUMMARY_LOCATION);
    if (Objects.isNull(artifact)) {
        return;
    }

    try {
        final AllureReportSummary summary = readSummary(artifact);
        model.put("allure_summary", summary);
    } catch (IOException e) {
        model.put("allure_error", e.getMessage());
    }
}
 
Example #4
Source File: BuildSummaryLinkExtension.java    From TeamCity.SonarQubePlugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private String readUrl(BuildArtifact artifact) throws IOException {
    String url;InputStream inputStream = null;
    try {
        inputStream = artifact.getInputStream();
        url = readUrlFromStream(inputStream);
    } finally {
        Util.close(inputStream);
    }
    return url;
}
 
Example #5
Source File: AllureReportBuildSummaryExtension.java    From allure-teamcity with Apache License 2.0 5 votes vote down vote up
public boolean isAvailable(@NotNull final HttpServletRequest request) {
    final SBuild build = BuildDataExtensionUtil.retrieveBuild(request, server);
    if (Objects.isNull(build)) {
        return false;
    }
    final BuildArtifact artifact = build.getArtifacts(BuildArtifactsViewMode.VIEW_HIDDEN_ONLY)
            .getArtifact(AllureConstants.ALLURE_ARTIFACT_SUMMARY_LOCATION);
    return Objects.nonNull(artifact);
}
 
Example #6
Source File: AllureReportBuildSummaryExtension.java    From allure-teamcity with Apache License 2.0 5 votes vote down vote up
private static AllureReportSummary readSummary(BuildArtifact artifact) throws IOException {
    try (InputStream inputStream = artifact.getInputStream()) {
        String summaryJson = IOUtils.toString(inputStream);
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(summaryJson, AllureReportSummary.class);
    }
}
 
Example #7
Source File: BuildSymbolsIndexProvider.java    From teamcity-symbol-server with Apache License 2.0 4 votes vote down vote up
public void generateMedatadata(@NotNull SBuild sBuild, @NotNull MetadataStorageWriter metadataStorageWriter) {
  final BuildArtifact symbols = sBuild.getArtifacts(BuildArtifactsViewMode.VIEW_HIDDEN_ONLY).getArtifact(".teamcity/symbols");
  final long buildId = sBuild.getBuildId();
  final Set<String> processedSymbols = new HashSet<>();
  if(symbols != null){
    for (BuildArtifact symbolSignaturesSource : symbols.getChildren()){
      if (!symbolSignaturesSource.getName().startsWith(SymbolsConstants.SYMBOL_SIGNATURES_FILE_NAME_PREFIX) &&
          !symbolSignaturesSource.getName().startsWith(SymbolsConstants.BINARY_SIGNATURES_FILE_NAME_PREFIX))
        continue;

      final Set<PdbSignatureIndexEntry> indexEntries;
      try {
        indexEntries = PdbSignatureIndexUtil.read(symbolSignaturesSource.getInputStream(), false);
      } catch (Exception e) {
        LOG.warnAndDebugDetails(String.format(
          "Failed to read symbols index file %s of build %s",
          symbolSignaturesSource.getRelativePath(), LogUtil.describe(sBuild)), e);
        continue;
      }

      LOG.debug(String.format("Build with id %d provides %d symbol file signatures.", buildId, indexEntries.size()));

      for (final PdbSignatureIndexEntry indexEntry : indexEntries) {
        final String signature = indexEntry.getGuid();
        final String fileName = indexEntry.getFileName();
        final String metadataKey = getMetadataKey(signature, fileName);

        if (processedSymbols.contains(metadataKey)) continue;

        String artifactPath = indexEntry.getArtifactPath();
        if(artifactPath == null){
          LOG.debug(String.format("Artifact path is not provided for artifact %s, locating it by name in build %s artifacts.", fileName, LogUtil.describe(sBuild)));
          artifactPath = locateArtifact(sBuild, fileName);
          if(artifactPath != null){
            LOG.debug(String.format("Located artifact by name %s, path - %s. Build - %s", fileName, artifactPath, LogUtil.describe(sBuild)));
          }
        }

        LOG.info(String.format(
          "Indexing symbol file %s with signature %s of build %s", fileName, signature, LogUtil.describe(sBuild)
        ));
        final HashMap<String, String> data = new HashMap<>();
        data.put(SIGNATURE_KEY, signature);
        data.put(FILE_NAME_KEY, fileName);
        data.put(ARTIFACT_PATH_KEY, artifactPath);

        metadataStorageWriter.addParameters(metadataKey, data);
        mySymbolsCache.removeEntry(metadataKey);
        processedSymbols.add(metadataKey);
      }
    }
  }
  if (processedSymbols.isEmpty()) {
    LOG.debug("Build with id " + buildId + " doesn't provide symbols index data.");
  }
}