Skip to content

Commit

Permalink
Merge branch 'release/0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ksm2 committed Jan 23, 2015
2 parents f3e1d70 + 3583f35 commit b6e96f3
Show file tree
Hide file tree
Showing 26 changed files with 1,075 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out/
.idea/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/org/json"]
path = src/org/json
url = [email protected]:CornyPhoenix/JSON-java.git
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)
=====================

Copyright (C) 2015 Konstantin Möllers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Redmine CLI 0.1
===============

> Redmine command line tool written in Java.
188 changes: 188 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="redmine-cli" default="all">


<property file="build.properties"/>
<!-- Uncomment the following property if no tests compilation is needed -->
<!--
<property name="skip.tests" value="true"/>
-->

<!-- Compiler options -->

<property name="compiler.debug" value="on"/>
<property name="compiler.generate.no.warnings" value="off"/>
<property name="compiler.args" value=""/>
<property name="compiler.max.memory" value="700m"/>
<patternset id="ignored.files">
<exclude name="**/CVS/**"/>
<exclude name="**/SCCS/**"/>
<exclude name="**/RCS/**"/>
<exclude name="**/rcs/**"/>
<exclude name="**/.DS_Store/**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/.pyc/**"/>
<exclude name="**/.pyo/**"/>
<exclude name="**/*.pyc/**"/>
<exclude name="**/*.pyo/**"/>
<exclude name="**/.git/**"/>
<exclude name="**/*.hprof/**"/>
<exclude name="**/_svn/**"/>
<exclude name="**/.hg/**"/>
<exclude name="**/*.lib/**"/>
<exclude name="**/*~/**"/>
<exclude name="**/__pycache__/**"/>
<exclude name="**/.bundle/**"/>
<exclude name="**/*.rbc/**"/>
<exclude name="**/*.aux/**"/>
<exclude name="**/*.tks/**"/>
</patternset>
<patternset id="library.patterns">
<include name="*.war"/>
<include name="*.ear"/>
<include name="*.apk"/>
<include name="*.zip"/>
<include name="*.swc"/>
<include name="*.ane"/>
<include name="*.egg"/>
<include name="*.jar"/>
</patternset>
<patternset id="compiler.resources">
<exclude name="**/?*.java"/>
<exclude name="**/?*.form"/>
<exclude name="**/?*.class"/>
<exclude name="**/?*.groovy"/>
<exclude name="**/?*.scala"/>
<exclude name="**/?*.flex"/>
<exclude name="**/?*.kt"/>
<exclude name="**/?*.clj"/>
</patternset>


<!-- Project Libraries -->

<path id="library.commons-cli-1.2.classpath">
<pathelement location="${basedir}/lib/commons-cli-1.2.jar"/>
</path>


<!-- Global Libraries -->

<!-- Modules -->


<!-- Module redmine-cli -->

<dirname property="module.redmine-cli.basedir" file="${ant.file}"/>



<property name="compiler.args.redmine-cli" value="-encoding UTF-8 -source 8 ${compiler.args}"/>

<property name="redmine-cli.output.dir" value="${module.redmine-cli.basedir}/out/production/redmine-cli"/>
<property name="redmine-cli.testoutput.dir" value="${module.redmine-cli.basedir}/out/test/redmine-cli"/>

<path id="redmine-cli.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path>

<path id="redmine-cli.module.production.classpath">
<path refid="library.commons-cli-1.2.classpath"/>
</path>

<path id="redmine-cli.runtime.production.module.classpath">
<pathelement location="${redmine-cli.output.dir}"/>
<path refid="library.commons-cli-1.2.classpath"/>
</path>

<path id="redmine-cli.module.classpath">
<pathelement location="${redmine-cli.output.dir}"/>
<path refid="library.commons-cli-1.2.classpath"/>
</path>

<path id="redmine-cli.runtime.module.classpath">
<pathelement location="${redmine-cli.testoutput.dir}"/>
<pathelement location="${redmine-cli.output.dir}"/>
<path refid="library.commons-cli-1.2.classpath"/>
</path>


<patternset id="excluded.from.module.redmine-cli">
<patternset refid="ignored.files"/>
</patternset>

<patternset id="excluded.from.compilation.redmine-cli">
<patternset refid="excluded.from.module.redmine-cli"/>
</patternset>

<path id="redmine-cli.module.sourcepath">
<dirset dir="${module.redmine-cli.basedir}">
<include name="src"/>
</dirset>
</path>


<target name="compile.module.redmine-cli" depends="compile.module.redmine-cli.production,compile.module.redmine-cli.tests" description="Compile module redmine-cli"/>

<target name="compile.module.redmine-cli.production" description="Compile module redmine-cli; production classes">
<mkdir dir="${redmine-cli.output.dir}"/>
<javac destdir="${redmine-cli.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true">
<compilerarg line="${compiler.args.redmine-cli}"/>
<bootclasspath refid="redmine-cli.module.bootclasspath"/>
<classpath refid="redmine-cli.module.production.classpath"/>
<src refid="redmine-cli.module.sourcepath"/>
<patternset refid="excluded.from.compilation.redmine-cli"/>
</javac>

<copy todir="${redmine-cli.output.dir}">
<fileset dir="${module.redmine-cli.basedir}/src">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target>

<target name="compile.module.redmine-cli.tests" depends="compile.module.redmine-cli.production" description="compile module redmine-cli; test classes" unless="skip.tests"/>

<target name="clean.module.redmine-cli" description="cleanup module">
<delete dir="${redmine-cli.output.dir}"/>
<delete dir="${redmine-cli.testoutput.dir}"/>
</target>

<target name="init" description="Build initialization">
<!-- Perform any build initialization in this target -->
</target>

<target name="clean" depends="clean.module.redmine-cli" description="cleanup all"/>

<target name="build.modules" depends="init, clean, compile.module.redmine-cli" description="build all modules"/>

<target name="init.artifacts">
<property name="artifacts.temp.dir" value="${basedir}/__artifacts_temp"/>
<property name="artifact.output.redmine-cli:jar" value="${basedir}/out/artifacts"/>
<mkdir dir="${artifacts.temp.dir}"/>
<property name="temp.jar.path.redmine-cli.jar" value="${artifacts.temp.dir}/redmine-cli.jar"/>
</target>

<target name="artifact.redmine-cli:jar" depends="init.artifacts, compile.module.redmine-cli" description="Build &#39;redmine-cli:jar&#39; artifact">
<property name="artifact.temp.output.redmine-cli:jar" value="${artifacts.temp.dir}/redmine_cli_jar"/>
<mkdir dir="${artifact.temp.output.redmine-cli:jar}"/>
<jar destfile="${temp.jar.path.redmine-cli.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
<zipfileset dir="${redmine-cli.output.dir}"/>
<zipfileset src="${basedir}/lib/commons-cli-1.2.jar"/>
</jar>
<copy file="${temp.jar.path.redmine-cli.jar}" tofile="${artifact.temp.output.redmine-cli:jar}/redmine-cli.jar"/>
</target>

<target name="build.all.artifacts" depends="artifact.redmine-cli:jar" description="Build all artifacts">
<mkdir dir="${artifact.output.redmine-cli:jar}"/>
<copy todir="${artifact.output.redmine-cli:jar}">
<fileset dir="${artifact.temp.output.redmine-cli:jar}"/>
</copy>

<!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target>

<target name="all" depends="build.modules, build.all.artifacts" description="build all"/>
</project>
1 change: 1 addition & 0 deletions redmine-cli.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
path.variable.maven_repository=/Users/moellers/.m2/repository
15 changes: 15 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Manifest-Version: 1.0
Main-Class: com.xeonlab.redmine.cli.RedmineCliApplication

Bundle-Version: 0.1
Bundle-Copyright: Copyright (C) 2015 Konstantin Möllers
Bundle-Name: Redmince CLI
Bundle-Description: Redmine command line tool written in Java
Bundle-License: MIT License
Bundle-Developers: Konstantin Möllers <[email protected]>
Bundle-Contributors: Konstantin Möllers <[email protected]>

Implementation-Version: 0.1
Implementation-Title: com.xeonlab.redmine.cli
Implementation-Vendor: Konstantin Möllers
Implementation-URL: https://github.com/CornyPhoenix/Redmine-CLI
100 changes: 100 additions & 0 deletions src/com/xeonlab/redmine/cli/RedmineCliApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.xeonlab.redmine.cli;

import com.xeonlab.redmine.cli.options.OptionsFactory;
import com.xeonlab.redmine.cli.options.RedmineOption;
import com.xeonlab.redmine.cli.request.RedmineUrlBuilder;
import com.xeonlab.redmine.cli.request.Request;
import com.xeonlab.redmine.cli.response.RedmineJSONResponseParser;
import com.xeonlab.redmine.cli.response.Response;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.json.JSONObject;
import org.json.JSONTokener;

public class RedmineCliApplication {

private final CommandLineParser parser;
private final Options options;

public RedmineCliApplication() {
parser = new GnuParser();
options = OptionsFactory.createOptions();

}

public static void main(String[] args) {
RedmineCliApplication application = new RedmineCliApplication();
application.initialize(args);
}

public void initialize(String[] args) {
try {
// Parse options.
CommandLine line = parser.parse(options, args);

// Apply all options on a request.
Request request = new Request();
for (Option option : line.getOptions()) {
RedmineOption redmineOption = (RedmineOption) option;
redmineOption.applyTo(request);
}

// Build URL to send request.
RedmineUrlBuilder urlBuilder = new RedmineUrlBuilder();
URL requestUrl = urlBuilder.parseRequest(request);

// Connect to URL.
System.out.println("Connecting to " + requestUrl.toString() + " ...");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(requestUrl.openStream(), "UTF-8"))) {
JSONTokener tokener = new JSONTokener(reader);
JSONObject info = (JSONObject) tokener.nextValue();

// Parse response.
RedmineJSONResponseParser responseParser = new RedmineJSONResponseParser();
Response response = responseParser.parse(info);

System.out.println(response);
} catch (IOException e) {
System.err.println("IO error – are you connected to internet?");
System.exit(5);
}

} catch (ParseException e) {
System.err.println("Could not parse arguments.");
printHelp();
System.exit(1);
}
}

private void printHelp() {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.setLeftPadding(3);
helpFormatter.setDescPadding(2);
helpFormatter.setNewLine("\n");
helpFormatter.setLongOptPrefix(" --");
helpFormatter.setOptionComparator((obj1, obj2) -> {
Option o1 = (Option) obj1;
Option o2 = (Option) obj2;
if (o1.isRequired()) {
return -1;
}

if (o2.isRequired()) {
return 1;
}

return 0;
});
helpFormatter.setWidth(100);
helpFormatter.printHelp("redmine", "\u001b[1;33mRedmine CLI tool\u001B[m\nRedmine command line tool.\nCopyright (C) 2015 by Konstantin Möllers.", options, "", true);
}
}
21 changes: 21 additions & 0 deletions src/com/xeonlab/redmine/cli/options/ApiKeyOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.xeonlab.redmine.cli.options;

import com.xeonlab.redmine.cli.request.Request;

/**
* @author Konstantin Simon Maria Moellers
* @version 2015-01-22
*/
final class ApiKeyOption extends RedmineOption {
ApiKeyOption() throws IllegalArgumentException {
super("k", "api-key", true, "API key to connect with redmine.");
setRequired(true);
setType(String.class);
setArgName("api-key");
}

@Override
public void applyTo(Request request) {
request.setApiKey(getValue());
}
}
20 changes: 20 additions & 0 deletions src/com/xeonlab/redmine/cli/options/AssignedToOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xeonlab.redmine.cli.options;

import com.xeonlab.redmine.cli.request.Request;

/**
* @author Konstantin Simon Maria Moellers
* @version 2015-01-22
*/
final class AssignedToOption extends RedmineOption {
AssignedToOption() throws IllegalArgumentException {
super("a", "assigned-to", true, "Assignee of issues to filter.");
setType(Integer.class);
setArgName("assignee");
}

@Override
public void applyTo(Request request) {
request.setAssignedTo(Integer.parseInt(getValue()));
}
}
Loading

0 comments on commit b6e96f3

Please sign in to comment.