Search in sources :

Example 1 with BaseProblem

use of org.gradle.problems.BaseProblem in project gradle by gradle.

the class ValidateStep method execute.

@Override
public R execute(UnitOfWork work, C context) {
    WorkValidationContext validationContext = context.getValidationContext();
    work.validate(validationContext);
    context.getBeforeExecutionState().ifPresent(beforeExecutionState -> validateImplementations(work, beforeExecutionState, validationContext));
    Map<Severity, List<String>> problems = validationContext.getProblems().stream().collect(groupingBy(BaseProblem::getSeverity, mapping(ValidateStep::renderedMessage, toList())));
    ImmutableCollection<String> warnings = ImmutableList.copyOf(problems.getOrDefault(Severity.WARNING, ImmutableList.of()));
    ImmutableCollection<String> errors = ImmutableList.copyOf(problems.getOrDefault(Severity.ERROR, ImmutableList.of()));
    if (!warnings.isEmpty()) {
        warningReporter.recordValidationWarnings(work, warnings);
    }
    if (!errors.isEmpty()) {
        int maxErrCount = Integer.getInteger(MAX_NB_OF_ERRORS, 5);
        ImmutableSortedSet<String> uniqueSortedErrors = ImmutableSortedSet.copyOf(errors);
        throw WorkValidationException.forProblems(uniqueSortedErrors).limitTo(maxErrCount).withSummary(helper -> String.format("%s found with the configuration of %s (%s).", helper.size() == 1 ? "A problem was" : "Some problems were", work.getDisplayName(), describeTypesChecked(validationContext.getValidatedTypes()))).get();
    }
    if (!warnings.isEmpty()) {
        LOGGER.info("Invalidating VFS because {} failed validation", work.getDisplayName());
        virtualFileSystem.invalidateAll();
    }
    return delegate.execute(work, new ValidationFinishedContext() {

        @Override
        public Optional<BeforeExecutionState> getBeforeExecutionState() {
            return context.getBeforeExecutionState();
        }

        @Override
        public Optional<ValidationResult> getValidationProblems() {
            return warnings.isEmpty() ? Optional.empty() : Optional.of(() -> warnings);
        }

        @Override
        public Optional<PreviousExecutionState> getPreviousExecutionState() {
            return context.getPreviousExecutionState();
        }

        @Override
        public File getWorkspace() {
            return context.getWorkspace();
        }

        @Override
        public Optional<ExecutionHistoryStore> getHistory() {
            return context.getHistory();
        }

        @Override
        public ImmutableSortedMap<String, ValueSnapshot> getInputProperties() {
            return context.getInputProperties();
        }

        @Override
        public ImmutableSortedMap<String, CurrentFileCollectionFingerprint> getInputFileProperties() {
            return context.getInputFileProperties();
        }

        @Override
        public UnitOfWork.Identity getIdentity() {
            return context.getIdentity();
        }

        @Override
        public Optional<String> getNonIncrementalReason() {
            return context.getNonIncrementalReason();
        }

        @Override
        public WorkValidationContext getValidationContext() {
            return context.getValidationContext();
        }
    });
}
Also used : BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) TypeValidationProblemRenderer.convertToSingleLine(org.gradle.internal.reflect.validation.TypeValidationProblemRenderer.convertToSingleLine) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ImmutableCollection(com.google.common.collect.ImmutableCollection) Severity(org.gradle.internal.reflect.validation.Severity) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext) ImmutableList(com.google.common.collect.ImmutableList) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) ModelType(org.gradle.model.internal.type.ModelType) Map(java.util.Map) Collectors.mapping(java.util.stream.Collectors.mapping) BaseProblem(org.gradle.problems.BaseProblem) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) UnitOfWork(org.gradle.internal.execution.UnitOfWork) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ValidationProblemBuilder(org.gradle.internal.reflect.validation.ValidationProblemBuilder) GeneratedSubclasses(org.gradle.api.internal.GeneratedSubclasses) TypeValidationProblemRenderer.renderMinimalInformationAbout(org.gradle.internal.reflect.validation.TypeValidationProblemRenderer.renderMinimalInformationAbout) WorkValidationException(org.gradle.internal.execution.WorkValidationException) Logger(org.slf4j.Logger) ImplementationSnapshot(org.gradle.internal.snapshot.impl.ImplementationSnapshot) Collection(java.util.Collection) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) TypeValidationContext(org.gradle.internal.reflect.validation.TypeValidationContext) MutableReference(org.gradle.internal.MutableReference) Collectors(java.util.stream.Collectors) File(java.io.File) VirtualFileSystem(org.gradle.internal.vfs.VirtualFileSystem) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) ValidationProblemId(org.gradle.internal.reflect.problems.ValidationProblemId) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Severity(org.gradle.internal.reflect.validation.Severity) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) File(java.io.File) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext)

Aggregations

ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 File (java.io.File)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 Collectors.mapping (java.util.stream.Collectors.mapping)1 Collectors.toList (java.util.stream.Collectors.toList)1 GeneratedSubclasses (org.gradle.api.internal.GeneratedSubclasses)1 MutableReference (org.gradle.internal.MutableReference)1 UnitOfWork (org.gradle.internal.execution.UnitOfWork)1 WorkValidationContext (org.gradle.internal.execution.WorkValidationContext)1 WorkValidationException (org.gradle.internal.execution.WorkValidationException)1 BeforeExecutionState (org.gradle.internal.execution.history.BeforeExecutionState)1 ExecutionHistoryStore (org.gradle.internal.execution.history.ExecutionHistoryStore)1