Java Code Examples for org.gradle.api.tasks.TaskContainer

The following examples show how to use org.gradle.api.tasks.TaskContainer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void createCompileTasksForBinary(final TaskContainer tasks, BinarySpec binarySpec) {
    final BinarySpecInternal binary = (BinarySpecInternal) binarySpec;
    if (binary.isLegacyBinary() || !language.applyToBinary(binary)) {
        return;
    }

    final SourceTransformTaskConfig taskConfig = language.getTransformTask();
    binary.getSource().withType(language.getSourceSetType(), new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet languageSourceSet) {
            LanguageSourceSetInternal sourceSet = (LanguageSourceSetInternal) languageSourceSet;
            if (sourceSet.getMayHaveSources()) {
                String taskName = binary.getNamingScheme().getTaskName(taskConfig.getTaskPrefix(), sourceSet.getFullName());
                Task task = tasks.create(taskName, taskConfig.getTaskType());

                taskConfig.configureTask(task, binary, sourceSet);

                task.dependsOn(sourceSet);
                binary.getTasks().add(task);
            }
        }
    });
}
 
Example 2
@Mutate
void createLifecycleTaskForBinary(TaskContainer tasks, BinaryContainer binaries) {
    Task assembleTask = tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME);
    for (BinarySpecInternal binary : binaries.withType(BinarySpecInternal.class)) {
        if (!binary.isLegacyBinary()) {
            Task binaryLifecycleTask = tasks.create(binary.getNamingScheme().getLifecycleTaskName());
            binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
            binaryLifecycleTask.setDescription(String.format("Assembles %s.", binary));
            binary.setBuildTask(binaryLifecycleTask);

            if (binary.isBuildable()) {
                assembleTask.dependsOn(binary);
            }
        }
    }
}
 
Example 3
@Mutate
@SuppressWarnings("GroovyUnusedDeclaration")
public static void createTasksForVisualStudio(TaskContainer tasks, VisualStudioExtensionInternal visualStudioExtension) {
    for (VisualStudioProject vsProject : visualStudioExtension.getProjects()) {
        vsProject.builtBy(createProjectsFileTask(tasks, vsProject));
        vsProject.builtBy(createFiltersFileTask(tasks, vsProject));
    }

    for (VisualStudioSolution vsSolution : visualStudioExtension.getSolutions()) {
        Task solutionTask = tasks.create(vsSolution.getName() + "VisualStudio");
        solutionTask.setDescription(String.format("Generates the '%s' Visual Studio solution file.", vsSolution.getName()));
        vsSolution.setBuildTask(solutionTask);
        vsSolution.builtBy(createSolutionTask(tasks, vsSolution));

        // Lifecycle task for component
        NativeComponentSpec component = vsSolution.getComponent();
        Task lifecycleTask = tasks.maybeCreate(component.getName() + "VisualStudio");
        lifecycleTask.dependsOn(vsSolution);
        lifecycleTask.setGroup("IDE");
        lifecycleTask.setDescription(String.format("Generates the Visual Studio solution for %s.", component));
    }

    addCleanTask(tasks);
}
 
Example 4
public void apply(final Project project) {
    project.getPlugins().apply(PublishingPlugin.class);

    final TaskContainer tasks = project.getTasks();
    final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME);
    publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache.");
    publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);

    // Can't move this to rules yet, because it has to happen before user deferred configurable actions
    project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() {
        public void execute(PublishingExtension extension) {
            // Register factory for MavenPublication
            extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver));
        }
    });
}
 
Example 5
@Finalize
public void createTestTasks(final TaskContainer tasks, BinaryContainer binaries) {
    for (NativeTestSuiteBinarySpec testBinary : binaries.withType(NativeTestSuiteBinarySpec.class)) {
        NativeBinarySpecInternal binary = (NativeBinarySpecInternal) testBinary;
        final BinaryNamingScheme namingScheme = binary.getNamingScheme();

        RunTestExecutable runTask = tasks.create(namingScheme.getTaskName("run"), RunTestExecutable.class);
        final Project project = runTask.getProject();
        runTask.setDescription(String.format("Runs the %s", binary.getNamingScheme().getDescription()));

        final InstallExecutable installTask = binary.getTasks().withType(InstallExecutable.class).iterator().next();
        runTask.getInputs().files(installTask.getOutputs().getFiles());
        runTask.setExecutable(installTask.getRunScript().getPath());
        runTask.setOutputDir(new File(project.getBuildDir(), "/test-results/" + namingScheme.getOutputDirectoryBase()));
    }
}
 
Example 6
private static void addDependencyOrdering(List<String> dependencies, TaskContainer tasks) {
    String previous = null;
    for (final String dependency : dependencies) {
        if (previous != null) {
            final String finalPrevious = previous;
            tasks.all(new Action<Task>() {
                public void execute(Task task) {
                    if (task.getName().equals(dependency)) {
                        task.shouldRunAfter(finalPrevious);
                    }
                }
            });
        }

        previous = dependency;
    }
}
 
Example 7
public void apply(final Project project) {
    project.getPlugins().apply(PublishingPlugin.class);

    final TaskContainer tasks = project.getTasks();
    final Task publishLifecycleTask = tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME);
    final Task publishLocalLifecycleTask = tasks.create(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME);
    publishLocalLifecycleTask.setDescription("Publishes all Maven publications produced by this project to the local Maven cache.");
    publishLocalLifecycleTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);

    // Can't move this to rules yet, because it has to happen before user deferred configurable actions
    project.getExtensions().configure(PublishingExtension.class, new Action<PublishingExtension>() {
        public void execute(PublishingExtension extension) {
            // Register factory for MavenPublication
            extension.getPublications().registerFactory(MavenPublication.class, new MavenPublicationFactory(dependencyMetaDataProvider, instantiator, fileResolver));
        }
    });

    modelRules.rule(new MavenPublishTaskModelRule(project, publishLifecycleTask, publishLocalLifecycleTask));
}
 
Example 8
@SuppressWarnings("UnusedDeclaration")
public void createTasksForVisualStudio(TaskContainer tasks, VisualStudioExtension visualStudioExtension) {
    for (VisualStudioProject vsProject : visualStudioExtension.getProjects()) {
        vsProject.builtBy(createProjectsFileTask(tasks, vsProject));
        vsProject.builtBy(createFiltersFileTask(tasks, vsProject));
    }

    for (VisualStudioSolution vsSolution : visualStudioExtension.getSolutions()) {
        Task solutionTask = tasks.create(vsSolution.getName() + "VisualStudio");
        solutionTask.setDescription(String.format("Generates the '%s' Visual Studio solution file.", vsSolution.getName()));
        vsSolution.setLifecycleTask(solutionTask);
        vsSolution.builtBy(createSolutionTask(tasks, vsSolution));

        // Lifecycle task for component
        ProjectNativeComponent component = vsSolution.getComponent();
        Task lifecycleTask = tasks.maybeCreate(component.getName() + "VisualStudio");
        lifecycleTask.dependsOn(vsSolution);
        lifecycleTask.setGroup("IDE");
        lifecycleTask.setDescription(String.format("Generates the Visual Studio solution for %s.", component));
    }

    addCleanTask(tasks);
}
 
Example 9
@Finalize
public void createTestTasks(final TaskContainer tasks, BinaryContainer binaries) {
    for (NativeTestSuiteBinarySpec testBinary : binaries.withType(NativeTestSuiteBinarySpec.class)) {
        NativeBinarySpecInternal binary = (NativeBinarySpecInternal) testBinary;
        final BinaryNamingScheme namingScheme = binary.getNamingScheme();

        RunTestExecutable runTask = tasks.create(namingScheme.getTaskName("run"), RunTestExecutable.class);
        final Project project = runTask.getProject();
        runTask.setDescription(String.format("Runs the %s", binary.getNamingScheme().getDescription()));

        final InstallExecutable installTask = binary.getTasks().withType(InstallExecutable.class).iterator().next();
        runTask.getInputs().files(installTask.getOutputs().getFiles());
        runTask.setExecutable(installTask.getRunScript().getPath());
        runTask.setOutputDir(new File(project.getBuildDir(), "/test-results/" + namingScheme.getOutputDirectoryBase()));
    }
}
 
