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

org.eclipse.edc.plugins.edcbuild.conventions.ConventionFunctions Maven / Gradle / Ivy

There is a newer version: 0.9.1
Show newest version
/*
 *  Copyright (c) 2022 Microsoft Corporation
 *
 *  This program and the accompanying materials are made available under the
 *  terms of the Apache License, Version 2.0 which is available at
 *  https://www.apache.org/licenses/LICENSE-2.0
 *
 *  SPDX-License-Identifier: Apache-2.0
 *
 *  Contributors:
 *       Microsoft Corporation - initial API and implementation
 *
 */

package org.eclipse.edc.plugins.edcbuild.conventions;

import org.gradle.api.GradleException;
import org.gradle.api.Project;

import java.util.function.Supplier;

import static java.util.Optional.ofNullable;

public class ConventionFunctions {

    /**
     * Supplies a generic {@link GradleException} with the given message.
     */
    public static Supplier gradleException(String message) {
        return () -> new GradleException(message);
    }

    /**
     * Supplies a {@link GradleException} that has a specific message indicating that a particular extension is missing.
     */
    static Supplier extensionException(Class extensionClass) {
        return gradleException(extensionClass.getSimpleName() + " expected but was null");
    }

    public static  A requireExtension(Project target, Class extensionClass) {
        return ofNullable(target.getExtensions().findByType(extensionClass))
                .orElseThrow(extensionException(extensionClass));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy