Search in sources :

Example 21 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class ToolChainAvailability method getUnavailableMessage.

public String getUnavailableMessage() {
    TreeFormatter formatter = new TreeFormatter();
    this.explain(formatter);
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 22 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class AbstractValueProcessor method newValueSerializationException.

private ValueSnapshottingException newValueSerializationException(Class<?> valueType, Throwable cause) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Could not serialize value of type ");
    formatter.appendType(valueType);
    return new ValueSnapshottingException(formatter.toString(), cause);
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ValueSnapshottingException(org.gradle.internal.snapshot.ValueSnapshottingException)

Example 23 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class Jsr330ConstructorSelector method vetoParameters.

@Override
public void vetoParameters(ClassGenerator.GeneratedConstructor<?> constructor, Object[] parameters) {
    for (Object param : parameters) {
        if (param == null) {
            TreeFormatter formatter = new TreeFormatter();
            formatter.node("Null value provided in parameters ");
            formatter.appendValues(parameters);
            throw new IllegalArgumentException(formatter.toString());
        }
    }
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 24 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class TypeValidationProblemRenderer method renderMinimalInformationAbout.

public static String renderMinimalInformationAbout(TypeValidationProblem problem, boolean renderDocLink, boolean renderSolutions) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node(introductionFor(problem.getWhere()) + maybeAppendDot(problem.getShortDescription()));
    problem.getWhy().ifPresent(reason -> {
        formatter.blankLine();
        formatter.node("Reason: " + StringUtils.capitalize(maybeAppendDot(reason)));
    });
    if (renderSolutions) {
        List<Solution> possibleSolutions = problem.getPossibleSolutions();
        int solutionCount = possibleSolutions.size();
        if (solutionCount > 0) {
            formatter.blankLine();
            if (solutionCount == 1) {
                formatter.node("Possible solution: " + StringUtils.capitalize(maybeAppendDot(possibleSolutions.get(0).getShortDescription())));
            } else {
                formatter.node("Possible solutions");
                formatter.startNumberedChildren();
                possibleSolutions.forEach(solution -> formatter.node(StringUtils.capitalize(maybeAppendDot(solution.getShortDescription()))));
                formatter.endChildren();
            }
        }
    }
    if (renderDocLink) {
        problem.getDocumentationLink().ifPresent(docLink -> {
            formatter.blankLine();
            formatter.node("Please refer to ").append(docLink).append(" for more details about this problem.");
        });
    }
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) Solution(org.gradle.problems.Solution)

Example 25 with TreeFormatter

use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.

the class AbstractClassGenerator method generateUnderLock.

private GeneratedClassImpl generateUnderLock(Class<?> type) {
    List<CustomInjectAnnotationPropertyHandler> customAnnotationPropertyHandlers = new ArrayList<>(enabledAnnotations.size());
    ServicesPropertyHandler servicesHandler = new ServicesPropertyHandler();
    InjectAnnotationPropertyHandler injectionHandler = new InjectAnnotationPropertyHandler();
    PropertyTypePropertyHandler propertyTypedHandler = new PropertyTypePropertyHandler();
    ManagedPropertiesHandler managedPropertiesHandler = new ManagedPropertiesHandler();
    NamePropertyHandler namePropertyHandler = new NamePropertyHandler();
    ExtensibleTypePropertyHandler extensibleTypeHandler = new ExtensibleTypePropertyHandler();
    DslMixInPropertyType dslMixInHandler = new DslMixInPropertyType(extensibleTypeHandler);
    // Order is significant. Injection handler should be at the end
    List<ClassGenerationHandler> handlers = new ArrayList<>(5 + enabledAnnotations.size() + disabledAnnotations.size());
    handlers.add(extensibleTypeHandler);
    handlers.add(dslMixInHandler);
    handlers.add(propertyTypedHandler);
    handlers.add(servicesHandler);
    handlers.add(namePropertyHandler);
    handlers.add(managedPropertiesHandler);
    for (Class<? extends Annotation> annotation : enabledAnnotations) {
        customAnnotationPropertyHandlers.add(new CustomInjectAnnotationPropertyHandler(annotation));
    }
    handlers.addAll(customAnnotationPropertyHandlers);
    handlers.add(injectionHandler);
    // Order is significant
    List<ClassValidator> validators = new ArrayList<>(2 + disabledAnnotations.size());
    for (Class<? extends Annotation> annotation : disabledAnnotations) {
        validators.add(new DisabledAnnotationValidator(annotation));
    }
    validators.add(new InjectionAnnotationValidator(enabledAnnotations, allowedTypesForAnnotation));
    Class<?> generatedClass;
    try {
        ClassInspectionVisitor inspectionVisitor = start(type);
        inspectType(type, validators, handlers, extensibleTypeHandler);
        for (ClassGenerationHandler handler : handlers) {
            handler.applyTo(inspectionVisitor);
        }
        ClassGenerationVisitor generationVisitor = inspectionVisitor.builder();
        for (ClassGenerationHandler handler : handlers) {
            handler.applyTo(generationVisitor);
        }
        boolean shouldImplementNameProperty = namePropertyHandler.hasNameProperty();
        if (type.isInterface()) {
            if (shouldImplementNameProperty) {
                generationVisitor.addNameConstructor();
            } else {
                generationVisitor.addDefaultConstructor();
            }
        } else {
            for (Constructor<?> constructor : type.getConstructors()) {
                generationVisitor.addConstructor(constructor, shouldImplementNameProperty);
            }
        }
        generatedClass = generationVisitor.generate();
    } catch (ClassGenerationException e) {
        throw e;
    } catch (Throwable e) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node("Could not generate a decorated class for type ");
        formatter.appendType(type);
        formatter.append(".");
        throw new ClassGenerationException(formatter.toString(), e);
    }
    ImmutableList.Builder<Class<? extends Annotation>> annotationsTriggeringServiceInjection = ImmutableList.builder();
    for (CustomInjectAnnotationPropertyHandler handler : customAnnotationPropertyHandlers) {
        if (handler.isUsed()) {
            annotationsTriggeringServiceInjection.add(handler.getAnnotation());
        }
    }
    // This is expensive to calculate, so cache the result
    Class<?> enclosingClass = type.getEnclosingClass();
    Class<?> outerType;
    if (enclosingClass != null && !Modifier.isStatic(type.getModifiers())) {
        outerType = enclosingClass;
    } else {
        outerType = null;
    }
    return new GeneratedClassImpl(generatedClass, outerType, injectionHandler.getInjectedServices(), annotationsTriggeringServiceInjection.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter) ClassGenerationException(org.gradle.internal.instantiation.ClassGenerationException) Annotation(java.lang.annotation.Annotation)

Aggregations

TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)46 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 GradleException (org.gradle.api.GradleException)3 VariantTransformConfigurationException (org.gradle.api.artifacts.transform.VariantTransformConfigurationException)3 ResolvedVariant (org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedVariant)3 Lists (com.google.common.collect.Lists)2 File (java.io.File)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 ArtifactTransformRegistration (org.gradle.api.internal.artifacts.ArtifactTransformRegistration)2 ConfigurationMetadata (org.gradle.internal.component.model.ConfigurationMetadata)2 ClassGenerationException (org.gradle.internal.instantiation.ClassGenerationException)2 Solution (org.gradle.problems.Solution)2 ImmutableMap (com.google.common.collect.ImmutableMap)1