Skip to content

Commit

Permalink
фdd more logging to the artifacts processing code (via #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
smecsia authored and eroshenkoam committed Mar 5, 2019
1 parent aaacedf commit a2c1c5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/main/java/io/qameta/allure/bamboo/AllureArtifactsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
import com.atlassian.sal.api.UrlMode;
import com.google.common.collect.ImmutableList;

import org.apache.log4j.Logger;
import org.apache.tools.ant.types.FileSet;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import javax.ws.rs.core.UriBuilder;
Expand Down Expand Up @@ -70,6 +71,8 @@
import static io.qameta.allure.bamboo.AllureBuildResult.fromCustomData;
import static io.qameta.allure.bamboo.util.ExceptionUtil.stackTraceToString;
import static java.lang.Integer.parseInt;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;
import static javax.ws.rs.core.UriBuilder.fromPath;
Expand All @@ -81,7 +84,7 @@
import static org.codehaus.plexus.util.FileUtils.copyURLToFile;

public class AllureArtifactsManager {
private static final Logger LOGGER = Logger.getLogger(AllureArtifactsManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AllureArtifactsManager.class);
private static final String REPORTS_SUBDIR = "allure-reports";

private final PluginAccessor pluginAccessor;
Expand Down Expand Up @@ -138,12 +141,11 @@ Optional<String> getArtifactUrl(final String planKeyString, final String buildNu
}

@Nullable
private String getLocalStorageURL(String planKeyString, String buildNumber, String filePath) {
private String getLocalStorageURL(String planKeyString, String buildNumber, String filePath) {
try {
final File file = getLocalStoragePath(planKeyString, buildNumber).resolve(filePath).toFile();
final String fullPath = (file.isDirectory()) ? new File(file, "index.html").getAbsolutePath() : file.getAbsolutePath();
return new File(fullPath).toURI().toURL().toString();

} catch (MalformedURLException e) {
// should never happen
throw new RuntimeException(e);
Expand All @@ -162,9 +164,15 @@ Collection<Path> downloadAllArtifactsTo(@NotNull ChainResultsSummary chainResult
final List<Path> resultsPaths = new ArrayList<>();
for (ChainStageResult stageResult : chainResultsSummary.getStageResults()) {
for (BuildResultsSummary resultsSummary : stageResult.getBuildResults()) {
for (ArtifactLink link : resultsSummary.getArtifactLinks()) {
LOGGER.info("Found {} artifacts totally for the build {}-{}",
of(resultsSummary.getProducedArtifactLinks()).map(Collection::size).orElse(0),
chainResultsSummary.getPlanKey(), chainResultsSummary.getBuildNumber());
for (ArtifactLink link : resultsSummary.getProducedArtifactLinks()) {
final MutableArtifact artifact = link.getArtifact();
if (isEmpty(artifactName) || artifactName.equals(artifact.getLabel())) {
LOGGER.info("artifact {} matches the configured artifact name {} for the build {}-{}",
artifact.getLabel(), artifactName,
chainResultsSummary.getPlanKey(), chainResultsSummary.getBuildNumber());
final File stageDir = new File(baseDir, UUID.randomUUID().toString());
forceMkdir(stageDir);
resultsPaths.add(stageDir.toPath());
Expand Down Expand Up @@ -194,7 +202,8 @@ Optional<AllureBuildResult> uploadReportArtifacts(@NotNull Chain chain, @NotNull
final ArtifactDefinitionContextImpl artifact = getAllureArtifactDef();
artifact.setLocation("");
final FileSet sourceFileSet;
sourceFileSet = ArtifactHandlingUtils.createFileSet(reportDir, artifact, true, LOGGER);
sourceFileSet = ArtifactHandlingUtils.createFileSet(reportDir, artifact, true,
org.apache.log4j.Logger.getLogger(getClass()));
sourceFileSet.setDir(reportDir);
sourceFileSet.setIncludes(artifact.getCopyPattern());
final Map<String, String> artifactConfig = getArtifactHandlersConfig(chain.getBuildDefinition());
Expand Down Expand Up @@ -248,7 +257,7 @@ private Path getLocalStoragePath(String planKey, String buildNumber) {
}

private void downloadAllArtifactsTo(ArtifactLinkDataProvider dataProvider, File tempDir, String startFrom) {
for (ArtifactFileData data : dataProvider.listObjects(startFrom)) {
for (ArtifactFileData data : requireNonNull(dataProvider).listObjects(startFrom)) {
try {
if (data instanceof TrampolineArtifactFileData) {
final TrampolineArtifactFileData trampolineData = (TrampolineArtifactFileData) data;
Expand Down Expand Up @@ -315,7 +324,6 @@ private String getArtifactFile(String filePath, ArtifactLinkDataProvider linkPro
private String getBambooArtifactUrl(ArtifactFileData data) {
return ofNullable(data.getUrl()).map(url -> (url.startsWith("/")) ?
getBaseUrl().path(url).build().toString() : url)
.map(url -> url)
.orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.atlassian.bamboo.plan.PlanResultKey;
import com.atlassian.bamboo.resultsummary.ResultsSummary;
import com.atlassian.bamboo.resultsummary.ResultsSummaryManager;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -13,10 +12,10 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down

0 comments on commit a2c1c5e

Please sign in to comment.