Skip to content

Commit da60c8c

Browse files
MediaMarcoftorkler
andcommitted
Created cli module
Co-authored-by: Florian Torkler <[email protected]>
1 parent b46076a commit da60c8c

39 files changed

+233
-113
lines changed

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ subprojects {
7272
apply plugin: 'signing'
7373
apply plugin: 'idea'
7474
apply plugin: 'maven'
75-
apply plugin: 'org.springframework.boot'
7675

7776
jar {
7877
manifest.attributes provider: 'gradle'

cli/build.gradle

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
def seleniumVersion = '3.8.1'
2+
ext['selenium.version'] = seleniumVersion
3+
4+
apply plugin: 'org.springframework.boot'
5+
6+
dependencies {
7+
compile project(":core")
8+
compile "com.beust:jcommander:1.72"
9+
compile "com.google.code.gson:gson:2.8.2"
10+
compile "ch.qos.logback:logback-classic:1.2.3"
11+
testCompile "junit:junit:4.12"
12+
testCompile "org.mockito:mockito-core:2.13.0"
13+
testCompile "org.hamcrest:hamcrest-core:1.3"
14+
testCompile "org.hamcrest:hamcrest-library:1.3"
15+
testCompile "com.github.stefanbirkner:system-rules:1.17.0"
16+
}
17+
18+
bootJar {
19+
enabled = true
20+
}
21+
22+
test {
23+
testLogging {
24+
exceptionFormat = 'full'
25+
showStandardStreams = true
26+
}
27+
}
28+
29+
task javadocJar(type: Jar, dependsOn: javadoc) {
30+
baseName = 'jlineup'
31+
classifier = 'javadoc'
32+
from 'build/docs/javadoc'
33+
}
34+
35+
task sourcesJar(type: Jar) {
36+
baseName = 'jlineup'
37+
from sourceSets.main.allSource
38+
classifier = 'sources'
39+
}
40+
41+
bootJar {
42+
baseName = "jlineup"
43+
archiveName = "jlineup.jar"
44+
mainClassName = 'de.otto.jlineup.cli.Main'
45+
launchScript()
46+
}
47+
48+
artifacts {
49+
archives sourcesJar
50+
archives javadocJar
51+
archives bootJar
52+
}
53+
54+
[distZip, bootDistZip, distTar, bootDistTar].each { task ->
55+
configurations.archives.artifacts.removeAll
56+
{ it.class.simpleName == "ArchivePublishArtifact" && it.archiveTask == task }
57+
task.enabled = false
58+
}
59+
60+
signing {
61+
sign configurations.archives
62+
}
63+
64+
tasks.processResources.doLast { task ->
65+
def resourcesDir = project.sourceSets.main.output.resourcesDir
66+
resourcesDir.mkdirs()
67+
68+
def versionProperties = new File(resourcesDir, "version.properties")
69+
if (versionProperties) {
70+
def gitVersion = runCommand("git log -n1 --format=format:%H")
71+
def fullVersion = version
72+
versionProperties.text = "\njlineup.commit = ${gitVersion}" + "\njlineup.version = ${fullVersion}"
73+
}
74+
}
75+
76+
uploadArchives {
77+
configuration = configurations.archives
78+
repositories {
79+
mavenDeployer {
80+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
81+
82+
// use this for local upload debugging instead of sonatype
83+
//repository(url: "file://${buildDir}/repo")
84+
//snapshotRepository(url: "file://${buildDir}/repo")
85+
86+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
87+
authentication(userName: sonatypeUsername, password: sonatypePassword)
88+
}
89+
90+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
91+
authentication(userName: sonatypeUsername, password: sonatypePassword)
92+
}
93+
94+
pom.project {
95+
name 'JLineup'
96+
packaging 'jar'
97+
description 'Webapp image comparison tool'
98+
url 'http://github.com/otto-de/jlineup'
99+
100+
scm {
101+
url 'scm:[email protected]:otto-de/jlineup.git'
102+
connection 'scm:[email protected]:otto-de/jlineup.git'
103+
}
104+
105+
licenses {
106+
license {
107+
name 'The Apache Software License, Version 2.0'
108+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
109+
}
110+
}
111+
112+
developers {
113+
developer {
114+
id 'mgeweke'
115+
name 'Marco Geweke'
116+
url 'https://github.com/MediaMarco'
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
124+
static String runCommand(command) {
125+
Process proc = command.execute()
126+
def out = new StringBuffer()
127+
proc.consumeProcessOutputStream(out)
128+
proc.consumeProcessErrorStream(out)
129+
proc.waitFor()
130+
def errorlevel = proc.exitValue()
131+
if (errorlevel != 0) {
132+
throw new RuntimeException("exec failed on command: '${command}' with errorlevel ${errorlevel}".toString())
133+
}
134+
out.toString().trim()
135+
}

core/src/main/java/de/otto/jlineup/config/CommandLineParameters.java cli/src/main/java/de/otto/jlineup/cli/CommandLineParameters.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
package de.otto.jlineup.config;
1+
package de.otto.jlineup.cli;
22

33
import com.beust.jcommander.DynamicParameter;
44
import com.beust.jcommander.Parameter;
5+
import de.otto.jlineup.config.Step;
56

67
import java.util.HashMap;
78
import java.util.Map;
89
import java.util.Objects;
910

10-
import static de.otto.jlineup.config.Step.*;
11-
1211
public class CommandLineParameters {
1312

1413
@Parameter(names = {"-?", "--help"}, help = true, description = "Shows this help")
1514
private boolean help = false;
1615

1716
@Parameter(names = {"-s", "--step"}, description = "JLineup step - 'before' just takes screenshots, 'after' takes screenshots and compares them with the 'before'-screenshots in the screenshots directory. 'compare' just compares existing screenshots, it's also included in 'after'.")
18-
private Step step = before;
17+
private Step step = Step.before;
1918

2019
@Parameter(names = {"--config", "-c"}, description = "Config file")
2120
private String configFile = "lineup.json";
@@ -68,15 +67,15 @@ String getConfigFile() {
6867
}
6968

7069
public boolean isAfter() {
71-
return step == after;
70+
return step == Step.after;
7271
}
7372

7473
public boolean isBefore() {
75-
return step != after && step != compare;
74+
return step != Step.after && step != Step.compare;
7675
}
7776

7877
public boolean isJustCompare() {
79-
return step == compare;
78+
return step == Step.compare;
8079
}
8180

8281
public boolean isHelp() {

core/src/main/java/de/otto/jlineup/Main.java cli/src/main/java/de/otto/jlineup/cli/Main.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package de.otto.jlineup;
1+
package de.otto.jlineup.cli;
22

33
import com.beust.jcommander.JCommander;
4+
import de.otto.jlineup.JLineup;
5+
import de.otto.jlineup.JLineupRunConfiguration;
6+
import de.otto.jlineup.Utils;
47
import de.otto.jlineup.browser.BrowserUtils;
5-
import de.otto.jlineup.config.CommandLineParameters;
68
import de.otto.jlineup.config.Config;
79

810
import java.io.FileNotFoundException;
@@ -17,17 +19,17 @@ public static void main(String[] args) throws Exception {
1719
jCommander.setProgramName("JLineup");
1820
if (parameters.isHelp()) {
1921
jCommander.usage();
20-
System.out.printf("Version: %s%n", Util.getVersion());
22+
System.out.printf("Version: %s%n", Utils.getVersion());
2123
return;
2224
}
2325

2426
if (parameters.isVersion()) {
25-
System.out.printf("JLineup version %s", Util.getVersion());
27+
System.out.printf("JLineup version %s", Utils.getVersion());
2628
return;
2729
}
2830

2931
if (parameters.isDebug()) {
30-
Util.setLogLevelToDebug();
32+
Utils.setLogLevelToDebug();
3133
}
3234

3335
Config config = null;
@@ -43,16 +45,16 @@ public static void main(String[] args) throws Exception {
4345
}
4446

4547
if (config.debug) {
46-
Util.setLogLevelToDebug();
48+
Utils.setLogLevelToDebug();
4749
}
4850

4951
if (config.logToFile || parameters.isLogToFile()) {
50-
Util.logToFile(parameters.getWorkingDirectory());
52+
Utils.logToFile(parameters.getWorkingDirectory());
5153
}
5254

53-
System.out.printf("Running JLineup [%s] with step '%s'.%n%n", Util.getVersion(), parameters.getStep());
55+
System.out.printf("Running JLineup [%s] with step '%s'.%n%n", Utils.getVersion(), parameters.getStep());
5456

55-
JLineupRunConfiguration jLineupRunConfiguration = JLineupRunConfiguration.fromCommandlineParameters(parameters);
57+
JLineupRunConfiguration jLineupRunConfiguration = de.otto.jlineup.cli.Utils.convertCommandLineParametersToRunConfiguration(parameters);
5658
JLineup jLineup = new JLineup(config, jLineupRunConfiguration);
5759

5860
int errorLevel = jLineup.run();
@@ -74,7 +76,7 @@ private static Config buildConfig(CommandLineParameters parameters) throws FileN
7476
}
7577
} else {
7678
try {
77-
config = Config.readConfig(parameters);
79+
config = de.otto.jlineup.cli.Utils.readConfig(parameters);
7880
} catch (FileNotFoundException e) {
7981
if (!parameters.isPrintConfig()) {
8082
System.err.println(e.getMessage());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.otto.jlineup.cli;
2+
3+
import de.otto.jlineup.JLineupRunConfiguration;
4+
import de.otto.jlineup.config.Config;
5+
6+
import java.io.FileNotFoundException;
7+
8+
import static com.google.common.base.MoreObjects.firstNonNull;
9+
import static java.util.Collections.emptyMap;
10+
11+
public class Utils {
12+
13+
public static Config readConfig(final CommandLineParameters parameters) throws FileNotFoundException {
14+
return Config.readConfig(parameters.getWorkingDirectory(), parameters.getConfigFile());
15+
}
16+
17+
public static JLineupRunConfiguration convertCommandLineParametersToRunConfiguration(CommandLineParameters commandLineParameters) {
18+
return JLineupRunConfiguration.jLineupRunConfigurationBuilder()
19+
.withWorkingDirectory(commandLineParameters.getWorkingDirectory())
20+
.withScreenshotsDirectory(commandLineParameters.getScreenshotDirectory())
21+
.withReportDirectory(commandLineParameters.getReportDirectory())
22+
.withStep(commandLineParameters.getStep())
23+
.withUrlReplacements(firstNonNull(commandLineParameters.getUrlReplacements(), emptyMap()))
24+
.build();
25+
}
26+
27+
}
File renamed without changes.

core/src/test/java/de/otto/jlineup/JLineupRunConfigurationTest.java cli/src/test/java/de/otto/jlineup/cli/JLineupRunConfigurationTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package de.otto.jlineup;
1+
package de.otto.jlineup.cli;
22

33
import com.beust.jcommander.JCommander;
4-
import de.otto.jlineup.config.CommandLineParameters;
4+
import de.otto.jlineup.JLineupRunConfiguration;
55
import de.otto.jlineup.config.Step;
66
import org.junit.Test;
77

@@ -23,7 +23,7 @@ public void shouldConvertCommandlineParameters() {
2323
JCommander jCommander = new JCommander(commandLineParameters);
2424
jCommander.parse(params);
2525

26-
JLineupRunConfiguration jLineupRunConfiguration = JLineupRunConfiguration.fromCommandlineParameters(commandLineParameters);
26+
JLineupRunConfiguration jLineupRunConfiguration = Utils.convertCommandLineParametersToRunConfiguration(commandLineParameters);
2727

2828
assertThat(jLineupRunConfiguration.getReportDirectory(), is("someReportDirectory"));
2929
assertThat(jLineupRunConfiguration.getScreenshotsDirectory(), is("someScreenshotDirectory"));

0 commit comments

Comments
 (0)