org.gradle.language.base.FunctionalSourceSet Java Examples

The following examples show how to use org.gradle.language.base.FunctionalSourceSet. 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
Source File: AndroidComponentModelSourceSet.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #2
Source File: BaseComponentModelPlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: AndroidConfigAdaptor.java    From javaide with 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 #4
Source File: ApplySourceSetConventions.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Convert a FunctionalSourceSet to an AndroidSourceDirectorySet.
 */
private static void convertSourceSet(
        AndroidSourceDirectorySet androidDir,
        FunctionalSourceSet source,
        String sourceName) {
    LanguageSourceSet languageSourceSet = source.get(sourceName);
    if (languageSourceSet == null) {
        return;
    }
    SourceDirectorySet dir = languageSourceSet.getSource();
    if (dir == null) {
        return;
    }
    androidDir.setSrcDirs(dir.getSrcDirs());
    androidDir.include(dir.getIncludes());
    androidDir.exclude(dir.getExcludes());
}
 
Example #6
Source File: AndroidConfigAdaptor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void applyProjectSourceSet() {
    for (FunctionalSourceSet source : getSources()) {
        String name = source.getName();
        AndroidSourceSet androidSource = name.equals(BuilderConstants.MAIN) ?
                sourceSetsContainer.maybeCreate(getDefaultConfig().getName()) :
                sourceSetsContainer.maybeCreate(name);

        convertSourceFile(androidSource.getManifest(), source, "manifest");
        convertSourceSet(androidSource.getResources(), source, "resource");
        convertSourceSet(androidSource.getJava(), source, "java");
        convertSourceSet(androidSource.getRes(), source, "res");
        convertSourceSet(androidSource.getAssets(), source, "assets");
        convertSourceSet(androidSource.getAidl(), source, "aidl");
        convertSourceSet(androidSource.getJni(), source, "jni");
        convertSourceSet(androidSource.getJniLibs(), source, "jniLibs");
    }
}
 
Example #7
Source File: ComponentModelBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #8
Source File: ComponentModelBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #9
Source File: BaseComponentSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <T extends BaseComponentSpec> T create(Class<T> type, ComponentSpecIdentifier identifier, FunctionalSourceSet mainSourceSet, Instantiator instantiator) {
    if (type.equals(BaseComponentSpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseComponentSpec.");
    }
    nextComponentInfo.set(new ComponentInfo(identifier, type.getSimpleName(), mainSourceSet));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create component of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextComponentInfo.set(null);
    }
}
 
Example #10
Source File: AbstractLanguageSourceSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AbstractLanguageSourceSet(String name, FunctionalSourceSet parent, String typeName, SourceDirectorySet source) {
    this.name = name;
    this.fullName = parent.getName() + StringUtils.capitalize(name);
    this.displayName = String.format("%s '%s:%s'", typeName, parent.getName(), name);
    this.source = source;
    super.builtBy(source.getBuildDependencies());
}
 
Example #11
Source File: BaseComponentSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ComponentInfo(ComponentSpecIdentifier componentIdentifier,
                      String typeName,
                      FunctionalSourceSet sourceSets) {
    this.componentIdentifier = componentIdentifier;
    this.typeName = typeName;
    this.sourceSets = sourceSets;
}
 
Example #12
Source File: AbstractLanguageSourceSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AbstractLanguageSourceSet(String name, FunctionalSourceSet parent, String typeName, SourceDirectorySet source) {
    this.name = name;
    this.fullName = parent.getName() + StringUtils.capitalize(name);
    this.displayName = String.format("%s '%s:%s'", typeName, parent.getName(), name);
    this.source = source;
    super.builtBy(source.getBuildDependencies());
}
 
Example #13
Source File: ConfigureGeneratedSourceSets.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(ProjectInternal project) {
    ProjectSourceSet projectSourceSet = project.getExtensions().getByType(ProjectSourceSet.class);
    for (FunctionalSourceSet functionalSourceSet : projectSourceSet) {
        for (LanguageSourceSetInternal languageSourceSet : functionalSourceSet.withType(LanguageSourceSetInternal.class)) {
            Task generatorTask = languageSourceSet.getGeneratorTask();
            if (generatorTask != null) {
                languageSourceSet.builtBy(generatorTask);
                maybeSetSourceDir(languageSourceSet.getSource(), generatorTask, "sourceDir");
                if (languageSourceSet instanceof HeaderExportingSourceSet) {
                    maybeSetSourceDir(((HeaderExportingSourceSet) languageSourceSet).getExportedHeaders(), generatorTask, "headerDir");
                }
            }
        }
    }
}
 
Example #14
Source File: ComponentModelBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #15
Source File: LanguageSourceSetContainer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 #16
Source File: BaseComponentSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ComponentInfo(ComponentSpecIdentifier componentIdentifier,
                      String typeName,
                      FunctionalSourceSet sourceSets) {
    this.componentIdentifier = componentIdentifier;
    this.typeName = typeName;
    this.sourceSets = sourceSets;
}
 
Example #17
Source File: BaseComponentSpec.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <T extends BaseComponentSpec> T create(Class<T> type, ComponentSpecIdentifier identifier, FunctionalSourceSet mainSourceSet, Instantiator instantiator) {
    if (type.equals(BaseComponentSpec.class)) {
        throw new ModelInstantiationException("Cannot create instance of abstract class BaseComponentSpec.");
    }
    nextComponentInfo.set(new ComponentInfo(identifier, type.getSimpleName(), mainSourceSet));
    try {
        try {
            return instantiator.newInstance(type);
        } catch (ObjectInstantiationException e) {
            throw new ModelInstantiationException(String.format("Could not create component of type %s", type.getSimpleName()), e.getCause());
        }
    } finally {
        nextComponentInfo.set(null);
    }
}
 
Example #18
Source File: ComponentModelBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #19
Source File: DefaultJvmLibrarySpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultJvmLibrarySpec(ComponentSpecIdentifier identifier, FunctionalSourceSet mainSourceSet) {
    this.identifier = identifier;
    this.mainSourceSet = mainSourceSet;
    sourceSets.addMainSources(mainSourceSet);
    this.languageOutputs.add(JvmResources.class);
    this.languageOutputs.add(JvmByteCode.class);
    this.binaries = new DefaultDomainObjectSet<BinarySpec>(JvmBinarySpec.class);
    this.jvmBinaries = this.binaries.withType(JvmBinarySpec.class);

}
 
Example #20
Source File: CUnitPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private CUnitTestSuiteSpec createCUnitTestSuite(final NativeComponentSpec testedComponent, Instantiator instantiator, ProjectSourceSet projectSourceSet) {
    String suiteName = String.format("%sTest", testedComponent.getName());
    String path = testedComponent.getProjectPath();
    ComponentSpecIdentifier id = new DefaultComponentSpecIdentifier(path, suiteName);
    FunctionalSourceSet testSuiteSourceSet = projectSourceSet.maybeCreate(suiteName);
    return instantiator.newInstance(DefaultCUnitTestSuiteSpec.class, id, testedComponent, testSuiteSourceSet);
}
 
Example #21
Source File: CUnitPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Mutate
public void configureCUnitTestSuiteSources(ProjectSourceSet projectSourceSet, TestSuiteContainer testSuites, @Path("buildDir") File buildDir) {

    for (final CUnitTestSuiteSpec suite : testSuites.withType(CUnitTestSuiteSpec.class)) {
        FunctionalSourceSet suiteSourceSet = ((ComponentSpecInternal) suite).getMainSource();
        CSourceSet launcherSources = suiteSourceSet.maybeCreate(CUNIT_LAUNCHER_SOURCE_SET, CSourceSet.class);
        File baseDir = new File(buildDir, String.format("src/%s/cunitLauncher", suite.getName()));
        launcherSources.getSource().srcDir(new File(baseDir, "c"));
        launcherSources.getExportedHeaders().srcDir(new File(baseDir, "headers"));
        CSourceSet testSources = suiteSourceSet.maybeCreate("c", CSourceSet.class);
        testSources.lib(launcherSources);
    }
}
 