Example 10
private static void addDependencyOrdering(List<String> dependencies, TaskContainer tasks) {
    String previous = null;
    for (final String dependency : dependencies) {
        if (previous != null) {
            final String finalPrevious = previous;
            tasks.all(new Action<Task>() {
                public void execute(Task task) {
                    if (task.getName().equals(dependency)) {
                        task.shouldRunAfter(finalPrevious);
                    }
                }
            });
        }

        previous = dependency;
    }
}
 
Example 11
private void addDependencyOrdering(Enumeration<String> dependencies) {
    TaskContainer tasks = gradleProject.getTasks();
    String previous = null;
    for (final String dependency : Collections.list(dependencies)) {
        if (previous != null) {
            final String finalPrevious = previous;
            tasks.all(new Action<Task>() {
                public void execute(Task task) {
                    if (task.getName().equals(dependency)) {
                        task.shouldRunAfter(finalPrevious);
                    }
                }
            });
        }

        previous = dependency;
    }
}
 
Example 12
private void addTasks(Pair result, TaskContainer tasks) {
    CredentialsEncryptor credentialsEncryptor = result.credentialsEncryptor;
    CredentialsPersistenceManager credentialsPersistenceManager = result.credentialsPersistenceManager;

    // add a task instance that stores new credentials through the credentials persistence manager
    AddCredentialsTask addCredentials = tasks.create(ADD_CREDENTIALS_TASK_NAME, AddCredentialsTask.class);
    addCredentials.setDescription("Adds the credentials specified through the project properties 'credentialsKey' and 'credentialsValue'.");
    addCredentials.setGroup("Credentials");
    addCredentials.setCredentialsEncryptor(credentialsEncryptor);
    addCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager);
    addCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE);
    LOGGER.debug(String.format("Registered task '%s'", addCredentials.getName()));

    // add a task instance that removes some credentials through the credentials persistence manager
    RemoveCredentialsTask removeCredentials = tasks.create(REMOVE_CREDENTIALS_TASK_NAME, RemoveCredentialsTask.class);
    removeCredentials.setDescription("Removes the credentials specified through the project property 'credentialsKey'.");
    removeCredentials.setGroup("Credentials");
    removeCredentials.setCredentialsPersistenceManager(credentialsPersistenceManager);
    removeCredentials.getOutputs().upToDateWhen(AlwaysFalseSpec.INSTANCE);
    LOGGER.debug(String.format("Registered task '%s'", removeCredentials.getName()));
}
 
Example 13
@Test
public void testMinikubeExtensionSetProperties() {
  Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build();
  project.getPluginManager().apply(MinikubePlugin.class);
  MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube");
  ex.setMinikube("/custom/minikube/path");

  TaskContainer t = project.getTasks();
  TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class);

  Assert.assertEquals(3, tc.size());

  tc.forEach(
      minikubeTask -> {
        Assert.assertEquals(minikubeTask.getMinikube(), "/custom/minikube/path");
      });
}
 
Example 14
@Override
public void apply(Project project) {
    final ConfigurationContainer configurations = project.getConfigurations();
    configurations.maybeCreate("test");
    configurations.maybeCreate("build");
    configurations.maybeCreate("tool");

    final ExtensionContainer extensions = project.getExtensions();
    final ExtensionAware golang = (ExtensionAware) extensions.create("golang", GolangSettings.class, true, project);
    golang.getExtensions().create("build", BuildSettings.class, true, project);
    golang.getExtensions().create("toolchain", ToolchainSettings.class, true, project);
    golang.getExtensions().create("dependencies", DependenciesSettings.class, true, project);
    golang.getExtensions().create("testing", TestingSettings.class, true, project);

    extensions.create(INSTANCE_PROPERTY_NAME, Reference.class, this);

    final TaskContainer tasks = project.getTasks();
    addTasks(tasks);
}
 
