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

com.ca.apim.gateway.cagatewayimport.CAGatewayImport Maven / Gradle / Ivy

Go to download

The gateway-import-plugin enables importing locally generated bundles to an existing running gateway instance.

There is a newer version: 1.0.9
Show newest version
/*
 * Copyright (c) 2018 CA. All rights reserved.
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

package com.ca.apim.gateway.cagatewayimport;

import com.ca.apim.gateway.cagatewayimport.config.GatewayImportConfig;
import com.ca.apim.gateway.cagatewayimport.config.GatewayImportConnectionProperties;
import com.ca.apim.gateway.cagatewayimport.tasks.ImportBundleTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;

public class CAGatewayImport implements Plugin {
    @Override
    public void apply(@NotNull final Project project) {
        // This plugin builds on the CAGatewayExportBase plugin to define conventions
        project.getPlugins().apply(CAGatewayImportBase.class);
        // Add the base plugin to add standard lifecycle tasks: https://docs.gradle.org/current/userguide/standard_plugins.html#sec:base_plugins
        project.getPlugins().apply("base");

        final GatewayImportConnectionProperties gatewayConnectionProperties = project.getExtensions().create("GatewayImportConnection", GatewayImportConnectionProperties.class, project);
        final GatewayImportConfig gatewayImportConfig = project.getExtensions().create("GatewayImportConfig", GatewayImportConfig.class, project);
        // Set Defaults
        project.afterEvaluate(p -> setDefaults(gatewayConnectionProperties));

        project.getTasks().create("import-bundle", ImportBundleTask.class, t -> {
            t.setGatewayConnectionProperties(gatewayConnectionProperties);
            t.setGatewayImportConfig(gatewayImportConfig);
        });
    }


    private static void setDefaults(final GatewayImportConnectionProperties gatewayConnectionProperties) {
        setDefault(gatewayConnectionProperties.getUrl(), () -> "https://localhost:8443/restman");
        setDefault(gatewayConnectionProperties.getUserName(), () -> "admin");
        setDefault(gatewayConnectionProperties.getUserPass(), () -> "password");
    }

    private static  void setDefault(Property property, Supplier supplier) {
        if (!property.isPresent()) {
            property.set(supplier.get());
        }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy