org.gradle.api.plugins.JavaBasePlugin Java Examples

The following examples show how to use org.gradle.api.plugins.JavaBasePlugin. 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: AspectJPlugin.java    From gradle-plugins with MIT License 7 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #2
Source File: GeneratePlugin.java    From jpa2ddl with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
	GeneratePluginExtension generatePluginExtension = project.getExtensions().create(EXTENSION_NAME,
			GeneratePluginExtension.class, project);

	GenerateTask generateTask = project.getTasks().create(TASK_NAME, GenerateTask.class);
	generateTask.setGroup(BasePlugin.BUILD_GROUP);
	generateTask.setDescription("Generates DDL scripts based on JPA model.");
	generateTask.setExtension(generatePluginExtension);
	generateTask.dependsOn(JavaBasePlugin.BUILD_TASK_NAME);


	project.afterEvaluate(evaluatedProject -> {
		fillDefaults(evaluatedProject, generatePluginExtension);
		SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
		Set<File> paths;
		if (sourceSets != null) {
			UnionFileCollection mainClasspath = (UnionFileCollection) sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
			paths = mainClasspath.getFiles();
		} else {
			paths = new HashSet<>();
		}
		generateTask.setOutputClassesDirs(paths);
	});
}
 
Example #3
Source File: ValidatePomsPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getTasks().withType(GenerateMavenPom.class, generateMavenPom -> {

        String checkTaskName;

        if (generateMavenPom.getName().startsWith("generate")) {
            checkTaskName = "validate" + generateMavenPom.getName().substring(8);
        } else {
            checkTaskName = "validate" + generateMavenPom.getName();
        }

        ValidateMavenPom validateMavenPom = project.getTasks().create(checkTaskName, ValidateMavenPom.class);

        project.afterEvaluate(p -> {

            Task check = project.getTasks().findByName(JavaBasePlugin.CHECK_TASK_NAME);
            if (check != null) {
                check.dependsOn(validateMavenPom);
            }

            validateMavenPom.dependsOn(generateMavenPom);
            validateMavenPom.getPomFile().set(generateMavenPom.getDestination());
        });
    });
}
 
Example #4
Source File: ValidatePomsPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getTasks().withType(GenerateMavenPom.class, generateMavenPom -> {

        String checkTaskName;

        if (generateMavenPom.getName().startsWith("generate")) {
            checkTaskName = "validate" + generateMavenPom.getName().substring(8);
        } else {
            checkTaskName = "validate" + generateMavenPom.getName();
        }

        ValidateMavenPom validateMavenPom = project.getTasks().create(checkTaskName, ValidateMavenPom.class);

        project.afterEvaluate(p -> {

            Task check = project.getTasks().findByName(JavaBasePlugin.CHECK_TASK_NAME);
            if (check != null) {
                check.dependsOn(validateMavenPom);
            }

            validateMavenPom.dependsOn(generateMavenPom);
            validateMavenPom.getPomFile().set(generateMavenPom.getDestination());
        });
    });
}
 
Example #5
Source File: AspectJPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    project.getPlugins().apply(AspectJBasePlugin.class);
    project.getPlugins().apply(JavaBasePlugin.class);

    JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);

    plugin.getSourceSets().all(this::configureSourceSet);

    project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {

        SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

        DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
        DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);

        Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
        Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());

        testAspectpath.extendsFrom(aspectpath);

        testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
    });
}
 
Example #6
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
@Test
void CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfJavaPluginIsApplied(Project project, TaskProvider<Cpd> cpdCheck) {
    // When:
    project.getPlugins().apply(JavaBasePlugin.class);

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().create("tmp", (SourceSet sourceSet) ->
            sourceSet.getJava().srcDir(testFile(JAVA, ".")));

    Task checkTask = project.getTasks().getByName("check");

    // Then:
    assertThat((Set<Task>) checkTask.getTaskDependencies().getDependencies(checkTask)).contains(cpdCheck.get());
    assertThat(cpdCheck.get().getSource()).containsExactlyInAnyOrderElementsOf(testFilesRecurseIn(JAVA, "."));
}
 
Example #7
Source File: SpringJavaFormatPlugin.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private void addSourceTasks() {
	this.project.getPlugins().withType(JavaBasePlugin.class, (plugin) -> {
		Task formatAll = this.project.task(FormatTask.NAME);
		formatAll.setDescription(FormatTask.DESCRIPTION);
		Task checkAll = this.project.task(CheckTask.NAME);
		checkAll.setDescription(CheckTask.DESCRIPTION);
		this.project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(checkAll);
		this.project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets()
				.all((sourceSet) -> addSourceTasks(sourceSet, checkAll, formatAll));
	});
}
 
