Java Code Examples for org.gradle.api.plugins.ExtensionAware

The following examples show how to use org.gradle.api.plugins.ExtensionAware. 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
private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
    task.setDescription(String.format("Compiles resources of the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());

    task.includes(new Callable<Set<File>>() {
        public Set<File> call() {
            return sourceSet.getExportedHeaders().getSrcDirs();
        }
    });
    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setOutputDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + ((LanguageSourceSetInternal) sourceSet).getFullName()));

    PreprocessingTool rcCompiler = (PreprocessingTool) ((ExtensionAware) binary).getExtensions().getByName("rcCompiler");
    task.setMacros(rcCompiler.getMacros());
    task.setCompilerArgs(rcCompiler.getArgs());

    FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
    binary.getTasks().getCreateOrLink().source(resourceOutputs);
    if (binary instanceof StaticLibraryBinarySpecInternal) {
        ((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
    }
}
 
Example 2
public void apply(final CUnitTestSuite cUnitTestSuite, final BinaryContainer binaries) {
    cUnitTestSuite.getTestedComponent().getBinaries().withType(ProjectNativeBinaryInternal.class).all(new Action<ProjectNativeBinaryInternal>() {
        public void execute(ProjectNativeBinaryInternal testedBinary) {
            final ProjectNativeBinary cunitExe = createTestBinary(cUnitTestSuite, testedBinary, project);
            ((ExtensionAware) cunitExe).getExtensions().create("cCompiler", DefaultPreprocessingTool.class);

            cUnitTestSuite.getBinaries().add(cunitExe);
            binaries.add(cunitExe);

            testedBinary.getSource().all(new Action<LanguageSourceSet>() {
                public void execute(LanguageSourceSet languageSourceSet) {
                    cunitExe.source(languageSourceSet);
                }
            });
        }
    });
}
 
Example 3
@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 4
Source Project: app-gradle-plugin   Source File: SourceContextPlugin.java    License: Apache License 2.0 6 votes vote down vote up
private void createExtension() {
  // obtain extensions defined by core plugin.
  ExtensionAware appengine = new ExtensionUtil(project).get("appengine");
  final ToolsExtension tools = ((AppEngineCoreExtensionProperties) appengine).getTools();

  // create source context extension and set defaults
  extension =
      appengine
          .getExtensions()
          .create(SOURCE_CONTEXT_EXTENSION, GenRepoInfoFileExtension.class, project);
  extension.setOutputDirectory(new File(project.getBuildDir(), "sourceContext"));
  extension.setSourceDirectory(new File(project.getProjectDir(), "src"));

  // wait to read the cloudSdkHome till after project evaluation
  project.afterEvaluate(
      project -> {
        try {
          cloudSdkOperations = new CloudSdkOperations(tools.getCloudSdkHome(), null);
        } catch (CloudSdkNotFoundException ex) {
          // this should be caught in AppEngineCorePluginConfig before it can ever reach here.
          throw new GradleException("Could not find CloudSDK: ", ex);
        }
      });
}
 
Example 5
Source Project: app-gradle-plugin   Source File: TestProject.java    License: Apache License 2.0 6 votes vote down vote up
private Project applyProjectBuilder(Class<?>... plugins) {
  Project p = ProjectBuilder.builder().withProjectDir(projectRoot).build();
  for (Class<?> clazz : plugins) {
    p.getPluginManager().apply(clazz);
  }

  Object appengineExt = p.getExtensions().getByName(APPENGINE_EXTENSION);
  DeployExtension deploy =
      ((ExtensionAware) appengineExt).getExtensions().getByType(DeployExtension.class);
  deploy.setProjectId("test-project");
  deploy.setVersion("test-version");

  ((ProjectInternal) p).evaluate();

  return p;
}
 
Example 6
@Test
public void testGetAllFields_NestedExtensions() throws IllegalAccessException {
  String expected =
      ""
          + "root {\n"
          + "  x {\n"
          + "    y {\n"
          + "      (int) yy = 0\n"
          + "      z {\n"
          + "        (String) zz = hello\n"
          + "        (Map<String, List<String>>) zzNested = {a=[a1, a2], b=[b1, b2]}\n"
          + "      }\n"
          + "    }\n"
          + "  }\n"
          + "}\n";
  Project p = ProjectBuilder.builder().build();
  ExtensionAware root = (ExtensionAware) p.getExtensions().create("root", ExtX.class);
  ExtensionAware x = (ExtensionAware) root.getExtensions().create("x", ExtX.class);
  ExtensionAware y = (ExtensionAware) x.getExtensions().create("y", ExtY.class);
  y.getExtensions().create("z", ExtZ.class);

  String result = ShowConfigurationTask.getExtensionData("root", root, 0);
  Assert.assertEquals(expected, result);
}
 
Example 7
Source Project: gradle-beanstalk-plugin   Source File: BeanstalkPlugin.java    License: MIT License 6 votes vote down vote up
public void apply(Project project) {
    NamedDomainObjectContainer<BeanstalkDeployment> deployments = project.container(BeanstalkDeployment.class);
    BeanstalkPluginExtension beanstalk = project.getExtensions().create("beanstalk", BeanstalkPluginExtension.class);
    ((ExtensionAware) beanstalk).getExtensions().add("deployments", deployments);

    project.afterEvaluate(p -> {
        for (BeanstalkDeployment deployment : deployments) {
            String name = deployment.getName();
            String task = "deploy" + Character.toUpperCase(name.charAt(0)) + name.substring(1);

            p.getTasks().create(task, DeployTask.class, deployTask -> {
                deployTask.setBeanstalk(beanstalk);
                deployTask.setDeployment(deployment);
            });
        }
    });
}
 
Example 8
private void configureResourceCompileTask(WindowsResourceCompile task, final NativeBinarySpecInternal binary, final WindowsResourceSet sourceSet) {
    task.setDescription(String.format("Compiles resources of the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());

    task.includes(new Callable<Set<File>>() {
        public Set<File> call() {
            return sourceSet.getExportedHeaders().getSrcDirs();
        }
    });
    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setOutputDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + ((LanguageSourceSetInternal) sourceSet).getFullName()));

    PreprocessingTool rcCompiler = (PreprocessingTool) ((ExtensionAware) binary).getExtensions().getByName("rcCompiler");
    task.setMacros(rcCompiler.getMacros());
    task.setCompilerArgs(rcCompiler.getArgs());

    FileTree resourceOutputs = task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.res"));
    binary.getTasks().getCreateOrLink().source(resourceOutputs);
    if (binary instanceof StaticLibraryBinarySpecInternal) {
        ((StaticLibraryBinarySpecInternal) binary).additionalLinkFiles(resourceOutputs);
    }
}
 
Example 9
public void apply(final CUnitTestSuite cUnitTestSuite, final BinaryContainer binaries) {
    cUnitTestSuite.getTestedComponent().getBinaries().withType(ProjectNativeBinaryInternal.class).all(new Action<ProjectNativeBinaryInternal>() {
        public void execute(ProjectNativeBinaryInternal testedBinary) {
            final ProjectNativeBinary cunitExe = createTestBinary(cUnitTestSuite, testedBinary, project);
            ((ExtensionAware) cunitExe).getExtensions().create("cCompiler", DefaultPreprocessingTool.class);

            cUnitTestSuite.getBinaries().add(cunitExe);
            binaries.add(cunitExe);

            testedBinary.getSource().all(new Action<LanguageSourceSet>() {
                public void execute(LanguageSourceSet languageSourceSet) {
                    cunitExe.source(languageSourceSet);
                }
            });
        }
    });
}
 
Example 10
@SuppressWarnings("NullableProblems")
@Override
public void apply(ExtensionAware extensionAware) {
    // abort if old Gradle version is not supported
    if (GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("5.0")) < 0) {
        throw new IllegalStateException("This version of the credentials plugin is not compatible with Gradle < 5.0");
    }

    // handle plugin application to settings file and project file
    if (extensionAware instanceof Settings) {
        Settings settings = (Settings) extensionAware;
        init(settings.getGradle(), settings, (String loc) -> settings.getSettingsDir().toPath().resolve(loc).toFile(), NOOP);
    } else if (extensionAware instanceof Project) {
        Project project = (Project) extensionAware;
        init(project.getGradle(), project, project::file, (Pair creds) -> addTasks(creds, project.getTasks()));
    } else {
        throw new IllegalStateException("The credentials plugin can only be applied to Settings and Project instances");
    }
}
 
