Search in sources :

Example 6 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class JettyPlugin method apply.

public void apply(Project project) {
    DeprecationLogger.nagUserOfPluginReplacedWithExternalOne("Jetty", "Gretty (https://github.com/akhikhl/gretty)");
    project.getPluginManager().apply(WarPlugin.class);
    JettyPluginConvention jettyConvention = new JettyPluginConvention();
    Convention convention = project.getConvention();
    convention.getPlugins().put("jetty", jettyConvention);
    configureMappingRules(project, jettyConvention);
    configureJettyRun(project);
    configureJettyRunWar(project);
    configureJettyStop(project, jettyConvention);
}
Also used : WarPluginConvention(org.gradle.api.plugins.WarPluginConvention) Convention(org.gradle.api.plugins.Convention) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention)

Example 7 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ScalaBasePlugin method configureScalaCompile.

private static void configureScalaCompile(final Project project, final SourceSet sourceSet) {
    String taskName = sourceSet.getCompileTaskName("scala");
    final ScalaCompile scalaCompile = project.getTasks().create(taskName, ScalaCompile.class);
    scalaCompile.dependsOn(sourceSet.getCompileJavaTaskName());
    Convention scalaConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
    ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class);
    SourceSetUtil.configureForSourceSet(sourceSet, scalaSourceSet.getScala(), scalaCompile, scalaCompile.getOptions(), project);
    scalaCompile.setDescription("Compiles the " + scalaSourceSet.getScala() + ".");
    scalaCompile.setSource(scalaSourceSet.getScala());
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(taskName);
    // cannot use convention mapping because the resulting object won't be serializable
    // cannot compute at task execution time because we need association with source set
    project.getGradle().addBuildListener(new BuildAdapter() {

        @Override
        public void projectsEvaluated(Gradle gradle) {
            IncrementalCompileOptions incrementalOptions = scalaCompile.getScalaCompileOptions().getIncrementalOptions();
            if (incrementalOptions.getAnalysisFile() == null) {
                String analysisFilePath = project.getBuildDir().getPath() + "/tmp/scala/compilerAnalysis/" + scalaCompile.getName() + ".analysis";
                incrementalOptions.setAnalysisFile(new File(analysisFilePath));
            }
            if (incrementalOptions.getPublishedCode() == null) {
                Jar jarTask = (Jar) project.getTasks().findByName(sourceSet.getJarTaskName());
                incrementalOptions.setPublishedCode(jarTask == null ? null : jarTask.getArchivePath());
            }
        }
    });
}
Also used : IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) ScalaSourceSet(org.gradle.api.tasks.ScalaSourceSet) DefaultScalaSourceSet(org.gradle.api.internal.tasks.DefaultScalaSourceSet) BuildAdapter(org.gradle.BuildAdapter) Jar(org.gradle.jvm.tasks.Jar) Gradle(org.gradle.api.invocation.Gradle) File(java.io.File)

Example 8 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canGetAllProperties.

@Test
public void canGetAllProperties() {
    Bean parent = new Bean();
    parent.defineProperty("parentProperty", "parentProperty");
    parent.setReadWriteProperty("ignore me");
    parent.doSetReadOnlyProperty("ignore me");
    Convention parentConvention = parent.extensibleDynamicObject.getConvention();
    parentConvention.getPlugins().put("parent", new ConventionBean());
    GroovyBean bean = new GroovyBean();
    bean.defineProperty("additional", "additional");
    bean.setReadWriteProperty("readWriteProperty");
    bean.doSetReadOnlyProperty("readOnlyProperty");
    bean.setGroovyProperty("groovyProperty");
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("conventionProperty");
    convention.getPlugins().put("bean", conventionBean);
    bean.setParent(parent.getAsDynamicObject());
    Map<String, Object> properties = bean.getProperties();
    assertThat(properties.get("properties"), sameInstance((Object) properties));
    assertThat(properties.get("readWriteProperty"), equalTo((Object) "readWriteProperty"));
    assertThat(properties.get("readOnlyProperty"), equalTo((Object) "readOnlyProperty"));
    assertThat(properties.get("parentProperty"), equalTo((Object) "parentProperty"));
    assertThat(properties.get("additional"), equalTo((Object) "additional"));
    assertThat(properties.get("groovyProperty"), equalTo((Object) "groovyProperty"));
    assertThat(properties.get("groovyDynamicProperty"), equalTo(null));
    assertThat(properties.get("conventionProperty"), equalTo((Object) "conventionProperty"));
}
Also used : Convention(org.gradle.api.plugins.Convention) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 9 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method canInvokeMethodDefinedByConvention.

@Test
public void canInvokeMethodDefinedByConvention() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    assertFalse(bean.hasMethod("conventionMethod", "a", "b"));
    convention.getPlugins().put("bean", new ConventionBean());
    assertTrue(bean.hasMethod("conventionMethod", "a", "b"));
    assertThat(bean.getAsDynamicObject().invokeMethod("conventionMethod", "a", "b"), equalTo((Object) "convention:a.b"));
}
Also used : Convention(org.gradle.api.plugins.Convention) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Test(org.junit.Test)

Example 10 with Convention

use of org.gradle.api.plugins.Convention in project gradle by gradle.

the class ExtensibleDynamicObjectTest method hasPropertyDefinedByConventionObject.

@Test
public void hasPropertyDefinedByConventionObject() {
    Bean bean = new Bean();
    Convention convention = bean.extensibleDynamicObject.getConvention();
    assertFalse(bean.hasProperty("conventionProperty"));
    assertFalse(bean.hasProperty("conventionProperty"));
    convention.getPlugins().put("test", new ConventionBean());
    assertTrue(bean.hasProperty("conventionProperty"));
}
Also used : Convention(org.gradle.api.plugins.Convention) Test(org.junit.Test)

Aggregations

Convention (org.gradle.api.plugins.Convention)18 Test (org.junit.Test)14 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)10 DynamicObject (org.gradle.internal.metaobject.DynamicObject)10 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)4 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)3 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)3 File (java.io.File)2 BuildAdapter (org.gradle.BuildAdapter)2 Gradle (org.gradle.api.invocation.Gradle)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)2 Jar (org.gradle.jvm.tasks.Jar)2 Callable (java.util.concurrent.Callable)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1 WarPluginConvention (org.gradle.api.plugins.WarPluginConvention)1 Spec (org.gradle.api.specs.Spec)1 SourceSet (org.gradle.api.tasks.SourceSet)1