Skip to content

Commit b6e96f3

Browse files
committed
Merge branch 'release/0.1'
2 parents f3e1d70 + 3583f35 commit b6e96f3

26 files changed

Lines changed: 1075 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out/
2+
.idea/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/org/json"]
2+
path = src/org/json
3+
url = git@github.com:CornyPhoenix/JSON-java.git

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright (C) 2015 Konstantin Möllers
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Redmine CLI 0.1
2+
===============
3+
4+
> Redmine command line tool written in Java.
5+

build.xml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="redmine-cli" default="all">
3+
4+
5+
<property file="build.properties"/>
6+
<!-- Uncomment the following property if no tests compilation is needed -->
7+
<!--
8+
<property name="skip.tests" value="true"/>
9+
-->
10+
11+
<!-- Compiler options -->
12+
13+
<property name="compiler.debug" value="on"/>
14+
<property name="compiler.generate.no.warnings" value="off"/>
15+
<property name="compiler.args" value=""/>
16+
<property name="compiler.max.memory" value="700m"/>
17+
<patternset id="ignored.files">
18+
<exclude name="**/CVS/**"/>
19+
<exclude name="**/SCCS/**"/>
20+
<exclude name="**/RCS/**"/>
21+
<exclude name="**/rcs/**"/>
22+
<exclude name="**/.DS_Store/**"/>
23+
<exclude name="**/.svn/**"/>
24+
<exclude name="**/.pyc/**"/>
25+
<exclude name="**/.pyo/**"/>
26+
<exclude name="**/*.pyc/**"/>
27+
<exclude name="**/*.pyo/**"/>
28+
<exclude name="**/.git/**"/>
29+
<exclude name="**/*.hprof/**"/>
30+
<exclude name="**/_svn/**"/>
31+
<exclude name="**/.hg/**"/>
32+
<exclude name="**/*.lib/**"/>
33+
<exclude name="**/*~/**"/>
34+
<exclude name="**/__pycache__/**"/>
35+
<exclude name="**/.bundle/**"/>
36+
<exclude name="**/*.rbc/**"/>
37+
<exclude name="**/*.aux/**"/>
38+
<exclude name="**/*.tks/**"/>
39+
</patternset>
40+
<patternset id="library.patterns">
41+
<include name="*.war"/>
42+
<include name="*.ear"/>
43+
<include name="*.apk"/>
44+
<include name="*.zip"/>
45+
<include name="*.swc"/>
46+
<include name="*.ane"/>
47+
<include name="*.egg"/>
48+
<include name="*.jar"/>
49+
</patternset>
50+
<patternset id="compiler.resources">
51+
<exclude name="**/?*.java"/>
52+
<exclude name="**/?*.form"/>
53+
<exclude name="**/?*.class"/>
54+
<exclude name="**/?*.groovy"/>
55+
<exclude name="**/?*.scala"/>
56+
<exclude name="**/?*.flex"/>
57+
<exclude name="**/?*.kt"/>
58+
<exclude name="**/?*.clj"/>
59+
</patternset>
60+
61+
62+
<!-- Project Libraries -->
63+
64+
<path id="library.commons-cli-1.2.classpath">
65+
<pathelement location="${basedir}/lib/commons-cli-1.2.jar"/>
66+
</path>
67+
68+
69+
<!-- Global Libraries -->
70+
71+
<!-- Modules -->
72+
73+
74+
<!-- Module redmine-cli -->
75+
76+
<dirname property="module.redmine-cli.basedir" file="${ant.file}"/>
77+
78+
79+
80+
<property name="compiler.args.redmine-cli" value="-encoding UTF-8 -source 8 ${compiler.args}"/>
81+
82+
<property name="redmine-cli.output.dir" value="${module.redmine-cli.basedir}/out/production/redmine-cli"/>
83+
<property name="redmine-cli.testoutput.dir" value="${module.redmine-cli.basedir}/out/test/redmine-cli"/>
84+
85+
<path id="redmine-cli.module.bootclasspath">
86+
<!-- Paths to be included in compilation bootclasspath -->
87+
</path>
88+
89+
<path id="redmine-cli.module.production.classpath">
90+
<path refid="library.commons-cli-1.2.classpath"/>
91+
</path>
92+
93+
<path id="redmine-cli.runtime.production.module.classpath">
94+
<pathelement location="${redmine-cli.output.dir}"/>
95+
<path refid="library.commons-cli-1.2.classpath"/>
96+
</path>
97+
98+
<path id="redmine-cli.module.classpath">
99+
<pathelement location="${redmine-cli.output.dir}"/>
100+
<path refid="library.commons-cli-1.2.classpath"/>
101+
</path>
102+
103+
<path id="redmine-cli.runtime.module.classpath">
104+
<pathelement location="${redmine-cli.testoutput.dir}"/>
105+
<pathelement location="${redmine-cli.output.dir}"/>
106+
<path refid="library.commons-cli-1.2.classpath"/>
107+
</path>
108+
109+
110+
<patternset id="excluded.from.module.redmine-cli">
111+
<patternset refid="ignored.files"/>
112+
</patternset>
113+
114+
<patternset id="excluded.from.compilation.redmine-cli">
115+
<patternset refid="excluded.from.module.redmine-cli"/>
116+
</patternset>
117+
118+
<path id="redmine-cli.module.sourcepath">
119+
<dirset dir="${module.redmine-cli.basedir}">
120+
<include name="src"/>
121+
</dirset>
122+
</path>
123+
124+
125+
<target name="compile.module.redmine-cli" depends="compile.module.redmine-cli.production,compile.module.redmine-cli.tests" description="Compile module redmine-cli"/>
126+
127+
<target name="compile.module.redmine-cli.production" description="Compile module redmine-cli; production classes">
128+
<mkdir dir="${redmine-cli.output.dir}"/>
129+
<javac destdir="${redmine-cli.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true">
130+
<compilerarg line="${compiler.args.redmine-cli}"/>
131+
<bootclasspath refid="redmine-cli.module.bootclasspath"/>
132+
<classpath refid="redmine-cli.module.production.classpath"/>
133+
<src refid="redmine-cli.module.sourcepath"/>
134+
<patternset refid="excluded.from.compilation.redmine-cli"/>
135+
</javac>
136+
137+
<copy todir="${redmine-cli.output.dir}">
138+
<fileset dir="${module.redmine-cli.basedir}/src">
139+
<patternset refid="compiler.resources"/>
140+
<type type="file"/>
141+
</fileset>
142+
</copy>
143+
</target>
144+
145+
<target name="compile.module.redmine-cli.tests" depends="compile.module.redmine-cli.production" description="compile module redmine-cli; test classes" unless="skip.tests"/>
146+
147+
<target name="clean.module.redmine-cli" description="cleanup module">
148+
<delete dir="${redmine-cli.output.dir}"/>
149+
<delete dir="${redmine-cli.testoutput.dir}"/>
150+
</target>
151+
152+
<target name="init" description="Build initialization">
153+
<!-- Perform any build initialization in this target -->
154+
</target>
155+
156+
<target name="clean" depends="clean.module.redmine-cli" description="cleanup all"/>
157+
158+
<target name="build.modules" depends="init, clean, compile.module.redmine-cli" description="build all modules"/>
159+
160+
<target name="init.artifacts">
161+
<property name="artifacts.temp.dir" value="${basedir}/__artifacts_temp"/>
162+
<property name="artifact.output.redmine-cli:jar" value="${basedir}/out/artifacts"/>
163+
<mkdir dir="${artifacts.temp.dir}"/>
164+
<property name="temp.jar.path.redmine-cli.jar" value="${artifacts.temp.dir}/redmine-cli.jar"/>
165+
</target>
166+
167+
<target name="artifact.redmine-cli:jar" depends="init.artifacts, compile.module.redmine-cli" description="Build &#39;redmine-cli:jar&#39; artifact">
168+
<property name="artifact.temp.output.redmine-cli:jar" value="${artifacts.temp.dir}/redmine_cli_jar"/>
169+
<mkdir dir="${artifact.temp.output.redmine-cli:jar}"/>
170+
<jar destfile="${temp.jar.path.redmine-cli.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
171+
<zipfileset dir="${redmine-cli.output.dir}"/>
172+
<zipfileset src="${basedir}/lib/commons-cli-1.2.jar"/>
173+
</jar>
174+
<copy file="${temp.jar.path.redmine-cli.jar}" tofile="${artifact.temp.output.redmine-cli:jar}/redmine-cli.jar"/>
175+
</target>
176+
177+
<target name="build.all.artifacts" depends="artifact.redmine-cli:jar" description="Build all artifacts">
178+
<mkdir dir="${artifact.output.redmine-cli:jar}"/>
179+
<copy todir="${artifact.output.redmine-cli:jar}">
180+
<fileset dir="${artifact.temp.output.redmine-cli:jar}"/>
181+
</copy>
182+
183+
<!-- Delete temporary files -->
184+
<delete dir="${artifacts.temp.dir}"/>
185+
</target>
186+
187+
<target name="all" depends="build.modules, build.all.artifacts" description="build all"/>
188+
</project>

