Skip to content

Commit

Permalink
Fix indexing of directory classpath entries
Browse files Browse the repository at this point in the history
  • Loading branch information
oehme committed Aug 21, 2016
1 parent e951ac5 commit 3234e13
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.xtext.gradle.builder

import com.google.common.hash.Funnels
import com.google.common.hash.HashCode
import com.google.common.hash.Hasher
import com.google.common.hash.Hashing
import com.google.common.io.Files
import com.google.inject.Guice
Expand Down Expand Up @@ -101,7 +103,7 @@ class XtextGradleBuilder implements IncrementalXtextBuilder {
private def indexChangedClasspathEntries(GradleBuildRequest gradleRequest) {
val registry = IResourceServiceProvider.Registry.INSTANCE
gradleRequest.dirtyClasspathEntries.filter[exists].forEach[dirtyClasspathEntry|
val hash = Files.hash(dirtyClasspathEntry, Hashing.md5)
val hash = hash(dirtyClasspathEntry)
if (dependencyHashes.get(dirtyClasspathEntry) != hash) {
val containerHandle = dirtyClasspathEntry.path
val request = new BuildRequest => [
Expand Down Expand Up @@ -131,6 +133,20 @@ class XtextGradleBuilder implements IncrementalXtextBuilder {
]
}

private def HashCode hash(File file) {
val hasher = Hashing.md5.newHasher
hash(file, hasher)
hasher.hash
}

private def void hash(File file, Hasher hasher) {
if (file.isDirectory) {
file.listFiles.forEach[hash(hasher)]
} else {
Files.asByteSource(file).copyTo(Funnels.asOutputStream(hasher))
}
}

private def preparResourceSet(BuildRequest it, String containerHandle, ResourceDescriptionsData indexChunk, GradleBuildRequest gradleRequest) {
resourceSet = sharedInjector.getInstance(XtextResourceSet) => [
classpathURIContext = gradleRequest.jvmTypesLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,18 @@ class BuildingASimpleXtendProject extends AbstractXtendIntegrationTest {
build("build")
}

@Test
def void theIndexerCanHandleDirectoryClasspathEntries() {
file('src/main/java/com/example/Foo.xtend').content = '''
package com.example
class Foo {}
'''
file('src/test/java/com/example/HelloWorld.xtend').content = '''
package com.example
class HelloWorld {}
'''

build("build")
}
}

0 comments on commit 3234e13

Please sign in to comment.