Skip to content

Commit

Permalink
Merge pull request #183 from rundeck/feature/lib2
Browse files Browse the repository at this point in the history
refactor to create separate client api lib
  • Loading branch information
gschueler authored Jun 29, 2018
2 parents d69c8ca + 6acb1a9 commit 9511812
Show file tree
Hide file tree
Showing 100 changed files with 233 additions and 153 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.idea
/build
*/build
*/out
*.ipr
*.iml
*.iws
Expand Down
17 changes: 3 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ plugins {
id 'groovy'
id 'com.github.johnrengelman.shadow' version '2.0.3'
id "nebula.ospackage" version "4.8.0"
id 'de.fuerstenau.buildconfig' version '1.1.8'
}
ext.githubUrl = "https://github.com/rundeck/rundeck-cli"
ext.changelogFile = file("CHANGELOG.md")
Expand Down Expand Up @@ -157,13 +156,6 @@ task changeLog(){
}
}

/**
* Generates java source with embedded version info
*/
buildConfig {
clsName = 'Version'
packageName = 'org.rundeck.client'
}

apply plugin: 'idea'
apply plugin: 'groovy'
Expand All @@ -183,24 +175,21 @@ repositories {
maven { url "https://jitpack.io" }
}

ext.toolbeltVersion = "0.2.1"
ext.toolbeltVersion = "0.2.2"
ext.toolbeltGroup = "${toolbeltVersion.contains('SNAPSHOT')?'org':'com.github'}.rundeck.cli-toolbelt"

dependencies {
compileOnly "org.projectlombok:lombok:1.16.16"
annotationProcessor "org.projectlombok:lombok:1.16.16"

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:converter-simplexml:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
compile project(":rd-api-client")

compile "$toolbeltGroup:toolbelt:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-snakeyaml:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-json-jackson:$toolbeltVersion"
compile "$toolbeltGroup:toolbelt-jewelcli:$toolbeltVersion"

testCompile project(":rd-api-client")
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'com.squareup.retrofit2:retrofit-mock:2.1.0'
testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
Expand Down
81 changes: 81 additions & 0 deletions rd-api-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

buildscript {
repositories {
jcenter()
}
}
plugins{
id 'de.fuerstenau.buildconfig' version '1.1.8'
}


repositories {
mavenLocal()
mavenCentral()
maven { url "https://jitpack.io" }
}


apply plugin: 'idea'
apply plugin: 'groovy'
apply plugin: 'de.fuerstenau.buildconfig'

/**
* Generates java source with embedded version info
*/
buildConfig {
clsName = 'Version'
packageName = 'org.rundeck.client'
}


dependencies {

compileOnly "org.projectlombok:lombok:1.16.16"

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:converter-simplexml:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'


testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'com.squareup.retrofit2:retrofit-mock:2.1.0'
testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19'
testCompile "org.codehaus.groovy:groovy-all:2.3.7"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}


// produce a jar file for our test classes
task testJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.java
}

// produce a jar file for our source files
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.java
}

// produce a jar file for our javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

if (JavaVersion.current().isJava8Compatible()) {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}