Example 11
private void init(Gradle gradle, ExtensionAware extensionAware, Function<String, File> locationResolver, Action<Pair> customizations) {
    // get the passphrase from the project properties, otherwise use the default passphrase
    String passphrase = getStringProperty(CREDENTIALS_PASSPHRASE_PROPERTY, DEFAULT_PASSPHRASE, extensionAware);

    // derive the name of the credentials file from the passphrase
    String credentialsFileName = deriveFileNameFromPassphrase(passphrase);

    // create credentials encryptor for the given passphrase
    CredentialsEncryptor credentialsEncryptor = CredentialsEncryptor.withPassphrase(passphrase.toCharArray());

    // create a credentials persistence manager that operates on the credentials file, possibly located in a user-configured folder
    String credentialsLocation = getStringProperty(CREDENTIALS_LOCATION_PROPERTY, null, extensionAware);
    File credentialsLocationDir = credentialsLocation != null ? locationResolver.apply(credentialsLocation) : gradle.getGradleUserHomeDir();
    File credentialsFile = new File(credentialsLocationDir, credentialsFileName);
    CredentialsPersistenceManager credentialsPersistenceManager = new CredentialsPersistenceManager(credentialsFile);

    // add a new 'credentials' property and transiently store the persisted credentials for access in build scripts
    CredentialsContainer credentialsContainer = new CredentialsContainer(credentialsEncryptor, credentialsPersistenceManager.readCredentials());
    setProperty(CREDENTIALS_CONTAINER_PROPERTY, credentialsContainer, extensionAware);
    LOGGER.debug("Registered property '" + CREDENTIALS_CONTAINER_PROPERTY + "'");

    // allow further ExtensionAware-specific customization
    customizations.execute(new Pair(credentialsEncryptor, credentialsPersistenceManager));
}
 