Example #8
Source File: CpdPluginTest.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
static Stream<Class<? extends Plugin>> CpdPlugin_shouldAddCpdCheckTaskAsDependencyOfCheckLifecycleTaskIfPluginIsApplied() {
    return Stream.of(
            LifecycleBasePlugin.class,
            BasePlugin.class,
            LanguageBasePlugin.class,
            JavaBasePlugin.class,

            JavaPlugin.class,
            GroovyPlugin.class,
            CppPlugin.class
        );
}
 
Example #9
Source File: CpdPlugin.java    From gradle-cpd-plugin with Apache License 2.0 5 votes vote down vote up
private void createTask(Project project) {
    TaskProvider<Cpd> taskProvider = project.getTasks().register(TASK_NAME_CPD_CHECK, Cpd.class, task -> {
        task.setDescription("Run CPD analysis for all sources");
        project.getAllprojects().forEach(p ->
                p.getPlugins().withType(JavaBasePlugin.class, plugin ->
                        p.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet ->
                                sourceSet.getAllJava().getSrcDirs().forEach(task::source)
                        )
                )
        );
    });

    project.getPlugins().withType(LifecycleBasePlugin.class, plugin ->
            project.getTasks().findByName(LifecycleBasePlugin.CHECK_TASK_NAME).dependsOn(taskProvider));
}
 
Example #10
Source File: PwtPlugin.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createCheckTask(final Project project) {
	project.getTasks().create(GwtCheckTask.NAME, GwtCheckTask.class);
	final PutnamiExtension extension = project.getExtensions().getByType(PutnamiExtension.class);
	final Task checkTask = project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME);
	checkTask.dependsOn(GwtCheckTask.NAME);
	project.getTasks().withType(GwtCheckTask.class, new Action<GwtCheckTask>() {
		@Override
		public void execute(final GwtCheckTask task) {
			task.configure(project, extension);
		}
	});
}
 
Example #11
Source File: AspectJPostCompileWeavingPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    aspectjBasePlugin = project.getPlugins().apply(AspectJBasePlugin.class);

    project.getPlugins().apply(JavaBasePlugin.class);

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(this::configureSourceSet);
}
 
Example #12
Source File: PackagePlugin.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    super.apply(project);
    PluginManager pluginManager = project.getPluginManager();
    if (!pluginManager.hasPlugin(ThorntailArquillianPlugin.PLUGIN_ID)) {
        pluginManager.apply(ThorntailArquillianPlugin.class);
    }
    project.afterEvaluate(__ -> {
        final TaskContainer tasks = project.getTasks();
        final PackageTask packageTask = tasks.create(THORNTAIL_PACKAGE_TASK_NAME, PackageTask.class);

        final Jar archiveTask = ThorntailUtils.getArchiveTask(project);
        packageTask.jarTask(archiveTask).dependsOn(archiveTask);

        tasks.getByName(JavaBasePlugin.BUILD_TASK_NAME).dependsOn(packageTask);

        Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);

        StartTask runTask = tasks.create(THORNTAIL_RUN_TASK_NAME, StartTask.class, StartTask::waitForProcess);
        runTask.dependsOn(classesTask);

        StartTask startTask = tasks.create(THORNTAIL_START_TASK_NAME, StartTask.class);
        startTask.dependsOn(classesTask);

        tasks.create(THORNTAIL_STOP_TASK_NAME, StopTask.class);
    });
}
 
Example #13
Source File: PluginValidationPlugin.java    From shipkit with MIT License 5 votes vote down vote up
@Override
public void apply(final Project project) {
    project.getPlugins().withId("java", plugin -> {
        TaskMaker.task(project, VALIDATE_PLUGINS, PluginValidatorTask.class, task -> {
            task.setDescription("Validates Gradle Plugins and their properties files");
            task.setSourceSet(JavaPluginUtil.getMainSourceSet(project));

            project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(task);
        });
    });
}
 
Example #14
Source File: AspectJPostCompileWeavingPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    aspectjBasePlugin = project.getPlugins().apply(AspectJBasePlugin.class);

    project.getPlugins().apply(JavaBasePlugin.class);

    project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(this::configureSourceSet);
}
 
Example #15
Source File: ClojureCommonBasePlugin.java    From clojurephant with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPluginManager().apply(JavaBasePlugin.class);

  SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
  configureSourceSets(project, sourceSets);
  configureToolsConfigurations(project);
}
 
Example #16
Source File: TaskManager.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create tasks before the evaluation (on plugin apply). This is useful for tasks that
 * could be referenced by custom build logic.
 */
