I2P Address: [http://git.idk.i2p]

Verified Commit 61f30dd2 authored by idk's avatar idk
Browse files

Get rid of separate generate cmd.

parent 174c183f
......@@ -2,8 +2,14 @@
export CLASSPATH="app.jar:$(HOME)/i2p/lib/*:$()/java/net/i2p/ExampleClientApp/*"
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
GOPATH:=$(HOME)/go
all: package jar check
fixvendor:
mkdir -p $(GOPATH)/pkg/mod/github.com/sridharv/gojava/
cp $(GOPATH)/src/github.com/sridharv/gojava/LoadJNI.java $(GOPATH)/pkg/mod/github.com/sridharv/gojava/LoadJNI.java
package: fmt
gojava -v -o app.jar build i2pgit.org/idk/clientapp
......
No preview for this file type
......@@ -2,12 +2,17 @@ package clientapp
import (
"fmt"
"io/ioutil"
"reflect"
"strings"
// "path/filepath"
)
//go:generate go run --tags=generate i2pgit.org/idk/clientapp/cmd
//go:generate go test
func Generator() error {
return ioutil.WriteFile(basicClientApp.GetName()+".java", []byte(GenerateJava(basicClientApp)), 0644)
}
// ClientAppState shadows ClientAppState from Java. In go there are no enums,
// only enum types instead, so this requires a function to convert it, which
......@@ -53,11 +58,17 @@ type ExampleClientApp struct {
// GetDisplayName() implements ClientApp in Java and in Go
func (e *ExampleClientApp) GetDisplayName() string {
if e.DisplayName == "" {
return e.GetName()
}
return e.DisplayName
}
// GetName() implements ClientApp in Java and in Go
func (e *ExampleClientApp) GetName() string {
if e.Name == "" {
return "ExampleClientApp"
}
return e.Name
}
......@@ -96,7 +107,7 @@ func GenerateJava(ClientAppImpl interface{}) string {
var pkgdeclaration string = fmt.Sprintf("\npackage net.i2p.%s;\n", ECA)
var importdeclaration string = "import net.i2p.app.ClientApp;\nimport net.i2p.app.ClientAppState;\n"
var declaration string = fmt.Sprintf("public class %s implements ClientApp {\n", ECA)
var innerdeclaration string = fmt.Sprintf("\tgo.%s.%s.%s _clientApp;\n", ClientPkgName(), ClientPkgJavaName(), ClientAppName())
var innerdeclaration string = fmt.Sprintf("\tgo.%s.%s.%s _clientApp;\n", ClientPkgName(ClientAppImpl), ClientPkgJavaName(ClientAppImpl), ClientAppName(ClientAppImpl))
var overrideDisplayName string = "\t@Override\n\tpublic String getDisplayName() {\n\t\treturn _clientApp.getDisplayName();\n\t}\n"
var overrideName string = "\t@Override\n\tpublic String getName() {\n\t\treturn _clientApp.getName();\n\t}\n"
var convertClientState string = ` private ClientAppState convertClientState(long cas){
......@@ -140,15 +151,17 @@ func GenerateJava(ClientAppImpl interface{}) string {
closerdeclaration
}
func ClientAppName() string {
var CA string = strings.Split(reflect.TypeOf(ExampleClientApp{}).String(), ".")[len(strings.Split(reflect.TypeOf(ExampleClientApp{}).String(), "."))-1]
return CA
func ClientAppName(clientAppImpl interface{}) string {
var CA string = strings.Split(reflect.TypeOf(clientAppImpl).String(), ".")[len(strings.Split(reflect.TypeOf(clientAppImpl).String(), "."))-1]
return strings.Replace(CA, "*", "", -1)
}
func ClientPkgJavaName() string {
return strings.Title(strings.ToLower(strings.Split(reflect.TypeOf(ExampleClientApp{}).String(), ".")[0]))
func ClientPkgJavaName(clientAppImpl interface{}) string {
TC := strings.Title(strings.ToLower(strings.Split(reflect.TypeOf(clientAppImpl).String(), ".")[0]))
return strings.Replace(TC, "*", "", -1)
}
func ClientPkgName() string {
return strings.Split(reflect.TypeOf(ExampleClientApp{}).String(), ".")[0]
func ClientPkgName(clientAppImpl interface{}) string {
PN := strings.Split(reflect.TypeOf(clientAppImpl).String(), ".")[0]
return strings.Replace(PN, "*", "", -1)
}
......@@ -3,5 +3,5 @@ package clientapp
import "testing"
func TestJavaOutput(t *testing.T) {
t.Log(GenerateJava(&ExampleClientApp{}))
t.Log(Generator())
}
//go:build generate
// +build generate
package main
import (
"io/ioutil"
. "i2pgit.org/idk/clientapp"
)
func main() {
ioutil.WriteFile(ClientAppName()+".java", []byte(GenerateJava(&ExampleClientApp{})), 0644)
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment