Search in sources :

Example 26 with TaskAction

use of org.gradle.api.tasks.TaskAction in project spring-boot by spring-projects.

the class RepackageTask method repackage.

@TaskAction
public void repackage() {
    Project project = getProject();
    SpringBootPluginExtension extension = project.getExtensions().getByType(SpringBootPluginExtension.class);
    ProjectLibraries libraries = getLibraries();
    project.getTasks().withType(Jar.class, new RepackageAction(extension, libraries));
}
Also used : Project(org.gradle.api.Project) SpringBootPluginExtension(org.springframework.boot.gradle.SpringBootPluginExtension) TaskAction(org.gradle.api.tasks.TaskAction)

Example 27 with TaskAction

use of org.gradle.api.tasks.TaskAction in project spring-boot by spring-projects.

the class FindMainClassTask method setMainClassNameProperty.

@TaskAction
public void setMainClassNameProperty() {
    Project project = getProject();
    if (!project.hasProperty("mainClassName") || project.property("mainClassName") == null) {
        String mainClass = findMainClass();
        if (project.hasProperty("mainClassName")) {
            project.setProperty("mainClassName", mainClass);
        } else {
            ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) project.getExtensions().getByName("ext");
            extraProperties.set("mainClassName", mainClass);
        }
    }
}
Also used : Project(org.gradle.api.Project) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension) TaskAction(org.gradle.api.tasks.TaskAction)

Example 28 with TaskAction

use of org.gradle.api.tasks.TaskAction in project gradle-eta by typelead.

the class EtaResolveDependencies method resolveDependencies.

@TaskAction
public void resolveDependencies() {
    /* Create the destination directory if it doesn't exist. */
    File workingDir = getDestinationDirectory();
    if (!workingDir.exists() && !workingDir.mkdirs()) {
        throw new GradleException("Unable to create destination directory: " + workingDir.getAbsolutePath());
    }
    /* Remove the cabal.project.freeze file from a previous run, if it exists. */
    File existingFreezeFile = getFreezeConfigFile();
    if (existingFreezeFile.exists() && !existingFreezeFile.delete()) {
        throw new GradleException("Unable to delete existing freeze file: " + existingFreezeFile.getAbsolutePath());
    }
    /* Generate the .cabal & cabal.project files. */
    final WriteResult[] writeResults = new WriteResult[2];
    DependencyUtils.foldEtaDependencies(project, dependencies.get(), (directDeps, projectDeps) -> {
        writeResults[0] = CabalHelper.generateCabalFile(getProject().getName(), getProject().getVersion().toString(), directDeps, workingDir);
    }, gitDeps -> {
        writeResults[1] = CabalHelper.generateCabalProjectFile(gitDeps, workingDir);
    });
    /* Delete existing *.cabal files to avoid errors when changing the project
           name. */
    final File oldCabalFile = writeResults[0].getFile();
    project.delete(project.fileTree(workingDir, fileTree -> {
        fileTree.include("*.cabal");
        fileTree.exclude(fileTreeElement -> {
            try {
                return fileTreeElement.getFile().getCanonicalPath().equals(oldCabalFile.getCanonicalPath());
            } catch (IOException e) {
                return true;
            }
        });
    }));
    /* Only run the freeze command if the cabal files have changed or the
           Eta version state has changed. */
    boolean changed = writeResults[0].isChanged() || writeResults[0].isChanged() || getVersionsChanged();
    if (changed) {
        /* Fork an etlas process to freeze the dependencies.  */
        EtlasCommand etlas = new EtlasCommand(getProject());
        etlas.getWorkingDirectory().set(workingDir);
        etlas.freeze();
    }
    setDidWork(changed);
}
Also used : ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) CabalHelper(com.typelead.gradle.utils.CabalHelper) OutputDirectory(org.gradle.api.tasks.OutputDirectory) EtaConfiguration(com.typelead.gradle.eta.api.EtaConfiguration) Inject(javax.inject.Inject) TaskAction(org.gradle.api.tasks.TaskAction) Configuration(org.gradle.api.artifacts.Configuration) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) DirectoryProperty(org.gradle.api.file.DirectoryProperty) EtaDirectDependency(com.typelead.gradle.eta.api.EtaDirectDependency) DefaultTask(org.gradle.api.DefaultTask) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) LinkedHashSet(java.util.LinkedHashSet) Internal(org.gradle.api.tasks.Internal) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) Project(org.gradle.api.Project) Set(java.util.Set) IOException(java.io.IOException) EtaExtension(com.typelead.gradle.eta.api.EtaExtension) Collectors(java.util.stream.Collectors) File(java.io.File) ProviderFactory(org.gradle.api.provider.ProviderFactory) Stream(java.util.stream.Stream) ProjectLayout(org.gradle.api.file.ProjectLayout) OutputFile(org.gradle.api.tasks.OutputFile) GradleException(org.gradle.api.GradleException) RegularFile(org.gradle.api.file.RegularFile) EtaGitDependency(com.typelead.gradle.eta.api.EtaGitDependency) DependencyUtils(com.typelead.gradle.eta.internal.DependencyUtils) Input(org.gradle.api.tasks.Input) SourceRepository(com.typelead.gradle.eta.api.SourceRepository) WriteResult(com.typelead.gradle.utils.CabalHelper.WriteResult) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) RegularFile(org.gradle.api.file.RegularFile) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) TaskAction(org.gradle.api.tasks.TaskAction)

