org.gradle.api.internal.plugins.PluginInspector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.plugins;
import javax.annotation.concurrent.ThreadSafe;
import org.gradle.api.Plugin;
import org.gradle.internal.Cast;
import org.gradle.model.internal.inspect.ModelRuleSourceDetector;
@ThreadSafe
public class PluginInspector {
private final ModelRuleSourceDetector modelRuleSourceDetector;
public PluginInspector(ModelRuleSourceDetector modelRuleSourceDetector) {
this.modelRuleSourceDetector = modelRuleSourceDetector;
}
public PotentialPlugin inspect(Class type) {
boolean implementsInterface = Plugin.class.isAssignableFrom(type);
boolean hasRules = this.modelRuleSourceDetector.hasRules(type);
if (implementsInterface) {
@SuppressWarnings("unchecked") Class extends Plugin>> cast = (Class extends Plugin>>) type;
return Cast.uncheckedCast(toImperative(cast, hasRules));
} else if (hasRules) {
return new PotentialPureRuleSourceClassPlugin(type);
} else {
return new PotentialUnknownTypePlugin(type);
}
}
private > PotentialPlugin toImperative(Class type, boolean hasRules) {
if (hasRules) {
return new PotentialHybridImperativeAndRulesPlugin(type);
} else {
return new PotentialImperativeClassPlugin(type);
}
}
private static class PotentialImperativeClassPlugin> implements PotentialPlugin {
private final Class clazz;
public PotentialImperativeClassPlugin(Class clazz) {
this.clazz = clazz;
}
@Override
public Class asClass() {
return clazz;
}
@Override
public boolean isImperative() {
return true;
}
@Override
public Type getType() {
return Type.IMPERATIVE_CLASS;
}
@Override
public boolean isHasRules() {
return false;
}
}
private static class PotentialHybridImperativeAndRulesPlugin> implements PotentialPlugin {
private final Class clazz;
public PotentialHybridImperativeAndRulesPlugin(Class clazz) {
this.clazz = clazz;
}
@Override
public Class asClass() {
return clazz;
}
@Override
public boolean isImperative() {
return true;
}
@Override
public boolean isHasRules() {
return true;
}
@Override
public Type getType() {
return Type.HYBRID_IMPERATIVE_AND_RULES_CLASS;
}
}
private static class PotentialPureRuleSourceClassPlugin implements PotentialPlugin {
private final Class clazz;
public PotentialPureRuleSourceClassPlugin(Class clazz) {
this.clazz = clazz;
}
@Override
public Class asClass() {
return clazz;
}
@Override
public boolean isImperative() {
return false;
}
@Override
public Type getType() {
return Type.PURE_RULE_SOURCE_CLASS;
}
@Override
public boolean isHasRules() {
return false;
}
}
private static class PotentialUnknownTypePlugin implements PotentialPlugin {
private final Class clazz;
public PotentialUnknownTypePlugin(Class clazz) {
this.clazz = clazz;
}
@Override
public Class asClass() {
return clazz;
}
@Override
public boolean isImperative() {
return false;
}
@Override
public boolean isHasRules() {
return false;
}
@Override
public Type getType() {
return Type.UNKNOWN;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy