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

org.gradle.nativeplatform.internal.AbstractTargetedNativeComponentSpec Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2011 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.nativeplatform.internal;

import com.google.common.collect.Lists;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Named;
import org.gradle.nativeplatform.BuildType;
import org.gradle.nativeplatform.Flavor;
import org.gradle.platform.base.internal.DefaultPlatformRequirement;
import org.gradle.platform.base.internal.PlatformRequirement;

import java.util.*;

public abstract class AbstractTargetedNativeComponentSpec extends AbstractNativeComponentSpec implements TargetedNativeComponentInternal {

    private final List targetPlatforms = Lists.newArrayList();
    private final Set buildTypes = new HashSet();
    private final Set flavors = new HashSet();

    @Override
    public List getTargetPlatforms() {
        return Collections.unmodifiableList(targetPlatforms);
    }

    @Override
    public void targetPlatform(String targetPlatform) {
        this.targetPlatforms.add(DefaultPlatformRequirement.create(targetPlatform));
    }

    @Override
    public void targetFlavors(String... flavorSelectors) {
        Collections.addAll(flavors, flavorSelectors);
    }

    @Override
    public void targetBuildTypes(String... buildTypeSelectors) {
        Collections.addAll(buildTypes, buildTypeSelectors);
    }

    @Override
    public Set chooseFlavors(Set candidates) {
        return chooseElements(Flavor.class, candidates, flavors);
    }

    @Override
    public Set chooseBuildTypes(Set candidates) {
        return chooseElements(BuildType.class, candidates, buildTypes);
    }

    protected  Set chooseElements(Class type, Set candidates, Set names) {
        if (names.isEmpty()) {
            return new LinkedHashSet(candidates);
        }

        Set unusedNames = new HashSet(names);
        Set chosen = new LinkedHashSet();
        for (T candidate : candidates) {
            if (unusedNames.remove(candidate.getName())) {
                chosen.add(candidate);
            }
        }

        if (!unusedNames.isEmpty()) {
            throw new InvalidUserDataException(String.format("Invalid %s: '%s'", type.getSimpleName(), unusedNames.iterator().next()));
        }

        return chosen;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy