Search in sources :

Example 31 with Convention

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

the class ExtensibleDynamicObjectTest method conventionPropertyTakesPrecedenceOverParentProperty.

@Test
public void conventionPropertyTakesPrecedenceOverParentProperty() {
    Bean parent = new Bean();
    parent.defineProperty("conventionProperty", "parent");
    Bean bean = new Bean();
    bean.setParent(parent.getAsDynamicObject());
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("value");
    convention.getPlugins().put("test", conventionBean);
    assertThat(bean.getProperty("conventionProperty"), equalTo((Object) "value"));
}
Also used : Convention(org.gradle.api.plugins.Convention) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 32 with Convention

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

the class ExtensibleDynamicObjectTest method inheritedConventionPropertiesTrackChanges.

@Test
public void inheritedConventionPropertiesTrackChanges() {
    Bean bean = new Bean();
    DynamicObject inherited = bean.getInheritable();
    assertFalse(inherited.hasProperty("conventionProperty"));
    Convention convention = bean.extensibleDynamicObject.getConvention();
    ConventionBean conventionBean = new ConventionBean();
    conventionBean.setConventionProperty("value");
    convention.getPlugins().put("convention", conventionBean);
    assertTrue(inherited.hasProperty("conventionProperty"));
    assertThat(inherited.getProperty("conventionProperty"), equalTo((Object) "value"));
}
Also used : Convention(org.gradle.api.plugins.Convention) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) Test(org.junit.Test)

Example 33 with Convention

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

the class GradleSourceFilesConfigurationTest method setUp.

@Before
public void setUp() throws URISyntaxException, IOException {
    Project mockProject = Mockito.mock(Project.class);
    Convention mockConvention = Mockito.mock(Convention.class);
    JavaPluginConvention mockJavaPluginConvention = Mockito.mock(JavaPluginConvention.class);
    SourceSetContainer mockSourceSetContainer = Mockito.mock(SourceSetContainer.class);
    SourceSet mockMainSourceSet = Mockito.mock(SourceSet.class);
    SourceSetOutput mockMainSourceSetOutput = Mockito.mock(SourceSetOutput.class);
    Set<File> classesFiles = ImmutableSet.of(Paths.get(Resources.getResource("application/classes").toURI()).toFile());
    FileCollection classesFileCollection = new TestFileCollection(classesFiles);
    File resourcesOutputDir = Paths.get(Resources.getResource("application/resources").toURI()).toFile();
    Set<File> allFiles = new HashSet<>(classesFiles);
    allFiles.add(resourcesOutputDir);
    allFiles.add(Paths.get(Resources.getResource("application/dependencies/libraryB.jar").toURI()).toFile());
    allFiles.add(Paths.get(Resources.getResource("application/dependencies/libraryA.jar").toURI()).toFile());
    allFiles.add(Paths.get(Resources.getResource("application/dependencies/dependency-1.0.0.jar").toURI()).toFile());
    FileCollection runtimeFileCollection = new TestFileCollection(allFiles);
    Mockito.when(mockProject.getConvention()).thenReturn(mockConvention);
    Mockito.when(mockConvention.getPlugin(JavaPluginConvention.class)).thenReturn(mockJavaPluginConvention);
    Mockito.when(mockJavaPluginConvention.getSourceSets()).thenReturn(mockSourceSetContainer);
    Mockito.when(mockSourceSetContainer.getByName("main")).thenReturn(mockMainSourceSet);
    Mockito.when(mockMainSourceSet.getOutput()).thenReturn(mockMainSourceSetOutput);
    Mockito.when(mockMainSourceSetOutput.getClassesDirs()).thenReturn(classesFileCollection);
    Mockito.when(mockMainSourceSetOutput.getResourcesDir()).thenReturn(resourcesOutputDir);
    Mockito.when(mockMainSourceSet.getRuntimeClasspath()).thenReturn(runtimeFileCollection);
    testGradleSourceFilesConfiguration = GradleSourceFilesConfiguration.getForProject(mockProject);
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) AbstractFileCollection(org.gradle.api.internal.file.AbstractFileCollection) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) SourceSetOutput(org.gradle.api.tasks.SourceSetOutput) File(java.io.File) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

Convention (org.gradle.api.plugins.Convention)33 Test (org.junit.Test)28 BeanDynamicObject (org.gradle.internal.metaobject.BeanDynamicObject)20 DynamicObject (org.gradle.internal.metaobject.DynamicObject)20 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)5 File (java.io.File)3 DefaultScalaSourceSet (org.gradle.api.internal.tasks.DefaultScalaSourceSet)3 ScalaSourceSet (org.gradle.api.tasks.ScalaSourceSet)3 BuildAdapter (org.gradle.BuildAdapter)2 Gradle (org.gradle.api.invocation.Gradle)2 SourceSet (org.gradle.api.tasks.SourceSet)2 IncrementalCompileOptions (org.gradle.api.tasks.scala.IncrementalCompileOptions)2 ScalaCompile (org.gradle.api.tasks.scala.ScalaCompile)2 Jar (org.gradle.jvm.tasks.Jar)2 HashSet (java.util.HashSet)1 Callable (java.util.concurrent.Callable)1 Project (org.gradle.api.Project)1 FileCollection (org.gradle.api.file.FileCollection)1 FileTreeElement (org.gradle.api.file.FileTreeElement)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1