// add all of the artifacts above to our archives list
artifacts {
archives testJar
archives sourceJar
archives javadocJar
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.rundeck.client.api.RundeckApi;
import org.rundeck.client.tool.AppConfig;
import org.rundeck.client.util.*;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
Expand All @@ -35,7 +34,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.rundeck.client.tool.Main.*;

/**
* Build a {@link Client} for {@link RundeckApi} using {@link #builder()}.
Expand All @@ -48,6 +46,12 @@ public class RundeckClient {
public static final String ENV_INSECURE_SSL = "RD_INSECURE_SSL";
public static final String ENV_INSECURE_SSL_HOSTNAME = "RD_INSECURE_SSL_HOSTNAME";
public static final String ENV_ALT_SSL_HOSTNAME = "RD_ALT_SSL_HOSTNAME";
public static final String ENV_HTTP_TIMEOUT = "RD_HTTP_TIMEOUT";
public static final String ENV_CONNECT_RETRY = "RD_CONNECT_RETRY";
/**
* If true, allow API version to be automatically degraded when unsupported version is detected
*/
public static final String RD_API_DOWNGRADE = "RD_API_DOWNGRADE";
public static final int INSECURE_SSL_LOGGING = 2;

private RundeckClient() {
Expand All @@ -74,7 +78,7 @@ <T> Builder accept(BuildWith<Builder, T> bw, T i) {
return this;
}

public Builder config(AppConfig config) {
public Builder config(RdClientConfig config) {
logging(config.getDebugLevel());
retryConnect(config.getBool(ENV_CONNECT_RETRY, true));
timeout(config.getLong(ENV_HTTP_TIMEOUT, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.rundeck.client.api;

import org.rundeck.client.api.RequestFailed;

public class AuthorizationFailed extends RequestFailed {
public AuthorizationFailed(final int statusCode, final String status) {
super(statusCode, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.rundeck.client.tool.AppConfig;
import org.rundeck.client.util.RdClientConfig;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -53,7 +53,7 @@ public String toBasicString() {
return String.format("[%s] <%s>", id, permalink);
}

public String toExtendedString(AppConfig config) {
public String toExtendedString(RdClientConfig config) {
return String.format(
"%s %s %s %s %s %s %s",
id,
Expand Down Expand Up @@ -85,7 +85,7 @@ private String shortened(final String description) {
return description;
}

public Map getInfoMap(AppConfig config) {
public Map getInfoMap(RdClientConfig config) {
HashMap<Object, Object> map = new HashMap<>();
map.put("id", getId());
map.put("description", shortened(getDescription()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.toolbelt.Formatable;
import org.rundeck.client.util.DataOutput;
import org.simpleframework.xml.Root;

import java.util.HashMap;
Expand All @@ -30,7 +30,7 @@
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@Root(strict = false)
public class JobFileItem implements Formatable {
public class JobFileItem implements DataOutput {
private String id;
private String user;
private String optionName;
Expand Down Expand Up @@ -148,12 +148,6 @@ public void setExecId(Long execId) {
this.execId = execId;
}

@Override
public List<?> asList() {
return null;
}

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("id", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.client.util.DataOutput;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author greg
* @since 3/2/17
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class JobFileItemList {
public class JobFileItemList implements DataOutput {
private Paging paging;
private List<JobFileItem> files;

Expand All @@ -41,6 +43,11 @@ public List<JobFileItem> getFiles() {
return files;
}

@Override
public List<?> asList() {
return getFiles().stream().map(JobFileItem::asMap).collect(Collectors.toList());
}

public void setFiles(List<JobFileItem> files) {
this.files = files;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.toolbelt.Formatable;
import org.rundeck.client.util.DataOutput;

import java.util.HashMap;
import java.util.List;
Expand All @@ -29,7 +29,7 @@
*/

@JsonIgnoreProperties(ignoreUnknown = true)
public class JobFileUploadResult implements Formatable {
public class JobFileUploadResult implements DataOutput {
private Integer total;
private Map<String, String> options;

Expand All @@ -49,12 +49,6 @@ public void setOptions(Map<String, String> options) {
this.options = options;
}

@Override
public List<?> asList() {
return null;
}

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("total", total);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.toolbelt.Formatable;
import org.rundeck.client.util.DataOutput;

import java.util.HashMap;
import java.util.List;
Expand All @@ -28,7 +28,7 @@
* @since 12/13/16
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ScmActionInputsResult implements Formatable {
public class ScmActionInputsResult implements DataOutput {
public String title;
public String description;
public String integration;
Expand All @@ -37,12 +37,6 @@ public class ScmActionInputsResult implements Formatable {
public List<ScmImportItem> importItems;
public List<ScmExportItem> exportItems;

@Override
public List<?> asList() {
return null;
}

@Override
public Map<?, ?> asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("title", title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.toolbelt.Formatable;
import org.rundeck.client.util.DataOutput;

import java.util.HashMap;
import java.util.List;
Expand All @@ -28,17 +28,13 @@
* @since 12/13/16
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ScmExportItem implements Formatable{
public class ScmExportItem implements DataOutput {
public String itemId;
public String originalId;
public ScmJobItem job;
public Boolean renamed;
private Boolean deleted;

@Override
public List<?> asList() {
return null;
}

public Map asMap() {
HashMap<String, Object> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.rundeck.toolbelt.Formatable;
import org.rundeck.client.util.DataOutput;

import java.util.HashMap;
import java.util.List;
Expand All @@ -28,16 +28,11 @@
* @since 12/13/16
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ScmImportItem implements Formatable {
public class ScmImportItem implements DataOutput {
public String itemId;
public Boolean tracked;
public ScmJobItem job;

@Override
public List<?> asList() {
return null;
}

public Map asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("itemId", itemId);
Expand Down
Loading

0 comments on commit 9511812

Please sign in to comment.