mirror of
https://github.com/go-i2p/gojava.git
synced 2025-07-03 17:59:42 -04:00
Renamed scanDir to sourceDir, reworked sourcedir test.
This commit is contained in:
@ -64,33 +64,12 @@ public class MoreAsserts {
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
private static boolean failed = false;
|
||||
|
||||
private static String pattern = ".*";
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
pattern = args[0];
|
||||
}
|
||||
|
||||
new TestRunner(new SeqTest()).runTests();
|
||||
new TestRunner(new ExtraTest()).runTests();
|
||||
|
||||
// NOTE: We need to call System.exit to force all go threads to exit.
|
||||
System.exit(failed ? 1 : 0);
|
||||
}
|
||||
|
||||
private static class TestRunner<T> {
|
||||
private T test;
|
||||
|
||||
public TestRunner(T test) {
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
public void runTests() {
|
||||
SeqTest test = new SeqTest();
|
||||
Class c = test.getClass();
|
||||
boolean failed = false;
|
||||
for (Method method : c.getDeclaredMethods()) {
|
||||
if (!method.getName().startsWith("test") || !Pattern.matches(pattern, method.getName())) {
|
||||
if (!method.getName().startsWith("test") || !Pattern.matches(args[0], method.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -104,14 +83,8 @@ public class MoreAsserts {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExtraTest {
|
||||
public void testCopyFromScanDir() {
|
||||
Dummy d = new Dummy();
|
||||
assertEquals("Values must match", 42, d.fortyTwo);
|
||||
}
|
||||
// NOTE: We need to call System.exit to force all go threads to exit.
|
||||
System.exit(failed ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ The same set of types are supported. Details on how the binding works can be fou
|
||||
-o string
|
||||
Path to write the generated jar file. (default "libgojava.jar")
|
||||
-s string
|
||||
Additional path to scan for Java files. These files will be compiled and
|
||||
Additional path to scan for Java source code. These files will be compiled and
|
||||
included in the final jar.
|
||||
-v Verbose output.
|
||||
```
|
||||
|
20
gojava.go
20
gojava.go
@ -10,10 +10,10 @@ Usage
|
||||
-o string
|
||||
Path to write the generated jar file. (default "libgojava.jar")
|
||||
-s string
|
||||
Additional path to scan for Java files. These files will be compiled and
|
||||
Additional path to scan for Java source code. These files will be compiled and
|
||||
included in the final jar.
|
||||
-v Verbose output.
|
||||
*/
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -133,19 +133,19 @@ func bindPackages(bindDir, javaDir string, pkgs []*types.Package) ([]string, err
|
||||
return javaFiles, nil
|
||||
}
|
||||
|
||||
func addExtraFiles(javaDir, scanDir string) ([]string, error) {
|
||||
if scanDir == "" {
|
||||
func addExtraFiles(javaDir, sourceDir string) ([]string, error) {
|
||||
if sourceDir == "" {
|
||||
return nil, nil
|
||||
}
|
||||
extraFiles := make([]string, 0)
|
||||
err := filepath.Walk(scanDir, func(path string, info os.FileInfo, walkErr error) error {
|
||||
err := filepath.Walk(sourceDir, func(path string, info os.FileInfo, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
fileName, err := filepath.Rel(scanDir, path)
|
||||
fileName, err := filepath.Rel(sourceDir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -160,7 +160,7 @@ func addExtraFiles(javaDir, scanDir string) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
if len(extraFiles) == 0 {
|
||||
verbosef("warning: argument -s was passed on command line, but no .java files were found in '%s'\n", scanDir)
|
||||
verbosef("warning: argument -s was passed on command line, but no .java files were found in '%s'\n", sourceDir)
|
||||
}
|
||||
return extraFiles, nil
|
||||
}
|
||||
@ -259,7 +259,7 @@ func createJar(target, jarDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func bindToJar(target string, scanDir string, pkgs ...string) error {
|
||||
func bindToJar(target string, sourceDir string, pkgs ...string) error {
|
||||
tmpDir, cleanup, err := initBuild()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -286,7 +286,7 @@ func bindToJar(target string, scanDir string, pkgs ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
extraFiles, err := addExtraFiles(javaDir, scanDir)
|
||||
extraFiles, err := addExtraFiles(javaDir, sourceDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -378,7 +378,7 @@ This generates a jar containing Java bindings to the specified Go packages.
|
||||
|
||||
func main() {
|
||||
o := flag.String("o", "libgojava.jar", "Path to the generated jar file.")
|
||||
s := flag.String("s", "", "Additional path to scan for Java files.")
|
||||
s := flag.String("s", "", "Additional path to scan for Java source code.")
|
||||
flag.BoolVar(&verbose, "v", false, "Verbose output.")
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintln(os.Stderr, usage)
|
||||
|
@ -13,15 +13,18 @@ import (
|
||||
|
||||
var javaTest = flag.String("javatest", ".*", "Run only java tests matching the regular expression")
|
||||
|
||||
func TestJavaBind(t *testing.T) {
|
||||
func init() {
|
||||
verbose = testing.Verbose()
|
||||
}
|
||||
|
||||
func TestJavaBind(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "gojavatest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jar := filepath.Join(tmpDir, "gojavatest.jar")
|
||||
if err := bindToJar(jar,
|
||||
"testdata",
|
||||
"",
|
||||
"github.com/sridharv/gomobile-java/bind/testpkg",
|
||||
"github.com/sridharv/gomobile-java/bind/testpkg/secondpkg",
|
||||
"github.com/sridharv/gomobile-java/bind/testpkg/simplepkg",
|
||||
@ -46,3 +49,23 @@ func TestJavaBind(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceDir(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "gojavatest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jar := filepath.Join(tmpDir, "gojavatest.jar")
|
||||
if err := bindToJar(jar,
|
||||
"testdata",
|
||||
"github.com/sridharv/gomobile-java/bind/testpkg",
|
||||
); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command("java", "-cp", jar, "go.SourceDirTest")
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
5
testdata/Dummy.java
vendored
5
testdata/Dummy.java
vendored
@ -1,5 +0,0 @@
|
||||
package go;
|
||||
|
||||
public class Dummy {
|
||||
public int fortyTwo = 42;
|
||||
}
|
7
testdata/SourceDirTest.java
vendored
Normal file
7
testdata/SourceDirTest.java
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
package go;
|
||||
|
||||
public class SourceDirTest {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("testSourceDirInclusion PASS");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user