Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="lib" path="lib/apple.jar"/>
<classpathentry kind="lib" path="lib/batik-1.8.jar"/>
<classpathentry kind="lib" path="lib/batik-anim-1.8.jar"/>
Expand Down Expand Up @@ -53,4 +52,5 @@
<classpathentry kind="lib" path="test-lib/fest-swing-1.2.jar"/>
<classpathentry kind="lib" path="test-lib/fest-util-1.1.2.jar"/>
<classpathentry kind="lib" path="test-lib/jcip-annotations-1.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
10 changes: 6 additions & 4 deletions app/src/cc/arduino/contributions/BuiltInCoreIsNewerCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@

package cc.arduino.contributions;

import cc.arduino.contributions.packages.ContributedPackage;
import cc.arduino.contributions.packages.ContributedPlatform;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;

import javax.swing.*;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -66,14 +68,14 @@ private void builtInPackageIsNewerCheck() throws InterruptedException {

List<ContributedPlatform> contributedPlatforms = BaseNoGui.indexer
.getPackages().stream() //
.map(pack -> pack.getPlatforms()) //
.flatMap(platfs -> platfs.stream()) //
.map(ContributedPackage::getPlatforms) //
.flatMap(Collection::stream) //
.collect(Collectors.toList());

Optional<ContributedPlatform> mayInstalledBuiltIn = contributedPlatforms
.stream() //
.filter(p -> p.isInstalled()) //
.filter(p -> p.isBuiltIn()) //
.filter(ContributedPlatform::isInstalled) //
.filter(ContributedPlatform::isBuiltIn) //
.findFirst();
if (!mayInstalledBuiltIn.isPresent()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public int compare(ContributedLibraryReleases o1, ContributedLibraryReleases o2)
ContributedLibrary lib1 = o1.getLatest();
ContributedLibrary lib2 = o2.getLatest();

if (lib1.getTypes() == null || lib2.getTypes() == null) {
if ((lib1.getTypes() == null) || (lib2.getTypes() == null)) {
return compareName(lib1, lib2);
}
if (lib1.getTypes().contains(firstType) && lib2.getTypes().contains(firstType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ public String toString() {

@Override
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
return new Predicate<ContributedLibraryReleases>() {
@Override
public boolean test(ContributedLibraryReleases t) {
return t.getInstalled().isPresent();
}
};
return t -> t.getInstalled().isPresent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ public String toString() {

@Override
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
return new Predicate<ContributedLibraryReleases>() {
@Override
public boolean test(ContributedLibraryReleases rel) {
ContributedLibrary lib = rel.getLatest();
return category.equals(lib.getCategory());
}
return rel -> {
ContributedLibrary lib = rel.getLatest();
return category.equals(lib.getCategory());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ public String toString() {

@Override
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
return new Predicate<ContributedLibraryReleases>() {
@Override
public boolean test(ContributedLibraryReleases lib) {
List<String> types = lib.getLatest().getTypes();
return types != null && types.contains(type);
}
return lib -> {
List<String> types = lib.getLatest().getTypes();
return types != null && types.contains(type);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@ public class DropdownUpdatableLibrariesItem implements DropdownItem<ContributedL

@Override
public Predicate<ContributedLibraryReleases> getFilterPredicate() {
return new Predicate<ContributedLibraryReleases>() {
@Override
public boolean test(ContributedLibraryReleases lib) {
Optional<ContributedLibrary> mayInstalled = lib.getInstalled();
if (!mayInstalled.isPresent()) {
return false;
}
return !lib.getLatest().equals(mayInstalled.get());
}
return lib -> {
Optional<ContributedLibrary> mayInstalled = lib.getInstalled();
return mayInstalled.filter(contributedLibrary -> !lib.getLatest().equals(contributedLibrary)).isPresent();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public boolean test(ContributedPlatform contributedPlatform) {
}

List<ContributedPlatform> platforms = BaseNoGui.indexer.getIndex().findPlatforms(packageName, architecture);
return platforms.stream()
.filter(platform -> VersionComparator.greaterThan(platform.getParsedVersion(), installed.getParsedVersion()))
.count() > 0;
return platforms.stream().anyMatch(platform -> VersionComparator.greaterThan(platform.getParsedVersion(), installed.getParsedVersion()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void add(ContributedPlatform platform) {

public ContributedPlatform getInstalled() {
List<ContributedPlatform> installedReleases = releases.stream()
.filter(p -> p.isInstalled()) //
.filter(ContributedPlatform::isInstalled) //
.collect(Collectors.toList());
Collections.sort(installedReleases, ContributedPlatform.BUILTIN_AS_LAST);
installedReleases.sort(ContributedPlatform.BUILTIN_AS_LAST);

if (installedReleases.isEmpty()) {
return null;
Expand All @@ -97,4 +97,4 @@ public void select(ContributedPlatform value) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public Component getTableCellEditorComponent(JTable table, Object _value,
.collect(Collectors.toList());

List<ContributedPlatform> installedBuiltIn = releases.stream() //
.filter(p -> p.isInstalled()) //
.filter(p -> p.isBuiltIn()) //
.filter(ContributedPlatform::isInstalled) //
.filter(ContributedPlatform::isBuiltIn) //
.collect(Collectors.toList());

if (installed != null && !installedBuiltIn.contains(installed)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
public static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
contribs = new LinkedList<>(contribs);
final VersionComparator versionComparator = new VersionComparator();
Collections.sort(contribs, (contrib1, contrib2) -> versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion()));
contribs.sort((contrib1, contrib2) -> versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion()));

if (contribs.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.awt.event.WindowEvent;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collectors;

import static processing.app.I18n.tr;
Expand Down Expand Up @@ -173,7 +174,7 @@ private void unofficialListURLLabelMouseClicked(java.awt.event.MouseEvent evt) {

public void setText(String text) {
Collection<String> urls = splitAndTrim(text, ",");
additionalBoardsManagerURLs.setText(urls.stream().filter(s -> s != null).collect(Collectors.joining("\n")));
additionalBoardsManagerURLs.setText(urls.stream().filter(Objects::nonNull).collect(Collectors.joining("\n")));
}

private Collection<String> splitAndTrim(String text, String separator) {
Expand All @@ -183,7 +184,7 @@ private Collection<String> splitAndTrim(String text, String separator) {

public String getText() {
Collection<String> urls = splitAndTrim(additionalBoardsManagerURLs.getText(), "\n");
return urls.stream().filter(s -> s != null).collect(Collectors.joining(","));
return urls.stream().filter(Objects::nonNull).collect(Collectors.joining(","));
}

// Variables declaration - do not modify//GEN-BEGIN:variables
Expand Down
14 changes: 4 additions & 10 deletions app/src/processing/app/AbstractTextMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,17 @@ public void windowGainedFocus(WindowEvent e) {
noLineEndingAlert.setMinimumSize(minimumSize);

lineEndings = new JComboBox(new String[]{tr("No line ending"), tr("Newline"), tr("Carriage return"), tr("Both NL & CR")});
lineEndings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
noLineEndingAlert.setForeground(pane.getBackground());
}
lineEndings.addActionListener(event -> {
PreferencesData.setInteger("serial.line_ending", lineEndings.getSelectedIndex());
noLineEndingAlert.setForeground(pane.getBackground());
});
if (PreferencesData.get("serial.line_ending") != null) {
lineEndings.setSelectedIndex(PreferencesData.getInteger("serial.line_ending"));
}
if (PreferencesData.get("serial.show_timestamp") != null) {
addTimeStampBox.setSelected(PreferencesData.getBoolean("serial.show_timestamp"));
}
addTimeStampBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected());
}
});
addTimeStampBox.addActionListener(e -> PreferencesData.setBoolean("serial.show_timestamp", addTimeStampBox.isSelected()));

lineEndings.setMaximumSize(lineEndings.getMinimumSize());

Expand Down
90 changes: 38 additions & 52 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,11 @@ public boolean add(File file) {
recentSketchesMenuItems.clear();
for (final File recentSketch : recentSketches) {
JMenuItem recentSketchMenuItem = new JMenuItem(recentSketch.getParentFile().getName());
recentSketchMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
try {
handleOpen(recentSketch);
} catch (Exception e) {
e.printStackTrace();
}
recentSketchMenuItem.addActionListener(actionEvent -> {
try {
handleOpen(recentSketch);
} catch (Exception e) {
e.printStackTrace();
}
});
recentSketchesMenuItems.add(recentSketchMenuItem);
Expand Down Expand Up @@ -1012,13 +1009,11 @@ protected boolean handleQuitEach() {
public void rebuildSketchbookMenus() {
//System.out.println("async enter");
//new Exception().printStackTrace();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//System.out.println("starting rebuild");
rebuildSketchbookMenu(Editor.sketchbookMenu);
rebuildToolbarMenu(Editor.toolbarMenu);
//System.out.println("done with rebuild");
}
SwingUtilities.invokeLater(() -> {
//System.out.println("starting rebuild");
rebuildSketchbookMenu(Editor.sketchbookMenu);
rebuildToolbarMenu(Editor.toolbarMenu);
//System.out.println("done with rebuild");
});
//System.out.println("async exit");
}
Expand All @@ -1030,13 +1025,11 @@ protected void rebuildToolbarMenu(JMenu menu) {

// Add the single "Open" item
item = Editor.newJMenuItem(tr("Open..."), 'O');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
handleOpenPrompt();
} catch (Exception e1) {
e1.printStackTrace();
}
item.addActionListener(e -> {
try {
handleOpenPrompt();
} catch (Exception e1) {
e1.printStackTrace();
}
});
menu.add(item);
Expand Down Expand Up @@ -1072,6 +1065,7 @@ private LibraryList getSortedLibraries() {
return installedLibraries;
}

@SuppressWarnings("MagicConstant")
public void rebuildImportMenu(JMenu importMenu) {
if (importMenu == null)
return;
Expand All @@ -1087,14 +1081,12 @@ public void rebuildImportMenu(JMenu importMenu) {
importMenu.addSeparator();

JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library..."));
addLibraryMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.this.handleAddLibrary();
BaseNoGui.librariesIndexer.rescanLibraries();
Base.this.onBoardOrPortChange();
Base.this.rebuildImportMenu(Editor.importMenu);
Base.this.rebuildExamplesMenu(Editor.examplesMenu);
}
addLibraryMenuItem.addActionListener(e -> {
Base.this.handleAddLibrary();
BaseNoGui.librariesIndexer.rescanLibraries();
Base.this.onBoardOrPortChange();
Base.this.rebuildImportMenu(Editor.importMenu);
Base.this.rebuildExamplesMenu(Editor.examplesMenu);
});
importMenu.add(addLibraryMenuItem);
importMenu.addSeparator();
Expand Down Expand Up @@ -1679,12 +1671,7 @@ protected boolean addSketches(JMenu menu, File folder) {
if (files == null) return false;

// Alphabetize files, since it's not always alpha order
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File file, File file2) {
return file.getName().compareToIgnoreCase(file2.getName());
}
});
Arrays.sort(files, (file, file2) -> file.getName().compareToIgnoreCase(file2.getName()));

boolean ifound = false;

Expand All @@ -1709,22 +1696,20 @@ private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib) {

private boolean addSketchesSubmenu(JMenu menu, String name, File folder) {

ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String path = e.getActionCommand();
File file = new File(path);
if (file.exists()) {
try {
handleOpen(file);
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
showWarning(tr("Sketch Does Not Exist"),
tr("The selected sketch no longer exists.\n"
+ "You may need to restart Arduino to update\n"
+ "the sketchbook menu."), null);
ActionListener listener = e -> {
String path = e.getActionCommand();
File file = new File(path);
if (file.exists()) {
try {
handleOpen(file);
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
showWarning(tr("Sketch Does Not Exist"),
tr("The selected sketch no longer exists.\n"
+ "You may need to restart Arduino to update\n"
+ "the sketchbook menu."), null);
}
};

Expand Down Expand Up @@ -2273,7 +2258,8 @@ public void handleAddLibrary() {
ZipDeflater zipDeflater = new ZipDeflater(sourceFile, tmpFolder);
zipDeflater.deflate();
File[] foldersInTmpFolder = tmpFolder.listFiles(new OnlyDirs());
if (foldersInTmpFolder.length != 1) {
/*if (Objects.requireNonNull(foldersInTmpFolder).length != 1) {*/
if (foldersInTmpFolder != null && foldersInTmpFolder.length != 1) {
throw new IOException(tr("Zip doesn't contain a library"));
}
sourceFile = foldersInTmpFolder[0];
Expand Down
Loading