Skip to content

Commit

Permalink
Adding GitHub Actions for Pull requests (#57)
Browse files Browse the repository at this point in the history
* style: Formatted all the code to Google style
* chore: Updated test dependencies
* feat: Adding noarch jar to build job
* ci: Added repo linter GHA
* ci: Added PR workflow
  • Loading branch information
carlosroman authored Oct 7, 2020
1 parent ee46a2b commit db408b6
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 131 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/push_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Java CI - PR

on: [ pull_request ]

env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

jobs:

test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
java-package: jdk
- name: Build with Gradle
run: ./gradlew build --info --stacktrace
- name: Package with Gradle
run: ./gradlew package --warn --stacktrace
- name: Push bin to GH workflow artifacts cache
uses: actions/upload-artifact@v2
with:
name: dist-linux
path: build/distributions

snyk:
name: Run security checks via snyk
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/gradle-jdk11@master
env:
SNYK_TOKEN: ${{env.SNYK_TOKEN}}
with:
args: --severity-threshold=high
31 changes: 31 additions & 0 deletions .github/workflows/repolinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NOTE: This file should always be named `repolinter.yml` to allow
# workflow_dispatch to work properly
name: Repolinter Action

# NOTE: This workflow will ONLY check the default branch!
# Currently there is no elegant way to specify the default
# branch in the event filtering, so branches are instead
# filtered in the "Test Default Branch" step.
on: [push, workflow_dispatch]

jobs:
repolint:
name: Run Repolinter
runs-on: ubuntu-latest
steps:
- name: Test Default Branch
id: default-branch
uses: actions/github-script@v2
with:
script: |
const data = await github.repos.get(context.repo)
return data.data && data.data.default_branch === context.ref.split('/').slice(-1)[0]
- name: Checkout Self
if: ${{ steps.default-branch.outputs.result == 'true' }}
uses: actions/checkout@v2
- name: Run Repolinter
if: ${{ steps.default-branch.outputs.result == 'true' }}
uses: newrelic/repolinter-action@v1
with:
config_url: https://raw.githubusercontent.com/newrelic/.github/main/repolinter-rulesets/community-plus.yml
output_type: issue
33 changes: 27 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
`maven-publish`
id("org.beryx.jlink") version ("2.21.2")
id("org.ysb33r.java.modulehelper") version ("0.9.0")
id("com.github.sherter.google-java-format") version ("0.8")
id("com.github.sherter.google-java-format") version ("0.9")
id("nebula.ospackage") version ("8.4.1")
id("fi.linuxbox.download") version ("0.6")
}
Expand All @@ -34,7 +34,7 @@ extraJavaModules {
module("commons-cli-1.4.jar", "commons.cli", "1.4") {
exports("org.apache.commons.cli")
}
module("gson-2.8.0.jar", "com.google.code.gson", "2.8.0") {
module("gson-2.8.0.jar", "com.google.code.gson", "2.8.6") {
exports("com.google.gson")
}
}
Expand Down Expand Up @@ -86,6 +86,20 @@ tasks.register<CreateStartScripts>("jmxtermScripts") {
(windowsStartScriptGenerator as TemplateBasedScriptGenerator).template = project.resources.text.fromFile(file("src/jmxterm/jmxterm.template.bat"))
}

tasks.register<Jar>("noarchJar") {
dependsOn(configurations.runtimeClasspath)
destinationDirectory.set(file("${buildDir}/distributions"))
archiveClassifier.set("noarch")

manifest.attributes("Main-Class" to "org.newrelic.nrjmx.Application")

from(sourceSets.main.get().output)

from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}

tasks.register<Zip>("jlinkDistZip") {
dependsOn(tasks.jlink, "downloadJmxTerm", "jmxtermScripts")
destinationDirectory.set(file("${buildDir}/distributions"))
Expand All @@ -102,7 +116,7 @@ tasks.register<Zip>("jlinkDistZip") {
into("lib")
}
from("${buildDir}/jmxterm/bin") {
into ("bin")
into("bin")
fileMode = 0x1ED
}
}
Expand All @@ -124,7 +138,7 @@ tasks.register<Tar>("jlinkDistTar") {
into("lib")
}
from("${buildDir}/jmxterm/bin") {
into ("bin")
into("bin")
fileMode = 0x1ED
}
}
Expand Down Expand Up @@ -208,5 +222,12 @@ tasks.distTar {
tasks.register("package") {
group = "Distribution"
description = "Builds all packages"
dependsOn("distTar", "distZip", "buildDeb", "buildRpm", "jlinkDistZip","jlinkDistTar")
}
dependsOn(
"noarchJar",
"distTar",
"distZip",
"buildDeb",
"buildRpm",
"jlinkDistZip",
"jlinkDistTar")
}
1 change: 1 addition & 0 deletions src/main/java/org/newrelic/nrjmx/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.commons.cli.HelpFormatter;