redmine-cli.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
path.variable.maven_repository=/Users/moellers/.m2/repository

src/META-INF/MANIFEST.MF

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.xeonlab.redmine.cli.RedmineCliApplication
3+
4+
Bundle-Version: 0.1
5+
Bundle-Copyright: Copyright (C) 2015 Konstantin Möllers
6+
Bundle-Name: Redmince CLI
7+
Bundle-Description: Redmine command line tool written in Java
8+
Bundle-License: MIT License
9+
Bundle-Developers: Konstantin Möllers <ksm.moellers@gmail.com>
10+
Bundle-Contributors: Konstantin Möllers <ksm.moellers@gmail.com>
11+
12+
Implementation-Version: 0.1
13+
Implementation-Title: com.xeonlab.redmine.cli
14+
Implementation-Vendor: Konstantin Möllers
15+
Implementation-URL: https://github.com/CornyPhoenix/Redmine-CLI
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.xeonlab.redmine.cli;
2+
3+
import com.xeonlab.redmine.cli.options.OptionsFactory;
4+
import com.xeonlab.redmine.cli.options.RedmineOption;
5+
import com.xeonlab.redmine.cli.request.RedmineUrlBuilder;
6+
import com.xeonlab.redmine.cli.request.Request;
7+
import com.xeonlab.redmine.cli.response.RedmineJSONResponseParser;
8+
import com.xeonlab.redmine.cli.response.Response;
9+
import java.io.BufferedReader;
10+
import java.io.IOException;
11+
import java.io.InputStreamReader;
12+
import java.net.URL;
13+
import org.apache.commons.cli.CommandLine;
14+
import org.apache.commons.cli.CommandLineParser;
15+
import org.apache.commons.cli.GnuParser;
16+
import org.apache.commons.cli.HelpFormatter;
17+
import org.apache.commons.cli.Option;
18+
import org.apache.commons.cli.Options;
19+
import org.apache.commons.cli.ParseException;
20+
import org.json.JSONObject;
21+
import org.json.JSONTokener;
22+
23+
public class RedmineCliApplication {
24+
25+
private final CommandLineParser parser;
26+
private final Options options;
27+
28+
public RedmineCliApplication() {
29+
parser = new GnuParser();
30+
options = OptionsFactory.createOptions();
31+
32+
}
33+
34+
public static void main(String[] args) {
35+
RedmineCliApplication application = new RedmineCliApplication();
36+
application.initialize(args);
37+
}
38+
39+
public void initialize(String[] args) {
40+
try {
41+
// Parse options.
42+
CommandLine line = parser.parse(options, args);
43+
44+
// Apply all options on a request.
45+
Request request = new Request();
46+
for (Option option : line.getOptions()) {
47+
RedmineOption redmineOption = (RedmineOption) option;
48+
redmineOption.applyTo(request);
49+
}
50+
51+
// Build URL to send request.
52+
RedmineUrlBuilder urlBuilder = new RedmineUrlBuilder();
53+
URL requestUrl = urlBuilder.parseRequest(request);
54+
55+
// Connect to URL.
56+
System.out.println("Connecting to " + requestUrl.toString() + " ...");
57+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(requestUrl.openStream(), "UTF-8"))) {
58+
JSONTokener tokener = new JSONTokener(reader);
59+
JSONObject info = (JSONObject) tokener.nextValue();
60+
61+
// Parse response.
62+
RedmineJSONResponseParser responseParser = new RedmineJSONResponseParser();
63+
Response response = responseParser.parse(info);
64+
65+
System.out.println(response);
66+
} catch (IOException e) {
67+
System.err.println("IO error – are you connected to internet?");
68+
System.exit(5);
69+
}
70+
71+
} catch (ParseException e) {
72+
System.err.println("Could not parse arguments.");
73+
printHelp();
74+
System.exit(1);
75+
}
76+
}
77+
78+
private void printHelp() {
79+
HelpFormatter helpFormatter = new HelpFormatter();
80+
helpFormatter.setLeftPadding(3);
81+
helpFormatter.setDescPadding(2);
82+
helpFormatter.setNewLine("\n");
83+
helpFormatter.setLongOptPrefix(" --");
84+
helpFormatter.setOptionComparator((obj1, obj2) -> {
85+
Option o1 = (Option) obj1;
86+
Option o2 = (Option) obj2;
87+
if (o1.isRequired()) {
88+
return -1;
89+
}
90+
91+
if (o2.isRequired()) {
92+
return 1;
93+
}
94+
95+
return 0;
96+
});
97+
helpFormatter.setWidth(100);
98+
helpFormatter.printHelp("redmine", "\u001b[1;33mRedmine CLI tool\u001B[m\nRedmine command line tool.\nCopyright (C) 2015 by Konstantin Möllers.", options, "", true);
99+
}
100+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.xeonlab.redmine.cli.options;
2+
3+
import com.xeonlab.redmine.cli.request.Request;
4+
5+
/**
6+
* @author Konstantin Simon Maria Moellers
7+
* @version 2015-01-22
8+
*/
9+
final class ApiKeyOption extends RedmineOption {
10+
ApiKeyOption() throws IllegalArgumentException {
11+
super("k", "api-key", true, "API key to connect with redmine.");
12+
setRequired(true);
13+
setType(String.class);
14+
setArgName("api-key");
15+
}
16+
17+
@Override
18+
public void applyTo(Request request) {
19+
request.setApiKey(getValue());
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.xeonlab.redmine.cli.options;
2+
3+
import com.xeonlab.redmine.cli.request.Request;
4+
5+
/**
6+
* @author Konstantin Simon Maria Moellers
7+
* @version 2015-01-22
8+
*/
9+
final class AssignedToOption extends RedmineOption {
10+
AssignedToOption() throws IllegalArgumentException {
11+
super("a", "assigned-to", true, "Assignee of issues to filter.");
12+
setType(Integer.class);
13+
setArgName("assignee");
14+
}
15+
16+
@Override
17+
public void applyTo(Request request) {
18+
request.setAssignedTo(Integer.parseInt(getValue()));
19+
}
20+
}

0 commit comments

Comments
 (0)