Search in sources :

Example 1 with JavaPluginConvention

use of org.gradle.api.plugins.JavaPluginConvention in project gradle by gradle.

the class IdeaModelBuilder method appendModule.

private void appendModule(Map<String, DefaultIdeaModule> modules, IdeaModule ideaModule, DefaultIdeaProject ideaProject, DefaultGradleProject rootGradleProject) {
    DefaultIdeaContentRoot contentRoot = new DefaultIdeaContentRoot().setRootDirectory(ideaModule.getContentRoot()).setSourceDirectories(srcDirs(ideaModule.getSourceDirs(), ideaModule.getGeneratedSourceDirs())).setTestDirectories(srcDirs(ideaModule.getTestSourceDirs(), ideaModule.getGeneratedSourceDirs())).setExcludeDirectories(ideaModule.getExcludeDirs());
    Project project = ideaModule.getProject();
    DefaultIdeaModule defaultIdeaModule = new DefaultIdeaModule().setName(ideaModule.getName()).setParent(ideaProject).setGradleProject(rootGradleProject.findByPath(ideaModule.getProject().getPath())).setContentRoots(Collections.singletonList(contentRoot)).setJdkName(ideaModule.getJdkName()).setCompilerOutput(new DefaultIdeaCompilerOutput().setInheritOutputDirs(ideaModule.getInheritOutputDirs() != null ? ideaModule.getInheritOutputDirs() : false).setOutputDir(ideaModule.getOutputDir()).setTestOutputDir(ideaModule.getTestOutputDir()));
    JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
    if (javaPluginConvention != null) {
        final IdeaLanguageLevel ideaModuleLanguageLevel = ideaModule.getLanguageLevel();
        JavaVersion moduleSourceLanguageLevel = convertIdeaLanguageLevelToJavaVersion(ideaModuleLanguageLevel);
        JavaVersion moduleTargetBytecodeVersion = ideaModule.getTargetBytecodeVersion();
        defaultIdeaModule.setJavaLanguageSettings(new DefaultIdeaJavaLanguageSettings().setSourceLanguageLevel(moduleSourceLanguageLevel).setTargetBytecodeVersion(moduleTargetBytecodeVersion));
    }
    modules.put(ideaModule.getName(), defaultIdeaModule);
}
Also used : DefaultIdeaContentRoot(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaContentRoot) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) DefaultGradleProject(org.gradle.tooling.internal.gradle.DefaultGradleProject) Project(org.gradle.api.Project) DefaultIdeaProject(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject) DefaultIdeaModule(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) DefaultIdeaJavaLanguageSettings(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings) DefaultIdeaLanguageLevel(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) DefaultIdeaCompilerOutput(org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaCompilerOutput)

Example 2 with JavaPluginConvention

use of org.gradle.api.plugins.JavaPluginConvention in project flyway by flyway.

the class AbstractFlywayTask method runTask.

@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;
    }
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Flyway(org.flywaydb.core.Flyway) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) URLClassLoader(java.net.URLClassLoader) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL) FlywayException(org.flywaydb.core.api.FlywayException) IOException(java.io.IOException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with JavaPluginConvention

use of org.gradle.api.plugins.JavaPluginConvention in project gradle by gradle.

the class JavaGradlePluginPlugin method createExtension.

private GradlePluginDevelopmentExtension createExtension(Project project) {
    JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSet defaultPluginSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    SourceSet defaultTestSourceSet = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
    return project.getExtensions().create(EXTENSION_NAME, GradlePluginDevelopmentExtension.class, project, defaultPluginSourceSet, defaultTestSourceSet);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention)

Example 4 with JavaPluginConvention

use of org.gradle.api.plugins.JavaPluginConvention in project spring-boot by spring-projects.

the class RunPluginFeatures method addBootRunTask.

private void addBootRunTask(final Project project) {
    final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
    BootRunTask run = project.getTasks().create(RUN_APP_TASK_NAME, BootRunTask.class);
    run.setDescription("Run the project with support for " + "auto-detecting main class and reloading static resources");
    run.setGroup("application");
    run.setClasspath(javaConvention.getSourceSets().findByName("main").getRuntimeClasspath());
    run.getConventionMapping().map("main", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (project.hasProperty("mainClassName") && project.property("mainClassName") != null) {
                return project.property("mainClassName");
            }
            ExtraPropertiesExtension extraPropertiesExtension = (ExtraPropertiesExtension) project.getExtensions().getByName("ext");
            if (extraPropertiesExtension.has("mainClassName") && extraPropertiesExtension.get("mainClassName") != null) {
                return extraPropertiesExtension.get("mainClassName");
            }
            return null;
        }
    });
    run.getConventionMapping().map("jvmArgs", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            if (project.hasProperty("applicationDefaultJvmArgs")) {
                return project.property("applicationDefaultJvmArgs");
            }
            return Collections.emptyList();
        }
    });
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ExtraPropertiesExtension(org.gradle.api.plugins.ExtraPropertiesExtension)

Aggregations

JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)4 SourceSet (org.gradle.api.tasks.SourceSet)2 IOException (java.io.IOException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Flyway (org.flywaydb.core.Flyway)1 FlywayException (org.flywaydb.core.api.FlywayException)1 JavaVersion (org.gradle.api.JavaVersion)1 Project (org.gradle.api.Project)1 ExtraPropertiesExtension (org.gradle.api.plugins.ExtraPropertiesExtension)1 TaskAction (org.gradle.api.tasks.TaskAction)1 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)1 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)1 DefaultIdeaCompilerOutput (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaCompilerOutput)1 DefaultIdeaContentRoot (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaContentRoot)1 DefaultIdeaJavaLanguageSettings (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings)1 DefaultIdeaLanguageLevel (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel)1 DefaultIdeaModule (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule)1 DefaultIdeaProject (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject)1