Search in sources :

Example 6 with ExtraPropertiesExtension

use of org.gradle.api.plugins.ExtraPropertiesExtension in project spring-boot by spring-projects.

the class RunPluginFeatures method addBootRunTask.

private void addBootRunTask(final Project project) {
    final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    BootRunTask run = project.getTasks().create(RUN_APP_TASK_NAME, BootRunTask.class);
    run.setDescription("Run the project with support for " + "auto-detecting main class and reloading static resources");
    run.setGroup("application");
    run.setClasspath(javaConvention.getSourceSets().findByName("main").getRuntimeClasspath());
    run.getConventionMapping().map("main", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (project.hasProperty("mainClassName") && project.property("mainClassName") != null) {
                return project.property("mainClassName");
            }
            ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project.getExtensions().getByName("ext");
            if (extraPropertiesExtension.has("mainClassName") && extraPropertiesExtension.get("mainClassName") != null) {
                return extraPropertiesExtension.get("mainClassName");
            }
            return null;
        }
    });
    run.getConventionMapping().map("jvmArgs", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (project.hasProperty("applicationDefaultJvmArgs")) {
                return project.property("applicationDefaultJvmArgs");
            }
            return Collections.emptyList();
        }
    });
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension)

Example 7 with ExtraPropertiesExtension

use of org.gradle.api.plugins.ExtraPropertiesExtension in project curiostack by curioswitch.

the class GcloudPlugin method apply.

@Override
public void apply(Project project) {
    var config = GcloudExtension.create(project);
    project.getExtensions().getExtraProperties().set("keys", new KmsKeyDecrypter(project));
    project.getPlugins().withType(ToolDownloaderPlugin.class, plugin -> plugin.registerToolIfAbsent("gcloud", tool -> {
        tool.getArtifact().set("google-cloud-sdk");
        tool.getVersion().set(ToolDependencies.getGcloudVersion(project));
        tool.getBaseUrl().set("https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/");
        tool.getArtifactPattern().set("[artifact]-[revision]-[classifier].[ext]");
        tool.getPathSubDirs().add("google-cloud-sdk/bin");
        var osClassifiers = tool.getOsClassifiers();
        osClassifiers.getLinux().set("linux-x86_64");
        osClassifiers.getMac().set("darwin-x86_64");
        osClassifiers.getWindows().set("windows-x86_64");
    }));
    DownloadToolUtil.getSetupTask(project, "gcloud").configure(t -> t.dependsOn(DownloadToolUtil.getSetupTask(project, "miniconda-build")));
    project.getPlugins().withType(CondaPlugin.class, plugin -> plugin.getCondas().withType(ModifiableCondaExtension.class).named("miniconda-build").configure(conda -> {
        conda.getPackages().add("lz4-c");
        conda.getPythonPackages().add("crcmod");
    }));
    ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties();
    ext.set(GcloudTask.class.getSimpleName(), GcloudTask.class);
    project.getTasks().addRule(new Rule() {

        @Override
        public String getDescription() {
            return "Pattern: \"gcloud_<command>\": Executes a Gcloud command.";
        }

        @Override
        public void apply(String taskName) {
            if (taskName.startsWith("gcloud_")) {
                GcloudTask task = project.getTasks().create(taskName, GcloudTask.class);
                List<String> tokens = ImmutableList.copyOf(taskName.split("_"));
                task.setArgs(tokens.subList(1, tokens.size()));
            }
        }
    });
    var gcloudSetup = project.getTasks().register("gcloudSetup");
    var gcloudInstallComponents = project.getTasks().register("gcloudInstallComponents", GcloudTask.class, t -> t.setArgs(ImmutableList.of("components", "install", "app-engine-python", "beta", "kubectl", "docker-credential-gcr")));
    var gcloudLoginToCluster = project.getTasks().register("gcloudLoginToCluster", GcloudTask.class, t -> t.args(ImmutableList.of("container", "clusters", "get-credentials", config.getClusterName(), config.getClusterRegion().map(value -> System.getenv("CLOUDSDK_COMPUTE_ZONE") != null ? "--zone=" + System.getenv("CLOUDSDK_COMPUTE_ZONE") : "--region=" + value))));
    project.allprojects(subproj -> subproj.getTasks().withType(KubectlTask.class).configureEach(t -> {
        t.dependsOn(gcloudInstallComponents, gcloudLoginToCluster);
    }));
    project.getTasks().withType(UploadCodeCovCacheTask.class).configureEach(t -> t.setDest(config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-codecov.tar.gz")));
    project.getTasks().withType(FetchCodeCovCacheTask.class).configureEach(t -> t.setSrc(config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-codecov.tar.gz")));
    project.allprojects(proj -> proj.getPlugins().withType(CurioServerPlugin.class, unused -> {
        ServerExtension server = proj.getExtensions().getByType(ServerExtension.class);
        server.getImagePrefix().set(config.getContainerRegistry().map(value -> value + "/" + config.getClusterProject().get() + "/"));
    }));
    project.afterEvaluate(p -> {
        if (System.getenv("CI") != null && project.getGradle().getStartParameter().isBuildCacheEnabled()) {
            project.getPlugins().withType(ToolDownloaderPlugin.class).all(plugin -> plugin.tools().all(tool -> {
                Provider<String> toolCachePath = config.getBuildCacheStorageBucket().map(value -> "gs://" + value + "/cloudbuild-cache-tool-" + tool.getName() + ".tar.lz4");
                var downloadCache = project.getTasks().register("toolsFetchCache" + TaskUtil.toTaskSuffix(tool.getName()), FetchToolCacheTask.class, t -> {
                    t.setSrc(toolCachePath);
                    t.onlyIf(unused -> !Files.exists(DownloadedToolManager.get(project).getCuriostackDir().resolve(tool.getName())));
                });
                var uploadCache = project.getTasks().register("toolsUploadCache" + TaskUtil.toTaskSuffix(tool.getName()), UploadToolCacheTask.class, t -> {
                    t.setDest(toolCachePath);
                    t.srcPath(tool.getName());
                    tool.getAdditionalCachedDirs().get().forEach(t::srcPath);
                });
                DownloadToolUtil.getDownloadTask(project, tool.getName()).configure(t -> t.dependsOn(downloadCache));
                // We disable cache upload by default and only enable it if a
                // setup task was run.
                uploadCache.configure(uc -> uc.setOnlyIf(unused -> "true".equals(System.getenv("CI_MASTER")) && DownloadToolUtil.getSetupTask(project, tool.getName()).get().getDidWork()));
                project.getPlugins().withType(CurioGenericCiPlugin.class, unused -> project.getTasks().named("continuousBuild").configure(cb -> cb.finalizedBy(uploadCache)));
            }));
        }
        gcloudSetup.configure(t -> t.dependsOn(gcloudInstallComponents));
    });
    addGenerateCloudBuildTask(project, config);
}
Also used : CurioGenericCiPlugin(org.curioswitch.gradle.plugins.ci.CurioGenericCiPlugin) Style(org.immutables.value.Value.Style) CondaPlugin(org.curioswitch.gradle.conda.CondaPlugin) ToolDependencies(org.curioswitch.gradle.plugins.curiostack.ToolDependencies) DownloadToolUtil(org.curioswitch.gradle.tooldownloader.util.DownloadToolUtil) Rule(org.gradle.api.Rule) ArrayList(java.util.ArrayList) ServerExtension(org.curioswitch.gradle.plugins.curioserver.ServerExtension) Provider(org.gradle.api.provider.Provider) UploadCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.UploadCodeCovCacheTask) ImmutableList(com.google.common.collect.ImmutableList) FetchCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.FetchCodeCovCacheTask) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) Map(java.util.Map) DownloadedToolManager(org.curioswitch.gradle.tooldownloader.DownloadedToolManager) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) GcloudTask(org.curioswitch.gradle.plugins.gcloud.tasks.GcloudTask) TaskUtil(org.curioswitch.gradle.helpers.task.TaskUtil) KmsKeyDecrypter(org.curioswitch.gradle.plugins.gcloud.keys.KmsKeyDecrypter) Nullable(javax.annotation.Nullable) ModifiableCondaExtension(org.curioswitch.gradle.conda.ModifiableCondaExtension) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension) Files(java.nio.file.Files) Project(org.gradle.api.Project) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UploadToolCacheTask(org.curioswitch.gradle.plugins.gcloud.tasks.UploadToolCacheTask) Include(com.fasterxml.jackson.annotation.JsonInclude.Include) IOException(java.io.IOException) FetchToolCacheTask(org.curioswitch.gradle.plugins.gcloud.tasks.FetchToolCacheTask) CurioServerPlugin(org.curioswitch.gradle.plugins.curioserver.CurioServerPlugin) Immutable(org.immutables.value.Value.Immutable) File(java.io.File) UncheckedIOException(java.io.UncheckedIOException) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) List(java.util.List) ToolDownloaderPlugin(org.curioswitch.gradle.tooldownloader.ToolDownloaderPlugin) ImplementationVisibility(org.immutables.value.Value.Style.ImplementationVisibility) KubectlTask(org.curioswitch.gradle.plugins.gcloud.tasks.KubectlTask) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) BuilderVisibility(org.immutables.value.Value.Style.BuilderVisibility) Feature(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature) Plugin(org.gradle.api.Plugin) ToolDownloaderPlugin(org.curioswitch.gradle.tooldownloader.ToolDownloaderPlugin) ServerExtension(org.curioswitch.gradle.plugins.curioserver.ServerExtension) FetchCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.FetchCodeCovCacheTask) GcloudTask(org.curioswitch.gradle.plugins.gcloud.tasks.GcloudTask) CurioServerPlugin(org.curioswitch.gradle.plugins.curioserver.CurioServerPlugin) FetchToolCacheTask(org.curioswitch.gradle.plugins.gcloud.tasks.FetchToolCacheTask) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension) ModifiableCondaExtension(org.curioswitch.gradle.conda.ModifiableCondaExtension) KmsKeyDecrypter(org.curioswitch.gradle.plugins.gcloud.keys.KmsKeyDecrypter) Provider(org.gradle.api.provider.Provider) UploadCodeCovCacheTask(org.curioswitch.gradle.plugins.ci.tasks.UploadCodeCovCacheTask) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Rule(org.gradle.api.Rule) CurioGenericCiPlugin(org.curioswitch.gradle.plugins.ci.CurioGenericCiPlugin) UploadToolCacheTask(org.curioswitch.gradle.plugins.gcloud.tasks.UploadToolCacheTask)

Aggregations

ExtraPropertiesExtension (org.gradle.api.plugins.ExtraPropertiesExtension)7 Project (org.gradle.api.Project)4 File (java.io.File)2 Include (com.fasterxml.jackson.annotation.JsonInclude.Include)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)1 JsonSerialize (com.fasterxml.jackson.databind.annotation.JsonSerialize)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Feature (com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 CondaPlugin (org.curioswitch.gradle.conda.CondaPlugin)1 ModifiableCondaExtension (org.curioswitch.gradle.conda.ModifiableCondaExtension)1