Skip to content

Commit 0c665eb

Browse files
committed
Initial source commit
1 parent acb84ea commit 0c665eb

File tree

15 files changed

+1154
-0
lines changed

15 files changed

+1154
-0
lines changed

pom.xml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.sonatype.oss</groupId>
6+
<artifactId>oss-parent</artifactId>
7+
<version>9</version>
8+
</parent>
9+
<groupId>pl.wavesoftware.utils</groupId>
10+
<artifactId>https-checker</artifactId>
11+
<version>0.1.0-SNAPSHOT</version>
12+
<packaging>jar</packaging>
13+
14+
<name>HTTPS Java Checker</name>
15+
<description>It can check is your Java installation can perform connection with given HTTPS address</description>
16+
<url>https://github.com/wavesoftware/java-https-checker</url>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>1.7</maven.compiler.source>
21+
<maven.compiler.target>1.7</maven.compiler.target>
22+
</properties>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>net.sourceforge.argparse4j</groupId>
27+
<artifactId>argparse4j</artifactId>
28+
<version>0.6.0</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.google.guava</groupId>
32+
<artifactId>guava</artifactId>
33+
<version>18.0</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
<version>4.10</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.mockito</groupId>
43+
<artifactId>mockito-all</artifactId>
44+
<version>1.9.5</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
<issueManagement>
50+
<system>Github</system>
51+
<url>https://github.com/wavesoftware/java-https-checker/issues</url>
52+
</issueManagement>
53+
54+
<licenses>
55+
<license>
56+
<name>The Apache Software License, Version 2.0</name>
57+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
58+
<distribution>repo</distribution>
59+
</license>
60+
</licenses>
61+
62+
<scm>
63+
<connection>scm:git:git@github.com:wavesoftware/java-https-checker.git</connection>
64+
<developerConnection>scm:git:git@github.com:wavesoftware/java-https-checker.git</developerConnection>
65+
<url>git@github.com:wavesoftware/java-https-checker.git</url>
66+
</scm>
67+
68+
<developers>
69+
<developer>
70+
<email>krzysztof.suszynski@wavesoftware.pl</email>
71+
<organization>Wave Software</organization>
72+
<name>Krzysztof Suszyński</name>
73+
</developer>
74+
</developers>
75+
76+
<build>
77+
78+
<plugins>
79+
<plugin>
80+
<artifactId>maven-assembly-plugin</artifactId>
81+
<executions>
82+
<execution>
83+
<phase>package</phase>
84+
<goals>
85+
<goal>single</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
<configuration>
90+
91+
<archive>
92+
<manifest>
93+
<addClasspath>true</addClasspath>
94+
<mainClass>pl.wavesoftware.utils.https.checker.HttpsCheckerMain</mainClass>
95+
</manifest>
96+
</archive>
97+
98+
<descriptorRefs>
99+
<descriptorRef>jar-with-dependencies</descriptorRef>
100+
</descriptorRefs>
101+
102+
</configuration>
103+
</plugin>
104+
</plugins>
105+
106+
</build>
107+
108+
<profiles>
109+
<profile>
110+
<id>ci</id>
111+
112+
<build>
113+
<plugins>
114+
<plugin>
115+
<groupId>org.jacoco</groupId>
116+
<artifactId>jacoco-maven-plugin</artifactId>
117+
<version>0.7.2.201409121644</version>
118+
119+
<executions>
120+
<execution>
121+
<id>jacoco-initialize</id>
122+
<goals>
123+
<goal>prepare-agent</goal>
124+
</goals>
125+
</execution>
126+
<execution>
127+
<id>jacoco-site</id>
128+
<phase>test</phase>
129+
<goals>
130+
<goal>report</goal>
131+
</goals>
132+
</execution>
133+
</executions>
134+
<configuration>
135+
<includes>
136+
<include>pl/wavesoftware/**</include>
137+
</includes>
138+
</configuration>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</profile>
143+
</profiles>
144+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2015 Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pl.wavesoftware.utils.https.checker;
17+
18+
import com.google.common.base.Preconditions;
19+
import java.io.PrintStream;
20+
import pl.wavesoftware.utils.https.checker.cli.Application;
21+
import pl.wavesoftware.utils.https.checker.cli.ProcessIO;
22+
import pl.wavesoftware.utils.https.checker.cli.Result;
23+
import pl.wavesoftware.utils.https.checker.cli.argsparse4j.Argparse4jParser;
24+
25+
/**
26+
*
27+
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
28+
*/
29+
public abstract class HttpsCheckerMain {
30+
31+
/**
32+
* Main method for Java
33+
*
34+
* @param args the command line arguments
35+
*/
36+
public static void main(String[] args) {
37+
System.exit(doMain(args).retcode());
38+
}
39+
40+
protected static Result doMain(String[] args) {
41+
Argparse4jParser argsParser = new Argparse4jParser();
42+
Application app = argsParser.parse(argsParser.configure(), args);
43+
ProcessIO pio = new StdProcessIO();
44+
return app.perform(pio);
45+
}
46+
47+
private static class StdProcessIO implements ProcessIO {
48+
49+
@Override
50+
public PrintStream getOut() {
51+
return Preconditions.checkNotNull(System.out);
52+
}
53+
54+
@Override
55+
public PrintStream getErr() {
56+
return Preconditions.checkNotNull(System.err);
57+
}
58+
}
59+
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2015 Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pl.wavesoftware.utils.https.checker.cli;
17+
18+
/**
19+
*
20+
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
21+
*/
22+
public interface Application {
23+
24+
/**
25+
* Get application params
26+
*
27+
* @return a params
28+
*/
29+
Params getParams();
30+
31+
/**
32+
* Perform application action
33+
*
34+
* @param pio process IO configuration
35+
* @return a apliaction result
36+
*/
37+
Result perform(ProcessIO pio);
38+
39+
/**
40+
* Application parameters
41+
*/
42+
interface Params {
43+
44+
/**
45+
* Gets a param as casted opbject
46+
*
47+
* @param <T> type of param to get
48+
* @param argument a key to get
49+
* @return a param as casted object
50+
*/
51+
<T> T get(Cli.Arguments argument);
52+
53+
}
54+
55+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2015 Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pl.wavesoftware.utils.https.checker.cli;
17+
18+
import com.google.common.base.Function;
19+
20+
/**
21+
*
22+
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
23+
* @param <T> type of args parser
24+
*/
25+
public interface ArgsParser<T> {
26+
27+
/**
28+
* Configures a Args parser
29+
*
30+
* @return a function that returns configured parser
31+
*/
32+
Function<Void, T> configure();
33+
34+
/**
35+
* Parse args to runnable configuration
36+
*
37+
* @param config a function config
38+
* @param args program's arguments
39+
* @return configuration that can be runned
40+
*/
41+
Application parse(Function<Void, T> config, String[] args);
42+
43+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2015 Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package pl.wavesoftware.utils.https.checker.cli;
17+
18+
import com.google.common.base.Preconditions;
19+
20+
/**
21+
*
22+
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
23+
*/
24+
public abstract class Cli {
25+
26+
public static final String APP_NAME = "HttpsChecker";
27+
28+
public static final String DESCRIPTION = "It can check is your Java installation can perform connection "
29+
+ "with given HTTPS address";
30+
31+
public static enum Retcodes {
32+
33+
OK(0),
34+
INVALID_ARGS(5),
35+
BAD_SSL(1),
36+
NO_CONNECTION(2);
37+
38+
public final short code;
39+
40+
private Retcodes(Integer code) {
41+
this.code = code.byteValue();
42+
}
43+
}
44+
45+
public static enum Arguments {
46+
47+
ADDRESS(
48+
new String[]{},
49+
"Address to be checked",
50+
String.class,
51+
null
52+
),
53+
QUIET(
54+
new String[]{"-q", "--quiet"},
55+
"Do not display anything, only retcodes",
56+
Boolean.class,
57+
false
58+
),
59+
MAX_REDIRECTS(
60+
new String[]{"-r", "--max_redirects"},
61+
"Number of redirects to perform at maximum",
62+
Short.class,
63+
Integer.valueOf(10).shortValue()
64+
);
65+
66+
public final String label;
67+
68+
public final String[] config;
69+
70+
public final Class<?> type;
71+
72+
public final Object defaultValue;
73+
74+
public final String help;
75+
76+
private Arguments(String[] config, String help, Class<?> type, Object defaultValue) {
77+
this.config = config;
78+
if (config.length > 0) {
79+
String last = config[Preconditions.checkElementIndex(config.length - 1, config.length)];
80+
this.label = last.replace("-", "").trim();
81+
} else {
82+
this.label = this.name().toLowerCase();
83+
}
84+
this.type = type;
85+
this.defaultValue = defaultValue;
86+
this.help = help;
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)