Example #22
Source File: AbstractNativeComponentSpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public AbstractNativeComponentSpec(ComponentSpecIdentifier id, FunctionalSourceSet mainSourceSet) {
    this.mainSourceSet = mainSourceSet;
    sourceSets.addMainSources(mainSourceSet);
    this.id = id;
    this.binaries = new DefaultDomainObjectSet<BinarySpec>(NativeBinarySpec.class);
    this.nativeBinaries = this.binaries.withType(NativeBinarySpec.class);
    this.inputTypes.add(ObjectFile.class);
}
 
Example #23
Source File: NativeComponentModelPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Finalize
public void applyHeaderSourceSetConventions(ProjectSourceSet sources) {
    for (FunctionalSourceSet functionalSourceSet : sources) {
        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 #24
Source File: NativeComponentModelPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Mutate
void configureGeneratedSourceSets(ProjectSourceSet sources) {
    for (FunctionalSourceSet functionalSourceSet : sources) {
        for (LanguageSourceSetInternal languageSourceSet : functionalSourceSet.withType(LanguageSourceSetInternal.class)) {
            Task generatorTask = languageSourceSet.getGeneratorTask();
            if (generatorTask != null) {
                languageSourceSet.builtBy(generatorTask);
                maybeSetSourceDir(languageSourceSet.getSource(), generatorTask, "sourceDir");
                if (languageSourceSet instanceof HeaderExportingSourceSet) {
                    maybeSetSourceDir(((HeaderExportingSourceSet) languageSourceSet).getExportedHeaders(), generatorTask, "headerDir");
                }
            }
        }
    }
}
 
Example #25
Source File: ConfigureGeneratedSourceSets.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void execute(ProjectInternal project) {
    ProjectSourceSet projectSourceSet = project.getExtensions().getByType(ProjectSourceSet.class);
    for (FunctionalSourceSet functionalSourceSet : projectSourceSet) {
        for (LanguageSourceSetInternal languageSourceSet : functionalSourceSet.withType(LanguageSourceSetInternal.class)) {
            Task generatorTask = languageSourceSet.getGeneratorTask();
            if (generatorTask != null) {
                languageSourceSet.builtBy(generatorTask);
                maybeSetSourceDir(languageSourceSet.getSource(), generatorTask, "sourceDir");
                if (languageSourceSet instanceof HeaderExportingSourceSet) {
                    maybeSetSourceDir(((HeaderExportingSourceSet) languageSourceSet).getExportedHeaders(), generatorTask, "headerDir");
                }
            }
        }
    }
}
 
Example #26
Source File: AndroidComponentModelSourceSet.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected FunctionalSourceSet doCreate(String name) {
    return getInstantiator().newInstance(
            DefaultFunctionalSourceSet.class,
            name,
            getInstantiator(),
            projectSourceSet);
}
 
Example #27
Source File: ComponentModelBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #28
Source File: DefaultProjectSourceSet.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected FunctionalSourceSet doCreate(String name) {
    return getInstantiator().newInstance(DefaultFunctionalSourceSet.class, name, getInstantiator());
}
 
Example #29
Source File: DefaultObjectiveCppSourceSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public DefaultObjectiveCppSourceSet(String name, FunctionalSourceSet parent, ProjectInternal project) {
    super(name, parent, project, "Objective-C++ source", new DefaultSourceDirectorySet("source", project.getFileResolver()));
}
 
Example #30
Source File: DefaultAssemblerSourceSet.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultAssemblerSourceSet(String name, FunctionalSourceSet parent, ProjectInternal project) {
    super(name, parent, "assembler source", new DefaultSourceDirectorySet("source", project.getFileResolver()));
}