Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 5607abd

Browse files
authored
Merge pull request #10 from sebright/support-java-6
Makes census-java compatible with Java 6
2 parents 8aa6b67 + 048858c commit 5607abd

File tree

17 files changed

+177
-73
lines changed

17 files changed

+177
-73
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "proto"]
22
path = proto
3-
url = https://github.com/google/census-proto
3+
url = https://github.com/google/census-proto.git

.travis.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,46 @@ sudo: required
22
dist: trusty
33
language: java
44

5-
jdk:
6-
- oraclejdk8
5+
matrix:
6+
include:
7+
- jdk: openjdk6
8+
env: BUILD=MVN
9+
10+
- jdk: oraclejdk7
11+
env: BUILD=MVN
12+
13+
- jdk: oraclejdk8
14+
env: BUILD=MVN
15+
16+
- jdk: oraclejdk8
17+
env: BUILD=BAZEL
718

819
before_install:
9-
- echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
10-
- curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -
11-
- sudo apt-get update
20+
- case "$BUILD" in
21+
"BAZEL")
22+
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list ;
23+
curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add - ;
24+
sudo apt-get update ;;
25+
esac
1226

1327
install:
14-
- sudo apt-get install bazel
28+
- case "$BUILD" in
29+
"BAZEL")
30+
sudo apt-get install bazel ;;
31+
"MVN")
32+
mkdir protoc ;
33+
cd protoc ;
34+
curl -L -o protoc.zip https://github.com/google/protobuf/releases/download/v3.0.2/protoc-3.0.2-linux-x86_64.zip ;
35+
unzip protoc.zip ;
36+
export PATH=`pwd`/bin/:$PATH ;
37+
protoc --version ;
38+
cd .. ;;
39+
esac
1540

1641
script:
17-
- bazel test ...
42+
- case "$BUILD" in
43+
"BAZEL")
44+
bazel test ... ;;
45+
"MVN")
46+
mvn package ;;
47+
esac

