Skip to content

Commit

Permalink
LGTM fixes
Browse files Browse the repository at this point in the history
Thank god, mostly formatting
  • Loading branch information
pkriens committed Apr 14, 2021
1 parent 3866d44 commit 339f959
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 81 deletions.
3 changes: 2 additions & 1 deletion biz.aQute.api/src/main/java/biz/aQute/result/Result.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package biz.aQute.result;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Expand All @@ -26,7 +27,7 @@ public static <X> Result<X> error(String format, Object... args) {
}
return new Result<X>(String.format(format, args));
} catch (Exception e) {
return new Result<X>(format + ": " + args);
return new Result<X>(format + ": " + Arrays.toString(args));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ public boolean forget(String userid) {
private String verify(String id, String pw) throws Exception {
Role role = userAdmin.getRole(id);
if (role == null) {
log.info("Failed login attempt for %s: no such user", id);
log.info("Failed login attempt for {}: no such user", id);
return null;
}

if (!(role instanceof User)) {
log.info("Failed login attempt for %s: id is not a user name but %s", id, role);
log.info("Failed login attempt for {}: id is not a user name but {}", id, role);
return null;
}

Expand All @@ -149,11 +149,11 @@ private String verify(String id, String pw) throws Exception {
return id;

if (root != null && root.equals(hash)) {
log.info("Root login by %s", id);
log.info("Root login by {}", id);
return id;
}

log.info("Failed login attempt for %s: invalid password", id);
log.info("Failed login attempt for {}: invalid password", id);
return null;
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public List<Role> role(String... filter) throws InvalidSyntaxException {
getRoles(roles, f);
} else {
Role r = userAdmin.getRole(f);
if (f != null)
if (r != null)
roles.add(r);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ String[] getPath(int n) {

void verifyCycle(Object o) {
if (isCycle(o)) {
throw new IllegalArgumentException("Cycle in DTO " + getPath(0));
throw new IllegalArgumentException("Cycle in DTO " + Arrays.toString(getPath(0)));
}
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ private boolean diff(List<Difference> diffs, Link link, Object older, Object new
diffs.add(new Diff(Reason.UNEQUAL, link));
return true;
} catch (Exception e) {
logger.warn("failed to diff %s to %s : %s", older, newer, e.getMessage(), e);
logger.warn("failed to diff {} to {} : {}", older, newer, e.getMessage(), e);
throw Exceptions.duck(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ class Number {
if (isPrintable(c)) {
return c.toString();
}
return String.format("\\u04X", (char) c);
return String.format("\\u%04X", (char) c);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public String inspect() {
f.format("DESCRIPTION\n");
f.format("\t1%s\n", topDescription);
}
f.format("\u2007\nSYNOPSIS\n", name);
f.format("\u2007\nSYNOPSIS %s\n", name);
for (Method m : methods) {
f.format("\t1%s", name);
String description = Help.getDescription(m);
Expand Down Expand Up @@ -389,15 +389,15 @@ private static int[] tabs(int width) {
}

private static Properties getResource(String path, Class<?> clazz) {
try {
InputStream in = clazz.getResourceAsStream(path);
try (InputStream in = clazz.getResourceAsStream(path)) {
if (in == null)
return null;

InputStreamReader rd = new InputStreamReader(in);
Properties p = new Properties();
p.load(rd);
return p;
try (InputStreamReader rd = new InputStreamReader(in)) {
Properties p = new Properties();
p.load(rd);
return p;
}
} catch (Exception e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public KibanaLogUploader(@Reference LogReaderService reader, Configuration confi
super("aQute.kibana");
reader.addLogListener(this::log);
this.index = configuration.index();
this.delay = configuration.delay() * 1000;
this.delay = configuration.delay() * 1000L;
for (String s : configuration.hosts()) {
uris.add(new URI(s));
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public void run() {
if (dtos.size() > 500)
dtos.subList(500, dtos.size()).clear();
}
Thread.sleep(1000 * failures);
Thread.sleep(1000L * failures);
} catch (InterruptedException ee) {
this.interrupt();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public PDU putU16(int v) {
}

public PDU putU16(int relPosition, int v) {
if (v < 0 && v > 0xFFFF) {
if (v < 0 || v > 0xFFFF) {
throw new IllegalArgumentException("U8 >=0 && < 0x1_0000 : " + v);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void run() {
InputStream in = channel.getInputStream();
OutputStream out = channel.getOutputStream();
serve(in, out);
logger.info("Closing client {}");
logger.info("Closing client {}", channel.getRemoteSocketAddress());
} catch (SocketTimeoutException se) {
// ignore
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -104,7 +105,7 @@ private Access line(String l) {
try {
bank = Bank.valueOf(parts[0]);
} catch (IllegalArgumentException e0) {
error("invalid bank in %s, must be one of %s", trimmed, Bank.values());
error("invalid bank in %s, must be one of %s", trimmed, Arrays.toString(Bank.values()));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ class UpdateAgentImpl implements UpdateAgent, Runnable {
private URI configUrl;

enum Phase {
VETOED, COMMITTED, OK
VETOED,
COMMITTED,
OK
}

UpdateAgentImpl(BundleContext context, Executor executor, PackageAdmin packageAdmin, Downloader downloader,
DigestVerifier verifier)
throws Exception {
DigestVerifier verifier) throws Exception {
this.executor = executor;
this.packageAdmin = packageAdmin;
this.downloader = downloader;
Expand Down Expand Up @@ -134,7 +135,8 @@ void update() throws Exception {

ConfigDTO currentConfig = store.read();

ConfigDTO nextConfig = downloader.download(configUrl, ConfigDTO.class).getValue();
ConfigDTO nextConfig = downloader.download(configUrl, ConfigDTO.class)
.getValue();

Phase phase = update(nextConfig.bundles);
if (phase == Phase.OK) {
Expand Down Expand Up @@ -203,7 +205,7 @@ Phase update(List<BundleRefDTO> bundleDtos) throws InterruptedException {
} catch (Exception e) {
e.printStackTrace();
state = State.RETRY_WAIT;
Thread.sleep(10000 * (retry + 1));
Thread.sleep(10000L * (retry + 1));
}
}
return phase;
Expand All @@ -225,22 +227,21 @@ private void refresh() throws InterruptedException {
}

private List<Void> sync(List<Promise<Void>> list) throws InvocationTargetException, InterruptedException {
return Promises.all(list).getValue();
return Promises.all(list)
.getValue();
}

private List<Promise<Void>> forEach(List<BundleAction> actions,
Function<? super BundleAction, ? extends Promise<Void>> mapper) {
return actions
.stream()
.map(mapper)
.collect(Collectors.toList());
Function<? super BundleAction, ? extends Promise<Void>> mapper) {
return actions.stream()
.map(mapper)
.collect(Collectors.toList());
}

private List<BundleAction> compare(List<BundleRefDTO> bundles) throws IOException {
List<BundleAction> actions = new ArrayList<>();
Map<String, BundleRefDTO> index = bundles
.stream()
.collect(Collectors.toMap(brf -> brf.location, x -> x));
Map<String, BundleRefDTO> index = bundles.stream()
.collect(Collectors.toMap(brf -> brf.location, x -> x));

for (Bundle bundle : context.getBundles()) {

Expand Down Expand Up @@ -315,8 +316,7 @@ Promise<Void> stop() {
return Promises.resolved(null);
}

void commit() throws Exception {
}
void commit() throws Exception {}

Promise<Void> start() {
return Promises.resolved(null);
Expand Down Expand Up @@ -352,18 +352,19 @@ Promise<Void> prepare() {

@Override
void commit() throws Exception {
InputStream inputStream = result.getValue();
try (InputStream inputStream = result.getValue()) {

MessageDigest md = MessageDigest.getInstance("SHA-256");
inputStream = new DigestInputStream(inputStream, md);
MessageDigest md = MessageDigest.getInstance("SHA-256");
DigestInputStream inputStream2 = new DigestInputStream(inputStream, md);

bundle = doAction(inputStream);
bundle = doAction(inputStream2);

if (!Arrays.equals(md.digest(), ref.digest)) {
bundle.uninstall();
throw new IllegalArgumentException("Invalid digest " + ref + " is " + Arrays.toString(ref.digest));
if (!Arrays.equals(md.digest(), ref.digest)) {
bundle.uninstall();
throw new IllegalArgumentException("Invalid digest " + ref + " is " + Arrays.toString(ref.digest));
}
verifier.updateDigest(bundle, ref.digest);
}
verifier.updateDigest(bundle, ref.digest);
}

protected Bundle doAction(InputStream inputStream) throws BundleException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,28 @@ public class LoggerFactory implements Closeable {
public void log(ServiceReference ref, int level,
String msg,
Throwable throwable) {
System.err.printf("%s:%s %s: %s\n", level(level),
System.err.printf("%s:%s:%s:%s\n", level(level),
ref,
throwable, msg);
msg, throwable);
}

@Override
public void log(ServiceReference ref, int level,
String msg) {
System.err.printf("%s:%s:%s: %s\n", level(level),
ref, msg);
System.err.printf("%s:%s:%s:\n", level(level), ref,
msg);
}

@Override
public void log(int level, String msg,
Throwable throwable) {
System.err.printf("%s:%s:%s: %s\n", level(level),
throwable,
msg);
System.err.printf("%s::%s:%s\n", level(level), msg,
throwable);
}

@Override
public void log(int level, String msg) {
System.err.printf("%s:%s:: %s\n", level(level),
System.err.printf("%s:::%s\n", level(level),
msg);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class AbstractGogoSshd {
void open() throws IOException {
sshd.start();
port = sshd.getPort();
logger.info("SshServer opened: %s", sshd.toString());
logger.info("SshServer opened: {}", sshd.toString());
}

private Command getCommand(CommandProcessor processor) {
Expand Down
Loading

0 comments on commit 339f959

Please sign in to comment.