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

org.gradle.api.internaldependencies.DefaultMutableModuleDependencyCapabilitiesHandler Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2019 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.artifacts.dependencies;

import org.gradle.api.capabilities.Capability;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.SetProperty;
import org.gradle.internal.typeconversion.NotationParser;

import javax.inject.Inject;

public abstract class DefaultMutableModuleDependencyCapabilitiesHandler implements ModuleDependencyCapabilitiesInternal {

    private final NotationParser capabilityNotationParser;

    @Inject
    public DefaultMutableModuleDependencyCapabilitiesHandler(NotationParser capabilityNotationParser) {
        this.capabilityNotationParser = capabilityNotationParser;
    }

    @Inject
    protected abstract ObjectFactory getObjectFactory();

    @Override
    public abstract SetProperty getRequestedCapabilities();

    @Override
    public void requireCapability(Object capabilityNotation) {
        if (capabilityNotation instanceof Provider) {
            getRequestedCapabilities().add(((Provider) capabilityNotation).map(capabilityNotationParser::parseNotation));
        } else {
            getRequestedCapabilities().add(capabilityNotationParser.parseNotation(capabilityNotation));
        }
    }

    @Override
    public void requireCapabilities(Object... capabilityNotations) {
        for (Object notation : capabilityNotations) {
            requireCapability(notation);
        }
    }

    @Override
    public ModuleDependencyCapabilitiesInternal copy() {
        DefaultMutableModuleDependencyCapabilitiesHandler out = getObjectFactory().newInstance(
            DefaultMutableModuleDependencyCapabilitiesHandler.class, capabilityNotationParser
        );
        out.getRequestedCapabilities().addAll(getRequestedCapabilities());
        return out;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy