From c37d2dbcaab9bf985ab200640648acf423abc739 Mon Sep 17 00:00:00 2001 From: Stefan Oehme Date: Sun, 5 Mar 2023 19:02:10 +0100 Subject: [PATCH] Fix handling of removed classpath folders --- .../test/BuildingASimpleXtendProject.xtend | 20 +++++++++++++++++++ .../xtext/gradle/tasks/XtextGenerate.xtend | 18 +++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/xtext-gradle-plugin/src/integTest/java/org/xtext/gradle/test/BuildingASimpleXtendProject.xtend b/xtext-gradle-plugin/src/integTest/java/org/xtext/gradle/test/BuildingASimpleXtendProject.xtend index 6c01f3f..36673fb 100644 --- a/xtext-gradle-plugin/src/integTest/java/org/xtext/gradle/test/BuildingASimpleXtendProject.xtend +++ b/xtext-gradle-plugin/src/integTest/java/org/xtext/gradle/test/BuildingASimpleXtendProject.xtend @@ -56,6 +56,26 @@ class BuildingASimpleXtendProject extends AbstractXtendIntegrationTest { snapshot.assertChangedClasses("UpStream", "DownStream") } + + @Test + def generatorHandlesDeletionOfClasspathFolders() { + createFile('src/main/java/UpStream.xtend', ''' + class UpStream {} + ''') + createFile('src/test/java/DownStream.xtend', ''' + class DownStream{ + } + ''') + build("build") + val snapshot = snapshot(projectDir) + + //remove the main sources from the test classpath + buildFile << "sourceSets.test.compileClasspath = configurations.testCompileClasspath" + build("build") + + snapshot.assertChangedClasses("DownStream") + } + @Test def affectedResourcesAreDetectedAcrossXtendAndJava() { diff --git a/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextGenerate.xtend b/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextGenerate.xtend index 604e744..04a652e 100644 --- a/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextGenerate.xtend +++ b/xtext-gradle-plugin/src/main/java/org/xtext/gradle/tasks/XtextGenerate.xtend @@ -127,10 +127,20 @@ abstract class XtextGenerate extends DefaultTask { request.dirtyFiles += file } ] - inputs.getFileChanges(classpath).forEach [ change | - // Gradle notifies us about individual .class files, but we only want their containing directory - request.dirtyClasspathEntries += classpath.files.findFirst[change.file.path.startsWith(it.path)] - ] + val classpathRoots = classpath.files + inputs.getFileChanges(classpath) + .forEach[change | + if (change.normalizedPath.isEmpty) { + request.dirtyClasspathEntries += change.file + } else { + val root = classpathRoots.findFirst[change.file.path.startsWith(it.path)] + if (root !== null) { + request.dirtyClasspathEntries += root + } else { + request.incremental = false + } + } + ] } def installDebugInfo(File classesDir) {