Example 12
private void configure(DefaultCUnitTestSuiteBinary testBinary, File buildDir) {
    BinaryNamingScheme namingScheme = testBinary.getNamingScheme();
    PlatformToolProvider toolProvider = testBinary.getPlatformToolProvider();
    File binaryOutputDir = new File(new File(buildDir, "binaries"), namingScheme.getOutputDirectoryBase());
    String baseName = testBinary.getComponent().getBaseName();

    testBinary.setExecutableFile(new File(binaryOutputDir, toolProvider.getExecutableName(baseName)));

    ((ExtensionAware) testBinary).getExtensions().create("cCompiler", DefaultPreprocessingTool.class);
}
 
Example 13
public void execute(NativeBinarySpec nativeBinary) {
    for (LanguageRegistration<?> language : languageRegistry) {
        Map<String, Class<?>> binaryTools = language.getBinaryTools();
        for (String toolName : binaryTools.keySet()) {
            ((ExtensionAware) nativeBinary).getExtensions().create(toolName, binaryTools.get(toolName));
        }
    }
}
 
Example 14
Source Project: gradle-golang-plugin   Source File: Settings.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public Settings(@Nonnull Project project, @Nonnull ExtensionContainer container) {
    _project = project;
    _golang = container.getByType(GolangSettings.class);
    if (!(_golang instanceof ExtensionAware)) {
        throw new IllegalStateException("golang instance (" + _golang + ") of provided extension container (" + container + ") is not an instance of " + ExtensionAware.class.getName() + ".");
    }
    final ExtensionContainer globalExtensions = ((ExtensionAware) _golang).getExtensions();
    _build = globalExtensions.getByType(BuildSettings.class);
    _toolchain = globalExtensions.getByType(ToolchainSettings.class);
    _dependencies = globalExtensions.getByType(DependenciesSettings.class);
    _testing = globalExtensions.getByType(TestingSettings.class);
}
 