core/java/com/google/census/CensusContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public final CensusContext with(
4949
/**
5050
* Serializes the {@link CensusContext} into the on-the-wire representation.
5151
*
52-
* <p>The inverse of {@link CensusContextFactory#deserialize()} and should be based on the
53-
* {@link CensusContext} protobuf representation.
52+
* <p>The inverse of {@link CensusContextFactory#deserialize(ByteBuffer)} and should be based on
53+
* the {@link CensusContext} protobuf representation.
5454
*
5555
* @return serialized bytes.
5656
*/

core/java/com/google/census/CensusScope.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package com.google.census;
1515

16+
import java.io.Closeable;
17+
1618
/**
1719
* {@link CensusScope} defines an arbitrary scope of code as a traceable operation. Supports
1820
* try-with-resources idiom.
@@ -31,7 +33,7 @@
3133
* }
3234
* </pre>
3335
*/
34-
public final class CensusScope implements AutoCloseable {
36+
public final class CensusScope implements Closeable {
3537
private final CensusContext saved;
3638

3739
/**

core/java/com/google/census/MetricMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public MetricMap build() {
107107
return new MetricMap(metrics);
108108
}
109109

110-
private ArrayList<Metric> metrics = new ArrayList<>();
110+
private ArrayList<Metric> metrics = new ArrayList<Metric>();
111111

112112
private Builder() {
113113
}

core/java/com/google/census/Provider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ T newInstance() {
4242
if (provider != null) {
4343
return (T) provider.newInstance();
4444
}
45-
} catch (InstantiationException | IllegalAccessException e) {
45+
} catch (InstantiationException e) {
46+
// TODO(dpo): decide what to do here - log, crash, or both.
47+
System.err.println(e);
48+
} catch (IllegalAccessException e) {
4649
// TODO(dpo): decide what to do here - log, crash, or both.
4750
System.err.println(e);
4851
}

core/javatests/com/google/census/CensusScopeTest.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,58 +41,76 @@ public void testNoScope() {
4141

4242
@Test
4343
public void testScope() {
44-
try (CensusScope scope = new CensusScope(Census.getCurrent().with(K1, V1))) {
44+
CensusScope scope = new CensusScope(Census.getCurrent().with(K1, V1));
45+
try {
4546
assertEquals(
4647
Census.getDefault().with(K1, V1),
4748
Census.getCurrent());
49+
} finally {
50+
scope.close();
4851
}
4952
assertEquals(Census.getDefault(), Census.getCurrent());
5053
}
5154

5255
@Test
5356
public void testNestedScope() {
54-
try (CensusScope s1 = new CensusScope(Census.getCurrent().with(K1, V1))) {
57+
CensusScope s1 = new CensusScope(Census.getCurrent().with(K1, V1));
58+
try {
5559
assertEquals(
5660
Census.getDefault().with(K1, V1),
5761
Census.getCurrent());
58-
try (CensusScope s2 = new CensusScope(Census.getCurrent().with(K2, V2))) {
62+
CensusScope s2 = new CensusScope(Census.getCurrent().with(K2, V2));
63+
try {
5964
assertEquals(
6065
Census.getDefault().with(K1, V1).with(K2, V2),
6166
Census.getCurrent());
67+
} finally {
68+
s2.close();
6269
}
6370
assertEquals(
6471
Census.getDefault().with(K1, V1),
6572
Census.getCurrent());
73+
} finally {
74+
s1.close();
6675
}
6776
assertEquals(Census.getDefault(), Census.getCurrent());
6877
}
6978

7079
@Test
7180
public void testOf1() {
72-
try (CensusScope scope = CensusScope.of(K1, V1)) {
81+
CensusScope scope = CensusScope.of(K1, V1);
82+
try {
7383
assertEquals(
7484
Census.getDefault().with(K1, V1),
7585
Census.getCurrent());
86+
} finally {
87+
scope.close();
7688
}
7789
assertEquals(Census.getDefault(), Census.getCurrent());
7890
}
7991

8092
@Test
8193
public void testOf2() {
82-
try (CensusScope scope = CensusScope.of(K1, V1, K2, V2)) {
94+
CensusScope scope = CensusScope.of(K1, V1, K2, V2);
95+
try {
8396
assertEquals(
8497
Census.getDefault().with(K1, V1, K2, V2),
8598
Census.getCurrent());
99+
} finally {
100+
scope.close();
86101
}
87102
assertEquals(Census.getDefault(), Census.getCurrent());
88103
}
89104

90105
@Test
91106
public void testOf3() {
92-
try (CensusScope scope = CensusScope.of(K1, V1, K2, V2, K3, V3)) {
107+
CensusScope scope = CensusScope.of(K1, V1, K2, V2, K3, V3);
108+
try {
93109
assertEquals(
94110
Census.getDefault().with(K1, V1, K2, V2, K3, V3),
95111
Census.getCurrent());
112+
} finally {
113+
scope.close();
96114
}
97115
assertEquals(Census.getDefault(), Census.getCurrent());
98116
}
@@ -101,10 +119,13 @@ public void testOf3() {
101119
public void testBuilder() {
102120
CensusScope.Builder builder =
103121
CensusScope.builder().set(K1, V1).set(K2, V2).set(K3, V3).set(K4, V4);
104-
try (CensusScope scope = builder.build()) {
122+
CensusScope scope = builder.build();
123+
try {
105124
assertEquals(
106125
Census.getDefault().builder().set(K1, V1).set(K2, V2).set(K3, V3).set(K4, V4).build(),
107126
Census.getCurrent());
127+
} finally {
128+
scope.close();
108129
}
109130
assertEquals(Census.getDefault(), Census.getCurrent());
110131
}

core/javatests/com/google/census/MetricMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void testBuilderEmpty() {
6262

6363
@Test
6464
public void testBuilder() {
65-
ArrayList<Metric> expected = new ArrayList<>(10);
65+
ArrayList<Metric> expected = new ArrayList<Metric>(10);
6666
MetricMap.Builder builder = MetricMap.builder();
6767
for (int i = 1; i <= 10; i++) {
6868
expected.add(new Metric(new MetricName("m" + i), i * 11.1));

core/javatests/com/google/census/ProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class ProviderTest {
2727
@Test
2828
public void testGoodClass() throws Exception {
29-
Provider<GetGen> provider = new Provider<>("com.google.census.ProviderTest$GetGen");
29+
Provider<GetGen> provider = new Provider<GetGen>("com.google.census.ProviderTest$GetGen");
3030
GetGen getGen0 = provider.newInstance();
3131
assertThat(getGen0.getGen()).isEqualTo(0);
3232
for (int i = 1; i < 10; i++) {
@@ -37,7 +37,7 @@ public void testGoodClass() throws Exception {
3737

3838
@Test
3939
public void testBadClass() throws Exception {
40-
Provider<GetGen> provider = new Provider<>("com.google.census.ProviderTest$BadClass");
40+
Provider<GetGen> provider = new Provider<GetGen>("com.google.census.ProviderTest$BadClass");
4141
assertThat(provider).isNotNull();
4242
assertThat(provider.newInstance()).isNull();
4343
}

core/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,45 @@
1515
<artifactId>census-parent</artifactId>
1616
<version>0.1.0-SNAPSHOT</version>
1717
</parent>
18+
<build>
19+
<sourceDirectory>java</sourceDirectory>
20+
<plugins>
21+
<plugin>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<version>3.5.1</version>
24+
<configuration>
25+
<source>1.6</source>
26+
<target>1.6</target>
27+
</configuration>
28+
</plugin>
29+
<plugin>
30+
<artifactId>maven-jar-plugin</artifactId>
31+
<version>2.3.1</version>
32+
</plugin>
33+
<plugin>
34+
<artifactId>maven-source-plugin</artifactId>
35+
<version>2.1.2</version>
36+
<executions>
37+
<execution>
38+
<id>attach-sources</id>
39+
<goals>
40+
<goal>jar-no-fork</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
<plugin>
46+
<artifactId>maven-javadoc-plugin</artifactId>
47+
<version>2.8.1</version>
48+
<executions>
49+
<execution>
50+
<id>attach-javadocs</id>
51+
<goals>
52+
<goal>jar</goal>
53+
</goals>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
</plugins>
58+
</build>
1859
</project>

0 commit comments

Comments
 (0)