Example 15
Source Project: pygradle   Source File: LayeredWheelCachePlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
    WheelExtension wheelExtension = ExtensionUtils.maybeCreateWheelExtension(project);
    EditablePythonAbiContainer supportedWheelFormats = ExtensionUtils.getEditablePythonAbiContainer(project);
    LayeredWheelCache wheelCache = new LayeredWheelCache(wheelExtension.getLayeredCacheMap(), supportedWheelFormats);

    TaskContainer tasks = project.getTasks();

    tasks.withType(ProvidesVenv.class, task -> task.setEditablePythonAbiContainer(supportedWheelFormats));

    tasks.withType(SupportsWheelCache.class, task -> task.setWheelCache(wheelCache));

    tasks.create(LayeredWheelCacheTask.TASK_LAYERED_WHEEL_CACHE, LayeredWheelCacheTask.class, task -> {
        tasks.getByName(TASK_VENV_CREATE.getValue()).dependsOn(task);
        tasks.getByName(TASK_FLAKE.getValue()).dependsOn(task);
    });
}
 
Example 16
private void addDependencyOrdering(Enumeration<String> dependencies) {
    TaskContainer tasks = gradleProject.getTasks();
    String previous = null;
    for (final String dependency : Collections.list(dependencies)) {
        if (previous != null) {
            final String finalPrevious = previous;
            tasks.all(new Action<Task>() {
                public void execute(Task task) {
                    if (task.getName().equals(dependency)) {
                        task.shouldRunAfter(finalPrevious);
                    }
                }
            });
        }

        previous = dependency;
    }
}
 
Example 17
private <R, S extends BinarySpec> void doRegister(MethodRuleDefinition<R> ruleDefinition, ModelRegistry modelRegistry, RuleSourceDependencies dependencies) {
    try {
        RuleMethodDataCollector dataCollector = new RuleMethodDataCollector();
        verifyMethodSignature(dataCollector, ruleDefinition);

        Class<S> binaryType =  dataCollector.getParameterType(BinarySpec.class);
        dependencies.add(ComponentModelBasePlugin.class);

        final ModelReference<TaskContainer> tasks = ModelReference.of(ModelPath.path("tasks"), new ModelType<TaskContainer>() {
        });

        modelRegistry.mutate(new BinaryTaskRule<R, S>(tasks, binaryType, ruleDefinition, modelRegistry));

    } catch (InvalidComponentModelException e) {
        invalidModelRule(ruleDefinition, e);
    }
}
 
Example 18
@Mutate
@SuppressWarnings("GroovyUnusedDeclaration")
public static void createTasksForVisualStudio(TaskContainer tasks, VisualStudioExtensionInternal visualStudioExtension) {
    for (VisualStudioProject vsProject : visualStudioExtension.getProjects()) {
        vsProject.builtBy(createProjectsFileTask(tasks, vsProject));
        vsProject.builtBy(createFiltersFileTask(tasks, vsProject));
    }

    for (VisualStudioSolution vsSolution : visualStudioExtension.getSolutions()) {
        Task solutionTask = tasks.create(vsSolution.getName() + "VisualStudio");
        solutionTask.setDescription(String.format("Generates the '%s' Visual Studio solution file.", vsSolution.getName()));
        vsSolution.setBuildTask(solutionTask);
        vsSolution.builtBy(createSolutionTask(tasks, vsSolution));

        // Lifecycle task for component
        NativeComponentSpec component = vsSolution.getComponent();
        Task lifecycleTask = tasks.maybeCreate(component.getName() + "VisualStudio");
        lifecycleTask.dependsOn(vsSolution);
        lifecycleTask.setGroup("IDE");
        lifecycleTask.setDescription(String.format("Generates the Visual Studio solution for %s.", component));
    }

    addCleanTask(tasks);
}
 
Example 19
@SuppressWarnings("UnusedDeclaration")
public void createTasksForVisualStudio(TaskContainer tasks, VisualStudioExtension visualStudioExtension) {
    for (VisualStudioProject vsProject : visualStudioExtension.getProjects()) {
        vsProject.builtBy(createProjectsFileTask(tasks, vsProject));
        vsProject.builtBy(createFiltersFileTask(tasks, vsProject));
    }

    for (VisualStudioSolution vsSolution : visualStudioExtension.getSolutions()) {
        Task solutionTask = tasks.create(vsSolution.getName() + "VisualStudio");
        solutionTask.setDescription(String.format("Generates the '%s' Visual Studio solution file.", vsSolution.getName()));
        vsSolution.setLifecycleTask(solutionTask);
        vsSolution.builtBy(createSolutionTask(tasks, vsSolution));

        // Lifecycle task for component
        ProjectNativeComponent component = vsSolution.getComponent();
        Task lifecycleTask = tasks.maybeCreate(component.getName() + "VisualStudio");
        lifecycleTask.dependsOn(vsSolution);
        lifecycleTask.setGroup("IDE");
        lifecycleTask.setDescription(String.format("Generates the Visual Studio solution for %s.", component));
    }

    addCleanTask(tasks);
}
 
Example 20
@Mutate
public void createTasks(TaskContainer tasks, BinaryContainer binaries) {
    for (JarBinarySpecInternal projectJarBinary : binaries.withType(JarBinarySpecInternal.class)) {
        Task jarTask = createJarTask(tasks, projectJarBinary);
        projectJarBinary.builtBy(jarTask);
        projectJarBinary.getTasks().add(jarTask);
    }
}
 
Example 21
private Task createJarTask(TaskContainer tasks, JarBinarySpecInternal binary) {
    Jar jar = tasks.create(binary.getNamingScheme().getTaskName("create"), Jar.class);
    jar.setDescription(String.format("Creates the binary file for %s.", binary.getNamingScheme().getDescription()));
    jar.from(binary.getClassesDir());
    jar.from(binary.getResourcesDir());

    jar.setDestinationDir(binary.getJarFile().getParentFile());
    jar.setArchiveName(binary.getJarFile().getName());

    return jar;
}
 
Example 22
private void createPublishTasksForEachMavenRepo(TaskContainer tasks, PublishingExtension extension, MavenPublicationInternal publication, String publicationName) {
    for (MavenArtifactRepository repository : extension.getRepositories().withType(MavenArtifactRepository.class)) {
        String repositoryName = repository.getName();

        String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName));

        PublishToMavenRepository publishTask = tasks.create(publishTaskName, PublishToMavenRepository.class);
        publishTask.setPublication(publication);
        publishTask.setRepository(repository);
        publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        publishTask.setDescription(String.format("Publishes Maven publication '%s' to Maven repository '%s'.", publicationName, repositoryName));

        publishLifecycleTask.dependsOn(publishTask);
    }
}
 
Example 23
public void mutate(TaskContainer container, Inputs inputs) {
    BinaryContainer binaries = inputs.get(0, ModelType.of(BinaryContainer.class)).getInstance();
    for (T binary : binaries.withType(binaryType)) {
        NamedEntityInstantiator<Task> instantiator = new Instantiator<Task>(binary, container);
        DefaultCollectionBuilder<Task> collectionBuilder = new DefaultCollectionBuilder<Task>(
                getSubject().getPath(),
                instantiator,
                new SimpleModelRuleDescriptor("Project.<init>.tasks()"),
                inputs,
                modelRegistry);

        invoke(inputs, collectionBuilder, binary, binaries);
    }
}
 
Example 24
@Mutate
public void createCUnitLauncherTasks(TaskContainer tasks, TestSuiteContainer testSuites, ProjectSourceSet sources) {
    for (final CUnitTestSuiteSpec suite : testSuites.withType(CUnitTestSuiteSpec.class)) {

        String taskName = suite.getName() + "CUnitLauncher";
        GenerateCUnitLauncher skeletonTask = tasks.create(taskName, GenerateCUnitLauncher.class);

        CSourceSet launcherSources = findLaucherSources(suite);
        skeletonTask.setSourceDir(launcherSources.getSource().getSrcDirs().iterator().next());
        skeletonTask.setHeaderDir(launcherSources.getExportedHeaders().getSrcDirs().iterator().next());
        launcherSources.builtBy(skeletonTask);
    }
}
 
Example 25
@SuppressWarnings("UnusedDeclaration")
public void realizePublishingTasks(TaskContainer tasks, PublishingExtension extension) {
    // Create generatePom tasks for any Maven publication
    PublicationContainer publications = extension.getPublications();

    for (final MavenPublicationInternal publication : publications.withType(MavenPublicationInternal.class)) {
        String publicationName = publication.getName();

        createGeneratePomTask(publication, publicationName);
        createLocalInstallTask(tasks, publication, publicationName);
        createPublishTasksForEachMavenRepo(tasks, extension, publication, publicationName);
    }
}
 
Example 26
@SuppressWarnings("UnusedDeclaration")
public void realizePublishingTasks(TaskContainer tasks, PublishingExtension extension) {
    // Create generatePom tasks for any Maven publication
    PublicationContainer publications = extension.getPublications();

    for (final MavenPublicationInternal publication : publications.withType(MavenPublicationInternal.class)) {
        String publicationName = publication.getName();

        createGeneratePomTask(publication, publicationName);
        createLocalInstallTask(tasks, publication, publicationName);
        createPublishTasksForEachMavenRepo(tasks, extension, publication, publicationName);
    }
}
 
Example 27
private void createPublishTasksForEachMavenRepo(TaskContainer tasks, PublishingExtension extension, MavenPublicationInternal publication, String publicationName) {
    for (MavenArtifactRepository repository : extension.getRepositories().withType(MavenArtifactRepository.class)) {
        String repositoryName = repository.getName();

        String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName));

        PublishToMavenRepository publishTask = tasks.create(publishTaskName, PublishToMavenRepository.class);
        publishTask.setPublication(publication);
        publishTask.setRepository(repository);
        publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        publishTask.setDescription(String.format("Publishes Maven publication '%s' to Maven repository '%s'.", publicationName, repositoryName));

        publishLifecycleTask.dependsOn(publishTask);
    }
}
 
Example 28
private void createLocalInstallTask(TaskContainer tasks, MavenPublicationInternal publication, String publicationName) {
    String installTaskName = String.format("publish%sPublicationToMavenLocal", capitalize(publicationName));

    PublishToMavenLocal publishLocalTask = tasks.create(installTaskName, PublishToMavenLocal.class);
    publishLocalTask.setPublication(publication);
    publishLocalTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    publishLocalTask.setDescription(String.format("Publishes Maven publication '%s' to the local Maven repository.", publicationName));

    publishLocalLifecycleTask.dependsOn(installTaskName);
}
 
Example 29
public void createTasks(TaskContainer tasks, PublishingExtension publishingExtension) {
    PublicationContainer publications = publishingExtension.getPublications();
    RepositoryHandler repositories = publishingExtension.getRepositories();

    for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) {

        final String publicationName = publication.getName();
        final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName));

        GenerateIvyDescriptor descriptorTask = tasks.create(descriptorTaskName, GenerateIvyDescriptor.class);
        descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName()));
        descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        descriptorTask.setDescriptor(publication.getDescriptor());

        ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping();
        descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
            public Object call() throws Exception {
                return new File(project.getBuildDir(), "publications/" + publication.getName() + "/ivy.xml");
            }
        });

        publication.setDescriptorFile(descriptorTask.getOutputs().getFiles());

        for (IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) {
            final String repositoryName = repository.getName();
            final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName));

            PublishToIvyRepository publishTask = tasks.create(publishTaskName, PublishToIvyRepository.class);
            publishTask.setPublication(publication);
            publishTask.setRepository(repository);
            publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
            publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName));

            tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTask);
        }
    }
}
 
Example 30
Source Project: jig   Source File: JigGradlePlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    ExtensionContainer extensions = project.getExtensions();
    extensions.create("jig", JigConfig.class);
    TaskContainer tasks = project.getTasks();

    JigReportsTask jigReports = tasks.create("jigReports", JigReportsTask.class);
    jigReports.setGroup("JIG");
    jigReports.setDescription("Generates JIG documentation for the main source code.");

    VerifyJigEnvironmentTask verifyTask = tasks.create("verifyJigEnvironment", VerifyJigEnvironmentTask.class);
    verifyTask.setGroup("JIG");
    verifyTask.setDescription("Verify JIG environment.");
}