public void createTasksBeforeEvaluate(@NonNull TaskFactory tasks) {
    tasks.create(MAIN_PREBUILD);

    tasks.create(SOURCE_SETS, SourceSetsTask.class, new Action<SourceSetsTask>() {
        @Override
        public void execute(SourceSetsTask sourceSetsTask) {
            sourceSetsTask.setConfig(extension);
            sourceSetsTask.setDescription(
                    "Prints out all the source sets defined in this project.");
            sourceSetsTask.setGroup(ANDROID_GROUP);
        }
    });

    tasks.create(LINT, Lint.class, new Action<Lint>() {
        @Override
        public void execute(Lint lintTask) {
            lintTask.setDescription("Runs lint on all variants.");
            lintTask.setVariantName("");
            lintTask.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
            lintTask.setLintOptions(getExtension().getLintOptions());
            lintTask.setSdkHome(sdkHandler.getSdkFolder());
            lintTask.setToolingRegistry(toolingRegistry);
        }
    });
    tasks.named(JavaBasePlugin.CHECK_TASK_NAME, new Action<Task>() {
        @Override
        public void execute(Task it) {
            it.dependsOn(LINT);
        }
    });
    createLintCompileTask(tasks);
}
 
Example #17
Source File: BaseComponentModelPlugin.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Replace BasePlugin's apply method for component model.
 */
@Override
public void apply(Project project) {
    try {
        List<Recorder.Property> propertyList = Lists.newArrayList(
                new Recorder.Property("plugin_version", Version.ANDROID_GRADLE_PLUGIN_VERSION),
                new Recorder.Property("next_gen_plugin", "true"),
                new Recorder.Property("gradle_version", project.getGradle().getGradleVersion())
        );

        ProcessRecorderFactory.initialize(
                new LoggerWrapper(project.getLogger()),
                project.getRootProject()
                        .file("profiler" + System.currentTimeMillis() + ".json"),
                propertyList);
    } catch (IOException e) {
        throw new RuntimeException("Unable to initialize ProcessRecorderFactory");
    }

    project.getPlugins().apply(JavaBasePlugin.class);

    // TODO: Create configurations for build types and flavors, or migrate to new dependency
    // management if it's ready.
    ConfigurationContainer configurations = project.getConfigurations();
    createConfiguration(configurations, "compile", "Classpath for default sources.");
    createConfiguration(configurations, "default-metadata", "Metadata for published APKs");
    createConfiguration(configurations, "default-mapping", "Metadata for published APKs");

}
 
Example #18
Source File: Lint.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Lint lint) {
    lint.setLintOptions(scope.getGlobalScope().getExtension().getLintOptions());
    lint.setSdkHome(scope.getGlobalScope().getSdkHandler().getSdkFolder());
    lint.setVariantName(scope.getVariantConfiguration().getFullName());
    lint.setToolingRegistry(scope.getGlobalScope().getToolingRegistry());
    lint.setDescription(("Runs lint on the " +
            StringHelper.capitalize(scope.getVariantConfiguration().getFullName()) + " build."));
    lint.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
}
 
Example #19
Source File: AggregateJavadocPlugin.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public void apply(Project project) {

    aggregateJavadoc = project.getTasks().register("aggregateJavadoc", Javadoc.class, aggregateJavadoc -> {
        aggregateJavadoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
        aggregateJavadoc.getConventionMapping().map("destinationDir", new Callable<Object>() {
            @Override
            public Object call() {
                File docsDir = Optional.ofNullable(project.getConvention().findPlugin(JavaPluginConvention.class))
                        .map(JavaPluginConvention::getDocsDir)
                        .orElse(new File(project.getBuildDir(), "docs"));
                return new File(docsDir, "aggregateJavadoc");
            }
        });
    });

    project.allprojects(p ->
            p.getPlugins().withType(JavaPlugin.class, jp ->
                    aggregateJavadoc.configure(aj -> {
                        TaskProvider<Javadoc> javadoc = p.getTasks().named(JavaPlugin.JAVADOC_TASK_NAME, Javadoc.class);

                        aj.source(javadoc.map(Javadoc::getSource));

                        if (aj.getClasspath() instanceof ConfigurableFileCollection) {
                            ((ConfigurableFileCollection) aj.getClasspath()).from(javadoc.map(Javadoc::getClasspath));
                        }
                        else {
                            ConfigurableFileCollection classpath = project.files();
                            classpath.from(aj.getClasspath());
                            classpath.from(javadoc.map(Javadoc::getClasspath));
                            aj.setClasspath(classpath);
                        }

                        StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) javadoc.get().getOptions();
                        StandardJavadocDocletOptions aggregateOptions = (StandardJavadocDocletOptions) aj.getOptions();

                        options.getLinks().forEach(link -> {
                            if (!aggregateOptions.getLinks().contains(link)) {
                                aggregateOptions.getLinks().add(link);
                            }
                        });
                        options.getLinksOffline().forEach(link -> {
                            if (!aggregateOptions.getLinksOffline().contains(link)) {
                                aggregateOptions.getLinksOffline().add(link);
                            }
                        });
                        options.getJFlags().forEach(jFlag -> {
                            if (!aggregateOptions.getJFlags().contains(jFlag)) {
                                aggregateOptions.getJFlags().add(jFlag);
                            }
                        });
                    })
            )
    );
}
 
