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

The following examples show how to use org.gradle.language.base.FunctionalSourceSet. 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
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 2
/**
 * 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 3
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 4
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 5
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 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 Project: javaide   Source File: AndroidConfigAdaptor.java    License: 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
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 8
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 9
private ComponentInfo(ComponentSpecIdentifier componentIdentifier,
                      String typeName,
                      FunctionalSourceSet sourceSets) {
    this.componentIdentifier = componentIdentifier;
    this.typeName = typeName;
    this.sourceSets = sourceSets;
}
 
Example 10
/**
 * 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 11
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 12
@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 13
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 14
@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 15
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 16
@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 17
@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 18
@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 19
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 20
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 21
@Override
protected FunctionalSourceSet doCreate(String name) {
    return getInstantiator().newInstance(
            DefaultFunctionalSourceSet.class,
            name,
            getInstantiator(),
            projectSourceSet);
}
 
Example 22
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 23
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 24
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 25
private ComponentInfo(ComponentSpecIdentifier componentIdentifier,
                      String typeName,
                      FunctionalSourceSet sourceSets) {
    this.componentIdentifier = componentIdentifier;
    this.typeName = typeName;
    this.sourceSets = sourceSets;
}
 
Example 26
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 27
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 28
public FunctionalSourceSet getMainSource() {
    return mainSourceSet;
}
 
Example 29
@Inject
public DefaultJavaSourceSet(String name, FunctionalSourceSet parent, FileResolver fileResolver) {
    super(name, parent, "Java source", new DefaultSourceDirectorySet("source", fileResolver));
    this.compileClasspath = new EmptyClasspath();
}
 
Example 30
public FunctionalSourceSet getMainSource() {
    return mainSourceSet;
}