Search in sources :

Example 1 with BuildOutcome

use of org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome in project gradle by gradle.

the class GradleBuildComparison method compare.

public BuildComparisonResult compare(FileStore<String> fileStore, File reportDir, Map<String, String> hostAttributes) {
    String executingSourceBuildMessage = executingMessage("source", sourceBuildExecuter);
    String executingTargetBuildMessage = executingMessage("target", targetBuildExecuter);
    if (!sourceBuildExecuter.isExecutable() || !targetBuildExecuter.isExecutable()) {
        throw new GradleException(String.format("Builds must be executed with %s or newer (source: %s, target: %s)", ComparableGradleBuildExecuter.EXEC_MINIMUM_VERSION, sourceBuildExecuter.getSpec().getGradleVersion(), targetBuildExecuter.getSpec().getGradleVersion()));
    }
    Set<BuildOutcome> sourceOutcomes;
    logger.info(executingSourceBuildMessage);
    progressLogger.started(executingSourceBuildMessage);
    ProjectOutcomes sourceOutput = executeBuild(sourceBuildExecuter);
    progressLogger.progress("inspecting source build outcomes");
    GradleBuildOutcomeSetTransformer sourceOutcomeTransformer = createOutcomeSetTransformer(fileStore, SOURCE_FILESTORE_PREFIX);
    sourceOutcomes = sourceOutcomeTransformer.transform(sourceOutput);
    logger.info(executingTargetBuildMessage);
    progressLogger.progress(executingTargetBuildMessage);
    ProjectOutcomes targetOutput = executeBuild(targetBuildExecuter);
    Set<BuildOutcome> targetOutcomes;
    progressLogger.progress("inspecting target build outcomes");
    GradleBuildOutcomeSetTransformer targetOutcomeTransformer = createOutcomeSetTransformer(fileStore, TARGET_FILESTORE_PREFIX);
    targetOutcomes = targetOutcomeTransformer.transform(targetOutput);
    progressLogger.progress("comparing build outcomes");
    BuildComparisonResult result = compareBuilds(sourceOutcomes, targetOutcomes);
    writeReport(result, reportDir, fileStore, hostAttributes);
    progressLogger.completed();
    return result;
}
Also used : BuildComparisonResult(org.gradle.api.plugins.buildcomparison.compare.internal.BuildComparisonResult) GradleException(org.gradle.api.GradleException) ProjectOutcomes(org.gradle.tooling.model.internal.outcomes.ProjectOutcomes) BuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome)

Example 2 with BuildOutcome

use of org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome in project gradle by gradle.

the class BuildComparisonSpecFactory method createSpec.

public BuildComparisonSpec createSpec(Set<BuildOutcome> from, Set<BuildOutcome> to) {
    BuildComparisonSpecBuilder builder = new DefaultBuildComparisonSpecBuilder();
    Set<BuildOutcome> toCopy = new HashSet<BuildOutcome>(to);
    for (BuildOutcome fromBuildOutcome : from) {
        BuildOutcome toBuildOutcome = null;
        Class<? extends BuildOutcome> associationType = null;
        for (BuildOutcome buildOutcome : toCopy) {
            toBuildOutcome = buildOutcome;
            associationType = associator.findAssociationType(fromBuildOutcome, toBuildOutcome);
            if (associationType != null) {
                break;
            }
        }
        if (associationType == null) {
            builder.addUnassociatedFrom(fromBuildOutcome);
        } else {
            builder.associate(associationType.cast(fromBuildOutcome), associationType.cast(toBuildOutcome), (Class<BuildOutcome>) associationType);
            toCopy.remove(toBuildOutcome);
        }
    }
    for (BuildOutcome buildOutcome : toCopy) {
        builder.addUnassociatedTo(buildOutcome);
    }
    return builder.build();
}
Also used : BuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome) HashSet(java.util.HashSet)

Example 3 with BuildOutcome

use of org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome in project gradle by gradle.

the class DefaultBuildComparator method compareBuilds.