Example #20
Source File: AggregateJavadocPlugin.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public void apply(Project project) {

    aggregateJavadoc = project.getTasks().register("aggregateJavadoc", Javadoc.class, aggregateJavadoc -> {
        aggregateJavadoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
        aggregateJavadoc.getConventionMapping().map("destinationDir", new Callable<Object>() {
            @Override
            public Object call() {
                File docsDir = Optional.ofNullable(project.getConvention().findPlugin(JavaPluginConvention.class))
                        .map(JavaPluginConvention::getDocsDir)
                        .orElse(new File(project.getBuildDir(), "docs"));
                return new File(docsDir, "aggregateJavadoc");
            }
        });
    });

    project.allprojects(p ->
            p.getPlugins().withType(JavaPlugin.class, jp ->
                    aggregateJavadoc.configure(aj -> {
                        TaskProvider<Javadoc> javadoc = p.getTasks().named(JavaPlugin.JAVADOC_TASK_NAME, Javadoc.class);

                        aj.source(javadoc.map(Javadoc::getSource));

                        if (aj.getClasspath() instanceof ConfigurableFileCollection) {
                            ((ConfigurableFileCollection) aj.getClasspath()).from(javadoc.map(Javadoc::getClasspath));
                        }
                        else {
                            ConfigurableFileCollection classpath = project.files();
                            classpath.from(aj.getClasspath());
                            classpath.from(javadoc.map(Javadoc::getClasspath));
                            aj.setClasspath(classpath);
                        }

                        StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) javadoc.get().getOptions();
                        StandardJavadocDocletOptions aggregateOptions = (StandardJavadocDocletOptions) aj.getOptions();

                        options.getLinks().forEach(link -> {
                            if (!aggregateOptions.getLinks().contains(link)) {
                                aggregateOptions.getLinks().add(link);
                            }
                        });
                        options.getLinksOffline().forEach(link -> {
                            if (!aggregateOptions.getLinksOffline().contains(link)) {
                                aggregateOptions.getLinksOffline().add(link);
                            }
                        });
                        options.getJFlags().forEach(jFlag -> {
                            if (!aggregateOptions.getJFlags().contains(jFlag)) {
                                aggregateOptions.getJFlags().add(jFlag);
                            }
                        });
                    })
            )
    );
}
 
Example #21
Source File: ProtobufPlugin.java    From curiostack with MIT License 4 votes vote down vote up
@Override
public void apply(Project project) {
  project.getPlugins().apply(BasePlugin.class);
  project.getPlugins().apply(OsDetectorPlugin.class);

  ProtobufExtension extension = ProtobufExtension.createAndAdd(project);
  project
      .getConfigurations()
      .create(
          "protobufTools",
          protobufTools -> {
            protobufTools.setCanBeResolved(true);
            protobufTools.setCanBeConsumed(false);
            protobufTools.setVisible(false);
          });

  SourceSetTasks mainTasks = configureSourceSet("main", project, extension);

  project
      .getPlugins()
      .withType(
          JavaBasePlugin.class,
          plugin -> {
            extension.getLanguages().maybeCreate("java");

            JavaPluginConvention convention =
                project.getConvention().getPlugin(JavaPluginConvention.class);
            convention
                .getSourceSets()
                .all(
                    sourceSet -> {
                      if (sourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME)) {
                        configureExtractIncludeTask(
                            mainTasks.extractIncludeProtos(), sourceSet, project);
                        configureSourceSetOutput(
                            sourceSet, mainTasks.generateProto(), extension, project);
                      } else {
                        SourceSetTasks tasks =
                            configureSourceSet(sourceSet.getName(), project, extension);
                        configureExtractIncludeTask(
                            tasks.extractIncludeProtos(), sourceSet, project);
                        configureSourceSetOutput(
                            sourceSet, tasks.generateProto(), extension, project);
                      }
                    });
          });
}