Search in sources :

Example 16 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method filteredCollectionExecutesClosureWhenMatchingObjectAdded.

@Test
public void filteredCollectionExecutesClosureWhenMatchingObjectAdded() {
    final TestClosure closure = context.mock(TestClosure.class);
    final Bean bean = new Bean();
    context.checking(new Expectations() {

        {
            one(closure).call(bean);
        }
    });
    Spec<Bean> spec = new Spec<Bean>() {

        public boolean isSatisfiedBy(Bean element) {
            return element == bean;
        }
    };
    container.matching(spec).whenObjectAdded(TestUtil.toClosure(closure));
    container.add(bean);
    container.add(new Bean());
}
Also used : TestClosure(org.gradle.util.TestClosure) Expectations(org.jmock.Expectations) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 17 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class DefaultNamedDomainObjectSetTest method filteredCollectionExecutesActionWhenMatchingObjectAdded.

@Test
public void filteredCollectionExecutesActionWhenMatchingObjectAdded() {
    final Action<Bean> action = context.mock(Action.class);
    final Bean bean = new Bean();
    context.checking(new Expectations() {

        {
            one(action).execute(bean);
        }
    });
    Spec<Bean> spec = new Spec<Bean>() {

        public boolean isSatisfiedBy(Bean element) {
            return element == bean;
        }
    };
    container.matching(spec).whenObjectAdded(action);
    container.add(bean);
    container.add(new Bean());
}
Also used : Expectations(org.jmock.Expectations) Spec(org.gradle.api.specs.Spec) Test(org.junit.Test)

Example 18 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class JacocoReport method generate.

@TaskAction
public void generate() {
    final Spec<File> fileExistsSpec = new Spec<File>() {

        @Override
        public boolean isSatisfiedBy(File file) {
            return file.exists();
        }
    };
    new AntJacocoReport(getAntBuilder()).execute(getJacocoClasspath(), getProject().getName(), getAllClassDirs().filter(fileExistsSpec), getAllSourceDirs().filter(fileExistsSpec), getExecutionData(), getReports());
}
Also used : AntJacocoReport(org.gradle.internal.jacoco.AntJacocoReport) Spec(org.gradle.api.specs.Spec) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 19 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class JacocoCoverageVerification method check.

@TaskAction
public void check() {
    final Spec<File> fileExistsSpec = new Spec<File>() {

        @Override
        public boolean isSatisfiedBy(File file) {
            return file.exists();
        }
    };
    JacocoCheckResult checkResult = new AntJacocoCheck(getAntBuilder()).execute(getJacocoClasspath(), getProject().getName(), getAllClassDirs().filter(fileExistsSpec), getAllSourceDirs().filter(fileExistsSpec), getExecutionData(), getViolationRules());
    if (!checkResult.isSuccess()) {
        throw new GradleException(checkResult.getFailureMessage());
    }
}
Also used : GradleException(org.gradle.api.GradleException) AntJacocoCheck(org.gradle.internal.jacoco.AntJacocoCheck) Spec(org.gradle.api.specs.Spec) File(java.io.File) JacocoCheckResult(org.gradle.internal.jacoco.JacocoCheckResult) TaskAction(org.gradle.api.tasks.TaskAction)

Example 20 with Spec

use of org.gradle.api.specs.Spec in project gradle by gradle.

the class ScalaBasePlugin method configureSourceSetDefaults.

private static void configureSourceSetDefaults(final Project project, final SourceDirectorySetFactory sourceDirectorySetFactory) {
    final JavaBasePlugin javaPlugin = project.getPlugins().getPlugin(JavaBasePlugin.class);
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(final SourceSet sourceSet) {
            String displayName = (String) InvokerHelper.invokeMethod(sourceSet, "getDisplayName", null);
            Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
            DefaultScalaSourceSet scalaSourceSet = new DefaultScalaSourceSet(displayName, sourceDirectorySetFactory);
            sourceSetConvention.getPlugins().put("scala", scalaSourceSet);
            final SourceDirectorySet scalaDirectorySet = scalaSourceSet.getScala();
            scalaDirectorySet.srcDir(new Callable<File>() {

                @Override
                public File call() throws Exception {
                    return project.file("src/" + sourceSet.getName() + "/scala");
                }
            });
            sourceSet.getAllJava().source(scalaDirectorySet);
            sourceSet.getAllSource().source(scalaDirectorySet);
            sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {

                @Override
                public boolean isSatisfiedBy(FileTreeElement element) {
                    return scalaDirectorySet.contains(element.getFile());
                }
            });
            configureScalaCompile(project, javaPlugin, sourceSet);
        }
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) FileTreeElement(org.gradle.api.file.FileTreeElement) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Spec(org.gradle.api.specs.Spec) Callable(java.util.concurrent.Callable)

Aggregations

Spec (org.gradle.api.specs.Spec)25 Test (org.junit.Test)8 Task (org.gradle.api.Task)7 File (java.io.File)6 Project (org.gradle.api.Project)4 TestClosure (org.gradle.util.TestClosure)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Expectations (org.jmock.Expectations)3 Callable (java.util.concurrent.Callable)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Usage (org.gradle.api.attributes.Usage)2 FileTreeElement (org.gradle.api.file.FileTreeElement)2 TaskInternal (org.gradle.api.internal.TaskInternal)2 SourceSet (org.gradle.api.tasks.SourceSet)2 TaskAction (org.gradle.api.tasks.TaskAction)2 TaskContainer (org.gradle.api.tasks.TaskContainer)2 SdkConstants (com.android.SdkConstants)1 NonNull (com.android.annotations.NonNull)1