Skip to content

Commit 347d6fc

Browse files
author
clouless
committed
switch to bazel build
1 parent 7418680 commit 347d6fc

File tree

7 files changed

+202
-49
lines changed

7 files changed

+202
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ output.xml
55
.classpath
66
.project
77
.settings
8+
bazel-*

BUILD

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
java_library(
4+
name = "java-xml-grepper-lib",
5+
srcs = glob(["src/main/java/io/codeclou/java/xml/grepper/*.java"]),
6+
deps = [
7+
"@commons_cli//jar",
8+
"@openpojo//jar",
9+
],
10+
)
11+
12+
java_binary(
13+
name = "java-xml-grepper",
14+
main_class = "io.codeclou.java.xml.grepper.Main",
15+
runtime_deps = [":java-xml-grepper-lib"],
16+
)
17+
18+
java_test(
19+
name = "tests",
20+
srcs = glob(["src/test/java/io/codeclou/java/xml/grepper/*.java"]),
21+
test_class = "io.codeclou.java.xml.grepper.TestAll",
22+
resources=glob(['src/test/resources/**/*']),
23+
deps = [
24+
":java-xml-grepper-lib",
25+
"@commons_cli//jar",
26+
"@openpojo//jar",
27+
# TEST SCOPE
28+
"@commons_io//jar",
29+
"@junit//jar",
30+
"@powermock_api_support//jar",
31+
"@powermock_core//jar",
32+
"@powermock_module_junit4//jar",
33+
"@powermock_module_junit4_common//jar",
34+
"@powermock_api_mockito//jar",
35+
"@powermock_api_mockito_common//jar",
36+
"@powermock_reflect//jar",
37+
"@mockito_all//jar",
38+
"@javassist//jar",
39+
],
40+
)

DEVELOPMENT.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
# Development
22

3-
### Build
3+
### Doc
4+
5+
We build with bazel:
6+
7+
* https://docs.bazel.build/versions/master/tutorial/java.html
8+
* https://github.com/bazelbuild/examples/tree/master/java-maven
9+
* https://github.com/johnynek/bazel-deps
10+
11+
"Fat-Jar":
12+
13+
* https://docs.bazel.build/versions/master/tutorial/java.html#package-a-java-target-for-deployment
14+
15+
16+
### Run Tests
417

518
```
6-
mvn package -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
7-
java -jar target/java-xml-grepper.jar
19+
bazel test :tests
820
```
921

