All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.internal.action.DefaultConfigurableRule Maven / Gradle / Ivy

There is a newer version: 8.6
Show newest version
/*
 * Copyright 2018 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.internal.action;

import com.google.common.base.Objects;
import org.gradle.api.Action;
import org.gradle.api.ActionConfiguration;
import org.gradle.api.artifacts.CacheableRule;
import org.gradle.api.internal.DefaultActionConfiguration;
import org.gradle.internal.isolation.Isolatable;
import org.gradle.internal.isolation.IsolatableFactory;
import org.gradle.internal.reflect.JavaPropertyReflectionUtil;
import org.gradle.internal.snapshot.impl.IsolatedArray;

import java.util.Arrays;

public class DefaultConfigurableRule
implements ConfigurableRule
{ private final static Object[] EMPTY_ARRAY = new Object[0]; private final Class> rule; private final Isolatable ruleParams; private final boolean cacheable; private DefaultConfigurableRule(Class> rule, Isolatable ruleParams) { this.rule = rule; this.ruleParams = ruleParams; this.cacheable = hasCacheableAnnotation(rule); } private static
boolean hasCacheableAnnotation(Class> rule) { return JavaPropertyReflectionUtil.getAnnotation(rule, CacheableRule.class) != null; } public static
ConfigurableRule
of(Class> rule) { return new DefaultConfigurableRule
(rule, IsolatedArray.EMPTY); } public static
ConfigurableRule
of(Class> rule, Action action, IsolatableFactory isolatableFactory) { Object[] params = EMPTY_ARRAY; if (action != null) { ActionConfiguration configuration = new DefaultActionConfiguration(); action.execute(configuration); params = configuration.getParams(); } return new DefaultConfigurableRule
(rule, isolatableFactory.isolate(params)); } @Override public Class> getRuleClass() { return rule; } @Override public Isolatable getRuleParams() { return ruleParams; } @Override public boolean isCacheable() { return cacheable; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DefaultConfigurableRule that = (DefaultConfigurableRule) o; return cacheable == that.cacheable && Objects.equal(rule, that.rule) && Objects.equal(ruleParams, that.ruleParams); } @Override public int hashCode() { return Objects.hashCode(rule, ruleParams, cacheable); } @Override public String toString() { return "DefaultConfigurableRule{" + "rule=" + rule + ", ruleParams=" + Arrays.toString(ruleParams.isolate()) + '}'; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy