/* * Connect to a JIRA instance and retrieve an issue * This class checks syntax and calls the appropriate RestConnect method to * connect to JIRA and do whatever was requested. */ package com.perforce.ts.rest; import java.io.Console; import java.util.Arrays; /** * * @author jbrown */ public class TestConnect { /** * Main entry * @param args the command line arguments */ public static void main(String[] args) { // arg check int rc = 1; try { rc = mainWork(args); } catch (Exception ex) { ex.printStackTrace(); } System.exit(rc); } /** * Checks input and does the needful. * 1 Argument Check. * 2 Prompt for password if needed. * 3 Instantiate a RestConnect instance and call the appropriate * method to do the work. * @param args * @return 64 for syntax error. 66 if no password, 0 is good, otherwise exception. * @throws Exception */ public static int mainWork(String[] args) throws Exception { // arg check if (args.length < 2) { printUsage(); return 64; } String url = args[0]; String user = args[1]; String password = null; int userColon = user.indexOf(":"); if (userColon > 0) { password = user.substring(userColon + 1); user = user.substring(0, userColon); } else if (hasStdin) { // prompt for password StringBuilder sb = new StringBuilder(); try { Console cons; System.out.print("Password: "); char[] passwd = System.console().readPassword(); password = new String(passwd); } catch (Exception e) { e.printStackTrace(); return 66; } } else { return 66; } String issue = null; if (args.length > 2) { issue = args[2]; } System.out.println(""); RestConnect rconn = new RestConnect(); if ("query".equalsIgnoreCase(issue)){ if (args.length > 3 && args[3].length() > 1) { String[] queries = Arrays.copyOfRange(args, 3, args.length); return rconn.connectAndQuery(url, user, password, queries); } else { printUsage(); return 64; } } else { return rconn.connectAndRun(url, user, password, issue, (args.length > 3 ? args[3] : (String)null)); } } private static void printUsage() { System.out.println("Usage 1: "); System.out.println(" java -jar jiraRestAccess.jar <url> <username:password> [<issue> [appendSummary] ] "); System.out.println("where:"); System.out.println(" url is the JIRA url, e.g., http://myjira:8080/"); System.out.println(" username:password is the user to connect to JIRA with. If password not provided, will prompt"); System.out.println(" issue (optional) is an issue an retrieve. If not provided, just connect and quit"); System.out.println(" appendToSummary (optional) update issue's summary by appending this to summary"); System.out.println(""); System.out.println("Usage 2: "); System.out.println(" java <optional props> -jar jiraRestAccess.jar <url> <username:password> query <jql-query...> "); System.out.println("where:"); System.out.println(" url is the JIRA url, e.g., http://myjira:8080/"); System.out.println(" username:password is the user to connect to JIRA with. If password not provided, will prompt"); System.out.println(" query - fixed text"); System.out.println(" jql-query the JQL query to run."); System.out.println(" Optional properties:"); System.out.println(" -Dbatch_size=<number> p4dtg's 'batch size for issues'"); System.out.println(" -Dbatch_sleep=<number> milliseconds to sleep between each batch "); } protected static boolean hasStdin = true; // for testing }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 24980 | Joel Brown |
Add query functionalty for testing query response times. Code pattern matches 2018.1 p4dtg's jira-rest plugin. |
||
#1 | 12538 | Joel Brown | Test program for JIRA REST connections, useful for troubleshooting p4dtg's JIRA-REST plugin. |