public BuildComparisonResult compareBuilds(BuildComparisonSpec spec) {
    Set<BuildOutcome> uncomparedFrom = new HashSet<BuildOutcome>(spec.getSource());
    Set<BuildOutcome> uncomparedTo = new HashSet<BuildOutcome>(spec.getTarget());
    Set<BuildOutcome> unknownFrom = new HashSet<BuildOutcome>();
    Set<BuildOutcome> unknownTo = new HashSet<BuildOutcome>();
    List<BuildOutcomeComparisonResult<?>> results = new LinkedList<BuildOutcomeComparisonResult<?>>();
    for (BuildOutcomeAssociation<? extends BuildOutcome> outcomeAssociation : spec.getOutcomeAssociations()) {
        BuildOutcome from = outcomeAssociation.getSource();
        boolean unknown = false;
        if (!uncomparedFrom.remove(from)) {
            unknown = true;
            unknownFrom.add(from);
        }
        BuildOutcome to = outcomeAssociation.getTarget();
        if (!uncomparedTo.remove(to)) {
            unknown = true;
            unknownTo.add(to);
        }
        // TODO - error if there are unknowns?
        if (!unknown) {
            BuildOutcomeComparator<?, ?> comparator = comparatorFactory.getComparator(outcomeAssociation.getType());
            if (comparator == null) {
                // TODO - better exception
                throw new RuntimeException(String.format("No comparator for %s", outcomeAssociation.getType()));
            }
            @SuppressWarnings("unchecked") BuildOutcomeComparisonResult<?> comparisonResult = comparator.compare((BuildOutcomeAssociation) outcomeAssociation);
            results.add(comparisonResult);
        }
    }
    return new BuildComparisonResult(uncomparedFrom, uncomparedTo, results);
}
Also used : BuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 4 with BuildOutcome

use of org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome in project gradle by gradle.

the class GradleBuildOutcomeSetTransformer method addFileBuildOutcome.

private void addFileBuildOutcome(GradleFileBuildOutcome outcome, ProjectOutcomes rootProject, Set<BuildOutcome> translatedOutcomes) {
    if (zipArchiveTypes.contains(outcome.getTypeIdentifier())) {
        File originalFile = outcome.getFile();
        String relativePath = GFileUtils.relativePath(rootProject.getProjectDirectory(), originalFile);
        LocallyAvailableResource resource = null;
        if (originalFile.exists()) {
            String filestoreDestination = fileStorePrefix + "/" + outcome.getTaskPath() + "/" + originalFile.getName();
            resource = fileStore.move(filestoreDestination, originalFile);
        }
        BuildOutcome buildOutcome = new GeneratedArchiveBuildOutcome(outcome.getTaskPath(), outcome.getDescription(), resource, relativePath);
        translatedOutcomes.add(buildOutcome);
    } else {
        String outcomeName = outcome.getTaskPath();
        if (isEmpty(outcomeName)) {
            outcomeName = GFileUtils.relativePath(rootProject.getProjectDirectory(), outcome.getFile());
        }
        translatedOutcomes.add(new UnknownBuildOutcome(outcomeName, outcome.getDescription()));
    }
}
Also used : LocallyAvailableResource(org.gradle.internal.resource.local.LocallyAvailableResource) GeneratedArchiveBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome) UnknownBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome) File(java.io.File) GeneratedArchiveBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome) GradleBuildOutcome(org.gradle.tooling.model.internal.outcomes.GradleBuildOutcome) UnknownBuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome) BuildOutcome(org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome) GradleFileBuildOutcome(org.gradle.tooling.model.internal.outcomes.GradleFileBuildOutcome)

Aggregations

BuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.BuildOutcome)4 HashSet (java.util.HashSet)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 GradleException (org.gradle.api.GradleException)1 BuildComparisonResult (org.gradle.api.plugins.buildcomparison.compare.internal.BuildComparisonResult)1 GeneratedArchiveBuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcome)1 UnknownBuildOutcome (org.gradle.api.plugins.buildcomparison.outcome.internal.unknown.UnknownBuildOutcome)1 LocallyAvailableResource (org.gradle.internal.resource.local.LocallyAvailableResource)1 GradleBuildOutcome (org.gradle.tooling.model.internal.outcomes.GradleBuildOutcome)1 GradleFileBuildOutcome (org.gradle.tooling.model.internal.outcomes.GradleFileBuildOutcome)1 ProjectOutcomes (org.gradle.tooling.model.internal.outcomes.ProjectOutcomes)1