Skip to content

Commit 3e7069a

Browse files
committed
Addressed codacy issues in DNS.
* Addressed codacy issues in DNS. This includes - removing static formatter from example - removing and unifying imports and full qualification - removing unused serializable import from Dns - replacing assert not true with assertFalse in ITDnsTest - removing unused method from LocalDnsHelperTest. * Fixed some other minor issues: - added joda formatter to example - style in ZoneTest - visibility in LocalDnsHelper - added private constructor to OptionParsers - adjusted pom.xml * Unified imports of model objects.
1 parent 25ccf08 commit 3e7069a

File tree

18 files changed

+85
-91
lines changed

18 files changed

+85
-91
lines changed

gcloud-java-dns/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<groupId>com.google.gcloud</groupId>
76
<artifactId>gcloud-java-dns</artifactId>
87
<packaging>jar</packaging>
98
<name>GCloud Java DNS</name>

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ChangeRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static ChangeRequest fromPb(Dns dns, String zoneName, Change pb) {
221221
static Function<Change, ChangeRequest> fromPbFunction(final Dns dns, final String zoneName) {
222222
return new Function<Change, ChangeRequest>() {
223223
@Override
224-
public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
224+
public ChangeRequest apply(Change pb) {
225225
return ChangeRequest.fromPb(dns, zoneName, pb);
226226
}
227227
};

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.gcloud.Service;
2424
import com.google.gcloud.dns.spi.DnsRpc;
2525

26-
import java.io.Serializable;
2726
import java.util.List;
2827

2928
/**

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsImpl.java

+29-32
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
package com.google.gcloud.dns;
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
20-
import static com.google.gcloud.RetryHelper.RetryHelperException;
2120
import static com.google.gcloud.RetryHelper.runWithRetries;
2221

2322
import com.google.api.services.dns.model.Change;
2423
import com.google.api.services.dns.model.ManagedZone;
24+
import com.google.api.services.dns.model.Project;
2525
import com.google.api.services.dns.model.ResourceRecordSet;
2626
import com.google.common.base.Function;
2727
import com.google.common.collect.ImmutableList;
@@ -121,8 +121,7 @@ private static Page<Zone> listZones(final DnsOptions serviceOptions,
121121
// this differs from the other list operations since zone is functional and requires dns service
122122
Function<ManagedZone, Zone> pbToZoneFunction = new Function<ManagedZone, Zone>() {
123123
@Override
124-
public Zone apply(
125-
com.google.api.services.dns.model.ManagedZone zonePb) {
124+
public Zone apply(ManagedZone zonePb) {
126125
return Zone.fromPb(serviceOptions.service(), zonePb);
127126
}
128127
};
@@ -142,7 +141,7 @@ public DnsRpc.ListResult<ManagedZone> call() {
142141
? ImmutableList.<Zone>of() : Iterables.transform(result.results(), pbToZoneFunction);
143142
return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap),
144143
cursor, zones);
145-
} catch (RetryHelperException e) {
144+
} catch (RetryHelper.RetryHelperException e) {
146145
throw DnsException.translateAndThrow(e);
147146
}
148147
}
@@ -169,10 +168,10 @@ public DnsRpc.ListResult<Change> call() {
169168
Iterable<ChangeRequest> changes = result.results() == null
170169
? ImmutableList.<ChangeRequest>of()
171170
: Iterables.transform(result.results(),
172-
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
171+
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
173172
return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor,
174173
optionsMap), cursor, changes);
175-
} catch (RetryHelperException e) {
174+
} catch (RetryHelper.RetryHelperException e) {
176175
throw DnsException.translateAndThrow(e);
177176
}
178177
}
@@ -201,7 +200,7 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
201200
: Iterables.transform(result.results(), RecordSet.FROM_PB_FUNCTION);
202201
return new PageImpl<>(new DnsRecordPageFetcher(zoneName, serviceOptions, cursor, optionsMap),
203202
cursor, recordSets);
204-
} catch (RetryHelperException e) {
203+
} catch (RetryHelper.RetryHelperException e) {
205204
throw DnsException.translateAndThrow(e);
206205
}
207206
}
@@ -210,10 +209,10 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
210209
public Zone create(final ZoneInfo zoneInfo, Dns.ZoneOption... options) {
211210
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
212211
try {
213-
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
214-
new Callable<com.google.api.services.dns.model.ManagedZone>() {
212+
ManagedZone answer = runWithRetries(
213+
new Callable<ManagedZone>() {
215214
@Override
216-
public com.google.api.services.dns.model.ManagedZone call() {
215+
public ManagedZone call() {
217216
return dnsRpc.create(zoneInfo.toPb(), optionsMap);
218217
}
219218
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -227,10 +226,10 @@ public com.google.api.services.dns.model.ManagedZone call() {
227226
public Zone getZone(final String zoneName, Dns.ZoneOption... options) {
228227
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
229228
try {
230-
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
231-
new Callable<com.google.api.services.dns.model.ManagedZone>() {
229+
ManagedZone answer = runWithRetries(
230+
new Callable<ManagedZone>() {
232231
@Override
233-
public com.google.api.services.dns.model.ManagedZone call() {
232+
public ManagedZone call() {
234233
return dnsRpc.getZone(zoneName, optionsMap);
235234
}
236235
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -258,10 +257,10 @@ public Boolean call() {
258257
public ProjectInfo getProject(Dns.ProjectOption... fields) {
259258
final Map<DnsRpc.Option, ?> optionsMap = optionMap(fields);
260259
try {
261-
com.google.api.services.dns.model.Project answer = runWithRetries(
262-
new Callable<com.google.api.services.dns.model.Project>() {
260+
Project answer = runWithRetries(
261+
new Callable<Project>() {
263262
@Override
264-
public com.google.api.services.dns.model.Project call() {
263+
public Project call() {
265264
return dnsRpc.getProject(optionsMap);
266265
}
267266
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -276,14 +275,13 @@ public ChangeRequest applyChangeRequest(final String zoneName,
276275
final ChangeRequestInfo changeRequest, ChangeRequestOption... options) {
277276
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
278277
try {
279-
com.google.api.services.dns.model.Change answer =
280-
runWithRetries(
281-
new Callable<com.google.api.services.dns.model.Change>() {
282-
@Override
283-
public com.google.api.services.dns.model.Change call() {
284-
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
285-
}
286-
}, options().retryParams(), EXCEPTION_HANDLER);
278+
Change answer = runWithRetries(
279+
new Callable<Change>() {
280+
@Override
281+
public Change call() {
282+
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
283+
}
284+
}, options().retryParams(), EXCEPTION_HANDLER);
287285
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer); // not null
288286
} catch (RetryHelper.RetryHelperException ex) {
289287
throw DnsException.translateAndThrow(ex);
@@ -295,14 +293,13 @@ public ChangeRequest getChangeRequest(final String zoneName, final String change
295293
Dns.ChangeRequestOption... options) {
296294
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
297295
try {
298-
com.google.api.services.dns.model.Change answer =
299-
runWithRetries(
300-
new Callable<com.google.api.services.dns.model.Change>() {
301-
@Override
302-
public com.google.api.services.dns.model.Change call() {
303-
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
304-
}
305-
}, options().retryParams(), EXCEPTION_HANDLER);
296+
Change answer = runWithRetries(
297+
new Callable<Change>() {
298+
@Override
299+
public Change call() {
300+
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
301+
}
302+
}, options().retryParams(), EXCEPTION_HANDLER);
306303
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer);
307304
} catch (RetryHelper.RetryHelperException ex) {
308305
throw DnsException.translateAndThrow(ex);

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ProjectInfo.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.api.services.dns.model.Project;
2122
import com.google.common.base.MoreObjects;
2223

2324
import java.io.Serializable;
@@ -143,14 +144,13 @@ com.google.api.services.dns.model.Quota toPb() {
143144
}
144145

145146
static Quota fromPb(com.google.api.services.dns.model.Quota pb) {
146-
Quota quota = new Quota(pb.getManagedZones(),
147+
return new Quota(pb.getManagedZones(),
147148
pb.getResourceRecordsPerRrset(),
148149
pb.getRrsetAdditionsPerChange(),
149150
pb.getRrsetDeletionsPerChange(),
150151
pb.getRrsetsPerManagedZone(),
151152
pb.getTotalRrdataSizePerChange()
152153
);
153-
return quota;
154154
}
155155

156156
@Override
@@ -243,8 +243,8 @@ String id() {
243243
return id;
244244
}
245245

246-
com.google.api.services.dns.model.Project toPb() {
247-
com.google.api.services.dns.model.Project pb = new com.google.api.services.dns.model.Project();
246+
Project toPb() {
247+
Project pb = new Project();
248248
pb.setId(id);
249249
pb.setNumber(number);
250250
if (this.quota != null) {
@@ -253,7 +253,7 @@ com.google.api.services.dns.model.Project toPb() {
253253
return pb;
254254
}
255255

256-
static ProjectInfo fromPb(com.google.api.services.dns.model.Project pb) {
256+
static ProjectInfo fromPb(Project pb) {
257257
Builder builder = builder();
258258
if (pb.getId() != null) {
259259
builder.id(pb.getId());

gcloud-java-dns/src/main/java/com/google/gcloud/dns/RecordSet.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,16 @@ public boolean equals(Object obj) {
285285
return obj instanceof RecordSet && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
286286
}
287287

288-
com.google.api.services.dns.model.ResourceRecordSet toPb() {
289-
com.google.api.services.dns.model.ResourceRecordSet pb =
290-
new com.google.api.services.dns.model.ResourceRecordSet();
288+
ResourceRecordSet toPb() {
289+
ResourceRecordSet pb = new ResourceRecordSet();
291290
pb.setName(this.name());
292291
pb.setRrdatas(this.records());
293292
pb.setTtl(this.ttl());
294293
pb.setType(this.type().name());
295294
return pb;
296295
}
297296

298-
static RecordSet fromPb(com.google.api.services.dns.model.ResourceRecordSet pb) {
297+
static RecordSet fromPb(ResourceRecordSet pb) {
299298
Builder builder = builder(pb.getName(), Type.valueOf(pb.getType()));
300299
if (pb.getRrdatas() != null) {
301300
builder.records(pb.getRrdatas());

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.api.services.dns.model.ManagedZone;
2122
import com.google.gcloud.Page;
2223

2324
import java.io.IOException;
@@ -205,12 +206,12 @@ public int hashCode() {
205206
return Objects.hash(super.hashCode(), options);
206207
}
207208

208-
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
209-
in.defaultReadObject();
209+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
210+
stream.defaultReadObject();
210211
this.dns = options.service();
211212
}
212213

213-
static Zone fromPb(Dns dns, com.google.api.services.dns.model.ManagedZone zone) {
214+
static Zone fromPb(Dns dns, ManagedZone zone) {
214215
ZoneInfo info = ZoneInfo.fromPb(zone);
215216
return new Zone(dns, new ZoneInfo.BuilderImpl(info));
216217
}

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ZoneInfo.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.api.services.dns.model.ManagedZone;
2122
import com.google.common.base.MoreObjects;
2223
import com.google.common.collect.ImmutableList;
2324
import com.google.common.collect.Lists;
@@ -248,9 +249,9 @@ public Builder toBuilder() {
248249
return new BuilderImpl(this);
249250
}
250251

251-
com.google.api.services.dns.model.ManagedZone toPb() {
252-
com.google.api.services.dns.model.ManagedZone pb =
253-
new com.google.api.services.dns.model.ManagedZone();
252+
ManagedZone toPb() {
253+
ManagedZone pb =
254+
new ManagedZone();
254255
pb.setDescription(this.description());
255256
pb.setDnsName(this.dnsName());
256257
if (this.generatedId() != null) {
@@ -267,7 +268,7 @@ com.google.api.services.dns.model.ManagedZone toPb() {
267268
return pb;
268269
}
269270

270-
static ZoneInfo fromPb(com.google.api.services.dns.model.ManagedZone pb) {
271+
static ZoneInfo fromPb(ManagedZone pb) {
271272
Builder builder = new BuilderImpl(pb.getName());
272273
if (pb.getDescription() != null) {
273274
builder.description(pb.getDescription());

gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/LocalDnsHelper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public class LocalDnsHelper {
122122
}
123123
}
124124

125-
private long delayChange;
125+
private final long delayChange;
126126
private final HttpServer server;
127127
private final int port;
128128

@@ -140,8 +140,8 @@ private enum CallRegex {
140140
PROJECT_GET("GET", CONTEXT + "/[^/]+"),
141141
RECORD_LIST("GET", CONTEXT + "/[^/]+/managedZones/[^/]+/rrsets");
142142

143-
private String method;
144-
private String pathRegex;
143+
private final String method;
144+
private final String pathRegex;
145145

146146
CallRegex(String method, String pathRegex) {
147147
this.pathRegex = pathRegex;
@@ -382,7 +382,7 @@ ConcurrentSkipListMap<String, ProjectContainer> projects() {
382382
}
383383

384384
/**
385-
* Creates new {@link LocalDnsHelper} instance that listens to requests on the local machine. This
385+
* Creates new {@code LocalDnsHelper} instance that listens to requests on the local machine. This
386386
* instance processes changes in separate thread. The parameter determines how long a thread
387387
* should wait before processing a change. If it is set to 0, the threading is turned off and the
388388
* mock will behave synchronously.

gcloud-java-dns/src/main/java/com/google/gcloud/dns/testing/OptionParsers.java

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
*/
3030
class OptionParsers {
3131

32+
private OptionParsers() {
33+
}
34+
3235
static Map<String, Object> parseListZonesOptions(String query) {
3336
Map<String, Object> options = new HashMap<>();
3437
if (query != null) {

gcloud-java-dns/src/test/java/com/google/gcloud/dns/ChangeRequestInfoTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.assertTrue;
2424
import static org.junit.Assert.fail;
2525

26+
import com.google.api.services.dns.model.Change;
2627
import com.google.common.collect.ImmutableList;
2728

2829
import org.junit.Test;
@@ -209,7 +210,7 @@ public void testRemoveDeletion() {
209210
@Test
210211
public void testDateParsing() {
211212
String startTime = "2016-01-26T18:33:43.512Z"; // obtained from service
212-
com.google.api.services.dns.model.Change change = CHANGE.toPb().setStartTime(startTime);
213+
Change change = CHANGE.toPb().setStartTime(startTime);
213214
ChangeRequestInfo converted = ChangeRequest.fromPb(change);
214215
assertNotNull(converted.startTimeMillis());
215216
assertEquals(change, converted.toPb());

gcloud-java-dns/src/test/java/com/google/gcloud/dns/DnsImplTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.api.services.dns.model.Change;
2323
import com.google.api.services.dns.model.ManagedZone;
24+
import com.google.api.services.dns.model.ResourceRecordSet;
2425
import com.google.common.collect.ImmutableList;
2526
import com.google.common.collect.ImmutableMap;
2627
import com.google.common.collect.Lists;
@@ -69,8 +70,7 @@ public class DnsImplTest {
6970
CHANGE_REQUEST_PARTIAL.toPb()));
7071
private static final DnsRpc.ListResult<ManagedZone> LIST_RESULT_OF_PB_ZONES =
7172
DnsRpc.ListResult.of("cursor", ImmutableList.of(ZONE_INFO.toPb()));
72-
private static final DnsRpc.ListResult<com.google.api.services.dns.model.ResourceRecordSet>
73-
LIST_OF_PB_DNS_RECORDS =
73+
private static final DnsRpc.ListResult<ResourceRecordSet> LIST_OF_PB_DNS_RECORDS =
7474
DnsRpc.ListResult.of("cursor", ImmutableList.of(DNS_RECORD1.toPb(), DNS_RECORD2.toPb()));
7575

7676
// Field options

0 commit comments

Comments
 (0)