/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin 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 either specify 'target' manually or apply a kotlin plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".kt") || name.endsWith(".kts"); })); } target = union; } super.setupTask(task); } }
/** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin 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 either specify 'target' manually or apply the 'scala' plugin."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllSource().filter(file -> { String name = file.getName(); return name.endsWith(".scala") || name.endsWith(".sc"); })); } target = union; } super.setupTask(task); } }
/** 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."); } FileCollection union = getProject().files(); for (SourceSet sourceSet : javaPlugin.getSourceSets()) { union = union.plus(sourceSet.getAllJava()); } target = union; } steps.replaceAll(step -> { if (LicenseHeaderStep.name().equals(step.getName())) { return step.filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { return step; } }); super.setupTask(task); } }
/** * get gradle main source set */ private static Set< SourceSet > sourceSetMain( Project project ) { JavaPluginConvention convention = project.getConvention().findPlugin( JavaPluginConvention.class ); Set< SourceSet > sourceSets = convention.getSourceSets().stream().filter( sourceSet -> sourceSet.getName().equals( SourceSet.MAIN_SOURCE_SET_NAME ) ).collect( Collectors.toSet() ); return sourceSets; }
public static <T> T getConvention(Object conventionTarget, Class<T> conventionType) { assertConventionObject(conventionTarget); return ((HasConvention) conventionTarget).getConvention() .findPlugin(conventionType); }
@Nullable static War getWarTask(Project project) { WarPluginConvention warPluginConvention = project.getConvention().findPlugin(WarPluginConvention.class); if (warPluginConvention == null) { return null; } return (War) warPluginConvention.getProject().getTasks().findByName("war"); }
private <T> T getPlugin(Class<T> type) { return getProject().getConvention().findPlugin(type); } }
private void configureAppPlugin() { final ApplicationPluginConvention convention = this.project.getConvention().findPlugin( ApplicationPluginConvention.class ); convention.setMainClassName( "io.purplejs.boot.MainApp" ); final JavaExec runTask = (JavaExec) this.project.getTasks().getByName( ApplicationPlugin.TASK_RUN_NAME ); runTask.systemProperty( "io.purplejs.runMode", "dev" ); final String devDirs = new File( this.project.getProjectDir(), "src/main/resources" ).getAbsolutePath(); runTask.systemProperty( "io.purplejs.devSourceDirs", devDirs ); } }
private static String getDefaultSourcepath(Project project, ScalaCompile scalaCompile) { // The source sets are configured in the JavaPlugin and ScalaPlugin and they use the JavaPluginConvention to store the source sets. SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets(); StringJoiner sourcepathJoiner = new StringJoiner(File.pathSeparator); for (SourceSet set : sourceSets) { if (set.getCompileTaskName("scala").equals(scalaCompile.getName())) { Convention scalaConvention = (Convention) InvokerHelper.getProperty(set, "convention"); ScalaSourceSet scalaSourceSet = scalaConvention.findPlugin(ScalaSourceSet.class); scalaSourceSet.getAllScala().getSourceDirectories().getFiles().forEach(file -> sourcepathJoiner.add(file.getAbsolutePath())); } } LOGGER.debug("Hydra sourcepath: {}.", sourcepathJoiner); return sourcepathJoiner.toString(); }
void validateAgainstDefaultBaseImageVersion(@Nullable String baseImage) { if (!PluginConfigurationProcessor.usingDefaultBaseImage(baseImage)) { return; } JavaVersion version = JavaVersion.current(); JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaPluginConvention != null) { version = JavaVersion.toVersion(javaPluginConvention.getTargetCompatibility()); } if (version.isJava9Compatible()) { throw new GradleException( "Jib's default base image uses Java 8, but project is using Java " + version.getMajorVersion() + "; perhaps you should configure a Java " + version.getMajorVersion() + "-compatible base image using the 'jib.from.image' parameter, or set targetCompatibility = 1.8 in your build configuration"); } }
private static void addGeneratedToMainSourceSet(Project subproj) { JavaPluginConvention javaPlugin = subproj.getConvention().findPlugin(JavaPluginConvention.class); javaPlugin.getSourceSets().getByName("main").getJava().srcDir(subproj.files(JAVA_GENERATED_SOURCE_DIRNAME)); }
/** * Applies the {@link JavaPlugin}. * * @param project * the {@link Project} that the {@link Plugin} is applied to */ private void applyJavaPlugin(Project project) { project.getPluginManager().apply(JavaPlugin.class); JavaPluginConvention javaPluginConv = project.getConvention().findPlugin(JavaPluginConvention.class); javaPluginConv.setSourceCompatibility(JavaVersion.VERSION_1_8); javaPluginConv.setTargetCompatibility(JavaVersion.VERSION_1_8); project.getTasks().withType(JavaCompile.class).forEach(task -> task.getOptions().setEncoding("UTF-8")); }
private Set<String> getGradlePluginDefinitions(final Project subProject) { Convention _convention = subProject.getConvention(); final JavaPluginConvention java = _convention.<JavaPluginConvention>findPlugin(JavaPluginConvention.class); boolean _notEquals = (!Objects.equal(java, null)); if (_notEquals) {
.getPomConfigurer(); MavenPluginConvention maven = getProject().getConvention() .findPlugin(MavenPluginConvention.class); if (maven != null) { output.mkdirs();
@Override public void apply(Project project) { project.getPluginManager().apply(JavaPlugin.class); JavaPluginConvention javaPluginConv = project.getConvention().findPlugin(JavaPluginConvention.class); javaPluginConv.setSourceCompatibility(JavaVersion.VERSION_1_8); javaPluginConv.setTargetCompatibility(JavaVersion.VERSION_1_8); project.getPluginManager().apply(IdeaPlugin.class); project.getRepositories().mavenCentral(); project.getDependencies().add("testCompile", "junit:junit:4.12"); Wrapper wrapper = project.getTasks().create("wrapper", Wrapper.class); wrapper.setGradleVersion("3.5"); Test test = (Test) project.getTasks().getByName("test"); TestLoggingContainer testLogging = test.getTestLogging(); testLogging.events("failed", "passed"); testLogging.setExceptionFormat(TestExceptionFormat.FULL); testLogging.setShowStackTraces(false); } }
.findPlugin(JavaPluginConvention.class); if (convention == null) { return null;
private void configureInjectionTasks() { if (isRootProject()) { project.getGradle().projectsEvaluated (gradle -> gradle.allprojects (p -> { JavaPluginConvention javaConvention = p.getConvention().findPlugin(JavaPluginConvention.class); EtaPlugin etaPlugin = p.getPlugins().findPlugin(EtaPlugin.class); if (javaConvention != null && etaPlugin == null) { javaConvention.getSourceSets().all (sourceSet -> configureSourceSetInjection(p, sourceSet)); } })); } }
if (p.getConvention().findPlugin(EtaPluginConvention.class) != null) { DependencyHandler dependencies = p.getDependencies(); for (Configuration c: p.getConfigurations()) { if (p.getPlugins().findPlugin(EtaPlugin.class) == null && p.getConvention() .findPlugin(JavaPluginConvention.class) != null) { p.getTasks().withType(EtaInjectDependencies.class).all (EtaInjectDependencies::injectDependencies);
private void addSourceSet(ConfigurableFileCollection sources, Project project, String sourceSet) { JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class); if (javaConvention != null) { SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(sourceSet); sources .from(project.files(mainSourceSet.getOutput().getResourcesDir())) .from(project.files(mainSourceSet.getOutput().getClassesDirs())) .from(project.files(mainSourceSet.getAllSource().getSrcDirs())); } }
JavaPluginConvention javaPluginConvention = target.getConvention().findPlugin(JavaPluginConvention.class); SourceSet generated = javaPluginConvention.getSourceSets().maybeCreate("generated");