Skip to content

Commit

Permalink
Add testing for other Gradle versions (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
king-tyler authored Jun 30, 2020
1 parent fabe694 commit 45413d0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
with:
java-version: ${{ matrix.jdk }}
- name: Build
run: ./gradlew build --info --stacktrace --warning-mode=fail
run: ./gradlew build "-PgradleVersions=6.2.2,current" --info --stacktrace --warning-mode=fail
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ within Gradle. This includes:
* Generates the project's `build.properties` when imported into Eclipse so that dsl project can be launched and tested
within Eclipse PDE.

These plugins have been successfully tested with Gradle 6.2 up to 6.5. They should work with newer versions as well.

## Usage

gradle-xtext-generator provides the following plugins:
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ tasks.named(JavaPlugin.TEST_TASK_NAME) {
systemProperty 'm2', file(repository.url)
systemProperty 'pluginVersion', version
systemProperty 'xtextVersion', xtextVersion
if (findProperty('gradleVersions') != null) {
systemProperty 'gradleVersions', gradleVersions
}
doFirst {
mkdir temporaryDir
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@
import org.gradle.api.UncheckedIOException;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class XtextProjectPluginsFunctionalTest {

private Path tempDir;

public static Stream<String> getGradleVersions() {
String gradleVersions = System.getProperty("gradleVersions");
Stream<String> current = Stream.of("current");
if (gradleVersions == null) {
return current;
} else {
return Stream.concat(current, Stream.of(gradleVersions.split(","))).distinct();
}
}

private void setupProject(String project) throws IOException {
tempDir = Files.createTempDirectory(Paths.get(System.getProperty("testdir")), project);
Path rootProject = Paths.get("src", "test", "resources", project);
Expand All @@ -56,41 +67,49 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
});
}

@Test
public void testXtextJavaProject() throws IOException {
@ParameterizedTest(name = "Xtext Java Project - Gradle {0}")
@MethodSource("getGradleVersions")
public void testXtextJavaProject(String gradleVersion) throws IOException {
setupProject("mydsl");
BuildResult result = runProject(CLEAN_TASK_NAME, BUILD_TASK_NAME, ECLIPSE_TASK_NAME);
BuildResult result = runProject(gradleVersion, CLEAN_TASK_NAME, BUILD_TASK_NAME, ECLIPSE_TASK_NAME);
checkProjectsGenerated(result, "example.mydsl", "example.mydsl.ide", "example.mydsl.ui", "example.mydsl.web");
checkEclipsePdeSetup(tempDir.resolve("example.mydsl.ui"));

result = runProject(BUILD_TASK_NAME);
result = runProject(gradleVersion, BUILD_TASK_NAME);
assertEquals(UP_TO_DATE, result.task(getTask(GENERATE_MWE2_TASK_NAME)).getOutcome());
Path pluginXml = tempDir
.resolve(Paths.get("example.mydsl", "build", "src-gen", "main", "resources", "plugin.xml"));
String pluginXmlText = new String(Files.readAllBytes(pluginXml), StandardCharsets.UTF_8);
assertTrue(pluginXmlText.contains("point=\"org.example.extension.point\""));
}

@Test
public void testXtextXtendProject() throws IOException {
@ParameterizedTest(name = "Xtext Xtend Project - Gradle {0}")
@MethodSource("getGradleVersions")
public void testXtextXtendProject(String gradleVersion) throws IOException {
setupProject("mydsl-xtend");
BuildResult result = runProject(CLEAN_TASK_NAME, BUILD_TASK_NAME);
BuildResult result = runProject(gradleVersion, CLEAN_TASK_NAME, BUILD_TASK_NAME);
checkProjectsGenerated(result, "example.mydsl", "example.mydsl.ide", "example.mydsl.ui", "example.mydsl.web");
}

@Test
public void testDifferentVersionXtextProject() throws IOException {
@ParameterizedTest(name = "Xtext 2.20.0 Java Project - Gradle {0}")
@MethodSource("getGradleVersions")
public void testDifferentVersionXtextProject(String gradleVersion) throws IOException {
setupProject("mydsl-xtext-version");
BuildResult result = runProject(CLEAN_TASK_NAME, BUILD_TASK_NAME);
BuildResult result = runProject(gradleVersion, CLEAN_TASK_NAME, BUILD_TASK_NAME);
checkProjectsGenerated(result, "example.mydsl", "example.mydsl.ide", "example.mydsl.ui", "example.mydsl.web");
}

private BuildResult runProject(String... tasks) {
List<String> arguments = new ArrayList<>(asList(tasks));
private BuildResult runProject(String gradleVersion, String... tasks) {
List<String> arguments = new ArrayList<>();
arguments.addAll(asList("-PxtextExampleVersion=" + System.getProperty("xtextVersion"),
"-PpluginVersion=" + System.getProperty("pluginVersion"),
"-Dmaven.repo.local=" + System.getProperty("m2"), "-s", "--warning-mode=fail"));
return GradleRunner.create().withProjectDir(tempDir.toFile()).forwardOutput().withArguments(arguments).build();
arguments.addAll(asList(tasks));
GradleRunner runner = GradleRunner.create();
if (!"current".equals(gradleVersion)) {
runner = runner.withGradleVersion(gradleVersion);
}
return runner.withProjectDir(tempDir.toFile()).forwardOutput().withArguments(arguments).build();
}

private void checkProjectsGenerated(BuildResult result, String runtimeProject, String genericIdeProject,
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/mydsl-xtend/example.mydsl.ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ repositories {
patternLayout {
artifact '[artifact]_[revision].[ext]'
}
metadataSources.artifact()
metadataSources {
artifact()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ repositories {
patternLayout {
artifact '[artifact]_[revision].[ext]'
}
metadataSources.artifact()
metadataSources {
artifact()
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/mydsl/example.mydsl.ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ repositories {
patternLayout {
artifact '[artifact]_[revision].[ext]'
}
metadataSources.artifact()
metadataSources {
artifact()
}
}
}

Expand Down

0 comments on commit 45413d0

Please sign in to comment.