Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the sourceset recognized by IDE. #51

Open
wants to merge 12 commits into
base: user/sv/gradle-6.0.1-Support
Choose a base branch
from
16 changes: 6 additions & 10 deletions src/main/java/org/gosulang/gradle/GosuBasePlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gosulang.gradle;


import org.codehaus.groovy.runtime.InvokerHelper;
import org.gosulang.gradle.tasks.DefaultGosuSourceSet;
import org.gosulang.gradle.tasks.GosuRuntime;
Expand All @@ -11,13 +10,11 @@
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.SourceDirectorySet;
//import org.gradle.api.internal.file.SourceDirectorySetFactory; //TODO unavoidable use of internal API
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.Convention;
import org.gradle.api.internal.ConventionMapping;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.internal.JvmPluginsHelper;
//import org.gradle.api.plugins.internal.SourceSetUtil;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.reporting.ReportingExtension;
import org.gradle.api.tasks.SourceSet;
Expand All @@ -44,9 +41,8 @@ public class GosuBasePlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
_project = project;
_project.getPluginManager().apply(JavaBasePlugin.class);

JavaBasePlugin javaBasePlugin = _project.getPlugins().getPlugin(JavaBasePlugin.class);
JavaPlugin javaBasePlugin = _project.getPlugins().getPlugin(JavaPlugin.class);

configureGosuRuntimeExtension();
configureCompileDefaults();
Expand All @@ -67,9 +63,9 @@ private void configureCompileDefaults() {
gosuCompile.getConventionMapping().map("gosuClasspath", () -> _gosuRuntime.inferGosuClasspath(gosuCompile.getClasspath())));
}

private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
private void configureSourceSetDefaults(final JavaPlugin javaBasePlugin) {
_project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(sourceSet -> {
GosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(sourceSet.getName(), _objectFactory);
GosuSourceSet gosuSourceSet = new DefaultGosuSourceSet(sourceSet.getName(), _objectFactory);

Convention sourceSetConvention = (Convention) InvokerHelper.getProperty(sourceSet, "convention");
sourceSetConvention.getPlugins().put("gosu", gosuSourceSet);
Expand All @@ -78,7 +74,7 @@ private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {

sourceSet.getResources().getFilter().exclude(element -> gosuSourceSet.getGosu().contains(element.getFile()));

sourceSet.getAllSource().source(gosuSourceSet.getGosu());
sourceSet.getJava().srcDir(gosuSourceSet.getGosu());

configureGosuCompile(javaBasePlugin, sourceSet, gosuSourceSet);
});
Expand All @@ -89,7 +85,7 @@ private void configureSourceSetDefaults(final JavaBasePlugin javaBasePlugin) {
* Gradle 4.0+: call local equivalent of o.g.a.p.i.SourceSetUtil.configureForSourceSet(sourceSet, gosuSourceSet.getGosu(), gosuCompile, _project)
* Gradle 2.x, 3.x: call javaPlugin.configureForSourceSet(sourceSet, gosuCompile);
*/
private void configureGosuCompile(JavaBasePlugin javaPlugin, SourceSet sourceSet, GosuSourceSet gosuSourceSet) {
private void configureGosuCompile(JavaPlugin javaPlugin, SourceSet sourceSet, GosuSourceSet gosuSourceSet) {
String compileTaskName = sourceSet.getCompileTaskName("gosu");
GosuCompile gosuCompile = _project.getTasks().create(compileTaskName, GosuCompile.class);

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/gosulang/gradle/GosuPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.Convention;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
Expand All @@ -18,8 +17,8 @@ public class GosuPlugin implements Plugin<Project> {
public static final String GOSUDOC_TASK_NAME = "gosudoc";

public void apply(Project project) {
project.getPluginManager().apply(GosuBasePlugin.class);
project.getPluginManager().apply(JavaPlugin.class);
project.getPluginManager().apply(GosuBasePlugin.class);

refreshTestRuntimeClasspath(project);
configureGosuDoc(project);
Expand All @@ -45,7 +44,6 @@ private void refreshTestRuntimeClasspath( final Project project ) {
private void configureGosuDoc( final Project project ) {
GosuDoc gosuDoc = project.getTasks().create(GOSUDOC_TASK_NAME, GosuDoc.class);
gosuDoc.setDescription("Generates Gosudoc API documentation for the main source code.");
gosuDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);

JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/gosulang/gradle/tasks/GosuConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.gosulang.gradle.tasks;

/**
* A class for holding any task constants.
*
* @author Ron Webb
* @since 2020-04-22
*/
public class GosuConstants {

private GosuConstants() {}

public static final String GROUP_NAME = "Gosu Plugin";

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gosulang.gradle.tasks.compile;

import groovy.lang.Closure;
import org.gosulang.gradle.tasks.GosuConstants;
import org.gosulang.gradle.tasks.InfersGosuRuntime;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class GosuCompile extends AbstractCompile implements InfersGosuRuntime {

@Inject
public GosuCompile() {
setGroup(GosuConstants.GROUP_NAME);
VersionNumber gradleVersion = VersionNumber.parse(getProject().getGradle().getGradleVersion());
if(gradleVersion.compareTo(VersionNumber.parse("4.2")) >= 0) {
_compileOptions = getServices().get(ObjectFactory.class).newInstance(CompileOptions.class);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/gosulang/gradle/tasks/gosudoc/GosuDoc.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gosulang.gradle.tasks.gosudoc;

import groovy.lang.Closure;
import org.gosulang.gradle.tasks.GosuConstants;
import org.gosulang.gradle.tasks.InfersGosuRuntime;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
Expand Down Expand Up @@ -29,6 +30,7 @@ public class GosuDoc extends SourceTask implements InfersGosuRuntime {
private String _title;

public GosuDoc() {
setGroup(GosuConstants.GROUP_NAME);
getLogging().captureStandardOutput(LogLevel.INFO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class AbstractGosuPluginSpecification extends Specification implements
* @return Delimited String of the values, joined as suitable for use in a classpath statement
*/
protected String asPath(String... values) {
return String.join(FS, values)
return String.join(FS, values).replace('\\', '\\\\')
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class IncrementalCompilationTest extends AbstractGosuPluginSpecification {
notThrown(UnexpectedBuildSuccess)
result.task(':compileGosu').outcome == FAILED
result.output.matches(skipUpToDateTaskExecuterExpectedOutput(gradleVersion))
result.output.contains('/src/main/gosu/B.gs has changed.')
result.output.contains('\\src\\main\\gosu\\B.gs has changed.')
result.output.contains('[3,46] error: No static property descriptor found for property, abc, on class, Type<B>')

where:
Expand All @@ -95,7 +95,9 @@ class IncrementalCompilationTest extends AbstractGosuPluginSpecification {

Closure<Pattern> skipUpToDateTaskExecuterExpectedOutput = { String gradleVersion ->
String regex = '.*Executing task \':compileGosu\'.*'
if(VersionNumber.parse(gradleVersion) >= VersionNumber.parse('4.5')) {
if(VersionNumber.parse(gradleVersion) >= VersionNumber.parse('5.1')) {
regex = '.*Task :compileGosu FAILED.*'
} else if(VersionNumber.parse(gradleVersion) >= VersionNumber.parse('4.5')) {
regex = '.*Task \':compileGosu\' is not up-to-date because:.*'
} else if(VersionNumber.parse(gradleVersion) >= VersionNumber.parse('4.3')) {
regex = '.*Up-to-date check for task \':compileGosu\' took \\d+.\\d+ secs. It is not up-to-date because:.*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.gosulang.gradle.unit
import org.gosulang.gradle.GosuBasePlugin
import org.gosulang.gradle.tasks.compile.GosuCompile
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -37,13 +37,14 @@ class GosuBasePluginTest {
@Before
public void applyPlugin() throws IOException {
project = createRootProject()
project.pluginManager.apply(JavaPlugin)
project.pluginManager.apply(GosuBasePlugin)
}

@Test
public void appliesTheJavaBasePluginToTheProject() {

assertTrue(project.plugins.hasPlugin(JavaBasePlugin))
assertTrue(project.plugins.hasPlugin(JavaPlugin))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.gosulang.gradle.unit

import org.gosulang.gradle.GosuBasePlugin
import org.gradle.api.GradleException
import org.gradle.api.plugins.JavaPlugin
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.util.VersionNumber
import spock.lang.Specification
Expand All @@ -11,6 +12,7 @@ class GosuRuntimeTest extends Specification {
def project = ProjectBuilder.builder().build()

def setup() {
project.pluginManager.apply(JavaPlugin)
project.pluginManager.apply(GosuBasePlugin)
}

Expand Down