public AtlasExtension(@NonNull final ProjectInternal project, @NonNull Instantiator instantiator, @NonNull NamedDomainObjectContainer<T> buildTypes, @NonNull NamedDomainObjectContainer<PatchConfig> patchConfigs, @NonNull NamedDomainObjectContainer<DexConfig>dexConfigs) { logger = Logging.getLogger(this.getClass()); this.project = project; this.patchConfigs = patchConfigs; this.dexConfigs = dexConfigs; this.buildTypes = buildTypes; this.multiDexConfigs = project.container(MultiDexConfig.class, new MultiDexConfigFactory( instantiator,project, project.getLogger())); tBuildConfig = (Z) instantiator.newInstance(TBuildConfig.class); manifestOptions = instantiator.newInstance(ManifestOptions.class); bundleConfig = instantiator.newInstance(BundleConfig.class); }
public AtlasExtension createExtendsion(Project project, Instantiator instantiator) { AtlasExtension atlasExtension = getExtendsion(project); if (null != atlasExtension) { return atlasExtension; } final NamedDomainObjectContainer<TBuildType> buildTypeContainer = project.container(TBuildType.class, new TBuildTypeFactory( instantiator, project, project.getLogger())); final NamedDomainObjectContainer<PatchConfig> patchConfigContainer = project.container(PatchConfig.class, new PatchConfigFactory( instantiator, project, project .getLogger())); final NamedDomainObjectContainer<DexConfig>dexConfigContainer = project.container(DexConfig.class,new DexConfigFactory(instantiator,project,project.getLogger())); return project.getExtensions().create("atlas", AtlasExtension.class, project, instantiator, buildTypeContainer, patchConfigContainer,dexConfigContainer); }
@Override public NamedDomainObjectContainer<ConfigurationVariant> getVariants() { if (variants == null) { // Create variants container only as required variants = new FactoryNamedDomainObjectContainer<ConfigurationVariant>(ConfigurationVariant.class, instantiator, new NamedDomainObjectFactory<ConfigurationVariant>() { @Override public ConfigurationVariant create(String name) { return instantiator.newInstance(DefaultVariant.class, name, parentAttributes, artifactNotationParser, fileCollectionFactory); } }); } return variants; }
@Finalize public void addMarkerPublications(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment) { if (!pluginDevelopment.isAutomatedPublishing()) { return; } PublicationContainer publications = publishing.getPublications(); NamedDomainObjectContainer<PluginDeclaration> declaredPlugins = pluginDevelopment.getPlugins(); for (PluginDeclaration declaration : declaredPlugins) { createMavenMarkerPublication(declaration, (MavenPublication) publications.getByName("pluginMaven"), publications); } }
@Finalize public void addMarkerPublications(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment) { if (!pluginDevelopment.isAutomatedPublishing()) { return; } PublicationContainer publications = publishing.getPublications(); NamedDomainObjectContainer<PluginDeclaration> declaredPlugins = pluginDevelopment.getPlugins(); for (PluginDeclaration declaration : declaredPlugins) { createIvyMarkerPublication(declaration, (IvyPublication) publications.getByName("pluginIvy"), publications); } }
public static void setProperty(Object object, String fieldName, String value) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchFieldException { String[] fieldNames = fieldName.split("\\."); Object last = object; for (int i = 0; i < fieldNames.length - 1; i++) { String field = fieldNames[i]; if (last instanceof NamedDomainObjectContainer) { last = ((NamedDomainObjectContainer)last).maybeCreate(field); } else { Field declaredField = last.getClass().getField(field); declaredField.setAccessible(true); if (null == declaredField.get(last)) { Object newInstance = declaredField.getType() .getConstructors() .getClass() .newInstance(); declaredField.set(last, newInstance); } last = declaredField.get(last); } } BeanUtils.setProperty(last, fieldNames[fieldNames.length - 1], value); }
private void configureForSourceSets(NamedDomainObjectContainer<AndroidSourceSet> sourceSets) { sourceSets.all(sourceSet -> { Task task = project.getTasks().create(getTaskName(sourceSet, getTaskBaseName(), null), getCastedTaskType()); task.setGroup(JavaBasePlugin.VERIFICATION_GROUP); configureForSourceSet(sourceSet, (T)task); }); }
private SamConfig createConfigDsl() { log.debug("Setup serverless config DSL"); final NamedDomainObjectContainer<Stage> stages = project.container(Stage.class); final SamConfigDsl samConfig = project.getExtensions().create("serverless", SamConfigDsl.class, project, stages); ((ExtensionAware) samConfig).getExtensions().add("stages", stages); return new SamConfig(project, samConfig); }
public TestedExtension(@NonNull ProjectInternal project, @NonNull Instantiator instantiator, @NonNull AndroidBuilder androidBuilder, @NonNull SdkHandler sdkHandler, @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs, @NonNull ExtraModelInfo extraModelInfo, boolean isLibrary) { super(project, instantiator, androidBuilder, sdkHandler, buildTypes, productFlavors, signingConfigs, extraModelInfo, isLibrary); getSourceSetsContainer().create(ANDROID_TEST.getPrefix()); getSourceSetsContainer().create(UNIT_TEST.getPrefix()); }
public TestExtension(@NonNull ProjectInternal project, @NonNull Instantiator instantiator, @NonNull AndroidBuilder androidBuilder, @NonNull SdkHandler sdkHandler, @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs, @NonNull ExtraModelInfo extraModelInfo, boolean isLibrary) { super(project, instantiator, androidBuilder, sdkHandler, buildTypes, productFlavors, signingConfigs, extraModelInfo, isLibrary); }
public AppExtension(@NonNull ProjectInternal project, @NonNull Instantiator instantiator, @NonNull AndroidBuilder androidBuilder, @NonNull SdkHandler sdkHandler, @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs, @NonNull ExtraModelInfo extraModelInfo, boolean isLibrary) { super(project, instantiator, androidBuilder, sdkHandler, buildTypes, productFlavors, signingConfigs, extraModelInfo, isLibrary); }
public LibraryExtension(@NonNull ProjectInternal project, @NonNull Instantiator instantiator, @NonNull AndroidBuilder androidBuilder, @NonNull SdkHandler sdkHandler, @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs, @NonNull ExtraModelInfo extraModelInfo, boolean isLibrary) { super(project, instantiator, androidBuilder, sdkHandler, buildTypes, productFlavors, signingConfigs, extraModelInfo, isLibrary); }
@Override public void createDefaultComponents( @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs) { // don't call super as we don't want the default app version. // must create signing config first so that build type 'debug' can be initialized // with the debug signing config. signingConfigs.create(BuilderConstants.DEBUG); buildTypes.create(BuilderConstants.DEBUG); }
@Override public void createDefaultComponents( @NonNull NamedDomainObjectContainer<BuildType> buildTypes, @NonNull NamedDomainObjectContainer<ProductFlavor> productFlavors, @NonNull NamedDomainObjectContainer<SigningConfig> signingConfigs) { // must create signing config first so that build type 'debug' can be initialized // with the debug signing config. signingConfigs.create(DEBUG); buildTypes.create(DEBUG); buildTypes.create(RELEASE); }
public AndroidConfigAdaptor( AndroidConfig model, NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer) { this.model = model; this.sourceSetsContainer = sourceSetsContainer; applyProjectSourceSet(); }
public void apply(final Project project) { NamedDomainObjectContainer<BeanstalkDeployment> deployments = project.container(BeanstalkDeployment.class); BeanstalkPluginExtension beanstalk = project.getExtensions().create("beanstalk", BeanstalkPluginExtension.class); ((ExtensionAware) beanstalk).getExtensions().add("deployments", deployments); project.getTasks().addRule(new DeployRule(deployments, project, beanstalk)); }
@Override public void variants(Action<? super NamedDomainObjectContainer<ConfigurationVariant>> configureAction) { configureAction.execute(getVariants()); }
public DefaultNativeComponentExtension(NamedDomainObjectContainer<NativeExecutableSpec> executables, NamedDomainObjectContainer<NativeLibrarySpec> libraries) { this.executables = executables; this.libraries = libraries; }
@Override public NamedDomainObjectContainer<NativeExecutableSpec> getExecutables() { return executables; }
@Override public void executables(Action<? super NamedDomainObjectContainer<? super NativeExecutableSpec>> action) { action.execute(executables); }
@Override public NamedDomainObjectContainer<NativeLibrarySpec> getLibraries() { return libraries; }
@Override public void libraries(Action<? super NamedDomainObjectContainer<? super NativeLibrarySpec>> action) { action.execute(libraries); }
public <T> NamedDomainObjectContainer<T> container(Class<T> type) { Instantiator instantiator = getServices().get(Instantiator.class); return instantiator.newInstance(FactoryNamedDomainObjectContainer.class, type, instantiator, new DynamicPropertyNamer()); }
public <T> NamedDomainObjectContainer<T> container(Class<T> type, NamedDomainObjectFactory<T> factory) { Instantiator instantiator = getServices().get(Instantiator.class); return instantiator.newInstance(FactoryNamedDomainObjectContainer.class, type, instantiator, new DynamicPropertyNamer(), factory); }
public <T> NamedDomainObjectContainer<T> container(Class<T> type, Closure factoryClosure) { Instantiator instantiator = getServices().get(Instantiator.class); return instantiator.newInstance(FactoryNamedDomainObjectContainer.class, type, instantiator, new DynamicPropertyNamer(), factoryClosure); }
public <U extends Task> NamedDomainObjectContainer<U> containerWithType(Class<U> type) { throw new UnsupportedOperationException(); }
public NamedDomainObjectContainerConfigureDelegate(Closure configureClosure, NamedDomainObjectContainer container) { super(configureClosure, container); _container = container; }
public NamedDomainObjectContainer<U> configure(Closure configureClosure) { NamedDomainObjectContainerConfigureDelegate delegate = new NamedDomainObjectContainerConfigureDelegate(configureClosure, this); return ConfigureUtil.configureSelf(configureClosure, this, delegate); }
public <U extends T> NamedDomainObjectContainer<U> containerWithType(Class<U> type) { return getInstantiator().newInstance(TypedDomainObjectContainerWrapper.class, type, this, getInstantiator()); }
public void buildTypes(Action<? super NamedDomainObjectContainer<T>> action) { action.execute(buildTypes); }
public void patchConfigs(Action<? super NamedDomainObjectContainer<PatchConfig>> action) { action.execute(patchConfigs); }
public void dexConfigs(Action<? super NamedDomainObjectContainer<DexConfig>>action){ action.execute(dexConfigs); }
public void multiDexConfigs(Action<? super NamedDomainObjectContainer<MultiDexConfig>> action) { action.execute(multiDexConfigs); }
public NamedDomainObjectContainer<PatchConfig> getPatchConfigs() { return patchConfigs; }
public NamedDomainObjectContainer<T> getBuildTypes() { return buildTypes; }
public NamedDomainObjectContainer<DexConfig> getDexConfig(){ return dexConfigs; }
public NamedDomainObjectContainer<MultiDexConfig> getMultiDexConfigs() { return multiDexConfigs; }
public void setMultiDexConfigs( NamedDomainObjectContainer<MultiDexConfig> multiDexConfigs) { this.multiDexConfigs = multiDexConfigs; }
private static void readConfig(Object object, String prefix, List<AtlasConfigField> configFieldList, int groupOrder, String variantName) throws IllegalAccessException { if (null == object) { return; } for (Field field : getAllFields(object.getClass())) { field.setAccessible(true); Config config = field.getAnnotation(Config.class); if (null != config) { AtlasConfigField configField = new AtlasConfigField(); configField.name = prefix + "." + field.getName(); configField.order = config.order(); configField.desc = config.message(); Object obj = field.get(object); String value = ""; if (obj != null && !(obj instanceof Map) && !(obj instanceof List)) { value = String.valueOf(obj); } configField.value = value; configField.groupOrder = groupOrder; configField.variantName = variantName; configField.type = field.getType().getSimpleName(); configField.advanced = config.advance(); configField.group = config.group(); String variant = StringUtils.isEmpty(variantName) ? "" : ("[" + variantName + "]"); String title = StringUtils.isEmpty(config.title()) ? config.message() : config.title(); configField.title = variant + title; configFieldList.add(configField); continue; } ConfigGroup configGroup = field.getAnnotation(ConfigGroup.class); if (null != configGroup) { Object nestedValue = field.get(object); if (nestedValue instanceof NamedDomainObjectContainer) { readConfig(((NamedDomainObjectContainer)nestedValue).maybeCreate("debug"), prefix + "." + field.getName() + ".debug", configFieldList, configGroup.order(), "debug"); readConfig(((NamedDomainObjectContainer)nestedValue).maybeCreate("release"), prefix + "." + field.getName() + ".release", configFieldList, configGroup.order(), "release"); } else { readConfig(nestedValue, prefix + "." + field.getName(), configFieldList, configGroup.order(), ""); } } } }
@Test public void normal() throws Exception { Project project = ProjectBuilder.builder().withName("api").build(); project.setGroup("org.curioswitch.test"); project.getPluginManager().apply(DependencyManagementPlugin.class); DependencyManagementExtension dependencyManagement = project.getExtensions().getByType(DependencyManagementExtension.class); dependencyManagement.dependencies( handler -> { handler.dependency("io.grpc:grpc-core:5.0.0"); handler.dependency("io.grpc:grpc-protobuf:5.0.0"); handler.dependency("io.grpc:grpc-stub:5.0.0"); handler.dependency("com.google.protobuf:protoc:6.0.0"); }); project.getPluginManager().apply("org.curioswitch.gradle-grpc-api-plugin"); project.setProperty("archivesBaseName", "curio-test-api"); ((DefaultProject) project).evaluate(); Task task = project.getTasks().findByName("generateProto"); assertThat(task).isInstanceOf(GenerateProtoTask.class).isNotNull(); GenerateProtoTask generateProtoTask = (GenerateProtoTask) task; // 2 output dirs for java and grpc, but they are the same in our config. String outputDir = project.getBuildDir().getAbsolutePath() + "/generated/source/proto/main"; assertThat(generateProtoTask.getAllOutputDirs().stream().map(File::getAbsolutePath)) .containsExactly(outputDir, outputDir); assertThat(generateProtoTask.getGenerateDescriptorSet()).isTrue(); assertThat(generateProtoTask.getDescriptorSetOptions().getIncludeSourceInfo()).isTrue(); assertThat(generateProtoTask.getDescriptorSetOptions().getIncludeImports()).isTrue(); assertThat(generateProtoTask.getDescriptorSetOptions().getPath().toString()) .isEqualTo( project.getBuildDir() + "/resources/main/META-INF/armeria/grpc/org.curioswitch.test.curio-test-api.dsc"); ProtobufConfigurator protobuf = project.getConvention().getPlugin(ProtobufConvention.class).getProtobuf(); protobuf.protoc( LambdaClosure.of( (ExecutableLocator locator) -> assertThat(locator.getArtifact()).isEqualTo("com.google.protobuf:protoc:6.0.0"))); protobuf.plugins( LambdaClosure.of( (NamedDomainObjectContainer<ExecutableLocator> locators) -> assertThat(locators.getByName("grpc").getArtifact()) .isEqualTo("io.grpc:protoc-gen-grpc-java:5.0.0"))); }