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);
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations