Java Examples for org.gradle.api.tasks.SourceSet

The following java examples will help you to understand the usage of org.gradle.api.tasks.SourceSet. These source code samples are taken from different open source projects.

Example 1
Project: gradle-jnaerator-plugin-master  File: JNAeratorPlugin.java View source code
@Override
public void apply(final Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    // final JNAeratorPluginExtension extension = project.getExtensions().create(JNAeratorPluginExtension.NAME, JNAeratorPluginExtension.class);
    // extension.setOutputDir(new File(project.getBuildDir(), "generated-sources/jnaerator"));
    JNAeratorTask task = project.getTasks().create("jnaerator", JNAeratorTask.class);
    task.setOutputDir(new File(project.getBuildDir(), "generated-sources/jnaerator"));
    project.getTasks().getByName("compileJava").dependsOn(task);
    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
    final SourceSet mainSourceSet = sourceSets.getByName("main");
    mainSourceSet.getJava().srcDir(task.getOutputDir());
}
Example 2
Project: gradle-master  File: JavaPlugin.java View source code
private void configureSourceSets(JavaPluginConvention pluginConvention, final BuildOutputCleanupRegistry buildOutputCleanupRegistry) {
    Project project = pluginConvention.getProject();
    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);
    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
    // Register the project's source set output directories
    pluginConvention.getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(SourceSet sourceSet) {
            buildOutputCleanupRegistry.registerOutputs(sourceSet.getOutput());
        }
    });
}
Example 3
Project: netbeans-gradle-javaee-project-master  File: NbJpaModelBuilder.java View source code
private void init() throws Exception {
    JavaPluginConvention java = project.getConvention().findPlugin(JavaPluginConvention.class);
    if (java == null) {
        return;
    }
    for (SourceSet sourceSet : java.getSourceSets()) {
        SourceDirectorySet resourceDirectorySet = sourceSet.getResources();
        Set<File> resourceDirectories = resourceDirectorySet.getSrcDirs();
        for (File resourceDirectory : resourceDirectories) {
            File metaInfDir = new File(resourceDirectory, "META-INF");
            if (metaInfDir.exists()) {
                File persistenceXmlFileObj = new File(metaInfDir, "persistence.xml");
                if (persistenceXmlFileObj.exists()) {
                    persistenceXmlFile = persistenceXmlFileObj.getCanonicalPath();
                    break;
                }
            }
        }
        if (persistenceXmlFile != null) {
            SourceDirectorySet allJavaDirectorySet = sourceSet.getAllJava();
            javaSourceDirs = allJavaDirectorySet.getSrcDirs();
            break;
        }
    }
}
Example 4
Project: st-js-gradle-plugin-master  File: StJsPlugin.java View source code
@Override
public void apply(final Project project) {
    boolean javaPlugin = project.getPlugins().hasPlugin(JavaPlugin.class);
    boolean warPlugin = project.getPlugins().hasPlugin(WarPlugin.class);
    final Logger logger = project.getLogger();
    if (!(javaPlugin && warPlugin)) {
        logger.error("st-js plugin can only be applied if jar or war plugin is applied, too!");
        throw new IllegalStateException("st-js plugin can only be applied if jar or war plugin is applied, too!");
    }
    final JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    final SourceSet main = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    final SourceDirectorySet allJava = main.getAllJava();
    if (allJava.getSrcDirs().size() != 1) {
        throw new IllegalStateException("Only a single source directory is supported!");
    }
    final GenerateStJsTask task = project.getTasks().create("stjs", GenerateStJsTask.class);
    task.setClasspath(main.getCompileClasspath());
    task.setWar(warPlugin);
    File generatedSourcesDirectory;
    if (warPlugin) {
        generatedSourcesDirectory = new File(project.getBuildDir(), "stjs");
        project.getTasks().getByPath(WarPlugin.WAR_TASK_NAME).dependsOn(task);
    } else {
        generatedSourcesDirectory = main.getOutput().getClassesDir();
        project.getTasks().getByPath(JavaPlugin.JAR_TASK_NAME).dependsOn(task);
    }
    task.setGeneratedSourcesDirectory(generatedSourcesDirectory);
    task.setCompileSourceRoots(allJava);
    task.setOutput(main.getOutput());
}
Example 5
Project: atom-game-framework-sdk-master  File: JavaSourcesModelBuilder.java View source code
public static SourceSetMethods getInstance(Project project) throws Exception {
    SourceSetMethods result = CACHE;
    GradleClass type = GradleClasses.getGradleClass(project, "org.gradle.api.tasks.SourceSet");
    if (result != null && type.equals(result.type)) {
        return result;
    }
    result = new SourceSetMethods(type);
    CACHE = result;
    return result;
}
Example 6
Project: gradle-velocity-plugin-master  File: VelocityPlugin.java View source code
@Override
public void apply(final Project project) {
    final VelocityPluginExtension extension = project.getExtensions().create("velocity", VelocityPluginExtension.class);
    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {

        @Override
        public void execute(SourceSet t) {
            apply(project, t, extension);
        }
    });
}
Example 7
Project: spotless-master  File: JavaExtension.java View source code
/** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */
@Override
protected void setupTask(SpotlessTask task) {
    if (target == null) {
        JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class);
        if (javaPlugin == null) {
            throw new GradleException("You must apply the java plugin before the spotless plugin if you are using the java extension.");
        }
        UnionFileCollection union = new UnionFileCollection();
        for (SourceSet sourceSet : javaPlugin.getSourceSets()) {
            union.add(sourceSet.getAllJava());
        }
        target = union;
    }
    // LicenseHeaderStep completely blows apart package-info.java - this common-sense check ensures that
    // it skips package-info.java. See https://github.com/diffplug/spotless/issues/1
    steps.replaceAll( step -> {
        if (LicenseHeaderStep.name().equals(step.getName())) {
            return step.filterByFile(SerializableFileFilter.skipFilesNamed("package-info.java"));
        } else {
            return step;
        }
    });
    super.setupTask(task);
}
Example 8
Project: webpie-master  File: TemplateCompilerPlugin.java View source code
public void execute(SourceSet sourceSet) {
    final DefaultTemplateSourceSet templateSourceSet = new DefaultTemplateSourceSet(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
    new DslObject(sourceSet).getConvention().getPlugins().put("templates", templateSourceSet);
    templateSourceSet.getTemplatesSrc().srcDir("src/" + sourceSet.getName() + "/java");
    sourceSet.getResources().getFilter().exclude(new Spec<FileTreeElement>() {

        public boolean isSatisfiedBy(FileTreeElement element) {
            return templateSourceSet.getTemplatesSrc().contains(element.getFile());
        }
    });
    sourceSet.getAllJava().source(templateSourceSet.getTemplatesSrc());
    sourceSet.getAllSource().source(templateSourceSet.getTemplatesSrc());
    String compileTaskName = sourceSet.getCompileTaskName("templates");
    TemplateCompilerTask compile = project.getTasks().create(compileTaskName, TemplateCompilerTask.class);
    javaBasePlugin.configureForSourceSet(sourceSet, compile);
    compile.setGroup("Build");
    compile.setDescription("Compiles the " + sourceSet.getName() + " Html or other template files source.");
    compile.dependsOn(sourceSet.getCompileJavaTaskName());
    compile.setSource(templateSourceSet.getTemplatesSrc());
    project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(compileTaskName);
}
Example 9
Project: liferay-portal-master  File: LiferayOSGiDefaultsPlugin.java View source code
private Jar _addTaskJarSources(Project project, boolean testProject) {
    Jar jar = GradleUtil.addTask(project, JAR_SOURCES_TASK_NAME, Jar.class);
    jar.setClassifier("sources");
    jar.setGroup(BasePlugin.BUILD_GROUP);
    jar.setDescription("Assembles a jar archive containing the main source files.");
    jar.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
    File docrootDir = project.file("docroot");
    if (docrootDir.exists()) {
        jar.from(docrootDir);
    } else {
        SourceSet sourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME);
        jar.from(sourceSet.getAllSource());
        if (testProject) {
            sourceSet = GradleUtil.getSourceSet(project, SourceSet.TEST_SOURCE_SET_NAME);
            jar.from(sourceSet.getAllSource());
            sourceSet = GradleUtil.getSourceSet(project, TestIntegrationBasePlugin.TEST_INTEGRATION_SOURCE_SET_NAME);
            jar.from(sourceSet.getAllSource());
        }
    }
    return jar;
}
Example 10
Project: putnami-gradle-plugin-master  File: GwtDevTask.java View source code
private void createWarExploded(DevOption sdmOption) throws IOException {
    WarPluginConvention warConvention = getProject().getConvention().getPlugin(WarPluginConvention.class);
    JavaPluginConvention javaConvention = getProject().getConvention().getPlugin(JavaPluginConvention.class);
    File warDir = sdmOption.getWar();
    ResourceUtils.copyDirectory(warConvention.getWebAppDir(), warDir);
    if (Boolean.TRUE.equals(sdmOption.getNoServer())) {
        File webInfDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF"));
        ResourceUtils.deleteDirectory(webInfDir);
    } else {
        SourceSet mainSourceSet = javaConvention.getSourceSets().getByName("main");
        File classesDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF/classes"));
        for (File file : mainSourceSet.getResources().getSrcDirs()) {
            ResourceUtils.copyDirectory(file, classesDir);
        }
        ResourceUtils.copyDirectory(mainSourceSet.getOutput().getClassesDir(), classesDir);
        for (File file : mainSourceSet.getOutput().getFiles()) {
            if (file.exists() && file.isFile()) {
                ResourceUtils.copy(file, new File(classesDir, file.getName()));
            }
        }
        File libDir = ResourceUtils.ensureDir(new File(warDir, "WEB-INF/lib"));
        for (File file : mainSourceSet.getRuntimeClasspath()) {
            if (file.exists() && file.isFile()) {
                ResourceUtils.copy(file, new File(libDir, file.getName()));
            }
        }
    }
}
Example 11
Project: checkstyle-idea-master  File: CustomSourceSetCreator.java View source code
public CustomSourceSetCreator establishCsAccessSourceSet() {
    final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
    final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    // Create the 'csaccess' source set
    final SourceSet csaccessSourceSet = sourceSets.create(CSACCESS_SOURCESET_NAME);
    csaccessSourceSet.setCompileClasspath(csaccessSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput()));
    csaccessSourceSet.setRuntimeClasspath(csaccessSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput()));
    sourceSets.add(csaccessSourceSet);
    // Derive all its configurations from 'main', so 'csaccess' code can see 'main' code
    final ConfigurationContainer configurations = project.getConfigurations();
    final Configuration compileConfig = configurations.getByName(mainSourceSet.getCompileConfigurationName());
    final Configuration compileOnlyConfig = configurations.getByName(mainSourceSet.getCompileOnlyConfigurationName());
    final Configuration compileClasspathConfig = configurations.getByName(mainSourceSet.getCompileClasspathConfigurationName());
    final Configuration runtimeConfig = configurations.getByName(mainSourceSet.getRuntimeConfigurationName());
    configurations.getByName(csaccessSourceSet.getCompileConfigurationName()).extendsFrom(compileConfig);
    configurations.getByName(csaccessSourceSet.getCompileOnlyConfigurationName()).extendsFrom(compileOnlyConfig);
    configurations.getByName(csaccessSourceSet.getCompileClasspathConfigurationName()).extendsFrom(compileClasspathConfig);
    configurations.getByName(csaccessSourceSet.getRuntimeConfigurationName()).extendsFrom(runtimeConfig);
    // Wire task dependencies to match the classpath dependencies (arrow means "depends on"):
    //    - compileTestJava -> compileCsaccessJava
    //    - testClasses     -> csaccessClasses
    //    - jar             -> csaccessClasses
    final TaskContainer tasks = project.getTasks();
    tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getCompileJavaTaskName()));
    tasks.getByName(JavaPlugin.TEST_CLASSES_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName()));
    tasks.getByName(JavaPlugin.JAR_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName()));
    return this;
}
Example 12
Project: gwt-gradle-plugin-master  File: GwtBasePlugin.java View source code
@Override
public void apply(final Project project) {
    this.project = project;
    project.getPlugins().apply(JavaPlugin.class);
    final File gwtBuildDir = new File(project.getBuildDir(), BUILD_DIR);
    extension = configureGwtExtension(gwtBuildDir);
    configureAbstractActionTasks();
    configureAbstractTasks();
    configureGwtCompile();
    configureGwtDev();
    configureGwtSuperDev();
    gwtConfiguration = project.getConfigurations().create(GWT_CONFIGURATION).setDescription("Classpath for GWT client libraries that are not included in the war");
    gwtSdkConfiguration = project.getConfigurations().create(GWT_SDK_CONFIGURATION).setDescription("Classpath for GWT SDK libraries (gwt-dev, gwt-user)");
    allGwtConfigurations = project.files(gwtConfiguration, gwtSdkConfiguration);
    addToMainSourceSetClasspath(allGwtConfigurations);
    final SourceSet testSourceSet = getTestSourceSet();
    testSourceSet.setCompileClasspath(testSourceSet.getCompileClasspath().plus(allGwtConfigurations));
    project.afterEvaluate(new Action<Project>() {

        @Override
        public void execute(final Project project) {
            FileCollection runtimeClasspath = allGwtConfigurations.plus(testSourceSet.getRuntimeClasspath());
            if (extension.getTest().isHasGwtTests()) {
                runtimeClasspath = project.files(getMainSourceSet().getAllJava().getSrcDirs().toArray()).plus(project.files(testSourceSet.getAllJava().getSrcDirs().toArray())).plus(runtimeClasspath);
                configureTestTasks(extension);
            }
            testSourceSet.setRuntimeClasspath(runtimeClasspath);
            boolean versionSet = false;
            int major = 2;
            int minor = 5;
            final String gwtVersion = extension.getGwtVersion();
            if (gwtVersion != null && !extension.getGwtVersion().isEmpty()) {
                final String[] token = gwtVersion.split("\\.");
                if (token.length >= 2) {
                    try {
                        major = Integer.parseInt(token[0]);
                        minor = Integer.parseInt(token[1]);
                        versionSet = true;
                    } catch (NumberFormatException e) {
                        logger.warn("GWT version " + extension.getGwtVersion() + " can not be parsed. Valid versions must have the format major.minor.patch where major and minor are positive integer numbers.");
                    }
                } else {
                    logger.warn("GWT version " + extension.getGwtVersion() + " can not be parsed. Valid versions must have the format major.minor.patch where major and minor are positive integer numbers.");
                }
            }
            if ((major == 2 && minor >= 5) || major > 2) {
                if (extension.isCodeserver()) {
                    createSuperDevModeTask(project);
                }
            }
            if (versionSet) {
                project.getDependencies().add(GWT_SDK_CONFIGURATION, gwtDependency(GWT_DEV, gwtVersion));
                project.getDependencies().add(GWT_SDK_CONFIGURATION, gwtDependency(GWT_USER, gwtVersion));
                project.getDependencies().add(JavaPlugin.RUNTIME_CONFIGURATION_NAME, gwtDependency(GWT_SERVLET, gwtVersion));
                if ((major == 2 && minor >= 5) || major > 2) {
                    if (extension.isCodeserver()) {
                        project.getDependencies().add(GWT_CONFIGURATION, gwtDependency(GWT_CODESERVER, gwtVersion));
                    }
                    if (extension.isElemental()) {
                        project.getDependencies().add(GWT_CONFIGURATION, gwtDependency(GWT_ELEMENTAL, gwtVersion));
                    }
                } else {
                    logger.warn("GWT version is <2.5 -> additional dependencies are not added.");
                }
            }
        }
    });
    project.getPlugins().withType(EclipsePlugin.class, new Action<EclipsePlugin>() {

        @Override
        public void execute(EclipsePlugin eclipsePlugin) {
            new GwtEclipsePlugin().apply(project, GwtBasePlugin.this);
        }
    });
    project.getPlugins().withType(IdeaPlugin.class, new Action<IdeaPlugin>() {

        @Override
        public void execute(IdeaPlugin ideaPlugin) {
            new GwtIdeaPlugin().apply(project, GwtBasePlugin.this);
        }
    });
}
Example 13
Project: jooby-master  File: JoobyProject.java View source code
public Set<File> classpath() {
    SourceSet sourceSet = sourceSet(project);
    Set<File> cp = new LinkedHashSet<>();
    // conf & public
    sourceSet.getResources().getSrcDirs().forEach(cp::add);
    // classes/main, resources/main + jars
    sourceSet.getRuntimeClasspath().getFiles().forEach(cp::add);
    // provided?
    Configuration provided = project.getConfigurations().findByName("provided");
    if (provided != null) {
        provided.getFiles().forEach(cp::add);
        ;
    }
    return cp;
}
Example 14
Project: juniversal-master  File: GradleProject.java View source code
@Override
public FileSet getTranslatableSourceFiles(SourceType sourceType) {
    SourceSet sourceSet = getSourceSet(sourceType);
    // Get all the Java source files, from the source directory(ies) defined in the source set.  Skip source
    // directories whose name ends with "-nontranslated"
    final FileSet sourceFiles = new FileSet();
    sourceSet.getJava().visit(new FileVisitor() {

        @Override
        public void visitDir(FileVisitDetails fileVisitDetails) {
            File parentFile = fileVisitDetails.getFile().getParentFile();
            if (parentFile.getName().endsWith("-nontranslated"))
                fileVisitDetails.stopVisiting();
        }

        @Override
        public void visitFile(FileVisitDetails fileVisitDetails) {
            File parentFile = fileVisitDetails.getFile().getParentFile();
            if (parentFile.getName().endsWith("-nontranslated"))
                fileVisitDetails.stopVisiting();
            else
                sourceFiles.add(fileVisitDetails.getFile());
        }
    });
    return sourceFiles;
}
Example 15
Project: Koloboke-master  File: GradlePlugin.java View source code
private static void setupTask(ProjectInternal project, SourceSet sourceSet, Flavor f) {
    String dirPath = String.format("src/%s/%s", sourceSet.getName(), f.templatesPart());
    FileResolver fileResolver = project.getFileResolver();
    File dir = fileResolver.resolve(dirPath);
    if (!dir.exists())
        return;
    // for each source set we will:
    // 1) Add a new 'javaTemplates' or 'resourceTemplates' source dirs
    String sourceSetName = ((DefaultSourceSet) sourceSet).getDisplayName();
    SourceDirectorySet templates = new DefaultSourceDirectorySet(sourceSetName + f.sourceSetNameEnd(), fileResolver);
    templates.srcDir(dirPath);
    sourceSet.getAllSource().source(templates);
    // 2) create an GeneratorTask for this sourceSet following the gradle
    //    naming conventions via call to sourceSet.getTaskName()
    final String taskName = sourceSet.getTaskName("generate", f.taskNameSuffix());
    GeneratorTask gen = project.getTasks().create(taskName, GeneratorTask.class);
    gen.setDescription(String.format(f.taskDescriptionFormat(), sourceSet.getName()));
    // 3) set up convention mapping for default sources
    // (allows user to not have to specify)
    gen.setSource(dir);
    // 4) Set up the Jpsg output directory (adding to javac inputs!)
    final String target = String.format("%s/generated-src/jpsg/%s/%s", project.getBuildDir(), sourceSet.getName(), f.generatedPart());
    gen.setTarget(target);
    f.getSourceDirectorySet(sourceSet).srcDir(new File(target));
    // 5) register fact that jpsg should be run before compiling
    project.getTasks().getByName(f.dependentTaskName(sourceSet)).dependsOn(taskName);
}
Example 16
Project: netbeans-gradle-project-master  File: JavaSourcesModelBuilder.java View source code
private JavaSourceSet parseSourceSet(SourceSet sourceSet) throws Exception {
    JavaOutputDirs outputDirs = parseOutputDirs(sourceSet.getOutput());
    JavaSourceSet.Builder result = new JavaSourceSet.Builder(sourceSet.getName(), outputDirs);
    SourceDirectorySet allSourceGroup = sourceSet.getAllSource();
    Set<File> others = new HashSet<File>(allSourceGroup.getSrcDirs());
    others.removeAll(addSourceGroup(JavaSourceGroupName.JAVA, sourceSet.getJava(), result));
    if (project.getPlugins().hasPlugin(GroovyPlugin.class)) {
        others.removeAll(addSourceGroup(JavaSourceGroupName.GROOVY, JavaSourcesUtils.getGroovySources(sourceSet), result));
    }
    if (project.getPlugins().hasPlugin(ScalaPlugin.class)) {
        others.removeAll(addSourceGroup(JavaSourceGroupName.SCALA, JavaSourcesUtils.getScalaSources(sourceSet), result));
    }
    others.removeAll(addSourceGroup(JavaSourceGroupName.RESOURCES, sourceSet.getResources(), result));
    result.addSourceGroup(new JavaSourceGroup(JavaSourceGroupName.OTHER, others));
    parseClassPaths(sourceSet, result);
    return result.create();
}
Example 17
Project: spring-boot-master  File: JavaPluginAction.java View source code
private BootJar configureBootJarTask(Project project) {
    BootJar bootJar = project.getTasks().create(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class);
    bootJar.setDescription("Assembles an executable jar archive containing the main" + " classes and their dependencies.");
    bootJar.setGroup(BasePlugin.BUILD_GROUP);
    bootJar.classpath((Callable<FileCollection>) () -> {
        JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
        SourceSet mainSourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        return mainSourceSet.getRuntimeClasspath();
    });
    bootJar.conventionMapping("mainClass", new MainClassConvention(project, bootJar::getClasspath));
    return bootJar;
}
Example 18
Project: android-gradle-plugin-master  File: DefaultAndroidSourceSet.java View source code
@Override
@NonNull
public String getPackageConfigurationName() {
    if (isLibrary) {
        if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
            return "publish";
        } else {
            return String.format("%sPublish", name);
        }
    }
    if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
        return "apk";
    } else {
        return String.format("%sApk", name);
    }
}
Example 19
Project: android-platform-tools-base-master  File: DefaultAndroidSourceSet.java View source code
@Override
@NonNull
public String getPackageConfigurationName() {
    if (isLibrary) {
        if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
            return "publish";
        } else {
            return String.format("%sPublish", name);
        }
    }
    if (name.equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
        return "apk";
    } else {
        return String.format("%sApk", name);
    }
}
Example 20
Project: clinic-softacad-master  File: InjectionAction.java View source code
private ClassLoader buildRuntimeScopeClassLoader() {
    final ArrayList<URL> classPathUrls = new ArrayList<URL>();
    final SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME);
    for (File file : mainSourceSet.getRuntimeClasspath()) {
        try {
            classPathUrls.add(file.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new InjectionException("Could not determine artifact URL [" + file.getPath() + "]", e);
        }
    }
    return new URLClassLoader(classPathUrls.toArray(new URL[classPathUrls.size()]), getClass().getClassLoader());
}
Example 21
Project: ForgeGradle-master  File: UserBasePlugin.java View source code
/**
     * Creates the api SourceSet and configures the classpaths of all the SourceSets to have MC and the MC deps in them.
     * Also sets the target JDK to java 6
     */
