Java Code Examples for org.gradle.language.base.LanguageSourceSet

The following examples show how to use org.gradle.language.base.LanguageSourceSet. 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
protected AbstractProjectNativeBinary(ProjectNativeComponent owner, Flavor flavor, ToolChainInternal toolChain, Platform targetPlatform, BuildType buildType,
                                      BinaryNamingScheme namingScheme, NativeDependencyResolver resolver) {
    this.component = owner;
    this.namingScheme = namingScheme;
    this.flavor = flavor;
    this.toolChain = toolChain;
    this.targetPlatform = targetPlatform;
    this.buildType = buildType;
    this.buildable = true;
    this.resolver = resolver;
    owner.getSource().all(new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet sourceSet) {
            source.add(sourceSet);
        }
    });
}
 
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
public void createCompileTasksForBinary(final TaskContainer tasks, BinarySpec binarySpec) {
    final BinarySpecInternal binary = (BinarySpecInternal) binarySpec;
    if (binary.isLegacyBinary() || !language.applyToBinary(binary)) {
        return;
    }

    final SourceTransformTaskConfig taskConfig = language.getTransformTask();
    binary.getSource().withType(language.getSourceSetType(), new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet languageSourceSet) {
            LanguageSourceSetInternal sourceSet = (LanguageSourceSetInternal) languageSourceSet;
            if (sourceSet.getMayHaveSources()) {
                String taskName = binary.getNamingScheme().getTaskName(taskConfig.getTaskPrefix(), sourceSet.getFullName());
                Task task = tasks.create(taskName, taskConfig.getTaskType());

                taskConfig.configureTask(task, binary, sourceSet);

                task.dependsOn(sourceSet);
                binary.getTasks().add(task);
            }
        }
    });
}
 
Example 4
public void execute(ProjectInternal project) {
    ProjectSourceSet projectSourceSet = project.getExtensions().getByType(ProjectSourceSet.class);
    for (FunctionalSourceSet functionalSourceSet : projectSourceSet) {
        for (LanguageSourceSet languageSourceSet : functionalSourceSet) {
            // Only apply default locations when none explicitly configured
            if (languageSourceSet.getSource().getSrcDirs().isEmpty()) {
                languageSourceSet.getSource().srcDir(String.format("src/%s/%s", functionalSourceSet.getName(), languageSourceSet.getName()));
            }
        }
        for (HeaderExportingSourceSet headerSourceSet : functionalSourceSet.withType(HeaderExportingSourceSet.class)) {
            // Only apply default locations when none explicitly configured
            if (headerSourceSet.getExportedHeaders().getSrcDirs().isEmpty()) {
                headerSourceSet.getExportedHeaders().srcDir(String.format("src/%s/headers", functionalSourceSet.getName()));
            }

            headerSourceSet.getImplicitHeaders().setSrcDirs(headerSourceSet.getSource().getSrcDirs());
            headerSourceSet.getImplicitHeaders().include("**/*.h");
        }
    }
}
 
Example 5
public SourceTransformTaskConfig getTransformTask() {
    return new SourceTransformTaskConfig() {
        public String getTaskPrefix() {
            return "process";
        }

        public Class<? extends DefaultTask> getTaskType() {
            return ProcessResources.class;
        }

        public void configureTask(Task task, BinarySpec binary, LanguageSourceSet sourceSet) {
            ProcessResources resourcesTask = (ProcessResources) task;
            JvmResourceSet resourceSet = (JvmResourceSet) sourceSet;
            JvmBinarySpec jvmBinary = (JvmBinarySpec) binary;
            resourcesTask.from(resourceSet.getSource());
            resourcesTask.setDestinationDir(jvmBinary.getResourcesDir());
            jvmBinary.getTasks().getJar().dependsOn(resourcesTask);
        }
    };
}
 
Example 6
protected AbstractNativeBinarySpec(NativeComponentSpec owner, Flavor flavor, NativeToolChain toolChain, PlatformToolProvider toolProvider, NativePlatform targetPlatform,
                                   BuildType buildType, BinaryNamingScheme namingScheme, NativeDependencyResolver resolver) {
    this.component = owner;
    this.toolProvider = toolProvider;
    this.namingScheme = namingScheme;
    this.flavor = flavor;
    this.toolChain = toolChain;
    this.targetPlatform = targetPlatform;
    this.buildType = buildType;
    this.buildable = true;
    this.resolver = resolver;
    component.getSource().all(new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet sourceSet) {
            sourceSets.add(sourceSet);
        }
    });
}
 
Example 7
/**
 * Set the default directory for each source sets if it is empty.
 */
public void setDefaultSrcDir() {
    all(new Action<FunctionalSourceSet>() {
        @Override
        public void execute(final FunctionalSourceSet functionalSourceSet) {
            functionalSourceSet.all(
                    new Action<LanguageSourceSet>() {
                        @Override
                        public void execute(LanguageSourceSet languageSourceSet) {
                            SourceDirectorySet source = languageSourceSet.getSource();
                            if (source.getSrcDirs().isEmpty()) {
                                source.srcDir("src/" + functionalSourceSet.getName() + "/" + languageSourceSet.getName());
                            }
                        }
                    });
        }
    });
}
 
Example 8
public void addDefaultAndroidSourceSet(
        @Path("android.sources") AndroidComponentModelSourceSet sources) {
    sources.addDefaultSourceSet("resources", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("java", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("manifest", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("res", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("assets", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("aidl", AndroidLanguageSourceSet.class);
    sources.addDefaultSourceSet("jniLibs", AndroidLanguageSourceSet.class);

    sources.all(new Action<FunctionalSourceSet>() {
        @Override
        public void execute(FunctionalSourceSet functionalSourceSet) {
            LanguageSourceSet manifest = functionalSourceSet.get("manifest");
            manifest.getSource().setIncludes(ImmutableList.of("AndroidManifest.xml"));
        }
    });
}
 
Example 9
Source Project: javaide   Source File: AndroidConfigAdaptor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert a FunctionalSourceSet to an AndroidSourceFile.
 */
private static void convertSourceFile(
        AndroidSourceFile androidFile,
        FunctionalSourceSet source,
        String sourceName) {
    LanguageSourceSet languageSourceSet = source.get(sourceName);
    if (languageSourceSet == null) {
        return;
    }
    SourceDirectorySet dir = languageSourceSet.getSource();
    if (dir == null) {
        return;
    }
    // We use the first file in the file tree until Gradle has a way to specify one source file
    // instead of an entire source set.
    Set<File> files = dir.getAsFileTree().getFiles();
    if (!files.isEmpty()) {
        androidFile.srcFile(Iterables.getOnlyElement(files));
    }
}
 
Example 10
public static NotationParser<Object, Set<LanguageSourceSet>> parser() {
    return NotationParserBuilder
            .toType(new TypeInfo<Set<LanguageSourceSet>>(Set.class))
            .parser(new FunctionalSourceSetConverter())
            .parser(new SingleLanguageSourceSetConverter())
            .parser(new LanguageSourceSetCollectionConverter())
            .toComposite();
}
 
Example 11
/**
 * Temporarily, we need to have a 'live' connection between a component's 'main' FunctionalSourceSet and the set of LanguageSourceSets for the component.
 * We should be able to do away with this, once sourceSets are part of the model proper.
 */
public void addMainSources(FunctionalSourceSet mainSources) {
    mainSources.all(new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet languageSourceSet) {
            add(languageSourceSet);
        }
    });
}
 
Example 12
@Override
public void render(LanguageSourceSet sourceSet, TextReportBuilder builder) {
    StyledTextOutput textOutput = builder.getOutput();
    textOutput.println(StringUtils.capitalize(sourceSet.getDisplayName()));
    Set<File> srcDirs = sourceSet.getSource().getSrcDirs();
    if (srcDirs.isEmpty()) {
        textOutput.println("    No source directories");
    } else {
        for (File file : srcDirs) {
            textOutput.formatln("    %s", fileResolver.resolveAsRelativePath(file));
        }
    }
}
 
Example 13
private <U extends LanguageSourceSet> void createDefaultSourceSetForComponents(final LanguageRegistration<U> languageRegistration, ComponentSpecContainer components) {
    components.withType(ComponentSpecInternal.class).all(new Action<ComponentSpecInternal>() {
        public void execute(final ComponentSpecInternal componentSpecInternal) {
            final FunctionalSourceSet functionalSourceSet = componentSpecInternal.getMainSource();
            if (componentSpecInternal.getInputTypes().contains(languageRegistration.getOutputType())) {
                functionalSourceSet.maybeCreate(languageRegistration.getName(), languageRegistration.getSourceSetType());
            }
        }
    });
}
 
Example 14
private <U extends LanguageSourceSet> void registerLanguageSourceSetFactory(final LanguageRegistration<U> languageRegistration, ProjectSourceSet sources, final FileResolver fileResolver) {
    sources.all(new Action<FunctionalSourceSet>() {
        public void execute(final FunctionalSourceSet functionalSourceSet) {
            NamedDomainObjectFactory<U> namedDomainObjectFactory = new NamedDomainObjectFactory<U>() {
                public U create(String name) {
                    Class<? extends U> sourceSetImplementation = languageRegistration.getSourceSetImplementation();
                    return instantiator.newInstance(sourceSetImplementation, name, functionalSourceSet, fileResolver);
                }
            };
            functionalSourceSet.registerFactory(languageRegistration.getSourceSetType(), namedDomainObjectFactory);
        }
    });
}
 
Example 15
@Finalize
// Needs to run after NativeComponentModelPlugin.Rules.configureGeneratedSourceSets()
void applyDefaultSourceConventions(ProjectSourceSet sources) {
    for (FunctionalSourceSet functionalSourceSet : sources) {
        for (LanguageSourceSet languageSourceSet : functionalSourceSet) {
            // Only apply default locations when none explicitly configured
            if (languageSourceSet.getSource().getSrcDirs().isEmpty()) {
                languageSourceSet.getSource().srcDir(String.format("src/%s/%s", functionalSourceSet.getName(), languageSourceSet.getName()));
            }
        }
    }
}
 
Example 16
private boolean hasExportedSymbols() {
    for (LanguageSourceSet languageSourceSet : getSource()) {
        if (!(languageSourceSet instanceof NativeResourceSet)) {
            if (!languageSourceSet.getSource().isEmpty()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 17
public SourceTransformTaskConfig getTransformTask() {
    return new SourceTransformTaskConfig() {
        public String getTaskPrefix() {
            return "compile";
        }

        public Class<? extends DefaultTask> getTaskType() {
            return PlatformJavaCompile.class;
        }

        public void configureTask(Task task, BinarySpec binarySpec, LanguageSourceSet sourceSet) {
            PlatformJavaCompile compile = (PlatformJavaCompile) task;
            JavaSourceSet javaSourceSet = (JavaSourceSet) sourceSet;
            JvmBinarySpec binary = (JvmBinarySpec) binarySpec;

            compile.setDescription(String.format("Compiles %s.", javaSourceSet));
            compile.setDestinationDir(binary.getClassesDir());
            compile.setToolChain(binary.getToolChain());
            compile.setPlatform(binary.getTargetPlatform());

            compile.setSource(javaSourceSet.getSource());
            compile.setClasspath(javaSourceSet.getCompileClasspath().getFiles());
            compile.setTargetCompatibility(binary.getTargetPlatform().getTargetCompatibility().toString());
            compile.setSourceCompatibility(binary.getTargetPlatform().getTargetCompatibility().toString());

            compile.setDependencyCacheDir(new File(compile.getProject().getBuildDir(), "jvm-dep-cache"));
            compile.dependsOn(javaSourceSet);
            binary.getTasks().getJar().dependsOn(compile);
        }
    };
}
 
Example 18
@Override
public void render(LanguageSourceSet sourceSet, TextReportBuilder builder) {
    StyledTextOutput textOutput = builder.getOutput();
    textOutput.println(StringUtils.capitalize(sourceSet.getDisplayName()));
    Set<File> srcDirs = sourceSet.getSource().getSrcDirs();
    if (srcDirs.isEmpty()) {
        textOutput.println("    No source directories");
    } else {
        for (File file : srcDirs) {
            textOutput.formatln("    %s", fileResolver.resolveAsRelativePath(file));
        }
    }
}
 
Example 19
private boolean hasExportedSymbols() {
    // TODO:DAZ This is a very rough approximation: actually inspect the binary to determine if there are exported symbols
    for (LanguageSourceSet languageSourceSet : getSource()) {
        if (!(languageSourceSet instanceof WindowsResourceSet)) {
            if (!languageSourceSet.getSource().isEmpty()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 20
private boolean hasExportedSymbols() {
    for (LanguageSourceSet languageSourceSet : getSource()) {
        if (!(languageSourceSet instanceof NativeResourceSet)) {
            if (!languageSourceSet.getSource().isEmpty()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 21
public void resolve(NativeBinaryResolveResult nativeBinaryResolveResult) {
    for (NativeBinaryRequirementResolveResult resolution : nativeBinaryResolveResult.getPendingResolutions()) {
        if (resolution.getInput() instanceof LanguageSourceSet) {
            LanguageSourceSet input = (LanguageSourceSet) resolution.getInput();
            resolution.setNativeDependencySet(createNativeDependencySet(input));
        }
    }
    delegate.resolve(nativeBinaryResolveResult);
}
 
Example 22
public static <T extends LanguageSourceSet> T create(Class<? extends LanguageSourceSet> publicType, Class<T> implementationType, ComponentSpecIdentifier componentId, SourceDirectorySetFactory sourceDirectorySetFactory) {
    NEXT_SOURCE_SET_INFO.set(new SourceSetInfo(componentId, publicType, sourceDirectorySetFactory));
    try {
        try {
            return DirectInstantiator.INSTANCE.newInstance(implementationType);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create LanguageSourceSet of type %s", publicType.getSimpleName()), e.getCause());
        }
    } finally {
        NEXT_SOURCE_SET_INFO.set(null);
    }
}
 
Example 23
public <T extends LanguageSourceSet> void registerLanguage(final LanguageRegistration<T> languageRegistration) {
    // Hardcoding registered language sets and default source sets for now.
    all(new Action<FunctionalSourceSet>() {
        @Override
        public void execute(final FunctionalSourceSet functionalSourceSet) {
            functionalSourceSet.registerFactory(
                    languageRegistration.getSourceSetType(),
                    languageRegistration.getSourceSetFactory(functionalSourceSet.getName()));
        }
    });
}
 
Example 24
public void addDefaultSourceSet(final String sourceSetName, final Class<? extends LanguageSourceSet> type) {
    all(new Action<FunctionalSourceSet>() {
        @Override
        public void execute(FunctionalSourceSet functionalSourceSet) {
            functionalSourceSet.maybeCreate(sourceSetName, type);
        }
    });
}
 
Example 25
private <U extends LanguageSourceSet> void createDefaultSourceSetForComponents(final LanguageRegistration<U> languageRegistration, ComponentSpecContainer components) {
    components.withType(ComponentSpecInternal.class).all(new Action<ComponentSpecInternal>() {
        public void execute(final ComponentSpecInternal componentSpecInternal) {
            final FunctionalSourceSet functionalSourceSet = componentSpecInternal.getMainSource();
            if (componentSpecInternal.getInputTypes().contains(languageRegistration.getOutputType())) {
                functionalSourceSet.maybeCreate(languageRegistration.getName(), languageRegistration.getSourceSetType());
            }
        }
    });
}
 
Example 26
public static NotationParser<Object, Set<LanguageSourceSet>> parser() {
    return NotationParserBuilder
            .toType(new TypeInfo<Set<LanguageSourceSet>>(Set.class))
            .parser(new FunctionalSourceSetConverter())
            .parser(new SingleLanguageSourceSetConverter())
            .parser(new LanguageSourceSetCollectionConverter())
            .toComposite();
}
 
Example 27
protected boolean hasSources() {
    for (LanguageSourceSet sourceSet : getSource()) {
        if (!sourceSet.getSource().isEmpty()) {
            return true;
        }
        if (sourceSet.hasBuildDependencies()) {
            return true;
        }
    }
    return false;
}
 
Example 28
/**
 * Temporarily, we need to have a 'live' connection between a component's 'main' FunctionalSourceSet and the set of LanguageSourceSets for the component.
 * We should be able to do away with this, once sourceSets are part of the model proper.
 */
public void addMainSources(FunctionalSourceSet mainSources) {
    mainSources.all(new Action<LanguageSourceSet>() {
        public void execute(LanguageSourceSet languageSourceSet) {
            add(languageSourceSet);
        }
    });
}
 
Example 29
public DomainObjectSet<LanguageSourceSet> getSource() {
    return sourceSets;
}
 
Example 30
public DomainObjectSet<LanguageSourceSet> getSource() {
    return sourceSets;
}