mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Code cleanup
This commit is contained in:
parent
88e8019419
commit
fbb61ffd3c
@ -67,7 +67,7 @@ public class GZippedJsonDownloader {
|
||||
os = new FileOutputStream(tmpFile);
|
||||
gzipIs = new GzipCompressorInputStream(new FileInputStream(gzipTmpFile));
|
||||
final byte[] buffer = new byte[4096];
|
||||
int n = 0;
|
||||
int n;
|
||||
while (-1 != (n = gzipIs.read(buffer))) {
|
||||
os.write(buffer, 0, n);
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ public class JsonDownloader {
|
||||
downloader.download(url, tmpFile, progress, statusText);
|
||||
} catch (InterruptedException e) {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
||||
String thisVersion = getParsedVersion();
|
||||
String otherVersion = ((ContributedLibrary) obj).getParsedVersion();
|
||||
|
||||
boolean versionEquals = thisVersion == otherVersion || (thisVersion != null && otherVersion != null && thisVersion.equals(otherVersion));
|
||||
boolean versionEquals = thisVersion != null && otherVersion != null && thisVersion.equals(otherVersion);
|
||||
|
||||
String thisName = getName();
|
||||
String otherName = ((ContributedLibrary) obj).getName();
|
||||
|
@ -79,7 +79,6 @@ public class LibraryInstaller {
|
||||
final MultiStepProgress progress = new MultiStepProgress(2);
|
||||
|
||||
// Step 1: Download index
|
||||
URL url = new URL(LIBRARY_INDEX_URL);
|
||||
File outputFile = indexer.getIndexFile();
|
||||
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
|
||||
try {
|
||||
|
@ -56,15 +56,15 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
||||
|
||||
public NetworkDiscovery() {
|
||||
DNSTaskStarter.Factory.setClassDelegate(new ArduinoDNSTaskStarter());
|
||||
this.boardPortsDiscoveredWithJmDNS = new LinkedList<BoardPort>();
|
||||
this.mappedJmDNSs = new Hashtable<InetAddress, JmDNS>();
|
||||
this.reachableBoardPorts = new LinkedList<BoardPort>();
|
||||
this.boardPortsDiscoveredWithJmDNS = new LinkedList<>();
|
||||
this.mappedJmDNSs = new Hashtable<>();
|
||||
this.reachableBoardPorts = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardPort> listDiscoveredBoards() {
|
||||
synchronized (reachableBoardPorts) {
|
||||
return new LinkedList<BoardPort>(reachableBoardPorts);
|
||||
return new LinkedList<>(reachableBoardPorts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
||||
|
||||
public List<BoardPort> getBoardPortsDiscoveredWithJmDNS() {
|
||||
synchronized (boardPortsDiscoveredWithJmDNS) {
|
||||
return new LinkedList<BoardPort>(boardPortsDiscoveredWithJmDNS);
|
||||
return new LinkedList<>(boardPortsDiscoveredWithJmDNS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,11 +114,7 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
||||
public void serviceRemoved(ServiceEvent serviceEvent) {
|
||||
String name = serviceEvent.getName();
|
||||
synchronized (boardPortsDiscoveredWithJmDNS) {
|
||||
for (BoardPort port : boardPortsDiscoveredWithJmDNS) {
|
||||
if (port.getBoardName().equals(name)) {
|
||||
boardPortsDiscoveredWithJmDNS.remove(port);
|
||||
}
|
||||
}
|
||||
boardPortsDiscoveredWithJmDNS.stream().filter(port -> port.getBoardName().equals(name)).forEach(boardPortsDiscoveredWithJmDNS::remove);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class SerialDiscovery implements Discovery {
|
||||
private final List<BoardPort> serialBoardPorts;
|
||||
|
||||
public SerialDiscovery() {
|
||||
this.serialBoardPorts = new LinkedList<BoardPort>();
|
||||
this.serialBoardPorts = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,9 +51,9 @@ public class SerialDiscovery implements Discovery {
|
||||
return getSerialBoardPorts();
|
||||
}
|
||||
|
||||
public List<BoardPort> getSerialBoardPorts() {
|
||||
private List<BoardPort> getSerialBoardPorts() {
|
||||
synchronized (serialBoardPorts) {
|
||||
return new LinkedList<BoardPort>(serialBoardPorts);
|
||||
return new LinkedList<>(serialBoardPorts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class BoardReachabilityFilter extends TimerTask {
|
||||
InetAddress inetAddress = InetAddress.getByName(board.getAddress());
|
||||
int broadcastedPort = Integer.valueOf(board.getPrefs().get("port"));
|
||||
|
||||
List<Integer> ports = new LinkedList<Integer>();
|
||||
List<Integer> ports = new LinkedList<>();
|
||||
ports.add(broadcastedPort);
|
||||
|
||||
//dirty code: allows non up to date yuns to be discovered. Newer yuns will broadcast port 22
|
||||
|
@ -44,7 +44,7 @@ public class NetworkChecker extends TimerTask {
|
||||
super();
|
||||
this.topologyListener = topologyListener;
|
||||
this.topology = topology;
|
||||
this.knownAddresses = Collections.synchronizedSet(new HashSet<InetAddress>());
|
||||
this.knownAddresses = Collections.synchronizedSet(new HashSet<>());
|
||||
}
|
||||
|
||||
public void start(Timer timer) {
|
||||
@ -55,18 +55,14 @@ public class NetworkChecker extends TimerTask {
|
||||
public void run() {
|
||||
try {
|
||||
InetAddress[] curentAddresses = topology.getInetAddresses();
|
||||
Set<InetAddress> current = new HashSet<InetAddress>(curentAddresses.length);
|
||||
Set<InetAddress> current = new HashSet<>(curentAddresses.length);
|
||||
for (InetAddress address : curentAddresses) {
|
||||
current.add(address);
|
||||
if (!knownAddresses.contains(address)) {
|
||||
topologyListener.inetAddressAdded(address);
|
||||
}
|
||||
}
|
||||
for (InetAddress address : knownAddresses) {
|
||||
if (!current.contains(address)) {
|
||||
topologyListener.inetAddressRemoved(address);
|
||||
}
|
||||
}
|
||||
knownAddresses.stream().filter(address -> !current.contains(address)).forEach(topologyListener::inetAddressRemoved);
|
||||
knownAddresses = current;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -66,7 +66,7 @@ public class SerialBoardsLister extends TimerTask {
|
||||
return;
|
||||
}
|
||||
|
||||
List<BoardPort> boardPorts = new LinkedList<BoardPort>();
|
||||
List<BoardPort> boardPorts = new LinkedList<>();
|
||||
|
||||
List<String> ports = Serial.list();
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class SCP extends SSH {
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
IOUtils.closeQuietly(out);
|
||||
IOUtils.closeQuietly(in);
|
||||
if (channel != null) {
|
||||
@ -69,7 +69,7 @@ public class SCP extends SSH {
|
||||
}
|
||||
}
|
||||
|
||||
protected void ensureAcknowledged() throws IOException {
|
||||
private void ensureAcknowledged() throws IOException {
|
||||
out.flush();
|
||||
|
||||
int b = in.read();
|
||||
|
@ -41,7 +41,7 @@ import java.io.PrintStream;
|
||||
|
||||
public class SSH {
|
||||
|
||||
protected final Session session;
|
||||
final Session session;
|
||||
|
||||
public SSH(Session session) {
|
||||
this.session = session;
|
||||
@ -79,7 +79,7 @@ public class SSH {
|
||||
}
|
||||
}
|
||||
|
||||
protected int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream stdout, PrintStream stdoutConsumer, InputStream stderr, PrintStream stderrConsumer) throws IOException {
|
||||
private int consumeOutputSyncAndReturnExitCode(Channel channel, InputStream stdout, PrintStream stdoutConsumer, InputStream stderr, PrintStream stderrConsumer) throws IOException {
|
||||
byte[] tmp = new byte[102400];
|
||||
while (true) {
|
||||
consumeStream(tmp, stdout, stdoutConsumer);
|
||||
@ -96,7 +96,7 @@ public class SSH {
|
||||
}
|
||||
}
|
||||
|
||||
protected void consumeStream(byte[] buffer, InputStream in, PrintStream out) throws IOException {
|
||||
private void consumeStream(byte[] buffer, InputStream in, PrintStream out) throws IOException {
|
||||
while (in.available() > 0) {
|
||||
int length = in.read(buffer, 0, buffer.length);
|
||||
if (length < 0) {
|
||||
|
@ -75,7 +75,10 @@ public class SSHUploader extends Uploader {
|
||||
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
prefs.putAll(BaseNoGui.getBoardPreferences());
|
||||
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
|
||||
if (boardPreferences != null) {
|
||||
prefs.putAll(boardPreferences);
|
||||
}
|
||||
String tool = prefs.getOrExcept("upload.tool");
|
||||
if (tool.contains(":")) {
|
||||
String[] split = tool.split(":", 2);
|
||||
@ -136,11 +139,7 @@ public class SSHUploader extends Uploader {
|
||||
throw new RunnerException(e);
|
||||
} finally {
|
||||
if (scp != null) {
|
||||
try {
|
||||
scp.close();
|
||||
} catch (IOException e) {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
scp.close();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
|
@ -204,7 +204,7 @@ public class SerialUploader extends Uploader {
|
||||
int elapsed = 0;
|
||||
while (elapsed < 10000) {
|
||||
List<String> now = Serial.list();
|
||||
List<String> diff = new ArrayList<String>(now);
|
||||
List<String> diff = new ArrayList<>(now);
|
||||
diff.removeAll(before);
|
||||
if (verbose) {
|
||||
System.out.print("PORTS {");
|
||||
@ -245,7 +245,7 @@ public class SerialUploader extends Uploader {
|
||||
throw new RunnerException(_("Couldn't find a Board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload."));
|
||||
}
|
||||
|
||||
public boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
|
||||
private boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {
|
||||
|
||||
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
|
||||
String programmer = PreferencesData.get("programmer");
|
||||
|
Loading…
x
Reference in New Issue
Block a user