protected void configureCompilation() {
    // get convention
    JavaPluginConvention javaConv = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
    SourceSet main = javaConv.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    SourceSet test = javaConv.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
    SourceSet api = javaConv.getSourceSets().create("api");
    api.setCompileClasspath(api.getCompileClasspath().plus(project.getConfigurations().getByName(CONFIG_MC)).plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)).plus(project.getConfigurations().getByName(CONFIG_PROVIDED)));
    main.setCompileClasspath(main.getCompileClasspath().plus(api.getOutput()).plus(project.getConfigurations().getByName(CONFIG_MC)).plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)).plus(project.getConfigurations().getByName(CONFIG_PROVIDED)));
    main.setRuntimeClasspath(main.getCompileClasspath().plus(api.getOutput()).plus(project.getConfigurations().getByName(CONFIG_MC)).plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)).plus(project.getConfigurations().getByName(CONFIG_START)));
    test.setCompileClasspath(test.getCompileClasspath().plus(api.getOutput()).plus(project.getConfigurations().getByName(CONFIG_MC)).plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)).plus(project.getConfigurations().getByName(CONFIG_PROVIDED)));
    test.setRuntimeClasspath(test.getRuntimeClasspath().plus(api.getOutput()).plus(project.getConfigurations().getByName(CONFIG_MC)).plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)));
    project.getConfigurations().getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME).extendsFrom(project.getConfigurations().getByName(CONFIG_DC_RESOLVED));
    project.getConfigurations().getByName(CONFIG_PROVIDED).extendsFrom(project.getConfigurations().getByName(CONFIG_DP_RESOLVED));
    project.getConfigurations().getByName(api.getCompileConfigurationName()).extendsFrom(project.getConfigurations().getByName("compile"));
    project.getConfigurations().getByName(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME).extendsFrom(project.getConfigurations().getByName("apiCompile"));
    Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
    javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
    // libs folder dependencies
    project.getDependencies().add(JavaPlugin.COMPILE_CONFIGURATION_NAME, project.fileTree("libs"));
    // set the compile target
    javaConv.setSourceCompatibility("1.6");
    javaConv.setTargetCompatibility("1.6");
}
Example 22
Project: hibernate-core-ogm-master  File: InjectionAction.java View source code
private ClassLoader buildRuntimeScopeClassLoader() {
    final ArrayList<URL> classPathUrls = new ArrayList<URL>();
    final SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME);
    for (File file : mainSourceSet.getRuntimeClasspath()) {
        try {
            classPathUrls.add(file.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new InjectionException("Could not determine artifact URL [" + file.getPath() + "]", e);
        }
    }
    return new URLClassLoader(classPathUrls.toArray(new URL[classPathUrls.size()]), getClass().getClassLoader());
}
Example 23
Project: hibernate-orm-master  File: HibernatePlugin.java View source code
@Override
public void execute(Task task) {
    project.getLogger().debug("Starting Hibernate enhancement on SourceSet.{}", sourceSet.getName());
    final ClassLoader classLoader = toClassLoader(sourceSet.getRuntimeClasspath());
    EnhancementContext enhancementContext = new DefaultEnhancementContext() {

        @Override
        public ClassLoader getLoadingClassLoader() {
            return classLoader;
        }

        @Override
        public boolean doBiDirectionalAssociationManagement(UnloadedField field) {
            return hibernateExtension.enhance.getEnableAssociationManagement();
        }

        @Override
        public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) {
            return hibernateExtension.enhance.getEnableDirtyTracking();
        }

        @Override
        public boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor) {
            return hibernateExtension.enhance.getEnableLazyInitialization();
        }

        @Override
        public boolean isLazyLoadable(UnloadedField field) {
            return hibernateExtension.enhance.getEnableLazyInitialization();
        }

        @Override
        public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
            return hibernateExtension.enhance.getEnableExtendedEnhancement();
        }
    };
    if (hibernateExtension.enhance.getEnableExtendedEnhancement()) {
        logger.warn("Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk.");
    }
    final Enhancer enhancer = Environment.getBytecodeProvider().getEnhancer(enhancementContext);
    final FileTree fileTree = project.fileTree(sourceSet.getOutput().getClassesDir());
    for (File file : fileTree) {
        if (!file.getName().endsWith(".class")) {
            continue;
        }
        final byte[] enhancedBytecode = doEnhancement(sourceSet.getOutput().getClassesDir(), file, enhancer);
        if (enhancedBytecode != null) {
            writeOutEnhancedClass(enhancedBytecode, file);
            logger.info("Successfully enhanced class [" + file + "]");
        } else {
            logger.info("Skipping class [" + file.getAbsolutePath() + "], not an entity nor embeddable");
        }
    }
}
Example 24
Project: intellij-community-master  File: ModuleExtendedModelBuilderImpl.java View source code
@Nullable
@Override
public Object buildAll(String modelName, Project project) {
    final String moduleName = project.getName();
    final String moduleGroup = project.getGroup().toString();
    final String moduleVersion = project.getVersion().toString();
    final File buildDir = project.getBuildDir();
    String javaSourceCompatibility = null;
    for (Task task : project.getTasks()) {
        if (task instanceof JavaCompile) {
            JavaCompile javaCompile = (JavaCompile) task;
            javaSourceCompatibility = javaCompile.getSourceCompatibility();
            if (task.getName().equals("compileJava"))
                break;
        }
    }
    final ModuleExtendedModelImpl moduleVersionModel = new ModuleExtendedModelImpl(moduleName, moduleGroup, moduleVersion, buildDir, javaSourceCompatibility);
    final List<File> artifacts = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Jar) {
            Jar jar = (Jar) task;
            artifacts.add(jar.getArchivePath());
        }
    }
    moduleVersionModel.setArtifacts(artifacts);
    final Set<String> sourceDirectories = new HashSet<String>();
    final Set<String> testDirectories = new HashSet<String>();
    final Set<String> resourceDirectories = new HashSet<String>();
    final Set<String> testResourceDirectories = new HashSet<String>();
    final List<File> testClassesDirs = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Test) {
            Test test = (Test) task;
            testClassesDirs.add(test.getTestClassesDir());
            if (test.hasProperty(TEST_SRC_DIRS_PROPERTY)) {
                Object testSrcDirs = test.property(TEST_SRC_DIRS_PROPERTY);
                if (testSrcDirs instanceof Iterable) {
                    for (Object dir : Iterable.class.cast(testSrcDirs)) {
                        addFilePath(testDirectories, dir);
                    }
                }
            }
        }
    }
    IdeaCompilerOutputImpl compilerOutput = new IdeaCompilerOutputImpl();
    if (project.hasProperty(SOURCE_SETS_PROPERTY)) {
        Object sourceSets = project.property(SOURCE_SETS_PROPERTY);
        if (sourceSets instanceof SourceSetContainer) {
            SourceSetContainer sourceSetContainer = (SourceSetContainer) sourceSets;
            for (SourceSet sourceSet : sourceSetContainer) {
                SourceSetOutput output = sourceSet.getOutput();
                if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setTestClassesDir(output.getClassesDir());
                    compilerOutput.setTestResourcesDir(output.getResourcesDir());
                }
                if (SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setMainClassesDir(output.getClassesDir());
                    compilerOutput.setMainResourcesDir(output.getResourcesDir());
                }
                for (File javaSrcDir : sourceSet.getAllJava().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testDirectories : sourceDirectories, javaSrcDir);
                }
                for (File resourcesSrcDir : sourceSet.getResources().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testResourceDirectories : resourceDirectories, resourcesSrcDir);
                }
            }
        }
    }
    File projectDir = project.getProjectDir();
    IdeaContentRootImpl contentRoot = new IdeaContentRootImpl(projectDir);
    final Set<String> ideaSourceDirectories = new HashSet<String>();
    final Set<String> ideaTestDirectories = new HashSet<String>();
    final Set<String> ideaGeneratedDirectories = new HashSet<String>();
    final Set<File> excludeDirectories = new HashSet<File>();
    enrichDataFromIdeaPlugin(project, excludeDirectories, ideaSourceDirectories, ideaTestDirectories, ideaGeneratedDirectories);
    if (ideaSourceDirectories.isEmpty()) {
        sourceDirectories.clear();
        resourceDirectories.clear();
    }
    if (ideaTestDirectories.isEmpty()) {
        testDirectories.clear();
        testResourceDirectories.clear();
    }
    ideaSourceDirectories.removeAll(resourceDirectories);
    sourceDirectories.removeAll(ideaTestDirectories);
    sourceDirectories.addAll(ideaSourceDirectories);
    ideaTestDirectories.removeAll(testResourceDirectories);
    testDirectories.addAll(ideaTestDirectories);
    // ensure disjoint directories with different type
    resourceDirectories.removeAll(sourceDirectories);
    testDirectories.removeAll(sourceDirectories);
    testResourceDirectories.removeAll(testDirectories);
    for (String javaDir : sourceDirectories) {
        contentRoot.addSourceDirectory(new IdeaSourceDirectoryImpl(new File(javaDir), ideaGeneratedDirectories.contains(javaDir)));
    }
    for (String testDir : testDirectories) {
        contentRoot.addTestDirectory(new IdeaSourceDirectoryImpl(new File(testDir), ideaGeneratedDirectories.contains(testDir)));
    }
    for (String resourceDir : resourceDirectories) {
        contentRoot.addResourceDirectory(new IdeaSourceDirectoryImpl(new File(resourceDir)));
    }
    for (String testResourceDir : testResourceDirectories) {
        contentRoot.addTestResourceDirectory(new IdeaSourceDirectoryImpl(new File(testResourceDir)));
    }
    for (File excludeDir : excludeDirectories) {
        contentRoot.addExcludeDirectory(excludeDir);
    }
    moduleVersionModel.setContentRoots(Collections.<ExtIdeaContentRoot>singleton(contentRoot));
    moduleVersionModel.setCompilerOutput(compilerOutput);
    ConfigurationContainer configurations = project.getConfigurations();
    SortedMap<String, Configuration> configurationsByName = configurations.getAsMap();
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<String, Set<File>>();
    for (Map.Entry<String, Configuration> configurationEntry : configurationsByName.entrySet()) {
        Set<File> files = configurationEntry.getValue().getAllArtifacts().getFiles().getFiles();
        artifactsByConfiguration.put(configurationEntry.getKey(), files);
    }
    moduleVersionModel.setArtifactsByConfiguration(artifactsByConfiguration);
    return moduleVersionModel;
}
Example 25
Project: liferay-gradle-plugin-master  File: ServiceBuilderPlugin.java View source code
private void configureServiceJavaDoc(Project project) {
    JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSet serviceSourceSet = javaConvention.getSourceSets().getByName(SERVICE_SOURCE_SET_NAME);
    Javadoc serviceJavadoc = project.getTasks().create(JAVADOC_SERVICE_TASK_NAME, Javadoc.class);
    serviceJavadoc.setDescription("Generates Javadoc API documentation for the servicebuilder service api.");
    serviceJavadoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
    serviceJavadoc.setClasspath(serviceSourceSet.getOutput().plus(serviceSourceSet.getCompileClasspath()));
    serviceJavadoc.setDestinationDir(new File(javaConvention.getDocsDir(), "serviceJavadoc"));
    serviceJavadoc.setSource(serviceSourceSet.getAllJava());
    Javadoc mainJavadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
    mainJavadoc.dependsOn(serviceJavadoc);
}
Example 26
Project: flyway-master  File: AbstractFlywayTask.java View source code
@TaskAction
public Object runTask() {
    try {
        List<URL> extraURLs = new ArrayList<URL>();
        if (isJavaProject()) {
            JavaPluginConvention plugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
            for (SourceSet sourceSet : plugin.getSourceSets()) {
                URL classesUrl = sourceSet.getOutput().getClassesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + classesUrl);
                extraURLs.add(classesUrl);
                URL resourcesUrl = sourceSet.getOutput().getResourcesDir().toURI().toURL();
                getLogger().debug("Adding directory to Classpath: " + resourcesUrl);
                extraURLs.add(resourcesUrl);
            }
            addDependenciesWithScope(extraURLs, "compile");
            addDependenciesWithScope(extraURLs, "runtime");
            addDependenciesWithScope(extraURLs, "testCompile");
            addDependenciesWithScope(extraURLs, "testRuntime");
        }
        ClassLoader classLoader = new URLClassLoader(extraURLs.toArray(new URL[extraURLs.size()]), getProject().getBuildscript().getClassLoader());
        Flyway flyway = new Flyway();
        flyway.setClassLoader(classLoader);
        flyway.configure(createFlywayConfig());
        return run(flyway);
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Example 27
Project: gradle-car-plugin-master  File: DefaultSourceSetContainer.java View source code
public String determineName(SourceSet ss) {
    return ss.getName();
}
Example 28
Project: gradle-msbuild-plugin-master  File: DefaultSourceSetContainer.java View source code
public String determineName(SourceSet ss) {
    return ss.getName();
}