Example 15
Source Project: gradle-golang-plugin   Source File: Settings.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public Settings(@Nonnull Project project, @Nonnull ExtensionContainer container, boolean init) {
    _project = project;
    _golang = container.create("golang", GolangSettings.class, init, project);
    final ExtensionContainer taskExtensions = ((ExtensionAware) _golang).getExtensions();
    _build = taskExtensions.create("build", BuildSettings.class, init, project);
    _toolchain = taskExtensions.create("toolchain", ToolchainSettings.class, init, project);
    _dependencies = taskExtensions.create("dependencies", DependenciesSettings.class, init, project);
    _testing = taskExtensions.create("testing", TestingSettings.class, init, project);
}
 
Example 16
/** Create nested configuration blocks as Extensions. */
public void createSubExtensions(Project project) {
  tools =
      ((ExtensionAware) this).getExtensions().create(TOOLS_EXT, ToolsExtension.class, project);
  deploy =
      ((ExtensionAware) this).getExtensions().create(DEPLOY_EXT, DeployExtension.class, project);
  stage =
      ((ExtensionAware) this)
          .getExtensions()
          .create(STAGE_EXT, StageStandardExtension.class, project);
  run = ((ExtensionAware) this).getExtensions().create(RUN_EXT, RunExtension.class, project);
}
 
Example 17
/** Create nested configuration blocks as Extensions. */
public void createSubExtensions(Project project) {
  tools =
      ((ExtensionAware) this).getExtensions().create(TOOLS_EXT, ToolsExtension.class, project);
  deploy =
      ((ExtensionAware) this).getExtensions().create(DEPLOY_EXT, DeployExtension.class, project);
  stage =
      ((ExtensionAware) this)
          .getExtensions()
          .create(STAGE_EXT, StageAppYamlExtension.class, project);
}
 
Example 18
Source Project: app-gradle-plugin   Source File: SourceContextPluginTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfiguration() throws IOException {
  File appengineWebXml =
      new File(testProjectDir.getRoot(), "src/main/webapp/WEB-INF/appengine-web.xml");
  appengineWebXml.getParentFile().mkdirs();
  appengineWebXml.createNewFile();
  Files.write(appengineWebXml.toPath(), "<web-app/>".getBytes());

  Project project = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build();
  project.getPluginManager().apply(JavaPlugin.class);
  project.getPluginManager().apply(WarPlugin.class);
  project.getPluginManager().apply(AppEngineStandardPlugin.class);
  project.getPluginManager().apply(SourceContextPlugin.class);

  DeployExtension deploy =
      project.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy();
  deploy.setProjectId("project");
  deploy.setVersion("version");
  ((ProjectInternal) project).evaluate();

  ExtensionAware ext =
      (ExtensionAware)
          project.getExtensions().getByName(AppEngineCorePluginConfiguration.APPENGINE_EXTENSION);
  GenRepoInfoFileExtension genRepoInfoExt =
      new ExtensionUtil(ext).get(SourceContextPlugin.SOURCE_CONTEXT_EXTENSION);
  Assert.assertEquals(
      new File(project.getBuildDir(), "sourceContext"), genRepoInfoExt.getOutputDirectory());
}
 
Example 19
Source Project: pygradle   Source File: ExtensionUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> T maybeCreate(PythonExtension extension, String name, Class<T> type, Object... args) {
    ExtensionContainer extensionContainer = ((ExtensionAware) extension).getExtensions();
    T maybeExtension = extensionContainer.findByType(type);
    if (maybeExtension == null) {
        maybeExtension = extensionContainer.create(name, type, args);
    }
    return maybeExtension;
}
 
Example 20
private void configure(DefaultCUnitTestSuiteBinary testBinary, File buildDir) {
    BinaryNamingScheme namingScheme = testBinary.getNamingScheme();
    PlatformToolProvider toolProvider = testBinary.getPlatformToolProvider();
    File binaryOutputDir = new File(new File(buildDir, "binaries"), namingScheme.getOutputDirectoryBase());
    String baseName = testBinary.getComponent().getBaseName();

    testBinary.setExecutableFile(new File(binaryOutputDir, toolProvider.getExecutableName(baseName)));

    ((ExtensionAware) testBinary).getExtensions().create("cCompiler", DefaultPreprocessingTool.class);
}
 
Example 21
public void execute(NativeBinarySpec nativeBinary) {
    for (LanguageRegistration<?> language : languageRegistry) {
        Map<String, Class<?>> binaryTools = language.getBinaryTools();
        for (String toolName : binaryTools.keySet()) {
            ((ExtensionAware) nativeBinary).getExtensions().create(toolName, binaryTools.get(toolName));
        }
    }
}
 
Example 22
private void configureCompileTask(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    task.setDescription(String.format("Compiles the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());
    task.setPositionIndependentCode(binary instanceof SharedLibraryBinarySpec);

    // TODO:DAZ Not sure if these both need to be lazy
    task.includes(new Callable<Set<File>>() {
        public Set<File> call() throws Exception {
            return ((HeaderExportingSourceSet) sourceSet).getExportedHeaders().getSrcDirs();
        }
    });
    task.includes(new Callable<List<FileCollection>>() {
        public List<FileCollection> call() {
            Collection<NativeDependencySet> libs = binary.getLibs((DependentSourceSet) sourceSet);
            return CollectionUtils.collect(libs, new Transformer<FileCollection, NativeDependencySet>() {
                public FileCollection transform(NativeDependencySet original) {
                    return original.getIncludeRoots();
                }
            });
        }
    });

    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setObjectFileDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + sourceSet.getFullName()));

    for (String toolName : language.getBinaryTools().keySet()) {
        Tool tool = (Tool) ((ExtensionAware) binary).getExtensions().getByName(toolName);
        if (tool instanceof PreprocessingTool) {
            task.setMacros(((PreprocessingTool) tool).getMacros());
        }

        task.setCompilerArgs(tool.getArgs());
    }


    binary.getTasks().getCreateOrLink().source(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}
 
Example 23
private void configureAssembleTask(Assemble task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    task.setDescription(String.format("Assembles the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());

    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setObjectFileDir(project.file(project.getBuildDir() + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + sourceSet.getFullName()));

    Tool assemblerTool = (Tool) ((ExtensionAware) binary).getExtensions().getByName("assembler");
    task.setAssemblerArgs(assemblerTool.getArgs());

    binary.getTasks().getCreateOrLink().source(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}
 
Example 24
Source Project: pushfish-android   Source File: DslObject.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtensionContainer getExtensions() {
    if (extensionContainer == null) {
        this.extensionContainer = toType(object, ExtensionAware.class).getExtensions();
    }
    return extensionContainer;
}
 
Example 25
Source Project: pushfish-android   Source File: DslObject.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExtensionContainer getExtensions() {
    if (extensionContainer == null) {
        this.extensionContainer = toType(object, ExtensionAware.class).getExtensions();
    }
    return extensionContainer;
}
 
Example 26
Source Project: app-gradle-plugin   Source File: ExtensionUtil.java    License: Apache License 2.0 4 votes vote down vote up
public ExtensionUtil(ExtensionAware searchRoot) {
  this.searchRoot = searchRoot;
}
 
Example 27
Source Project: app-gradle-plugin   Source File: ShowConfigurationTask.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
// recursive (but doesn't search through nested objects, only nested extensions)
static String getExtensionData(String extensionName, Object extensionInstance, int depth)
    throws IllegalAccessException {
  StringBuilder result = new StringBuilder("");
  // extension start block
  result.append(spaces(depth)).append(extensionName).append(" {\n");

  // all non-extension fields
  for (Field field : extensionInstance.getClass().getSuperclass().getDeclaredFields()) {
    // ignore synthetic fields (stuff added by compiler or instrumenter)
    if (field.isSynthetic()) {
      continue;
    }
    // This is just a helper for the extensions, don't show it
    if (field.getType().equals(org.gradle.api.Project.class)) {
      continue;
    }
    // ignore fields marked with InternalProperty
    if (field.getAnnotationsByType(InternalProperty.class).length > 0) {
      continue;
    }
    result.append(getFieldData(field, extensionInstance, depth + 1));
  }

  // all extension fields
  Map<String, Object> map =
      ((ExtensionContainerInternal) ((ExtensionAware) extensionInstance).getExtensions())
          .getAsMap();
  for (String childExtensionName : map.keySet()) {
    Object childExtensionInstance = map.get(childExtensionName);
    // only expand out extensions we understand (we're ignoring the default ext group here, which
    // is not ExtensionAware)
    if (childExtensionInstance instanceof ExtensionAware) {
      result.append(getExtensionData(childExtensionName, map.get(childExtensionName), depth + 1));
    }
  }

  // extension end block
  result.append(spaces(depth)).append("}\n");

  return result.toString();
}
 
Example 28
Source Project: pygradle   Source File: ExtensionUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T getPythonComponentExtension(PythonExtension extension, Class<T> type) {
    ExtensionContainer extensionContainer = ((ExtensionAware) extension).getExtensions();
    return extensionContainer.getByType(type);
}
 
Example 29
Source Project: pygradle   Source File: ExtensionUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T findPythonComponentExtension(PythonExtension extension, Class<T> type) {
    ExtensionContainer extensionContainer = ((ExtensionAware) extension).getExtensions();
    return extensionContainer.findByType(type);
}
 
Example 30
private void configureCompileTask(AbstractNativeCompileTask task, final NativeBinarySpecInternal binary, final LanguageSourceSetInternal sourceSet) {
    task.setDescription(String.format("Compiles the %s of %s", sourceSet, binary));

    task.setToolChain(binary.getToolChain());
    task.setTargetPlatform(binary.getTargetPlatform());
    task.setPositionIndependentCode(binary instanceof SharedLibraryBinarySpec);

    // TODO:DAZ Not sure if these both need to be lazy
    task.includes(new Callable<Set<File>>() {
        public Set<File> call() throws Exception {
            return ((HeaderExportingSourceSet) sourceSet).getExportedHeaders().getSrcDirs();
        }
    });
    task.includes(new Callable<List<FileCollection>>() {
        public List<FileCollection> call() {
            Collection<NativeDependencySet> libs = binary.getLibs((DependentSourceSet) sourceSet);
            return CollectionUtils.collect(libs, new Transformer<FileCollection, NativeDependencySet>() {
                public FileCollection transform(NativeDependencySet original) {
                    return original.getIncludeRoots();
                }
            });
        }
    });

    task.source(sourceSet.getSource());

    final Project project = task.getProject();
    task.setObjectFileDir(project.file(String.valueOf(project.getBuildDir()) + "/objs/" + binary.getNamingScheme().getOutputDirectoryBase() + "/" + sourceSet.getFullName()));

    for (String toolName : language.getBinaryTools().keySet()) {
        Tool tool = (Tool) ((ExtensionAware) binary).getExtensions().getByName(toolName);
        if (tool instanceof PreprocessingTool) {
            task.setMacros(((PreprocessingTool) tool).getMacros());
        }

        task.setCompilerArgs(tool.getArgs());
    }


    binary.getTasks().getCreateOrLink().source(task.getOutputs().getFiles().getAsFileTree().matching(new PatternSet().include("**/*.obj", "**/*.o")));
}