10-
### Testcoverage
11-
12-
[Run OpenClover](http://openclover.org/) with maven:
22+
### Build
1323

14-
```bash
15-
mvn clean clover:setup test clover:aggregate clover:clover
1624
```
25+
# JAR / BINARY
26+
bazel build //:java-xml-grepper
27+
28+
./bazel-bin/java-xml-grepper
1729
18-
Now look into `target/site/clover/`
30+
31+
# FAT JAR
32+
bazel build //:java-xml-grepper_deploy.jar
33+
34+
java -jar bazel-bin/java-xml-grepper_deploy.jar
35+
```

WORKSPACE

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#
2+
# COMPILE SCOPE
3+
#
4+
maven_jar(
5+
name = "commons_cli",
6+
artifact = "commons-cli:commons-cli:1.4",
7+
server = "maven_central_server",
8+
)
9+
maven_jar(
10+
name = "openpojo",
11+
artifact = "com.openpojo:openpojo:0.8.6",
12+
server = "maven_central_server",
13+
)
14+
#
15+
# TEST SCOPE
16+
#
17+
maven_jar(
18+
name = "commons_io",
19+
artifact = "commons-io:commons-io:jar:2.6",
20+
server = "maven_central_server",
21+
)
22+
maven_jar(
23+
name = "junit",
24+
artifact = "junit:junit:4.12",
25+
server = "maven_central_server",
26+
)
27+
maven_jar(
28+
name = "powermock_api_support",
29+
artifact = "org.powermock:powermock-api-support:jar:1.7.0",
30+
server = "maven_central_server",
31+
)
32+
maven_jar(
33+
name = "powermock_core",
34+
artifact = "org.powermock:powermock-core:jar:1.7.0",
35+
server = "maven_central_server",
36+
)
37+
maven_jar(
38+
name = "powermock_module_junit4",
39+
artifact = "org.powermock:powermock-module-junit4:1.7.0",
40+
server = "maven_central_server",
41+
)
42+
maven_jar(
43+
name = "powermock_module_junit4_common",
44+
artifact = "org.powermock:powermock-module-junit4-common:jar:1.7.0",
45+
server = "maven_central_server",
46+
)
47+
maven_jar(
48+
name = "powermock_api_mockito",
49+
artifact = "org.powermock:powermock-api-mockito:1.7.0",
50+
server = "maven_central_server",
51+
)
52+
maven_jar(
53+
name = "powermock_api_mockito_common",
54+
artifact = "org.powermock:powermock-api-mockito-common:1.7.0",
55+
server = "maven_central_server",
56+
)
57+
maven_jar(
58+
name = "powermock_reflect",
59+
artifact = "org.powermock:powermock-reflect:jar:1.7.0",
60+
server = "maven_central_server",
61+
)
62+
maven_jar(
63+
name = "mockito_all",
64+
artifact = "org.mockito:mockito-all:1.10.19",
65+
server = "maven_central_server",
66+
)
67+
maven_jar(
68+
name = "javassist",
69+
artifact = "javassist:javassist:3.12.0.GA",
70+
server = "maven_central_server",
71+
)
72+
#
73+
# REPOS
74+
#
75+
maven_server(
76+
name = "maven_central_server",
77+
url = "https://repo1.maven.org/maven2/",
78+
)

pom.xml renamed to deprecated_pom.xml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,6 @@
6161
<scope>test</scope>
6262
</dependency>
6363
</dependencies>
64-
<build>
65-
<plugins>
66-
<plugin>
67-
<groupId>org.openclover</groupId>
68-
<artifactId>clover-maven-plugin</artifactId>
69-
<version>4.2.0</version>
70-
</plugin>
71-
<plugin>
72-
<artifactId>maven-assembly-plugin</artifactId>
73-
<version>3.1.0</version>
74-
<configuration>
75-
<finalName>java-xml-grepper</finalName>
76-
<archive>
77-
<manifest>
78-
<mainClass>io.codeclou.java.xml.grepper.Main</mainClass>
79-
</manifest>
80-
</archive>
81-
<descriptorRefs>
82-
<descriptorRef>jar-with-dependencies</descriptorRef>
83-
</descriptorRefs>
84-
<appendAssemblyId>false</appendAssemblyId>
85-
</configuration>
86-
<executions>
87-
<execution>
88-
<id>make-assembly</id>
89-
<phase>package</phase>
90-
<goals>
91-
<goal>single</goal>
92-
</goals>
93-
</execution>
94-
</executions>
95-
</plugin>
96-
</plugins>
97-
</build>
9864
<properties>
9965
<powermock.version>1.7.0</powermock.version>
10066
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2017 Bernhard Grünewaldt
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 all
14+
* 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 THE
22+
* SOFTWARE.
23+
*/
24+
package io.codeclou.java.xml.grepper;
25+
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.Suite;
28+
import org.junit.runners.Suite.SuiteClasses;
29+
30+
@RunWith(Suite.class)
31+
@SuiteClasses({MainTest.class, XmlGrepperTest.class})
32+
public class TestAll { }

src/test/java/io/codeclou/java/xml/grepper/XmlGrepperTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,37 @@
2727
import org.junit.Test;
2828
import org.mockito.internal.util.reflection.Whitebox;
2929

30+
import java.io.BufferedReader;
3031
import java.io.File;
32+
import java.io.FileInputStream;
33+
import java.io.IOException;
34+
import java.io.InputStream;
35+
import java.io.StringWriter;
3136

3237
import static junit.framework.TestCase.assertFalse;
3338
import static org.junit.Assert.assertEquals;
3439
import static org.junit.Assert.assertTrue;
40+
import org.apache.commons.io.FileUtils;
41+
import org.apache.commons.io.IOUtils;
42+
3543

3644
public class XmlGrepperTest {
3745

38-
@Rule
39-
public PreventExitTestRule preventExit = new PreventExitTestRule();
46+
// NOTE: Bazel has its own GoogleSecurityManager that prevents System.exit()
47+
//@Rule
48+
//public PreventExitTestRule preventExit = new PreventExitTestRule();
4049

41-
private File getTestFile(String filename) {
50+
private File getTestFile(String filename) throws IOException {
51+
// Since Bazel creates a test.jar somewhere we need to extract the testfile
52+
// out of the jar and put it accessible on the Filesystem somewhere to e.g. /tmp/
4253
ClassLoader classLoader = getClass().getClassLoader();
43-
return new File(classLoader.getResource(filename).getFile());
54+
InputStream inputstream = classLoader.getResource(filename).openStream();
55+
StringWriter writer = new StringWriter();
56+
IOUtils.copy(inputstream, writer, "utf-8");
57+
String fileContent = writer.toString();
58+
File testFileOutsideTestJar = File.createTempFile("xmlgrepper", ".dat");
59+
FileUtils.write(testFileOutsideTestJar, fileContent, "utf-8");
60+
return testFileOutsideTestJar;
4461
}
4562

4663
@Test
@@ -82,7 +99,8 @@ public void testRunValidInputWithInvalidFolders() throws Exception {
8299

83100
@Test
84101
public void testRunValidInputWithValidXpath() throws Exception {
85-
String[] args = {"-f=src/test/resources/pom-1-test.xml", "-x=foo"};
102+
File pomXMl = getTestFile("pom-1-test.xml");
103+
String[] args = {"-f=" + pomXMl.getAbsolutePath(), "-x=foo"};
86104
XmlGrepper grepper = new XmlGrepper();
87105
grepper.run(args);
88106
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(grepper, "hasCmdLineParameterErrors");
@@ -93,7 +111,8 @@ public void testRunValidInputWithValidXpath() throws Exception {
93111

94112
@Test()
95113
public void testRunValidInputWithInValidXpath() throws Exception {
96-
String[] args = {"-f=src/test/resources/pom-1-test.xml", "-x=???S?Sßß"};
114+
File pomXMl = getTestFile("pom-1-test.xml");
115+
String[] args = {"-f=" + pomXMl.getAbsolutePath(), "-x=???S?Sßß"};
97116
XmlGrepper grepper = new XmlGrepper();
98117
try {
99118
grepper.run(args);

0 commit comments

Comments
 (0)