Skip to content

Commit 3b37854

Browse files
committed
Conflicts: .classpath .settings/org.eclipse.jdt.core.prefs
2 parents 468d80a + ef72daa commit 3b37854

9 files changed

Lines changed: 226 additions & 180 deletions

File tree

.classpath

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
<attribute name="maven.pomderived" value="true"/>
1212
</attributes>
1313
</classpathentry>
14-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
15-
<attributes>
16-
<attribute name="maven.pomderived" value="true"/>
17-
</attributes>
18-
</classpathentry>
1914
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
2015
<attributes>
2116
<attribute name="optional" value="true"/>
@@ -31,6 +26,10 @@
3126
<attributes>
3227
<attribute name="maven.pomderived" value="true"/>
3328
</attributes>
29+
<accessrules>
30+
<accessrule kind="nonaccessible" pattern="**/repackaged/**"/>
31+
</accessrules>
3432
</classpathentry>
33+
<classpathentry kind="var" path="ECLIPSE_HOME"/>
3534
<classpathentry kind="output" path="target/classes"/>
3635
</classpath>

.project

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
<arguments>
1111
</arguments>
1212
</buildCommand>
13+
<buildCommand>
14+
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
1318
<buildCommand>
1419
<name>org.eclipse.m2e.core.maven2Builder</name>
1520
<arguments>
1621
</arguments>
1722
</buildCommand>
1823
<buildCommand>
19-
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
24+
<name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>
2025
<arguments>
2126
</arguments>
2227
</buildCommand>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,101 @@
11
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
3+
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
4+
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
5+
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
6+
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
7+
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
28
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
39
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
410
org.eclipse.jdt.core.compiler.compliance=1.7
11+
<<<<<<< HEAD
12+
=======
13+
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
14+
>>>>>>> ef72daa81c73f99e2156f5bfe8127591fc6358e9
515
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
16+
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
17+
org.eclipse.jdt.core.compiler.problem.comparingIdentical=error
18+
org.eclipse.jdt.core.compiler.problem.deadCode=warning
19+
org.eclipse.jdt.core.compiler.problem.deprecation=warning
20+
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
21+
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
22+
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
23+
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
624
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
25+
<<<<<<< HEAD
26+
=======
27+
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
28+
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
29+
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
30+
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
31+
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
32+
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
33+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
34+
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
35+
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
36+
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
37+
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
38+
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
39+
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
40+
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
41+
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning
42+
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
43+
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
44+
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
45+
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
46+
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
47+
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
48+
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
49+
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error
50+
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error
51+
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
52+
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
53+
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
54+
org.eclipse.jdt.core.compiler.problem.nullReference=warning
55+
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
56+
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
57+
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
58+
org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
59+
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error
60+
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
61+
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
62+
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
63+
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
64+
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
65+
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
66+
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
67+
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
68+
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
69+
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
70+
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
71+
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
72+
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
73+
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
74+
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
75+
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
76+
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
77+
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
78+
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
79+
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
80+
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
81+
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
82+
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
83+
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
84+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
85+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
86+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
87+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
88+
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
89+
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
90+
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
91+
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
92+
org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
93+
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
94+
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
95+
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
96+
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
97+
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
98+
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
99+
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
100+
>>>>>>> ef72daa81c73f99e2156f5bfe8127591fc6358e9
7101
org.eclipse.jdt.core.compiler.source=1.7

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,17 @@
1414
<artifactId>google-oauth-client</artifactId>
1515
<version>1.18.0-rc</version>
1616
</dependency>
17+
<dependency>
18+
<groupId>com.google.guava</groupId>
19+
<artifactId>guava</artifactId>
20+
<version>RELEASE</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>com.google.apis</groupId>
24+
<artifactId>
25+
google-api-services-datastore-protobuf
26+
</artifactId>
27+
<version>v1beta2-rev1-2.1.0</version>
28+
</dependency>
1729
</dependencies>
1830
</project>
Lines changed: 69 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,105 @@
11
package com.google.gcloud;
22

3-
import java.util.Arrays;
4-
import java.util.List;
53

6-
import com.google.api.client.auth.oauth2.Credential;
4+
import com.google.api.client.googleapis.compute.ComputeCredential;
5+
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
76
import com.google.api.client.http.HttpRequestInitializer;
87
import com.google.api.client.http.HttpTransport;
8+
import com.google.api.client.http.javanet.NetHttpTransport;
9+
import com.google.api.client.json.jackson.JacksonFactory;
10+
import com.google.common.base.MoreObjects;
11+
import com.google.common.base.Preconditions;
912

