Search in sources :

Example 16 with TreeFormatter

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

the class PublicationWarningsCollector method complete.

public void complete(String header, Set<String> silencedVariants) {
    saveVariantWarnings();
    variantToWarnings.keySet().removeAll(silencedVariants);
    if (!variantToWarnings.isEmpty()) {
        TreeFormatter treeFormatter = new TreeFormatter();
        treeFormatter.node(header + " warnings (silence with '" + disableMethod + "(variant)')");
        treeFormatter.startChildren();
        variantToWarnings.forEach((key, warnings) -> {
            treeFormatter.node("Variant " + key + ":");
            treeFormatter.startChildren();
            if (warnings.getVariantUnsupported() != null) {
                warnings.getVariantUnsupported().forEach(treeFormatter::node);
            }
            if (warnings.getUnsupportedUsages() != null) {
                treeFormatter.node(unsupportedFeature);
                treeFormatter.startChildren();
                warnings.getUnsupportedUsages().forEach(treeFormatter::node);
                treeFormatter.endChildren();
            }
            if (warnings.getIncompatibleUsages() != null) {
                treeFormatter.node(incompatibleFeature);
                treeFormatter.startChildren();
                warnings.getIncompatibleUsages().forEach(treeFormatter::node);
                treeFormatter.endChildren();
            }
            treeFormatter.endChildren();
        });
        treeFormatter.endChildren();
        treeFormatter.node(footer);
        logger.lifecycle(treeFormatter.toString());
    }
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 17 with TreeFormatter

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

the class DependencyInjectingInstantiator method convertParameters.

private Object[] convertParameters(Class<?> type, ClassGenerator.GeneratedConstructor<?> constructor, ServiceLookup services, Object[] parameters) {
    constructorSelector.vetoParameters(constructor, parameters);
    Class<?>[] parameterTypes = constructor.getParameterTypes();
    if (parameterTypes.length < parameters.length) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node("Too many parameters provided for constructor for type ");
        formatter.appendType(type);
        formatter.append(String.format(". Expected %s, received %s.", parameterTypes.length, parameters.length));
        throw new IllegalArgumentException(formatter.toString());
    }
    if (parameterTypes.length == parameters.length) {
        // No services to be mixed in
        return verifyParameters(constructor, parameters);
    } else {
        return addServicesToParameters(type, constructor, services, parameters);
    }
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 18 with TreeFormatter

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

the class Jsr330ConstructorSelector method validateType.

private static <T> void validateType(Class<T> type) {
    if (!type.isInterface() && type.getEnclosingClass() != null && !Modifier.isStatic(type.getModifiers())) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node(type);
        formatter.append(" is a non-static inner class.");
        throw new IllegalArgumentException(formatter.toString());
    }
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 19 with TreeFormatter

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

the class ParamsMatchingConstructorSelector method forParams.

@Override
public <T> ClassGenerator.GeneratedConstructor<? extends T> forParams(final Class<T> type, Object[] params) {
    ClassGenerator.GeneratedClass<?> generatedClass = classGenerator.generate(type);
    if (generatedClass.getOuterType() != null && (params.length == 0 || !generatedClass.getOuterType().isInstance(params[0]))) {
        TreeFormatter formatter = new TreeFormatter();
        formatter.node(type);
        formatter.append(" is a non-static inner class.");
        throw new IllegalArgumentException(formatter.toString());
    }
    List<? extends ClassGenerator.GeneratedConstructor<?>> constructors = generatedClass.getConstructors();
    if (constructors.size() == 1) {
        return Cast.uncheckedCast(constructors.get(0));
    }
    ClassGenerator.GeneratedConstructor<?> match = null;
    // sorted by the number of parameters the constructor requires
    for (ClassGenerator.GeneratedConstructor<?> constructor : constructors) {
        Class<?>[] parameterTypes = constructor.getParameterTypes();
        // parameters we were given. This can't be the constructor
        if (parameterTypes.length < params.length) {
            continue;
        }
        int fromParam = 0;
        int toParam = 0;
        for (; fromParam < params.length; fromParam++) {
            Object param = params[fromParam];
            while (param != null && toParam < parameterTypes.length) {
                Class<?> toType = parameterTypes[toParam];
                if (toType.isPrimitive()) {
                    toType = JavaReflectionUtil.getWrapperTypeForPrimitiveType(toType);
                }
                if (toType.isInstance(param)) {
                    break;
                }
                toParam++;
            }
            if (toParam == parameterTypes.length) {
                break;
            }
            toParam++;
        }
        // we can inject additional services
        if (fromParam == params.length) {
            if (match == null) {
                // We had no previous match, so choose this candidate
                match = constructor;
            } else if (parameterTypes.length < match.getParameterTypes().length) {
                // We had a previous match, if this candidate has fewer parameters, choose it as the best match
                match = constructor;
            } else if (parameterTypes.length == match.getParameterTypes().length) {
                // We have a previous match with the same number of parameters as this candidate.
                // This means for the given parameters, we've found two constructors that could be used
                // Given constructors C1 and C2.
                // C1(A, B, C, D)
                // C2(A, B, X, D)
                // C1 and C2 both accept the parameters A, B and D, but
                // C1 accepts a parameter of type C at position 2 and
                // C2 accepts a parameter of type X at position 2.
                // This will trigger this check because we cannot tell which is the "better"
                // constructor assuming that the other parameter could be injected.
                TreeFormatter formatter = new TreeFormatter();
                formatter.node("Multiple constructors for parameters ");
                formatter.appendValues(params);
                formatter.startNumberedChildren();
                formatter.node("candidate: ");
                formatter.appendType(type);
                formatter.appendTypes(parameterTypes);
                formatter.node("best match: ");
                formatter.appendType(type);
                formatter.appendTypes(match.getParameterTypes());
                formatter.endChildren();
                throw new IllegalArgumentException(formatter.toString());
            }
        }
    }
    if (match != null) {
        return Cast.uncheckedCast(match);
    }
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("No constructors of type ");
    formatter.appendType(type);
    formatter.append(" match parameters: ");
    formatter.appendValues(params);
    throw new IllegalArgumentException(formatter.toString());
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 20 with TreeFormatter

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

the class IsolationException method format.

private static String format(Object value) {
    TreeFormatter formatter = new TreeFormatter();
    formatter.node("Could not isolate value ");
    formatter.appendValue(value);
    formatter.append(" of type ");
    formatter.appendType(value.getClass());
    return formatter.toString();
}
Also used : TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

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