Skip to content

Commit c2dcc3a

Browse files
authored
Merge pull request #1090 from mziccard/add-nio-support
Add Google Cloud Storage NIO Alpha support
2 parents a09e00c + 90f2c4b commit c2dcc3a

File tree

73 files changed

+8044
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+8044
-134
lines changed

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryError.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
package com.google.cloud.bigquery;
218

319
import com.google.api.services.bigquery.model.ErrorProto;

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
package com.google.cloud.bigquery;
218

319
import com.google.api.services.bigquery.model.JobStatistics2;

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/JobStatus.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
package com.google.cloud.bigquery;
218

319
import com.google.common.base.MoreObjects;

gcloud-java-bigquery/src/main/java/com/google/cloud/bigquery/UserDefinedFunction.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
package com.google.cloud.bigquery;
218

319
import com.google.api.services.bigquery.model.UserDefinedFunctionResource;

gcloud-java-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryErrorTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
117
package com.google.cloud.bigquery;
218

319
import static org.junit.Assert.assertEquals;

gcloud-java-contrib/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ Packages that provide higher-level abstraction/functionality for common gcloud-j
99
[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/gcloud-java)
1010
[![Dependency Status](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56bd8ee72a29ed002d2b0969)
1111

12+
Contents
13+
--------
14+
15+
* [gcloud-java-nio](./gcloud-java-nio/): NIO Filesystem Provider for Google Cloud Storage.
16+
* [gcloud-java-nio-examples](./gcloud-java-nio-examples/): How to add Google Cloud Storage NIO after the fact.
17+
1218
Quickstart
1319
----------
20+
21+
### gcloud-java-nio
22+
1423
If you are using Maven, add this to your pom.xml file
1524
```xml
1625
<dependency>
@@ -28,6 +37,10 @@ If you are using SBT, add this to your dependencies
2837
libraryDependencies += "com.google.cloud" % "gcloud-java-contrib" % "0.2.4"
2938
```
3039

40+
### gcloud-java-nio-examples
41+
42+
See its [README](./gcloud-java-nio-examples/README.md) for instructions on how to run it.
43+
3144
Java Versions
3245
-------------
3346

@@ -42,6 +55,11 @@ It is currently in major version zero (``0.y.z``), which means that anything
4255
may change at any time and the public API should not be considered
4356
stable.
4457

58+
See also
59+
--------
60+
61+
* [gcloud-java-examples](../gcloud-java-examples) for an example of how to use NIO normally.
62+
4563
Contributing
4664
------------
4765

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Example of adding the Google Cloud Storage NIO Provider to a legacy jar
2+
=======================================================================
3+
4+
This project shows how to add Google Cloud Storage capabilities to a jar file for a Java 7
5+
application that uses Java NIO without the need to recompile.
6+
7+
Note that whenever possible, you instead want to recompile the app and use the normal
8+
dependency mechanism to add a dependency to gcloud-java-nio. You can see examples of
9+
this in the [gcloud-java-examples](../../gcloud-java-examples) project.
10+
11+
To run this example:
12+
13+
1. Before running the example, go to the [Google Developers Console][developers-console] to ensure that Google Cloud Storage API is enabled.
14+
15+
2. Log in using gcloud SDK (`gcloud auth login` in command line)
16+
17+
3. Compile the JAR with:
18+
```
19+
mvn package -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
20+
```
21+
22+
4. Run the sample with:
23+
24+
```
25+
java -cp gcloud-java-contrib/gcloud-java-nio/target/gcloud-java-nio-0.2.5-SNAPSHOT-shaded.jar:gcloud-java-contrib/gcloud-java-nio-examples/target/gcloud-java-nio-examples-0.2.5-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems
26+
```
27+
28+
Notice that it lists Google Cloud Storage, which it wouldn't if you ran it without the NIO jar:
29+
```
30+
java -cp gcloud-java-contrib/gcloud-java-nio-examples/target/gcloud-java-nio-examples-0.2.5-SNAPSHOT.jar com.google.cloud.nio.examples.ListFilesystems
31+
```
32+
33+
The sample doesn't have anything about Google Cloud Storage in it. It gets that ability from the NIO
34+
jar that we're adding to the classpath. You can use the NIO "fat shaded" jar for this purpose as it
35+
also includes the dependencies for gcloud-java-nio.
36+
The underlying mechanism is Java's standard [ServiceLoader](https://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html)
37+
facility, the [standard way](http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html) to plug in NIO providers like this one.
38+
39+
If you have access to a project's source code you can also simply add gcloud-java-nio as
40+
a dependency and let Maven pull in the required dependencies (this is what the NIO unit tests do).
41+
This approach is preferable as the fat jar approach may waste memory on multiple copies of
42+
dependencies.
43+
44+
[developers-console]:https://console.developers.google.com/
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0"?>
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+
<artifactId>gcloud-java-nio-examples</artifactId>
5+
<packaging>jar</packaging>
6+
<name>GCloud Java NIO examples</name>
7+
<url>https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-contrib/gcloud-java-nio-examples</url>
8+
<description>
9+
Demonstrates how to use the gcloud-java-nio jar to add Google Cloud Storage functionality to legacy code.
10+
</description>
11+
<parent>
12+
<groupId>com.google.cloud</groupId>
13+
<artifactId>gcloud-java-contrib</artifactId>
14+
<version>0.2.5-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>nio</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>gcloud-java-storage</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.guava</groupId>
27+
<artifactId>guava</artifactId>
28+
<version>19.0</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.google.code.findbugs</groupId>
32+
<artifactId>jsr305</artifactId>
33+
<version>2.0.1</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>javax.inject</groupId>
37+
<artifactId>javax.inject</artifactId>
38+
<version>1</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.google.auto.service</groupId>
42+
<artifactId>auto-service</artifactId>
43+
<version>1.0-rc2</version>
44+
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
45+
</dependency>
46+
<dependency>
47+
<groupId>com.google.auto.value</groupId>
48+
<artifactId>auto-value</artifactId>
49+
<version>1.1</version>
50+
<scope>provided</scope> <!-- to leave out of the all-deps jar -->
51+
</dependency>
52+
<dependency>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
55+
<version>4.12</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.google.guava</groupId>
60+
<artifactId>guava-testlib</artifactId>
61+
<version>19.0</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.google.truth</groupId>
66+
<artifactId>truth</artifactId>
67+
<version>0.27</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.mockito</groupId>
72+
<artifactId>mockito-core</artifactId>
73+
<version>1.9.5</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-assembly-plugin</artifactId>
78+
<version>2.5.4</version>
79+
</dependency>
80+
</dependencies>
81+
<build>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.codehaus.mojo</groupId>
85+
<artifactId>exec-maven-plugin</artifactId>
86+
<configuration>
87+
<skip>false</skip>
88+
</configuration>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
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+
17+
package com.google.cloud.nio.examples;
18+
19+
import java.io.IOException;
20+
import java.net.URI;
21+
import java.nio.file.FileSystem;
22+
import java.nio.file.FileSystems;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
26+
import java.nio.file.spi.FileSystemProvider;
27+
28+
/**
29+
* ListFilesystems is a super-simple program that lists the available NIO filesystems.
30+
*/
31+
public class ListFilesystems {
32+
33+
/**
34+
* See the class documentation.
35+
*/
36+
public static void main(String[] args) throws IOException {
37+
listFilesystems();
38+
}
39+
40+
private static void listFilesystems() {
41+
System.out.println("Installed filesystem providers:");
42+
for (FileSystemProvider p : FileSystemProvider.installedProviders()) {
43+
System.out.println(" " + p.getScheme());
44+
}
45+
}
46+
47+
}

0 commit comments

Comments
 (0)