Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic links and fix Filters compile error #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ gradle-app.setting
*.ipr
*.iws
generator/generator
gradle.properties
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Rancher Java SDK

This project is a autogenerated Java Client for [Rancher](rancher.com)
This project is a autogenerated Java Client for [Rancher](http://rancher.com)

This project automatically generates the type definitions use a Go template generator and the Rancher provided API schema.
It was originally derived from the [Go-Rancher](https://github.com/rancher/go-rancher) library.
Expand Down
30 changes: 26 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'

repositories {
jcenter()
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
group = "io.rancher"
version = "0.3-SNAPSHOT"

jar {
baseName = "rancher-java-sdk"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile "com.squareup.retrofit2:retrofit:2.0.0-beta3"
Expand All @@ -23,7 +31,7 @@ task javadocJar(type: Jar) {

publishing {
publications {
sdk(MavenPublication) {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier 'sources'
Expand All @@ -33,4 +41,18 @@ publishing {
}
}
}
}
repositories {
maven {
credentials {
username "$nexusUser"
password"$nexusPass"
}

if (project.version.endsWith('-SNAPSHOT')) {
url "https://nexus.cropster.xyz/repository/cropster-snapshots/"
} else {
url "https://nexus.cropster.xyz/repository/cropster/"
}
}
}
}
16 changes: 10 additions & 6 deletions generator/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
.PHONY clean deps
.PHONY := clean deps build default

default: clean build
./generator

clean:
go clean -i ./...
rm -rf ../src/main/java/io/rancher/type
rm -rf ../src/main/java/io/rancher/service
go clean -i ./...
rm -rf ../src/main/java/io/rancher/type
rm -rf ../src/main/java/io/rancher/service

deps:
go get -t ./...
go get -t ./...

build:
go build ./...
go build ./...

37 changes: 37 additions & 0 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"
"text/template"
"sort"

"github.com/rancher/go-rancher/client"
)
Expand Down Expand Up @@ -48,6 +49,7 @@ func (m metadata) ListImports() []string {
imports[i] = k
i++
}
sort.Strings(imports)
return imports
}

Expand All @@ -58,6 +60,7 @@ func (m metadata) ListActionImports() []string {
imports[i] = k
i++
}
sort.Strings(imports)
return imports
}

Expand Down Expand Up @@ -168,6 +171,37 @@ func getResourceActions(schema client.Schema, m metadata) map[string]client.Acti
return result
}

func getServiceLinks(schema client.Schema, m metadata) map[string]string {
result := map[string]string{}
for i := range schema.IncludeableLinks {
link := schema.IncludeableLinks[i]
if _, ok := schemaExists[link]; ok {
if strings.HasSuffix(link, "s") {
singular := link[:len(link)-1]
class := capitalize(singular)
result[link] = "TypeCollection<" + class +">"
m.importActionClass("io.rancher.type." + class)
} else {
class := capitalize(link)
result[link] = class
m.importActionClass("io.rancher.type." + class)
}
}
}
return result
}

func getLinks(schema client.Schema) map[string]string {
result := map[string]string{}
for i := range schema.IncludeableLinks {
link := schema.IncludeableLinks[i]
if _, ok := schemaExists[link]; ok {
result[link] = capitalize(link);
}
}
return result
}

func generateType(schema client.Schema) error {
return generateTemplate(schema, path.Join(TYPE_SOURCE_OUTPUT_DIR, capitalize(schema.Id)+".java"), "type.template")
}
Expand Down Expand Up @@ -197,6 +231,8 @@ func generateTemplate(schema client.Schema, outputPath string, templateName stri
"collection": capitalize(schema.Id) + "Collection",
"structFields": typeMap,
"resourceActions": getResourceActions(schema, metadata),
"serviceLinks": getServiceLinks(schema, metadata),
"links": getLinks(schema),
"type": schema.Id,
"meta": metadata,
}
Expand Down Expand Up @@ -251,6 +287,7 @@ func generateFiles() error {
}

schemaExists[schema.Id] = true
schemaExists[schema.PluralName] = true
}

for _, schema := range schemas.Data {
Expand Down
Loading