Example 29 with TaskAction

use of org.gradle.api.tasks.TaskAction in project gradle-eta by typelead.

the class EtaSetupEnvironment method setupEnvironment.

@TaskAction
public void setupEnvironment() {
    EtlasCommand etlas = new EtlasCommand(getProject());
    ResolvedExecutable etlasExec = resolveEtlas();
    /* This is a bootstrap step since we need to populate
           this property in order for the following etlas
           invocation to work. */
    resolvedEtlas.set(etlasExec);
    ensureTelemetryPreferencesAndUpdate(etlas);
    if (etlasExec.getVersion() == null) {
        etlasExec.setVersion(etlas.numericVersion());
    }
    ResolvedExecutable etaExec = resolveEta(etlas);
    resolvedEta.set(etaExec);
    if (etaExec.isFresh()) {
        getProject().getLogger().lifecycle("Installing Eta v" + etaExec.getVersion());
        etlas.installEta();
    }
    boolean changed = SnapshotUtils.takeSnapshotAndCompare(getVersionsSnapshot(), etaExec, etlasExec, getEtaSpec(), getEtlasSpec());
    resolvedEtaInfo.set(fetchEtaInfo(etlas, etaExec, changed));
    versionsChanged.set(Boolean.valueOf(changed));
    setDidWork(changed);
}
Also used : ResolvedExecutable(com.typelead.gradle.utils.ResolvedExecutable) EtlasCommand(com.typelead.gradle.utils.EtlasCommand) TaskAction(org.gradle.api.tasks.TaskAction)

Example 30 with TaskAction

use of org.gradle.api.tasks.TaskAction in project curiostack by curioswitch.

the class DeployConfigMapTask method exec.

@TaskAction
public void exec() {
    ImmutableDeploymentExtension config = getProject().getExtensions().getByType(DeploymentExtension.class);
    final ImmutableDeploymentConfiguration deploymentConfig = config.getTypes().getByName(type);
    Map<String, RpcAcl> aclMap = deploymentConfig.rpcAcls().entrySet().stream().map(entry -> new SimpleImmutableEntry<>(entry.getKey(), ImmutableRpcAcl.builder().rate(entry.getValue()).build())).collect(toImmutableMap(Entry::getKey, Entry::getValue));
    final String serializedAcls;
    try {
        serializedAcls = OBJECT_MAPPER.writeValueAsString(aclMap);
    } catch (JsonProcessingException e) {
        throw new UncheckedIOException("Could not serialize acls.", e);
    }
    ConfigMap configMap = new ConfigMapBuilder().withMetadata(new ObjectMetaBuilder().withName("rpcacls").withNamespace(deploymentConfig.namespace()).build()).withData(ImmutableMap.of("rpcacls.json", serializedAcls)).build();
    KubernetesClient client = new DefaultKubernetesClient();
    client.resource(configMap).createOrReplace();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Style(org.immutables.value.Value.Style) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImmutableDeploymentExtension(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Immutable(org.immutables.value.Value.Immutable) ImmutableDeploymentConfiguration(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension.ImmutableDeploymentConfiguration) UncheckedIOException(org.gradle.api.UncheckedIOException) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) TaskAction(org.gradle.api.tasks.TaskAction) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImplementationVisibility(org.immutables.value.Value.Style.ImplementationVisibility) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Entry(java.util.Map.Entry) DefaultTask(org.gradle.api.DefaultTask) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BuilderVisibility(org.immutables.value.Value.Style.BuilderVisibility) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) DeploymentExtension(org.curioswitch.gradle.plugins.curioserver.DeploymentExtension) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) UncheckedIOException(org.gradle.api.UncheckedIOException) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) ImmutableDeploymentExtension(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ImmutableDeploymentConfiguration(org.curioswitch.gradle.plugins.curioserver.ImmutableDeploymentExtension.ImmutableDeploymentConfiguration) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

TaskAction (org.gradle.api.tasks.TaskAction)167 File (java.io.File)66 GradleException (org.gradle.api.GradleException)38 IOException (java.io.IOException)35 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)32 ArrayList (java.util.ArrayList)29 Project (org.gradle.api.Project)18 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)16 InputFile (org.gradle.api.tasks.InputFile)16 OutputFile (org.gradle.api.tasks.OutputFile)15 FileCollection (org.gradle.api.file.FileCollection)13 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)12 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)12 Map (java.util.Map)12 DefaultTask (org.gradle.api.DefaultTask)12 HashMap (java.util.HashMap)10 InvalidUserDataException (org.gradle.api.InvalidUserDataException)9 AndroidLibrary (com.android.builder.model.AndroidLibrary)8 URLClassLoader (java.net.URLClassLoader)8 WorkResult (org.gradle.api.tasks.WorkResult)8