10-
public class ServiceOptions {
13+
import java.io.IOException;
14+
import java.security.GeneralSecurityException;
15+
import java.security.PrivateKey;
16+
import java.util.Set;
17+
18+
public abstract class ServiceOptions {
1119

12-
private final String host;
1320
private static final String DEFAULT_HOST = "https://www.googleapis.com";
14-
private final HttpRequestInitializer initializer;
15-
private final Credential credential;
16-
private final HttpTransport transport;
17-
18-
public static final List<String> SCOPES = Arrays.asList(
19-
"https://www.googleapis.com/auth/datastore",
20-
"https://www.googleapis.com/auth/userinfo.email");
21-
22-
ServiceOptions(Builder b) {
23-
this.dataset = b.dataset;
24-
this.host = b.host != null ? b.host : DEFAULT_HOST;
25-
this.initializer = b.initializer;
26-
this.credential = b.credential;
27-
this.transport = b.transport;
21+
22+
private final String host;
23+
private final HttpTransport httpTransport;
24+
private final HttpRequestInitializer httpRequestInitializer;
25+
26+
protected ServiceOptions(Builder builder) {
27+
host = MoreObjects.firstNonNull(builder.host, DEFAULT_HOST);
28+
httpTransport = MoreObjects.firstNonNull(builder.httpTransport, getDefaultHttpTransport());
29+
httpRequestInitializer = builder.httpRequestInitializer;
2830
}
2931

30-
/**
31-
* Builder for {@link ServiceOptions}.
32-
*/
33-
protected static class Builder {
34-
private String dataset;
35-
private String host;
36-
private HttpRequestInitializer initializer;
37-
private Credential credential;
38-
private HttpTransport transport;
39-
40-
public Builder() { }
41-
42-
public Builder(ServiceOptions options) {
43-
this.dataset = options.dataset;
44-
this.host = options.host;
45-
this.initializer = options.initializer;
46-
this.credential = options.credential;
47-
this.transport = options.transport;
32+
private static HttpTransport getDefaultHttpTransport() {
33+
try {
34+
NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
35+
// Try to connect using Google Compute Engine service account credentials.
36+
ComputeCredential credential = new ComputeCredential(transport, new JacksonFactory());
37+
// Force token refresh to detect if we are running on Google Compute Engine.
38+
credential.refreshToken();
39+
return credential.getTransport();
40+
} catch (IOException | GeneralSecurityException e) {
41+
return new NetHttpTransport();
4842
}
43+
}
4944

50-
public ServiceOptions build() {
51-
return new ServiceOptions(this);
52-
}
45+
protected abstract static class Builder {
5346

54-
/**
55-
* Sets the dataset used to access the datastore.
56-
*/
57-
public Builder dataset(String newDataset) {
58-
dataset = newDataset;
59-
return this;
47+
private String host;
48+
private HttpTransport httpTransport;
49+
private HttpRequestInitializer httpRequestInitializer;
50+
private PrivateKey privateKey;
51+
52+
public Builder() {}
53+
54+
protected Builder(ServiceOptions options) {
55+
host = options.host;
56+
httpTransport = options.httpTransport;
57+
httpRequestInitializer = options.httpRequestInitializer;
6058
}
6159

62-
/**
63-
* Sets the host used to access the datastore.
64-
*/
65-
public Builder host(String newHost) {
66-
host = newHost;
60+
protected abstract ServiceOptions build();
61+
62+
public Builder setHost(String host) {
63+
this.host = host;
6764
return this;
6865
}
6966

70-
/**
71-
* Sets the (optional) initializer to run on HTTP requests to the API.
72-
*/
73-
public Builder initializer(HttpRequestInitializer newInitializer) {
74-
initializer = newInitializer;
67+
public Builder setHttpTransport(HttpTransport httpTransport) {
68+
this.httpTransport = httpTransport;
7569
return this;
7670
}
7771

78-
/**
79-
* Sets the Google APIs credentials used to access the API.
80-
*/
81-
public Builder credential(Credential newCredential) {
82-
credential = newCredential;
72+
public Builder setHttpRequestInitializer(HttpRequestInitializer httpRequestInitializer) {
73+
// TODO: replace HttpRequestInitializer with CrendentialProvider - 2 subclasses
74+
// one that is set with HttpRequestInitializer (and another that is set
75+
// with both private key and service account)
76+
// Also, consider instead of HttpRequestIntializer option to have "AppEngine" option
77+
// which will use reflection to create HttpRequestInitializer
78+
Preconditions.checkArgument(
79+
privateKey == null, "Can't set both PrivateKey and HttpRequestInitializer");
80+
this.httpRequestInitializer = httpRequestInitializer;
8381
return this;
8482
}
8583

86-
/**
87-
* Sets the transport used to access the API.
88-
*/
89-
public Builder transport(HttpTransport transport) {
90-
this.transport = transport;
84+
public Builder setPrivateKey(PrivateKey privateKey) {
85+
Preconditions.checkArgument(
86+
httpRequestInitializer == null, "Can't set both PrivateKey and HttpRequestInitializer");
87+
this.privateKey = privateKey;
9188
return this;
9289
}
9390
}
9491

95-
// === getters ===
96-
97-
public String getDataset() {
98-
return dataset;
99-
}
92+
protected abstract Set<String> getScopes();
10093

10194
public String getHost() {
10295
return host;
10396
}
10497

105-
public HttpRequestInitializer getInitializer() {
106-
return initializer;
107-
}
108-
109-
public Credential getCredential() {
110-
return credential;
98+
public HttpTransport getHttpTransport() {
99+
return httpTransport;
111100
}
112101

113-
public HttpTransport getTransport() {
114-
return transport;
102+
public HttpRequestInitializer getHttpRequestInitializer() {
103+
return httpRequestInitializer;
115104
}
116-
}
105+
}

src/main/java/com/google/gcloud/datastore/DatastoreService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public interface DatastoreService {
44

5-
String get(String key)
5+
String get(String key);
66

77
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.google.gcloud.datastore;
22

33

4-
public interface DatastoreServiceFactory {
4+
public class DatastoreServiceFactory {
55

6-
DatastoreService getDatastoreService(DatastoreServiceOptions options);
6+
public DatastoreService getDatastoreService(DatastoreServiceOptions options) {
7+
return new DatastoreServiceImpl(options);
8+
}
79
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.google.gcloud.datastore;
2+
3+
final class DatastoreServiceImpl implements DatastoreService {
4+
5+
private final DatastoreServiceOptions options;
6+
7+
DatastoreServiceImpl(DatastoreServiceOptions options) {
8+
this.options = options;
9+
}
10+
11+
@Override
12+
public String get(String key) {
13+
// TODO Auto-generated method stub
14+
return null;
15+
}
16+
17+
}

0 commit comments

Comments
 (0)