-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from wiwa/f/targetroot-javac-classdir
Allow javac plugin to infer targetroot from javac class output directory
- Loading branch information
Showing
7 changed files
with
132 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
package tests; | ||
|
||
import java.net.URI; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.tools.FileObject; | ||
import javax.tools.ForwardingJavaFileManager; | ||
import javax.tools.JavaFileObject; | ||
import javax.tools.StandardJavaFileManager; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.sourcegraph.semanticdb_javac.SemanticdbJavacOptions; | ||
|
||
public class SimpleFileManager | ||
extends ForwardingJavaFileManager<StandardJavaFileManager> { | ||
extends ForwardingJavaFileManager<StandardJavaFileManager> { | ||
|
||
public List<SimpleClassFile> compiled = new ArrayList<>(); | ||
protected SimpleFileManager(StandardJavaFileManager fileManager) { | ||
super(fileManager); | ||
} | ||
public final List<SimpleClassFile> compiled = new ArrayList<>(); | ||
public final Path targetroot; | ||
|
||
protected SimpleFileManager(StandardJavaFileManager fileManager, Path targetroot) { | ||
super(fileManager); | ||
this.targetroot = targetroot; | ||
} | ||
|
||
// standard constructors/getters | ||
// standard constructors/getters | ||
|
||
@Override | ||
public JavaFileObject getJavaFileForOutput(Location location, | ||
String className, JavaFileObject.Kind kind, FileObject sibling) { | ||
SimpleClassFile result = new SimpleClassFile( | ||
URI.create("string://" + className)); | ||
compiled.add(result); | ||
return result; | ||
@Override | ||
public JavaFileObject getJavaFileForOutput(Location location, | ||
String className, JavaFileObject.Kind kind, FileObject sibling) { | ||
URI uri = targetroot.resolve(className).toUri(); | ||
SimpleClassFile result = new SimpleClassFile(uri); | ||
if (!className.equals(SemanticdbJavacOptions.stubClassName)) { | ||
compiled.add(result); | ||
} | ||
return result; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/unit/src/test/scala/tests/JavacClassesDirectorySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package tests | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
import scala.meta.inputs.Input | ||
|
||
import munit.FunSuite | ||
|
||
class JavacClassesDirectorySuite extends FunSuite with TempDirectories { | ||
val sourceroot = new DirectoryFixture() | ||
|
||
override def munitFixtures: Seq[Fixture[_]] = | ||
super.munitFixtures ++ List(sourceroot) | ||
|
||
test("targetroot:javac-classes-directory") { | ||
val compiler = | ||
new TestCompiler( | ||
classpath = TestCompiler.PROCESSOR_PATH, | ||
options = Nil, | ||
targetroot = sourceroot(), | ||
sourceroot = sourceroot() | ||
) | ||
val compileResult = compiler.compile( | ||
List( | ||
Input.VirtualFile( | ||
"example/Example.java", | ||
"""package example; | ||
|public class Example{}""".stripMargin | ||
) | ||
), | ||
List( | ||
s"-Xplugin:semanticdb -sourceroot:${sourceroot()} -targetroot:javac-classes-directory", | ||
"-d", | ||
sourceroot().toString | ||
) | ||
) | ||
assert(clue(compileResult).isSuccess) | ||
val semanticdbPath = Paths | ||
.get("META-INF") | ||
.resolve("semanticdb") | ||
.resolve("example") | ||
.resolve("Example.java.semanticdb") | ||
assert(Files.isRegularFile(clue(sourceroot().resolve(semanticdbPath)))) | ||
} | ||
|
||
} |