public class Application {

public static void printHelp() {
new HelpFormatter().printHelp("nrjmx", Arguments.options());
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/newrelic/nrjmx/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

package org.newrelic.nrjmx;

import org.apache.commons.cli.*;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

class Arguments {

private static Options options = null;
private String hostname;
private String connectionURL;
private int port;
Expand All @@ -24,8 +30,6 @@ class Arguments {
private boolean isRemoteJBossStandalone;
private boolean help;

private static Options options = null;

private Arguments() {}

static Options options() {
Expand Down
44 changes: 25 additions & 19 deletions src/main/java/org/newrelic/nrjmx/JMXFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* OutputStream (usually stdout)
*/
public class JMXFetcher {

public static final String defaultURIPath = "jmxrmi";
public static final Boolean defaultJBossModeIsStandalone = false;

Expand All @@ -49,24 +50,6 @@ public class JMXFetcher {
private String connectionString;
private Map<String, Object> connectionEnv = new HashMap<>();

public class ConnectionError extends Exception {
public ConnectionError(String message, Exception cause) {
super(message, cause);
}
}

public class QueryError extends Exception {
public QueryError(String message, Exception cause) {
super(message, cause);
}
}

public class ValueError extends Exception {
public ValueError(String message) {
super(message);
}
}

/**
* Builds a new JMXFetcher with user & pass from a connection URL.
*
Expand Down Expand Up @@ -383,7 +366,9 @@ private void parseValue(String name, Object value) throws ValueError {
Set<String> fieldKeys = cdata.getCompositeType().keySet();

for (String field : fieldKeys) {
if (field.length() < 1) continue;
if (field.length() < 1) {
continue;
}

String fieldKey = field.substring(0, 1).toUpperCase() + field.substring(1);
parseValue(String.format("%s.%s", name, fieldKey), cdata.get(field));
Expand Down Expand Up @@ -430,4 +415,25 @@ private Float parseFloat(Float value) {

return value;
}

public class ConnectionError extends Exception {

public ConnectionError(String message, Exception cause) {
super(message, cause);
}
}

public class QueryError extends Exception {

public QueryError(String message, Exception cause) {
super(message, cause);
}
}

public class ValueError extends Exception {

public ValueError(String message) {
super(message);
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/org/newrelic/nrjmx/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

package org.newrelic.nrjmx;

import java.util.logging.*;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class Logging {

public static void setup(Logger logger, boolean verbose) {
logger.setUseParentHandlers(false);
Handler consoleHandler = new ConsoleHandler();
Expand Down
11 changes: 8 additions & 3 deletions test-nrjmx/src/test/java/org/newrelic/jmx/CatsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@

package org.newrelic.jmx;

import org.testcontainers.shaded.okhttp3.*;
import org.testcontainers.shaded.okhttp3.FormBody;
import org.testcontainers.shaded.okhttp3.MediaType;
import org.testcontainers.shaded.okhttp3.OkHttpClient;
import org.testcontainers.shaded.okhttp3.Request;
import org.testcontainers.shaded.okhttp3.RequestBody;
import org.testcontainers.shaded.okhttp3.Response;

public class CatsClient {

private String baseURL;
private OkHttpClient client = new OkHttpClient();

public CatsClient(String baseURL) {
public CatsClient(final String baseURL) {
this.baseURL = baseURL;
}

public String add(String catName) {
public String add(final String catName) {

RequestBody catBody =
FormBody.create(MediaType.parse("application/json"), "{\"name\":\"" + catName + "\"}");
Expand Down
Loading

0 comments on commit db408b6

Please sign in to comment.