Search in sources :

Example 6 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class PluginRequestsSerializer method read.

@Override
public PluginRequests read(Decoder decoder) throws Exception {
    int requestCount = decoder.readSmallInt();
    if (requestCount == 0) {
        return DefaultPluginRequests.EMPTY;
    }
    List<PluginRequestInternal> requests = Lists.newArrayListWithCapacity(requestCount);
    for (int i = 0; i < requestCount; i++) {
        PluginId pluginId = DefaultPluginId.unvalidated(decoder.readString());
        String version = decoder.readNullableString();
        boolean apply = decoder.readBoolean();
        String decodedLineNumber = decoder.readNullableString();
        Integer lineNumber = decodedLineNumber == null ? null : Integer.valueOf(decodedLineNumber);
        String scriptDisplayName = decoder.readString();
        requests.add(i, new DefaultPluginRequest(pluginId, version, apply, lineNumber, scriptDisplayName, null));
    }
    return new DefaultPluginRequests(requests);
}
Also used : PluginId(org.gradle.plugin.use.PluginId) DefaultPluginId(org.gradle.plugin.use.internal.DefaultPluginId)

Example 7 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class PluginRequestCollector method listPluginRequests.

@VisibleForTesting
List<PluginRequestInternal> listPluginRequests() {
    List<PluginRequestInternal> pluginRequests = collect(specs, new Transformer<PluginRequestInternal, DependencySpecImpl>() {

        public PluginRequestInternal transform(DependencySpecImpl original) {
            return new DefaultPluginRequest(original.id, original.version, original.apply, original.lineNumber, scriptSource);
        }
    });
    Map<PluginId, Collection<PluginRequestInternal>> groupedById = CollectionUtils.groupBy(pluginRequests, new Transformer<PluginId, PluginRequestInternal>() {

        public PluginId transform(PluginRequestInternal pluginRequest) {
            return pluginRequest.getId();
        }
    });
    // Check for duplicates
    for (PluginId key : groupedById.keySet()) {
        Collection<PluginRequestInternal> pluginRequestsForId = groupedById.get(key);
        if (pluginRequestsForId.size() > 1) {
            Iterator<PluginRequestInternal> iterator = pluginRequestsForId.iterator();
            PluginRequestInternal first = iterator.next();
            PluginRequestInternal second = iterator.next();
            InvalidPluginRequestException exception = new InvalidPluginRequestException(second, "Plugin with id '" + key + "' was already requested at line " + first.getLineNumber());
            throw new LocationAwareException(exception, second.getScriptDisplayName(), second.getLineNumber());
        }
    }
    return pluginRequests;
}
Also used : InvalidPluginRequestException(org.gradle.plugin.management.internal.InvalidPluginRequestException) DefaultPluginRequest(org.gradle.plugin.management.internal.DefaultPluginRequest) PluginId(org.gradle.plugin.use.PluginId) LocationAwareException(org.gradle.internal.exceptions.LocationAwareException) PluginRequestInternal(org.gradle.plugin.management.internal.PluginRequestInternal) Collection(java.util.Collection) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class DefaultInjectedPluginDependencies method listPluginRequests.

List<PluginRequestInternal> listPluginRequests() {
    List<PluginRequestInternal> pluginRequests = collect(dependencies, new Transformer<PluginRequestInternal, DefaultInjectedPluginDependency>() {

        public PluginRequestInternal transform(DefaultInjectedPluginDependency original) {
            return new SelfResolvingPluginRequest(original.getId(), classLoaderScope);
        }
    });
    Map<PluginId, Collection<PluginRequestInternal>> groupedById = CollectionUtils.groupBy(pluginRequests, new Transformer<PluginId, PluginRequestInternal>() {

        public PluginId transform(PluginRequestInternal pluginRequest) {
            return pluginRequest.getId();
        }
    });
    // Check for duplicates
    for (PluginId key : groupedById.keySet()) {
        Collection<PluginRequestInternal> pluginRequestsForId = groupedById.get(key);
        if (pluginRequestsForId.size() > 1) {
            PluginRequestInternal first = pluginRequests.get(0);
            throw new InvalidPluginRequestException(first, "Plugin with id '" + key + "' was already requested.");
        }
    }
    return pluginRequests;
}
Also used : InvalidPluginRequestException(org.gradle.plugin.management.internal.InvalidPluginRequestException) PluginRequestInternal(org.gradle.plugin.management.internal.PluginRequestInternal) Collection(java.util.Collection) PluginId(org.gradle.plugin.use.PluginId)

Example 9 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class DefaultPluginManager method doApply.

private void doApply(final PluginImplementation<?> plugin) {
    PluginId pluginId = plugin.getPluginId();
    String pluginIdStr = pluginId == null ? null : pluginId.toString();
    Class<?> pluginClass = plugin.asClass();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(pluginClass.getClassLoader());
        if (plugin.getType().equals(PotentialPlugin.Type.UNKNOWN)) {
            throw new InvalidPluginException("'" + pluginClass.getName() + "' is neither a plugin or a rule source and cannot be applied.");
        } else {
            Runnable adder = addPluginInternal(plugin);
            if (adder != null) {
                buildOperationExecutor.run(new AddPluginBuildOperation(adder, plugin, pluginIdStr, pluginClass));
            }
        }
    } catch (PluginApplicationException e) {
        throw e;
    } catch (Exception e) {
        throw new PluginApplicationException(plugin.getDisplayName(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }
}
Also used : InvalidPluginException(org.gradle.api.plugins.InvalidPluginException) PluginId(org.gradle.plugin.use.PluginId) DefaultPluginId(org.gradle.plugin.use.internal.DefaultPluginId) ObjectInstantiationException(org.gradle.api.reflect.ObjectInstantiationException) UnknownPluginException(org.gradle.api.plugins.UnknownPluginException) PluginInstantiationException(org.gradle.api.plugins.PluginInstantiationException) InvalidPluginException(org.gradle.api.plugins.InvalidPluginException)

Example 10 with PluginId

use of org.gradle.plugin.use.PluginId in project gradle by gradle.

the class DefaultPluginManager method pluginsForId.

public DomainObjectSet<PluginWithId> pluginsForId(String id) {
    PluginId pluginId = DefaultPluginId.unvalidated(id);
    DomainObjectSet<PluginWithId> pluginsForId = idMappings.get(pluginId);
    if (pluginsForId == null) {
        pluginsForId = new DefaultDomainObjectSet<PluginWithId>(PluginWithId.class, Sets.<PluginWithId>newLinkedHashSet());
        idMappings.put(pluginId, pluginsForId);
        for (PluginImplementation<?> plugin : plugins.values()) {
            if (plugin.isAlsoKnownAs(pluginId)) {
                pluginsForId.add(new PluginWithId(pluginId, plugin.asClass()));
            }
        }
    }
    return pluginsForId;
}
Also used : PluginId(org.gradle.plugin.use.PluginId) DefaultPluginId(org.gradle.plugin.use.internal.DefaultPluginId)

Aggregations

PluginId (org.gradle.plugin.use.PluginId)11 DefaultPluginId (org.gradle.plugin.use.internal.DefaultPluginId)5 InvalidPluginRequestException (org.gradle.plugin.management.internal.InvalidPluginRequestException)3 PluginRequestInternal (org.gradle.plugin.management.internal.PluginRequestInternal)3 Collection (java.util.Collection)2 Nullable (javax.annotation.Nullable)2 PluginResolveContext (org.gradle.plugin.use.resolve.internal.PluginResolveContext)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)1 Map (java.util.Map)1 RepositoryHandler (org.gradle.api.artifacts.dsl.RepositoryHandler)1 PluginDescriptor (org.gradle.api.internal.plugins.PluginDescriptor)1 PluginImplementation (org.gradle.api.internal.plugins.PluginImplementation)1 InvalidPluginException (org.gradle.api.plugins.InvalidPluginException)1 PluginInstantiationException (org.gradle.api.plugins.PluginInstantiationException)1 UnknownPluginException (org.gradle.api.plugins.UnknownPluginException)1 ObjectInstantiationException (org.gradle.api.reflect.ObjectInstantiationException)1 LocationAwareException (org.gradle.internal.exceptions.LocationAwareException)1 DefaultPluginRequest (org.gradle.plugin.management.internal.DefaultPluginRequest)1 AlreadyOnClasspathPluginResolver (org.gradle.plugin.use.resolve.internal.AlreadyOnClasspathPluginResolver)1