1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Propagate fixes for Arduino from CDT 9.0 to master.

Change-Id: If7d02530ba46f01f7f58724cba7b4921b93ca895
This commit is contained in:
Doug Schaefer 2016-08-09 15:52:10 -04:00
parent 0f11ffff88
commit e747b21ae0
25 changed files with 677 additions and 419 deletions

View file

@ -172,7 +172,7 @@ public class FullIntegration {
ArduinoRemoteConnection arduinoTarget = createTarget(board); ArduinoRemoteConnection arduinoTarget = createTarget(board);
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
.getProvider(ArduinoBuildConfigurationProvider.ID); .getProvider(ArduinoBuildConfigurationProvider.ID);
ArduinoBuildConfiguration config = provider.createConfiguration(project, arduinoTarget, "run", monitor); ArduinoBuildConfiguration config = provider.getConfiguration(project, arduinoTarget, "run", monitor);
System.out.println(String.format("Building board: %s\n %s - %s", board.getName(), board.getId(), System.out.println(String.format("Building board: %s\n %s - %s", board.getName(), board.getId(),
board.getPlatform().getInstallPath())); board.getPlatform().getInstallPath()));

View file

@ -39,7 +39,13 @@ public class ArduinoPreferences {
} }
public static void setArduinoHome(Path home) { public static void setArduinoHome(Path home) {
getPrefs().put(ARDUINO_HOME, home.toString()); IEclipsePreferences prefs = getPrefs();
prefs.put(ARDUINO_HOME, home.toString());
try {
prefs.flush();
} catch (BackingStoreException e) {
Activator.log(e);
}
} }
public static String getBoardUrls() { public static String getBoardUrls() {

View file

@ -23,10 +23,10 @@ public class HierarchicalProperties {
public HierarchicalProperties() { public HierarchicalProperties() {
} }
public HierarchicalProperties(Properties properties) { public HierarchicalProperties(LinkedProperties properties) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) { for (Object keyObj : properties.orderedKeys()) {
String key = (String) entry.getKey(); String key = (String) keyObj;
String value = (String) entry.getValue(); String value = (String) properties.get(key);
putProperty(key, value); putProperty(key, value);
} }
} }

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2016 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.arduino.core.internal;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Properties;
public class LinkedProperties extends Properties {
private static final long serialVersionUID = 1L;
private final HashSet<Object> keys = new LinkedHashSet<Object>();
public Iterable<Object> orderedKeys() {
return Collections.list(keys());
}
public Enumeration<Object> keys() {
return Collections.<Object>enumeration(keys);
}
public Object put(Object key, Object value) {
keys.add(key);
return super.put(key, value);
}
}

View file

@ -93,4 +93,11 @@ public class ArduinoBoard {
return true; return true;
} }
@Override
public String toString() {
String arch = getPlatform().getArchitecture();
String pkg = getPlatform().getPackage().getName();
return pkg + ',' + arch + ',' + id + ',' + name;
}
} }

View file

@ -190,6 +190,7 @@ public class ArduinoLibrary {
public Path getInstallPath() { public Path getInstallPath() {
return installPath == null return installPath == null
? ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replaceAll("[ ()]", "_")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ? ArduinoPreferences.getArduinoHome().resolve("libraries").resolve(name.replaceAll("[ ()]", "_")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
.resolve(version)
: installPath; : installPath;
} }

View file

@ -83,6 +83,7 @@ public class ArduinoManager {
private Properties props; private Properties props;
private Path arduinoHome = ArduinoPreferences.getArduinoHome();
private Map<String, ArduinoPackage> packages; private Map<String, ArduinoPackage> packages;
private Map<String, ArduinoLibrary> installedLibraries; private Map<String, ArduinoLibrary> installedLibraries;
@ -91,6 +92,14 @@ public class ArduinoManager {
} }
private synchronized void init() throws CoreException { private synchronized void init() throws CoreException {
if (!arduinoHome.equals(ArduinoPreferences.getArduinoHome())) {
// Arduino Home changed, reset.
props = null;
packages = null;
installedLibraries = null;
arduinoHome = ArduinoPreferences.getArduinoHome();
}
if (props == null) { if (props == null) {
if (!Files.exists(ArduinoPreferences.getArduinoHome())) { if (!Files.exists(ArduinoPreferences.getArduinoHome())) {
try { try {
@ -113,9 +122,6 @@ public class ArduinoManager {
// See if we need a conversion // See if we need a conversion
int version = Integer.parseInt(props.getProperty(VERSION_KEY, "1")); //$NON-NLS-1$ int version = Integer.parseInt(props.getProperty(VERSION_KEY, "1")); //$NON-NLS-1$
if (version < Integer.parseInt(VERSION)) { if (version < Integer.parseInt(VERSION)) {
// Need to move the directories around
convertPackageDirs();
props.setProperty(VERSION_KEY, VERSION); props.setProperty(VERSION_KEY, VERSION);
try (FileWriter writer = new FileWriter(getVersionFile().toFile())) { try (FileWriter writer = new FileWriter(getVersionFile().toFile())) {
props.store(writer, ""); //$NON-NLS-1$ props.store(writer, ""); //$NON-NLS-1$
@ -126,42 +132,6 @@ public class ArduinoManager {
} }
} }
private void convertPackageDirs() throws CoreException {
Path packagesDir = ArduinoPreferences.getArduinoHome().resolve("packages"); //$NON-NLS-1$
if (!Files.isDirectory(packagesDir)) {
return;
}
try {
Files.list(packagesDir).forEach(path -> {
try {
Path hardwarePath = path.resolve("hardware"); //$NON-NLS-1$
Path badPath = hardwarePath.resolve(path.getFileName());
Path tmpDir = Files.createTempDirectory(packagesDir, "tbd"); //$NON-NLS-1$
Path badPath2 = tmpDir.resolve(badPath.getFileName());
Files.move(badPath, badPath2);
Files.list(badPath2).forEach(archPath -> {
try {
Optional<Path> latest = Files.list(archPath)
.reduce((path1, path2) -> compareVersions(path1.getFileName().toString(),
path2.getFileName().toString()) > 0 ? path1 : path2);
if (latest.isPresent()) {
Files.move(latest.get(), hardwarePath.resolve(archPath.getFileName()));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
recursiveDelete(tmpDir);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (RuntimeException | IOException e) {
throw Activator.coreException(e);
}
}
public void convertLibrariesDir() throws CoreException { public void convertLibrariesDir() throws CoreException {
Path librariesDir = ArduinoPreferences.getArduinoHome().resolve("libraries"); //$NON-NLS-1$ Path librariesDir = ArduinoPreferences.getArduinoHome().resolve("libraries"); //$NON-NLS-1$
if (!Files.isDirectory(librariesDir)) { if (!Files.isDirectory(librariesDir)) {
@ -219,15 +189,15 @@ public class ArduinoManager {
return pkg != null ? pkg.getInstalledPlatform(architecture) : null; return pkg != null ? pkg.getInstalledPlatform(architecture) : null;
} }
public synchronized Collection<ArduinoPlatform> getAvailablePlatforms(IProgressMonitor monitor) throws CoreException { public synchronized Collection<ArduinoPlatform> getAvailablePlatforms(IProgressMonitor monitor)
throws CoreException {
List<ArduinoPlatform> platforms = new ArrayList<>(); List<ArduinoPlatform> platforms = new ArrayList<>();
URL[] urls = ArduinoPreferences.getBoardUrlList(); URL[] urls = ArduinoPreferences.getBoardUrlList();
SubMonitor sub = SubMonitor.convert(monitor, urls.length + 1); SubMonitor sub = SubMonitor.convert(monitor, urls.length + 1);
sub.beginTask("Downloading package descriptions", urls.length); //$NON-NLS-1$ sub.beginTask("Downloading package descriptions", urls.length); //$NON-NLS-1$
for (URL url : urls) { for (URL url : urls) {
Path packagePath = ArduinoPreferences.getArduinoHome() Path packagePath = ArduinoPreferences.getArduinoHome().resolve(Paths.get(url.getPath()).getFileName());
.resolve(Paths.get(url.getPath()).getFileName());
try { try {
Files.createDirectories(ArduinoPreferences.getArduinoHome()); Files.createDirectories(ArduinoPreferences.getArduinoHome());
try (InputStream in = url.openStream()) { try (InputStream in = url.openStream()) {
@ -249,6 +219,36 @@ public class ArduinoManager {
return platforms; return platforms;
} }
public synchronized Collection<ArduinoPlatform> getPlatformUpdates(IProgressMonitor monitor)
throws CoreException {
List<ArduinoPlatform> platforms = new ArrayList<>();
URL[] urls = ArduinoPreferences.getBoardUrlList();
SubMonitor sub = SubMonitor.convert(monitor, urls.length + 1);
sub.beginTask("Downloading package descriptions", urls.length); //$NON-NLS-1$
for (URL url : urls) {
Path packagePath = ArduinoPreferences.getArduinoHome().resolve(Paths.get(url.getPath()).getFileName());
try {
Files.createDirectories(ArduinoPreferences.getArduinoHome());
try (InputStream in = url.openStream()) {
Files.copy(in, packagePath, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw Activator.coreException(String.format("Error loading %s", url.toString()), e); //$NON-NLS-1$
}
sub.worked(1);
}
sub.beginTask("Loading available package updates", 1); //$NON-NLS-1$
resetPackages();
for (ArduinoPackage pkg : getPackages()) {
platforms.addAll(pkg.getPlatformUpdates());
}
sub.done();
return platforms;
}
public void installPlatforms(Collection<ArduinoPlatform> platforms, IProgressMonitor monitor) throws CoreException { public void installPlatforms(Collection<ArduinoPlatform> platforms, IProgressMonitor monitor) throws CoreException {
SubMonitor sub = SubMonitor.convert(monitor, platforms.size()); SubMonitor sub = SubMonitor.convert(monitor, platforms.size());
for (ArduinoPlatform platform : platforms) { for (ArduinoPlatform platform : platforms) {
@ -293,8 +293,8 @@ public class ArduinoManager {
} }
private synchronized void initPackages() throws CoreException { private synchronized void initPackages() throws CoreException {
init();
if (packages == null) { if (packages == null) {
init();
packages = new HashMap<>(); packages = new HashMap<>();
try { try {
@ -304,8 +304,13 @@ public class ArduinoManager {
try (Reader reader = new FileReader(path.toFile())) { try (Reader reader = new FileReader(path.toFile())) {
PackageIndex index = new Gson().fromJson(reader, PackageIndex.class); PackageIndex index = new Gson().fromJson(reader, PackageIndex.class);
for (ArduinoPackage pkg : index.getPackages()) { for (ArduinoPackage pkg : index.getPackages()) {
pkg.init(); ArduinoPackage p = packages.get(pkg.getName());
packages.put(pkg.getName(), pkg); if (p == null) {
pkg.init();
packages.put(pkg.getName(), pkg);
} else {
p.merge(pkg);
}
} }
} catch (IOException e) { } catch (IOException e) {
Activator.log(e); Activator.log(e);
@ -353,8 +358,7 @@ public class ArduinoManager {
// For backwards compat, check platform name // For backwards compat, check platform name
for (ArduinoPlatform platform : getInstalledPlatforms()) { for (ArduinoPlatform platform : getInstalledPlatforms()) {
if (platform.getPackage().getName().equals(packageName) if (platform.getPackage().getName().equals(packageName) && platform.getName().equals(architecture)) {
&& platform.getName().equals(architecture)) {
return platform.getBoardByName(boardId); return platform.getBoardByName(boardId);
} }
} }
@ -367,7 +371,7 @@ public class ArduinoManager {
return pkg != null ? pkg.getTool(toolName, version) : null; return pkg != null ? pkg.getTool(toolName, version) : null;
} }
public void initInstalledLibraries() throws CoreException { private void initInstalledLibraries() throws CoreException {
init(); init();
if (installedLibraries == null) { if (installedLibraries == null) {
installedLibraries = new HashMap<>(); installedLibraries = new HashMap<>();
@ -375,7 +379,7 @@ public class ArduinoManager {
Path librariesDir = ArduinoPreferences.getArduinoHome().resolve("libraries"); //$NON-NLS-1$ Path librariesDir = ArduinoPreferences.getArduinoHome().resolve("libraries"); //$NON-NLS-1$
if (Files.isDirectory(librariesDir)) { if (Files.isDirectory(librariesDir)) {
try { try {
Files.find(librariesDir, 2, Files.find(librariesDir, 3,
(path, attrs) -> path.getFileName().toString().equals("library.properties")) //$NON-NLS-1$ (path, attrs) -> path.getFileName().toString().equals("library.properties")) //$NON-NLS-1$
.forEach(path -> { .forEach(path -> {
try { try {
@ -434,6 +438,39 @@ public class ArduinoManager {
} }
} }
public Collection<ArduinoLibrary> getLibraryUpdates(IProgressMonitor monitor) throws CoreException {
try {
initInstalledLibraries();
Map<String, ArduinoLibrary> libs = new HashMap<>();
SubMonitor sub = SubMonitor.convert(monitor, "Downloading library index", 2);
Path librariesPath = ArduinoPreferences.getArduinoHome().resolve(LIBRARIES_FILE);
URL librariesUrl = new URL(LIBRARIES_URL);
Files.createDirectories(ArduinoPreferences.getArduinoHome());
Files.copy(librariesUrl.openStream(), librariesPath, StandardCopyOption.REPLACE_EXISTING);
sub.worked(1);
try (Reader reader = new FileReader(librariesPath.toFile())) {
sub.setTaskName("Calculating library updates");
LibraryIndex libraryIndex = new Gson().fromJson(reader, LibraryIndex.class);
for (ArduinoLibrary library : libraryIndex.getLibraries()) {
String libraryName = library.getName();
ArduinoLibrary installed = installedLibraries.get(libraryName);
if (installed != null && compareVersions(library.getVersion(), installed.getVersion()) > 0) {
ArduinoLibrary current = libs.get(libraryName);
if (current == null || compareVersions(library.getVersion(), current.getVersion()) > 0) {
libs.put(libraryName, library);
}
}
}
}
sub.done();
return libs.values();
} catch (IOException e) {
throw Activator.coreException(e);
}
}
public void installLibraries(Collection<ArduinoLibrary> libraries, IProgressMonitor monitor) throws CoreException { public void installLibraries(Collection<ArduinoLibrary> libraries, IProgressMonitor monitor) throws CoreException {
SubMonitor sub = SubMonitor.convert(monitor, libraries.size()); SubMonitor sub = SubMonitor.convert(monitor, libraries.size());
for (ArduinoLibrary library : libraries) { for (ArduinoLibrary library : libraries) {
@ -462,8 +499,7 @@ public class ArduinoManager {
sub.done(); sub.done();
} }
public Collection<ArduinoLibrary> getLibraries(IProject project) public Collection<ArduinoLibrary> getLibraries(IProject project) throws CoreException {
throws CoreException {
initInstalledLibraries(); initInstalledLibraries();
IEclipsePreferences settings = getSettings(project); IEclipsePreferences settings = getSettings(project);
String librarySetting = settings.get(LIBRARIES, "[]"); //$NON-NLS-1$ String librarySetting = settings.get(LIBRARIES, "[]"); //$NON-NLS-1$
@ -577,7 +613,16 @@ public class ArduinoManager {
} }
// Strip the first directory of the path // Strip the first directory of the path
Path entryPath = installPath.resolve(path.subpath(1, path.getNameCount())); Path entryPath;
switch (path.getName(0).toString()) {
case "i586":
case "i686":
// Cheat for Intel
entryPath = installPath.resolve(path);
break;
default:
entryPath = installPath.resolve(path.subpath(1, path.getNameCount()));
}
Files.createDirectories(entryPath.getParent()); Files.createDirectories(entryPath.getParent());

View file

@ -7,19 +7,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -36,6 +31,7 @@ public class ArduinoPackage {
// end JSON fields // end JSON fields
private Map<String, ArduinoPlatform> installedPlatforms; private Map<String, ArduinoPlatform> installedPlatforms;
private Map<String, ArduinoTool> latestTools;
public String getName() { public String getName() {
return name; return name;
@ -70,6 +66,34 @@ public class ArduinoPackage {
} }
} }
void merge(ArduinoPackage other) {
// Redo calculated fields
installedPlatforms = null;
latestTools = null;
if (other.platforms != null) {
if (platforms != null) {
platforms.addAll(other.platforms);
} else {
platforms = other.platforms;
}
for (ArduinoPlatform platform : other.platforms) {
platform.init(this);
}
}
if (other.tools != null) {
if (tools != null) {
tools.addAll(other.tools);
} else {
tools = other.tools;
}
for (ArduinoTool tool : other.tools) {
tool.init(this);
}
}
}
public ArduinoPlatform getPlatform(String architecture, String version) { public ArduinoPlatform getPlatform(String architecture, String version) {
if (platforms != null) { if (platforms != null) {
for (ArduinoPlatform plat : platforms) { for (ArduinoPlatform plat : platforms) {
@ -85,36 +109,23 @@ public class ArduinoPackage {
return ArduinoPreferences.getArduinoHome().resolve("packages").resolve(getName()); //$NON-NLS-1$ return ArduinoPreferences.getArduinoHome().resolve("packages").resolve(getName()); //$NON-NLS-1$
} }
private void initInstalledPlatforms() throws CoreException { private synchronized void initInstalledPlatforms() throws CoreException {
if (installedPlatforms == null) { if (installedPlatforms == null) {
installedPlatforms = new HashMap<>(); installedPlatforms = new HashMap<>();
if (Files.isDirectory(getInstallPath())) { Path hardware = getInstallPath().resolve("hardware"); //$NON-NLS-1$
Path platformTxt = Paths.get("platform.txt"); //$NON-NLS-1$ if (Files.isDirectory(hardware)) {
try { for (ArduinoPlatform platform : platforms) {
Path hardware = getInstallPath().resolve("hardware"); String arch = platform.getArchitecture();
if (Files.exists(hardware)) { String version = platform.getVersion();
Files.find(hardware, 2, // $NON-NLS-1$
(path, attrs) -> path.getFileName().equals(platformTxt)).forEach(path -> {
try (FileReader reader = new FileReader(path.toFile())) {
Properties platformProperties = new Properties();
platformProperties.load(reader);
String arch = path.getName(path.getNameCount() - 2).toString();
String version = platformProperties.getProperty("version"); //$NON-NLS-1$
ArduinoPlatform platform = getPlatform(arch, version); Path platPath = hardware.resolve(arch).resolve(version);
if (platform != null) { if (Files.exists(platPath)) {
platform.setPlatformProperties(platformProperties); ArduinoPlatform current = installedPlatforms.get(arch);
installedPlatforms.put(arch, platform); if (current == null || ArduinoManager.compareVersions(version, current.getVersion()) > 0) {
} // TODO manually add it if was removed installedPlatforms.put(arch, platform);
// from index }
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} }
} catch (IOException e) {
throw Activator.coreException(e);
} }
} }
} }
@ -147,9 +158,24 @@ public class ArduinoPackage {
Map<String, ArduinoPlatform> platformMap = new HashMap<>(); Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) { for (ArduinoPlatform platform : platforms) {
if (!installedPlatforms.containsKey(platform.getArchitecture())) { if (!installedPlatforms.containsKey(platform.getArchitecture())) {
ArduinoPlatform p = platformMap.get(platform.getName()); ArduinoPlatform p = platformMap.get(platform.getArchitecture());
if (p == null || ArduinoManager.compareVersions(platform.getVersion(), p.getVersion()) > 0) { if (p == null || ArduinoManager.compareVersions(platform.getVersion(), p.getVersion()) > 0) {
platformMap.put(platform.getName(), platform); platformMap.put(platform.getArchitecture(), platform);
}
}
}
return platformMap.values();
}
public Collection<ArduinoPlatform> getPlatformUpdates() throws CoreException {
initInstalledPlatforms();
Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) {
ArduinoPlatform installed = installedPlatforms.get(platform.getArchitecture());
if (installed != null && ArduinoManager.compareVersions(platform.getVersion(), installed.getVersion()) > 0) {
ArduinoPlatform current = platformMap.get(platform.getArchitecture());
if (current == null || ArduinoManager.compareVersions(platform.getVersion(), current.getVersion()) > 0) {
platformMap.put(platform.getArchitecture(), platform);
} }
} }
} }
@ -169,29 +195,40 @@ public class ArduinoPackage {
return null; return null;
} }
public ArduinoTool getLatestTool(String toolName) { private void initLatestTools() {
ArduinoTool latest = null; if (latestTools == null) {
for (ArduinoTool tool : tools) { latestTools = new HashMap<>();
if (tool.getName().equals(toolName) && tool.isInstalled()) {
if (latest == null || ArduinoManager.compareVersions(tool.getVersion(), latest.getVersion()) > 0) { for (ArduinoTool tool : tools) {
latest = tool; ArduinoTool current = latestTools.get(tool.getName());
if (current == null || ArduinoManager.compareVersions(tool.getVersion(), current.getVersion()) > 0) {
latestTools.put(tool.getName(), tool);
} }
} }
} }
return latest; }
public ArduinoTool getLatestTool(String toolName) {
initLatestTools();
return latestTools.get(toolName);
}
public Collection<ArduinoTool> getLatestTools() {
initLatestTools();
return latestTools.values();
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof ArduinoPackage) { if (obj instanceof ArduinoPackage) {
return ((ArduinoPackage) obj).getName().equals(name); return ((ArduinoPackage) obj).getName().equals(getName());
} }
return super.equals(obj); return super.equals(obj);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return name.hashCode(); return getName().hashCode();
} }
} }

View file

@ -24,11 +24,11 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
import org.eclipse.cdt.arduino.core.internal.LinkedProperties;
import org.eclipse.cdt.arduino.core.internal.Messages; import org.eclipse.cdt.arduino.core.internal.Messages;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -52,9 +52,11 @@ public class ArduinoPlatform {
private List<ToolDependency> toolsDependencies; private List<ToolDependency> toolsDependencies;
// end JSON fields // end JSON fields
private Path installPath;
private ArduinoPackage pkg; private ArduinoPackage pkg;
private HierarchicalProperties boardsProperties; private HierarchicalProperties boardsProperties;
private Properties platformProperties; private LinkedProperties platformProperties;
private HierarchicalProperties programmerProperties;
private Map<String, String> menus = new HashMap<>(); private Map<String, String> menus = new HashMap<>();
private Map<String, ArduinoLibrary> libraries; private Map<String, ArduinoLibrary> libraries;
@ -81,7 +83,7 @@ public class ArduinoPlatform {
} }
public String getVersion() { public String getVersion() {
return version; return version.replace('+', '_');
} }
public String getCategory() { public String getCategory() {
@ -104,13 +106,13 @@ public class ArduinoPlatform {
return size; return size;
} }
public void setPlatformProperties(Properties platformProperties) { public void setPlatformProperties(LinkedProperties platformProperties) {
this.platformProperties = platformProperties; this.platformProperties = platformProperties;
} }
public List<ArduinoBoard> getBoards() { public List<ArduinoBoard> getBoards() {
if (boardsProperties == null) { if (boardsProperties == null) {
Properties boardProps = new Properties(); LinkedProperties boardProps = new LinkedProperties();
if (Files.exists(getInstallPath())) { if (Files.exists(getInstallPath())) {
try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile()); //$NON-NLS-1$ try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile()); //$NON-NLS-1$
@ -182,9 +184,9 @@ public class ArduinoPlatform {
return null; return null;
} }
public Properties getPlatformProperties() throws CoreException { public LinkedProperties getPlatformProperties() throws CoreException {
if (platformProperties == null) { if (platformProperties == null) {
platformProperties = new Properties(); platformProperties = new LinkedProperties();
try (BufferedReader reader = new BufferedReader( try (BufferedReader reader = new BufferedReader(
new FileReader(getInstallPath().resolve("platform.txt").toFile()))) { //$NON-NLS-1$ new FileReader(getInstallPath().resolve("platform.txt").toFile()))) { //$NON-NLS-1$
// There are regex's here and need to preserve the \'s // There are regex's here and need to preserve the \'s
@ -197,14 +199,50 @@ public class ArduinoPlatform {
platformProperties.load(reader1); platformProperties.load(reader1);
} }
} catch (IOException e) { } catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading platform.txt", e)); //$NON-NLS-1$ throw Activator.coreException(e);
} }
} }
return platformProperties; return platformProperties;
} }
public HierarchicalProperties getProgrammers() throws CoreException {
if (programmerProperties == null) {
LinkedProperties props = new LinkedProperties();
Path programmersTxt = getInstallPath().resolve("programmers.txt"); //$NON-NLS-1$
if (Files.exists(programmersTxt)) {
try (FileInputStream in = new FileInputStream(programmersTxt.toFile())) {
props.load(in);
programmerProperties = new HierarchicalProperties(props);
} catch (IOException e) {
throw Activator.coreException(e);
}
} else {
// TODO for now, grab the one from the arduino package
ArduinoManager manager = Activator.getService(ArduinoManager.class);
ArduinoPackage arduinoPkg = manager.getPackage("arduino"); //$NON-NLS-1$
if (arduinoPkg != null) {
ArduinoPlatform arduinoPlat = arduinoPkg.getInstalledPlatform(getArchitecture());
if (arduinoPlat != null) {
programmerProperties = arduinoPlat.getProgrammers();
}
}
}
}
return programmerProperties;
}
public Path getInstallPath() { public Path getInstallPath() {
return getPackage().getInstallPath().resolve("hardware").resolve(architecture); //$NON-NLS-1$ if (installPath == null) {
Path oldPath = getPackage().getInstallPath().resolve("hardware").resolve(getPackage().getName()) //$NON-NLS-1$
.resolve(getArchitecture()).resolve(getVersion());
if (Files.exists(oldPath)) {
installPath = oldPath;
} else {
installPath = getPackage().getInstallPath().resolve("hardware").resolve(getArchitecture()) //$NON-NLS-1$
.resolve(getVersion());
}
}
return installPath;
} }
private void initLibraries() throws CoreException { private void initLibraries() throws CoreException {

View file

@ -38,7 +38,7 @@ public class ArduinoTool {
} }
public String getVersion() { public String getVersion() {
return version; return version.replace('+', '_');
} }
public List<ArduinoToolSystem> getSystems() { public List<ArduinoToolSystem> getSystems() {
@ -53,26 +53,7 @@ public class ArduinoTool {
} }
public Path getInstallPath() { public Path getInstallPath() {
// TODO remove migration in Neon return getPackage().getInstallPath().resolve("tools").resolve(getName()).resolve(getVersion()); //$NON-NLS-1$
Path oldPath = ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$
.resolve(version);
Path newPath = getPackage().getInstallPath().resolve("tools").resolve(name).resolve(version); //$NON-NLS-1$
if (Files.exists(oldPath)) {
try {
Files.createDirectories(newPath.getParent());
Files.move(oldPath, newPath);
for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
if (Files.newDirectoryStream(parent).iterator().hasNext()) {
break;
} else {
Files.delete(parent);
}
}
} catch (IOException e) {
Activator.log(e);
}
}
return newPath;
} }
public boolean isInstalled() { public boolean isInstalled() {

View file

@ -55,6 +55,7 @@ public class ArduinoToolSystem {
case Platform.OS_MACOSX: case Platform.OS_MACOSX:
switch (host) { switch (host) {
case "i386-apple-darwin11": //$NON-NLS-1$ case "i386-apple-darwin11": //$NON-NLS-1$
case "i386-apple-darwin": //$NON-NLS-1$
case "x86_64-apple-darwin": //$NON-NLS-1$ case "x86_64-apple-darwin": //$NON-NLS-1$
return true; return true;
default: default:

View file

@ -28,18 +28,18 @@ public class ToolDependency {
} }
public String getVersion() { public String getVersion() {
return version; return version.replace('+', '_');
} }
public ArduinoTool getTool() throws CoreException { public ArduinoTool getTool() throws CoreException {
return Activator.getService(ArduinoManager.class).getTool(packager, name, version); return Activator.getService(ArduinoManager.class).getTool(getPackager(), getName(), getVersion());
} }
public void install(IProgressMonitor monitor) throws CoreException { public void install(IProgressMonitor monitor) throws CoreException {
ArduinoTool tool = getTool(); ArduinoTool tool = getTool();
if (tool == null) { if (tool == null) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), throw new CoreException(new Status(IStatus.ERROR, Activator.getId(),
String.format("Tool not found %s %s", name, version))); String.format("Tool not found %s %s", getName(), getVersion())));
} }
getTool().install(monitor); getTool().install(monitor);
} }

View file

@ -69,108 +69,57 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.content.IContentType;
import org.osgi.service.prefs.BackingStoreException; import org.eclipse.remote.core.IRemoteConnectionChangeListener;
import org.osgi.service.prefs.Preferences; import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
import freemarker.cache.TemplateLoader; import freemarker.cache.TemplateLoader;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
public class ArduinoBuildConfiguration extends CBuildConfiguration implements TemplateLoader { public class ArduinoBuildConfiguration extends CBuildConfiguration
implements TemplateLoader, IRemoteConnectionChangeListener {
private static final String PACKAGE_NAME = "packageName"; //$NON-NLS-1$ private static final ArduinoManager manager = Activator.getService(ArduinoManager.class);
private static final String PLATFORM_NAME = "platformName"; //$NON-NLS-1$ private static final boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32);
private static final String BOARD_NAME = "boardName"; //$NON-NLS-1$
private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$
private static ArduinoManager manager = Activator.getService(ArduinoManager.class); private final ArduinoRemoteConnection target;
private final ArduinoBoard board;
private final String launchMode; private final String launchMode;
private ArduinoBoard defaultBoard;
private Properties properties; private Properties properties;
// for Makefile generation // for Makefile generation
private Configuration templateConfig; private Configuration templateConfig;
private final static boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32); /**
* Default configuration.
public ArduinoBuildConfiguration(IBuildConfiguration config, String name) throws CoreException { *
super(config, name); * @param config
*/
Preferences settings = getSettings(); ArduinoBuildConfiguration(IBuildConfiguration config, String name, String launchMode, ArduinoBoard defaultBoard, IToolChain toolChain) throws CoreException {
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$ super(config, ".default", toolChain); //$NON-NLS-1$
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$ this.target = null;
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$ this.launchMode = launchMode;
ArduinoBoard b = manager.getBoard(packageName, platformName, boardName); this.defaultBoard = defaultBoard;
if (b == null) {
// Default to Uno or first one we find
b = manager.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (b == null) {
Collection<ArduinoBoard> boards = manager.getInstalledBoards();
if (!boards.isEmpty()) {
b = boards.iterator().next();
}
}
}
board = b;
int i = name.lastIndexOf('.');
this.launchMode = name.substring(i + 1);
} }
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoBoard board, String launchMode, ArduinoBuildConfiguration(IBuildConfiguration config, String name, String launchMode, ArduinoRemoteConnection target,
IToolChain toolChain) throws CoreException { IToolChain toolChain) throws CoreException {
super(config, name, toolChain); super(config, name, toolChain);
this.board = board; this.target = target;
this.launchMode = launchMode; this.launchMode = launchMode;
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
// Store the board identifer remoteManager.addRemoteConnectionChangeListener(this);
ArduinoPlatform platform = board.getPlatform();
ArduinoPackage pkg = platform.getPackage();
Preferences settings = getSettings();
settings.put(PACKAGE_NAME, pkg.getName());
settings.put(PLATFORM_NAME, platform.getName());
settings.put(BOARD_NAME, board.getName());
try {
settings.flush();
} catch (BackingStoreException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
}
} }
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoRemoteConnection target, @Override
String launchMode, IToolChain toolChain) throws CoreException { public synchronized void connectionChanged(RemoteConnectionChangeEvent event) {
this(config, name, target.getBoard(), launchMode, toolChain); if (event.getConnection().equals(target.getRemoteConnection())) {
properties = null;
// Store the menu settings
HierarchicalProperties menus = board.getMenus();
if (menus != null) {
Preferences settings = getSettings();
for (String id : menus.getChildren().keySet()) {
String value = target.getMenuValue(id);
if (value != null) {
settings.put(MENU_QUALIFIER + id, value);
}
}
try {
settings.flush();
} catch (BackingStoreException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Saving preferences", e)); //$NON-NLS-1$
}
} }
} }
static String generateName(ArduinoBoard board, String launchMode) {
ArduinoPlatform platform = board.getPlatform();
ArduinoPackage pkg = platform.getPackage();
return pkg.getName() + '.' + platform.getArchitecture() + '.' + board.getId() + '.' + launchMode;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getAdapter(Class<T> adapter) { public <T> T getAdapter(Class<T> adapter) {
@ -184,31 +133,21 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
return launchMode; return launchMode;
} }
public boolean matches(ArduinoRemoteConnection target) throws CoreException { public ArduinoRemoteConnection getTarget() {
ArduinoBoard otherBoard = target.getBoard(); return target;
if (!getBoard().equals(otherBoard)) {
return false;
}
Preferences settings = getSettings();
HierarchicalProperties menus = board.getMenus();
if (menus != null) {
for (String id : menus.getChildren().keySet()) {
if (!settings.get(MENU_QUALIFIER + id, "").equals(target.getMenuValue(id))) { //$NON-NLS-1$
return false;
}
}
}
return true;
} }
public ArduinoBoard getBoard() throws CoreException { public ArduinoBoard getBoard() throws CoreException {
return board; if (target != null) {
return target.getBoard();
} else {
return defaultBoard;
}
} }
private synchronized Properties getProperties() throws CoreException { private synchronized Properties getProperties() throws CoreException {
if (properties == null) { if (properties == null) {
ArduinoBoard board = getBoard();
ArduinoPlatform platform = board.getPlatform(); ArduinoPlatform platform = board.getPlatform();
// IDE generated properties // IDE generated properties
@ -219,20 +158,21 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$ properties.put("build.arch", platform.getArchitecture().toUpperCase()); //$NON-NLS-1$
properties.put("build.path", "."); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("build.path", "."); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("build.core.path", //$NON-NLS-1$ properties.put("build.core.path", //$NON-NLS-1$
platform.getInstallPath().resolve("core").resolve("{build.core}").toString()); //$NON-NLS-1$ //$NON-NLS-2$ platform.getInstallPath().resolve("cores").resolve("{build.core}").toString()); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("build.system.path", platform.getInstallPath().resolve("system").toString()); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("build.system.path", platform.getInstallPath().resolve("system").toString()); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("build.variant.path", //$NON-NLS-1$ properties.put("build.variant.path", //$NON-NLS-1$
platform.getInstallPath().resolve("variants").resolve("{build.variant}").toString()); //$NON-NLS-1$ //$NON-NLS-2$ platform.getInstallPath().resolve("variants").resolve("{build.variant}").toString()); //$NON-NLS-1$ //$NON-NLS-2$
// Everyone seems to want to use the avr-gcc and avrdude tools // Everyone seems to want to use arduino package tools
ArduinoPackage arduinoPackage = manager.getPackage("arduino"); //$NON-NLS-1$ ArduinoPackage arduinoPackage = manager.getPackage("arduino"); //$NON-NLS-1$
ArduinoTool avrgcc = arduinoPackage.getLatestTool("avr-gcc"); //$NON-NLS-1$ if (arduinoPackage != null) {
if (avrgcc != null) { for (ArduinoTool tool : arduinoPackage.getLatestTools()) {
properties.put("runtime.tools.avr-gcc.path", avrgcc.getInstallPath().toString()); //$NON-NLS-1$ properties.put("runtime.tools." + tool.getName() + ".path", tool.getInstallPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$
} }
ArduinoTool avrdude = arduinoPackage.getLatestTool("avrdude"); //$NON-NLS-1$ for (ArduinoTool tool : arduinoPackage.getTools()) {
if (avrdude != null) { properties.put("runtime.tools." + tool.getName() + '-' + tool.getVersion() + ".path", //$NON-NLS-1$ //$NON-NLS-2$
properties.put("runtime.tools.avrdude.path", avrdude.getInstallPath().toString()); //$NON-NLS-1$ tool.getInstallPath().toString());
}
} }
// Super Platform // Super Platform
@ -257,24 +197,22 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
// Board // Board
ArduinoBoard board = getBoard();
properties.putAll(board.getBoardProperties()); properties.putAll(board.getBoardProperties());
// Menus // Menus
Preferences settings = getSettings();
HierarchicalProperties menus = board.getMenus(); HierarchicalProperties menus = board.getMenus();
if (menus != null) { if (menus != null) {
for (Entry<String, HierarchicalProperties> menuEntry : menus.getChildren().entrySet()) { for (Entry<String, HierarchicalProperties> menuEntry : menus.getChildren().entrySet()) {
String key = menuEntry.getKey(); String key = menuEntry.getKey();
String defaultValue; String value = target.getMenuValue(key);
Iterator<HierarchicalProperties> i = menuEntry.getValue().getChildren().values().iterator(); if (value == null || value.isEmpty()) {
if (i.hasNext()) { Iterator<HierarchicalProperties> i = menuEntry.getValue().getChildren().values().iterator();
defaultValue = i.next().getValue(); if (i.hasNext()) {
} else { HierarchicalProperties first = i.next();
defaultValue = ""; //$NON-NLS-1$ value = first.getValue();
}
} }
String value = settings.get(MENU_QUALIFIER + key, defaultValue); if (value != null && !value.isEmpty()) {
if (!value.isEmpty()) {
properties.putAll(board.getMenuProperties(key, value)); properties.putAll(board.getMenuProperties(key, value));
} }
} }
@ -291,8 +229,11 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
ArduinoBoard board = getBoard(); ArduinoBoard board = getBoard();
ArduinoPlatform platform = board.getPlatform(); ArduinoPlatform platform = board.getPlatform();
Properties properties = new Properties();
Map<String, Object> buildModel = new HashMap<>(); Map<String, Object> buildModel = new HashMap<>();
buildModel.put("boardId", board.getId()); //$NON-NLS-1$ buildModel.put("boardId", board.getId()); //$NON-NLS-1$
properties.put("object_file", "$@"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("source_file", "$<"); //$NON-NLS-1$ //$NON-NLS-2$
// The list of source files in the project // The list of source files in the project
final Path projectPath = new File(project.getLocationURI()).toPath(); final Path projectPath = new File(project.getLocationURI()).toPath();
@ -322,7 +263,6 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
buildModel.put("libraries_path", pathString(ArduinoPreferences.getArduinoHome().resolve("libraries"))); //$NON-NLS-1$ //$NON-NLS-2$ buildModel.put("libraries_path", pathString(ArduinoPreferences.getArduinoHome().resolve("libraries"))); //$NON-NLS-1$ //$NON-NLS-2$
// the recipes // the recipes
Properties properties = new Properties();
properties.putAll(getProperties()); properties.putAll(getProperties());
buildModel.put("build_path", properties.get("build.path")); //$NON-NLS-1$ //$NON-NLS-2$ buildModel.put("build_path", properties.get("build.path")); //$NON-NLS-1$ //$NON-NLS-2$
buildModel.put("project_name", project.getName()); //$NON-NLS-1$ buildModel.put("project_name", project.getName()); //$NON-NLS-1$
@ -336,12 +276,18 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
includes += '"' + pathString(include) + '"'; includes += '"' + pathString(include) + '"';
} }
for (ArduinoLibrary lib : manager.getLibraries(project)) { for (ArduinoLibrary lib : manager.getLibraries(project)) {
for (Path include : lib.getIncludePath()) { for (Path include : lib.getIncludePath()) {
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$ includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
} }
} }
// Magic recipes for platform builds with platform includes
properties.put("includes", includes); //$NON-NLS-1$ properties.put("includes", includes); //$NON-NLS-1$
buildModel.put("recipe_cpp_o_pattern_plat", resolveProperty("recipe.cpp.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
buildModel.put("recipe_c_o_pattern_plat", resolveProperty("recipe.c.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
buildModel.put("recipe_S_o_pattern_plat", resolveProperty("recipe.S.o.pattern", properties)); //$NON-NLS-1$ //$NON-NLS-2$
ArduinoPlatform corePlatform = platform; ArduinoPlatform corePlatform = platform;
String core = properties.getProperty("build.core"); //$NON-NLS-1$ String core = properties.getProperty("build.core"); //$NON-NLS-1$
@ -352,29 +298,30 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
core = segments[1]; core = segments[1];
} }
} }
buildModel.put("platform_path", pathString(corePlatform.getInstallPath())); //$NON-NLS-1$
Path corePath = corePlatform.getInstallPath().resolve("cores").resolve(core); //$NON-NLS-1$ Path corePath = corePlatform.getInstallPath().resolve("cores").resolve(core); //$NON-NLS-1$
buildModel.put("platform_core_path", pathString(corePath)); //$NON-NLS-1$ buildModel.put("platform_core_path", pathString(corePath)); //$NON-NLS-1$
List<String> coreSources = new ArrayList<>(); List<String> coreSources = new ArrayList<>();
getSources(coreSources, corePath, true); getSources(coreSources, corePath, true);
buildModel.put("platform_core_srcs", coreSources); //$NON-NLS-1$ buildModel.put("platform_core_srcs", coreSources); //$NON-NLS-1$
ArduinoPlatform variantPlatform = platform;
String variant = properties.getProperty("build.variant"); //$NON-NLS-1$
if (variant.contains(":")) { //$NON-NLS-1$
String[] segments = variant.split(":"); //$NON-NLS-1$
if (segments.length == 2) {
variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture());
variant = segments[1];
}
}
Path variantPath = variantPlatform.getInstallPath().resolve("variants").resolve(variant); //$NON-NLS-1$
buildModel.put("platform_variant_path", pathString(variantPath)); //$NON-NLS-1$
List<String> variantSources = new ArrayList<>(); List<String> variantSources = new ArrayList<>();
getSources(variantSources, variantPath, true); String variant = properties.getProperty("build.variant"); //$NON-NLS-1$
if (variant != null) {
ArduinoPlatform variantPlatform = platform;
if (variant.contains(":")) { //$NON-NLS-1$
String[] segments = variant.split(":"); //$NON-NLS-1$
if (segments.length == 2) {
variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture());
variant = segments[1];
}
}
Path variantPath = variantPlatform.getInstallPath().resolve("variants").resolve(variant); //$NON-NLS-1$
buildModel.put("platform_variant_path", pathString(variantPath)); //$NON-NLS-1$
getSources(variantSources, variantPath, true);
}
buildModel.put("platform_variant_srcs", variantSources); //$NON-NLS-1$ buildModel.put("platform_variant_srcs", variantSources); //$NON-NLS-1$
properties.put("object_file", "$@"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("source_file", "$<"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("archive_file", "core.a"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("archive_file", "core.a"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("archive_file_path", "{build.path}/{archive_file}"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("archive_file_path", "{build.path}/{archive_file}"); //$NON-NLS-1$ //$NON-NLS-2$
properties.put("object_files", "$(PROJECT_OBJS) $(LIBRARIES_OBJS)"); //$NON-NLS-1$ //$NON-NLS-2$ properties.put("object_files", "$(PROJECT_OBJS) $(LIBRARIES_OBJS)"); //$NON-NLS-1$ //$NON-NLS-2$
@ -538,7 +485,10 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
public String[] getUploadCommand(String serialPort) throws CoreException { public String[] getUploadCommand(String serialPort) throws CoreException {
String toolName = getProperties().getProperty("upload.tool"); //$NON-NLS-1$ Properties properties = new Properties();
properties.putAll(getProperties());
String toolName = properties.getProperty("upload.tool"); //$NON-NLS-1$
ArduinoPlatform platform = getBoard().getPlatform(); ArduinoPlatform platform = getBoard().getPlatform();
if (toolName.contains(":")) { //$NON-NLS-1$ if (toolName.contains(":")) { //$NON-NLS-1$
String[] segments = toolName.split(":"); //$NON-NLS-1$ String[] segments = toolName.split(":"); //$NON-NLS-1$
@ -548,8 +498,6 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
} }
Properties properties = getProperties();
ArduinoTool uploadTool = platform.getPackage().getLatestTool(toolName); ArduinoTool uploadTool = platform.getPackage().getLatestTool(toolName);
if (uploadTool != null) { if (uploadTool != null) {
properties.putAll(uploadTool.getToolProperties()); properties.putAll(uploadTool.getToolProperties());
@ -577,14 +525,33 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
} }
// TODO make this a preference String command;
properties.put("upload.verbose", properties.getProperty("upload.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (properties.get("upload.protocol") != null) { //$NON-NLS-1$
properties.put("upload.verify", properties.getProperty("upload.params.verify", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // TODO make this a preference
properties.put("upload.verbose", properties.getProperty("upload.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
properties.put("upload.verify", properties.getProperty("upload.params.verify", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// TODO needed this for esptool command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
properties.put("upload.resetmethod", "ck"); //$NON-NLS-1$ //$NON-NLS-2$ } else {
// use the bootloader
String programmer = target.getProgrammer();
if (programmer != null) {
HierarchicalProperties programmers = getBoard().getPlatform().getProgrammers();
if (programmers != null) {
HierarchicalProperties programmerProps = programmers.getChild(programmer);
if (programmerProps != null) {
properties.putAll(programmerProps.flatten());
}
}
}
// TODO preference
properties.put("program.verbose", properties.getProperty("program.params.verbose", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
properties.put("program.verify", properties.getProperty("program.params.verify", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
command = resolveProperty("program.pattern", properties); //$NON-NLS-1$
}
String command = resolveProperty("upload.pattern", properties); //$NON-NLS-1$
if (command == null) { if (command == null) {
throw Activator.coreException("Upload command not specified", null); throw Activator.coreException("Upload command not specified", null);
} }
@ -608,12 +575,16 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
ArduinoPlatform variantPlatform = platform; ArduinoPlatform variantPlatform = platform;
String variant = properties.getProperty("build.variant"); //$NON-NLS-1$ String variant = properties.getProperty("build.variant"); //$NON-NLS-1$
if (variant.contains(":")) { //$NON-NLS-1$ if (variant != null) {
String[] segments = variant.split(":"); //$NON-NLS-1$ if (variant.contains(":")) { //$NON-NLS-1$
if (segments.length == 2) { String[] segments = variant.split(":"); //$NON-NLS-1$
variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture()); if (segments.length == 2) {
variant = segments[1]; variantPlatform = manager.getInstalledPlatform(segments[0], platform.getArchitecture());
variant = segments[1];
}
} }
} else {
return Arrays.asList(corePlatform.getInstallPath().resolve("cores").resolve(core)); //$NON-NLS-1$
} }
return Arrays.asList(corePlatform.getInstallPath().resolve("cores").resolve(core), //$NON-NLS-1$ return Arrays.asList(corePlatform.getInstallPath().resolve("cores").resolve(core), //$NON-NLS-1$

View file

@ -23,6 +23,9 @@ import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteServicesManager;
public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationProvider { public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationProvider {
@ -49,52 +52,54 @@ public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationPr
} }
} }
if (board != null) { if (board != null) {
// Create the toolChain IToolChain toolChain = createToolChain(config);
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); return new ArduinoBuildConfiguration(config, name, "run", board, toolChain); //$NON-NLS-1$
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
IToolChain toolChain = new ArduinoToolChain(provider, config);
toolChainManager.addToolChain(toolChain);
return new ArduinoBuildConfiguration(config, name, board, "run", toolChain); //$NON-NLS-1$
} }
return null;
} else { } else {
return new ArduinoBuildConfiguration(config, name); IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
} IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
} IRemoteConnection connection = connectionType.getConnection(name);
if (connection == null) {
throw Activator.coreException(String.format("Unknown connection: %s", name), null);
}
public ArduinoBuildConfiguration getConfiguration(IProject project, ArduinoRemoteConnection target, ArduinoRemoteConnection target = connection.getService(ArduinoRemoteConnection.class);
String launchMode, if (target != null) {
IProgressMonitor monitor) throws CoreException { IToolChain toolChain = createToolChain(config);
ArduinoBoard board = target.getBoard(); return new ArduinoBuildConfiguration(config, name, "run", target, toolChain); //$NON-NLS-1$
for (IBuildConfiguration config : project.getBuildConfigs()) {
ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
if (cconfig != null) {
ArduinoBuildConfiguration arduinoConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class);
if (arduinoConfig != null && arduinoConfig.getLaunchMode().equals(launchMode)
&& arduinoConfig.getBoard().equals(board) && arduinoConfig.matches(target)) {
return arduinoConfig;
}
} }
} }
return null; return null;
} }
public ArduinoBuildConfiguration createConfiguration(IProject project, ArduinoRemoteConnection target, public ArduinoBuildConfiguration getConfiguration(IProject project, ArduinoRemoteConnection target,
String launchMode, String launchMode, IProgressMonitor monitor) throws CoreException {
IProgressMonitor monitor) throws CoreException { for (IBuildConfiguration config : project.getBuildConfigs()) {
ArduinoBoard board = target.getBoard(); ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
String configName = ArduinoBuildConfiguration.generateName(board, launchMode); if (cconfig != null) {
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, ArduinoBuildConfiguration arduinoConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class);
monitor); if (arduinoConfig != null && target.equals(arduinoConfig.getTarget())
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class); && arduinoConfig.getLaunchMode().equals(launchMode)) {
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID); return arduinoConfig;
IToolChain toolChain = new ArduinoToolChain(provider, config); }
toolChainManager.addToolChain(toolChain); }
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, target, launchMode, }
// Make a new one
String configName = target.getRemoteConnection().getName();
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, monitor);
IToolChain toolChain = createToolChain(config);
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, "run", target, //$NON-NLS-1$
toolChain); toolChain);
configManager.addBuildConfiguration(config, arduinoConfig); configManager.addBuildConfiguration(config, arduinoConfig);
return arduinoConfig; return arduinoConfig;
} }
private IToolChain createToolChain(IBuildConfiguration config) throws CoreException {
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
IToolChain toolChain = new ArduinoToolChain(provider, config);
toolChainManager.addToolChain(toolChain);
return toolChain;
}
} }

View file

@ -115,10 +115,6 @@ public class ArduinoLaunchConfigurationDelegate extends LaunchConfigurationTarge
IProgressMonitor monitor) throws CoreException { IProgressMonitor monitor) throws CoreException {
ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager ArduinoBuildConfigurationProvider provider = (ArduinoBuildConfigurationProvider) buildConfigManager
.getProvider(ArduinoBuildConfigurationProvider.ID); .getProvider(ArduinoBuildConfigurationProvider.ID);
ArduinoBuildConfiguration config = provider.getConfiguration(project, arduinoTarget, launchMode, monitor); return provider.getConfiguration(project, arduinoTarget, launchMode, monitor);
if (config == null) {
config = provider.createConfiguration(project, arduinoTarget, launchMode, monitor);
}
return config;
} }
} }

View file

@ -23,9 +23,11 @@ public class ArduinoLaunchConfigurationProvider extends ProjectLaunchConfigProvi
@Override @Override
public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class); if (target != null) {
if (connection != null) { IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
return connection.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID); if (connection != null) {
return connection.getConnectionType().getId().equals(ArduinoRemoteConnection.TYPE_ID);
}
} }
return false; return false;
} }

View file

@ -40,10 +40,12 @@ public class ArduinoRemoteConnection
private static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$ private static final String PLATFORM_NAME = "arduinoPlatformName"; //$NON-NLS-1$
private static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$ private static final String BOARD_NAME = "arduinoBoardName"; //$NON-NLS-1$
private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$ private static final String MENU_QUALIFIER = "menu_"; //$NON-NLS-1$
private static final String PROGRAMMER = "programmer"; //$NON-NLS-1$
private final IRemoteConnection remoteConnection; private final IRemoteConnection remoteConnection;
private SerialPort serialPort; private SerialPort serialPort;
private SerialPortCommandShell commandShell; private SerialPortCommandShell commandShell;
private ArduinoBoard board;
private static final Map<IRemoteConnection, ArduinoRemoteConnection> connectionMap = new HashMap<>(); private static final Map<IRemoteConnection, ArduinoRemoteConnection> connectionMap = new HashMap<>();
@ -61,19 +63,27 @@ public class ArduinoRemoteConnection
ArduinoPackage pkg = platform.getPackage(); ArduinoPackage pkg = platform.getPackage();
workingCopy.setAttribute(PACKAGE_NAME, pkg.getName()); workingCopy.setAttribute(PACKAGE_NAME, pkg.getName());
} }
public static void setPortName(IRemoteConnectionWorkingCopy workingCopy, String portName) { public static void setPortName(IRemoteConnectionWorkingCopy workingCopy, String portName) {
workingCopy.setAttribute(PORT_NAME, portName); workingCopy.setAttribute(PORT_NAME, portName);
} }
public static void setMenuValue(IRemoteConnectionWorkingCopy workingCopy, String key, String value) { public static void setMenuValue(IRemoteConnectionWorkingCopy workingCopy, String key, String value) {
workingCopy.setAttribute(MENU_QUALIFIER + key, value); workingCopy.setAttribute(MENU_QUALIFIER + key, value);
} }
public static void setProgrammer(IRemoteConnectionWorkingCopy workingCopy, String programmer) {
workingCopy.setAttribute(PROGRAMMER, programmer);
}
public String getMenuValue(String key) { public String getMenuValue(String key) {
return remoteConnection.getAttribute(MENU_QUALIFIER + key); return remoteConnection.getAttribute(MENU_QUALIFIER + key);
} }
public String getProgrammer() {
return remoteConnection.getAttribute(PROGRAMMER);
}
@Override @Override
public void connectionChanged(RemoteConnectionChangeEvent event) { public void connectionChanged(RemoteConnectionChangeEvent event) {
if (event.getType() == RemoteConnectionChangeEvent.CONNECTION_REMOVED) { if (event.getType() == RemoteConnectionChangeEvent.CONNECTION_REMOVED) {
@ -122,8 +132,33 @@ public class ArduinoRemoteConnection
} }
public ArduinoBoard getBoard() throws CoreException { public ArduinoBoard getBoard() throws CoreException {
return Activator.getService(ArduinoManager.class).getBoard(remoteConnection.getAttribute(PACKAGE_NAME), if (board == null) {
remoteConnection.getAttribute(PLATFORM_NAME), remoteConnection.getAttribute(BOARD_NAME)); String pkgName = remoteConnection.getAttribute(PACKAGE_NAME);
String platName = remoteConnection.getAttribute(PLATFORM_NAME);
String boardName = remoteConnection.getAttribute(BOARD_NAME);
ArduinoManager manager = Activator.getService(ArduinoManager.class);
board = manager.getBoard(pkgName, platName, boardName);
if (board == null) {
// Old style board attributes?
ArduinoPackage pkg = manager.getPackage(pkgName);
if (pkg != null) {
for (ArduinoPlatform plat : pkg.getAvailablePlatforms()) {
if (plat.getName().equals(platName)) {
platName = plat.getArchitecture();
for (ArduinoBoard b : plat.getBoards()) {
if (b.getName().equals(boardName)) {
board = b;
return board;
}
}
}
}
}
}
}
return board;
} }
public String getPortName() { public String getPortName() {

View file

@ -1,9 +1,11 @@
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
SHELL = $(ComSpec) SHELL = $(ComSpec)
RMDIR = rmdir /s /q RMDIR = rmdir /s /q
RM = del /q
mymkdir = if not exist "$1" mkdir "$1" mymkdir = if not exist "$1" mkdir "$1"
else else
RMDIR = rm -fr RMDIR = rm -fr
RM = rm -f
mymkdir = mkdir -p $1 mymkdir = mkdir -p $1
endif endif
@ -11,7 +13,7 @@ PROJECT_OBJS = \
<#list project_srcs as file> <#list project_srcs as file>
<#assign cpp = file?matches("(.*)\\.cpp")> <#assign cpp = file?matches("(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/project/${cpp?groups[1]}.cpp.o \ project/${cpp?groups[1]}.cpp.o \
</#if> </#if>
</#list> </#list>
@ -19,15 +21,15 @@ PLATFORM_CORE_OBJS = \
<#list platform_core_srcs as file> <#list platform_core_srcs as file>
<#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/core/${cpp?groups[1]}.cpp.o \ core/${cpp?groups[1]}.cpp.o \
</#if> </#if>
<#assign c = file?matches("${platform_core_path}/(.*)\\.c")> <#assign c = file?matches("${platform_core_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/core/${c?groups[1]}.c.o \ core/${c?groups[1]}.c.o \
</#if> </#if>
<#assign S = file?matches("${platform_core_path}/(.*)\\.S")> <#assign S = file?matches("${platform_core_path}/(.*)\\.S")>
<#if S> <#if S>
${build_path}/core/${S?groups[1]}.S.o \ core/${S?groups[1]}.S.o \
</#if> </#if>
</#list> </#list>
@ -35,15 +37,15 @@ PLATFORM_VARIANT_OBJS = \
<#list platform_variant_srcs as file> <#list platform_variant_srcs as file>
<#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/variant/${cpp?groups[1]}.cpp.o \ variant/${cpp?groups[1]}.cpp.o \
</#if> </#if>
<#assign c = file?matches("${platform_variant_path}/(.*)\\.c")> <#assign c = file?matches("${platform_variant_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/variant/${c?groups[1]}.c.o \ variant/${c?groups[1]}.c.o \
</#if> </#if>
<#assign S = file?matches("${platform_variant_path}/(.*)\\.S")> <#assign S = file?matches("${platform_variant_path}/(.*)\\.S")>
<#if S> <#if S>
${build_path}/variant/${S?groups[1]}.S.o \ variant/${S?groups[1]}.S.o \
</#if> </#if>
</#list> </#list>
@ -51,62 +53,63 @@ LIBRARIES_OBJS = \
<#list libraries_srcs as file> <#list libraries_srcs as file>
<#assign cpp = file?matches("${libraries_path}/(.*?)/(.*)\\.cpp")> <#assign cpp = file?matches("${libraries_path}/(.*?)/(.*)\\.cpp")>
<#if !cpp> <#if !cpp>
<#assign cpp = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.cpp")>
</#if> </#if>
<#if cpp> <#if cpp>
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o \ libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o \
</#if> </#if>
<#assign c = file?matches("${libraries_path}/(.*?)/(.*)\\.c")> <#assign c = file?matches("${libraries_path}/(.*?)/(.*)\\.c")>
<#if !c> <#if !c>
<#assign c = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.c")> <#assign c = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.c")>
</#if> </#if>
<#if c> <#if c>
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.o \ libraries/${c?groups[1]}/${c?groups[2]}.c.o \
</#if> </#if>
<#assign S = file?matches("${libraries_path}/(.*?)/(.*)\\.S")> <#assign S = file?matches("${libraries_path}/(.*?)/(.*)\\.S")>
<#if !S> <#if !S>
<#assign S = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.S")> <#assign S = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.S")>
</#if> </#if>
<#if S> <#if S>
${build_path}/libraries/${S?groups[1]}/${S?groups[2]}.S.o \ libraries/${S?groups[1]}/${S?groups[2]}.S.o \
</#if> </#if>
</#list> </#list>
TARGETS = \ TARGETS = \
<#if recipe_objcopy_hex_pattern??> <#if recipe_objcopy_hex_pattern??>
${build_path}/${project_name}.hex \ ${project_name}.hex \
</#if> </#if>
<#if recipe_objcopy_epp_pattern??> <#if recipe_objcopy_epp_pattern??>
${build_path}/${project_name}.eep \ ${project_name}.eep \
</#if> </#if>
<#if recipe_objcopy_bin_pattern??> <#if recipe_objcopy_bin_pattern??>
${build_path}/${project_name}.bin \ ${project_name}.bin \
</#if> </#if>
all: $(TARGETS) all: $(TARGETS)
<#if recipe_objcopy_hex_pattern??> <#if recipe_objcopy_hex_pattern??>
${build_path}/${project_name}.hex: ${build_path}/${project_name}.elf ${project_name}.hex: ${project_name}.elf
${recipe_objcopy_hex_pattern} ${recipe_objcopy_hex_pattern}
</#if> </#if>
<#if recipe_objcopy_epp_pattern??> <#if recipe_objcopy_epp_pattern??>
${build_path}/${project_name}.eep: ${build_path}/${project_name}.elf ${project_name}.eep: ${project_name}.elf
${recipe_objcopy_eep_pattern} ${recipe_objcopy_eep_pattern}
</#if> </#if>
<#if recipe_objcopy_bin_pattern??> <#if recipe_objcopy_bin_pattern??>
${build_path}/${project_name}.bin: ${build_path}/${project_name}.elf ${project_name}.bin: ${project_name}.elf
${recipe_objcopy_bin_pattern} ${recipe_objcopy_bin_pattern}
</#if> </#if>
${build_path}/${project_name}.elf: $(PROJECT_OBJS) $(LIBRARIES_OBJS) ${build_path}/core.a ${project_name}.elf: $(PROJECT_OBJS) $(LIBRARIES_OBJS) core.a
${recipe_c_combine_pattern} ${recipe_c_combine_pattern}
${build_path}/core.a: $(PLATFORM_CORE_OBJS) $(PLATFORM_VARIANT_OBJS) core.a: $(PLATFORM_CORE_OBJS) $(PLATFORM_VARIANT_OBJS)
clean: clean:
$(RMDIR) ${build_path}/* -$(RMDIR) project core variant libraries
-$(RM) *.hex *.eep *.bin *.elf *.a *.ar *.d
size: size:
${recipe_size_pattern} ${recipe_size_pattern}
@ -114,13 +117,13 @@ size:
<#list project_srcs as file> <#list project_srcs as file>
<#assign cpp = file?matches("(.*)\\.cpp")> <#assign cpp = file?matches("(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/project/${cpp?groups[1]}.cpp.o: ../../${file} ${build_path}/project/${cpp?groups[1]}.cpp.d project/${cpp?groups[1]}.cpp.o: ../../${file} project/${cpp?groups[1]}.cpp.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern}
${build_path}/project/${cpp?groups[1]}.cpp.d: ; project/${cpp?groups[1]}.cpp.d: ;
-include ${build_path}/project/${cpp?groups[1]}.cpp.d -include project/${cpp?groups[1]}.cpp.d
</#if> </#if>
</#list> </#list>
@ -128,33 +131,33 @@ ${build_path}/project/${cpp?groups[1]}.cpp.d: ;
<#list platform_core_srcs as file> <#list platform_core_srcs as file>
<#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_core_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/core/${cpp?groups[1]}.cpp.o: ${file} ${build_path}/core/${cpp?groups[1]}.cpp.d core/${cpp?groups[1]}.cpp.o: ${file} core/${cpp?groups[1]}.cpp.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
${build_path}/core/${cpp?groups[1]}.cpp.d: ; core/${cpp?groups[1]}.cpp.d: ;
-include ${build_path}/core/${cpp?groups[1]}.cpp.d -include core/${cpp?groups[1]}.cpp.d
</#if> </#if>
<#assign c = file?matches("${platform_core_path}/(.*)\\.c")> <#assign c = file?matches("${platform_core_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/core/${c?groups[1]}.c.o: ${file} ${build_path}/core/${c?groups[1]}.c.d core/${c?groups[1]}.c.o: ${file} core/${c?groups[1]}.c.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_c_o_pattern} ${recipe_c_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
${build_path}/core/${c?groups[1]}.c.d: ; core/${c?groups[1]}.c.d: ;
-include ${build_path}/core/${c?groups[1]}.c.d -include core/${c?groups[1]}.c.d
</#if> </#if>
<#assign S = file?matches("${platform_core_path}/(.*)\\.S")> <#assign S = file?matches("${platform_core_path}/(.*)\\.S")>
<#if S> <#if S>
${build_path}/core/${S?groups[1]}.S.o: ${file} core/${S?groups[1]}.S.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_S_o_pattern} ${recipe_S_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
</#if> </#if>
@ -163,33 +166,33 @@ ${build_path}/core/${S?groups[1]}.S.o: ${file}
<#list platform_variant_srcs as file> <#list platform_variant_srcs as file>
<#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_variant_path}/(.*)\\.cpp")>
<#if cpp> <#if cpp>
${build_path}/variant/${cpp?groups[1]}.cpp.o: ${file} ${build_path}/variant/${cpp?groups[1]}.cpp.d variant/${cpp?groups[1]}.cpp.o: ${file} variant/${cpp?groups[1]}.cpp.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
${build_path}/variant/${cpp?groups[1]}.cpp.d: ; variant/${cpp?groups[1]}.cpp.d: ;
-include ${build_path}/variant/${cpp?groups[1]}.cpp.d -include variant/${cpp?groups[1]}.cpp.d
</#if> </#if>
<#assign c = file?matches("${platform_variant_path}/(.*)\\.c")> <#assign c = file?matches("${platform_variant_path}/(.*)\\.c")>
<#if c> <#if c>
${build_path}/variant/${c?groups[1]}.c.o: ${file} ${build_path}/variant/${c?groups[1]}.c.d variant/${c?groups[1]}.c.o: ${file} variant/${c?groups[1]}.c.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_c_o_pattern} ${recipe_c_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
${build_path}/variant/${c?groups[1]}.c.d: ; variant/${c?groups[1]}.c.d: ;
-include ${build_path}/variant/${c?groups[1]}.c.d -include variant/${c?groups[1]}.c.d
</#if> </#if>
<#assign S = file?matches("${platform_variant_path}/(.*)\\.S")> <#assign S = file?matches("${platform_variant_path}/(.*)\\.S")>
<#if S> <#if S>
${build_path}/variant/${S?groups[1]}.S.o: ${file} variant/${S?groups[1]}.S.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_S_o_pattern} ${recipe_S_o_pattern_plat}
${recipe_ar_pattern} ${recipe_ar_pattern}
</#if> </#if>
@ -198,38 +201,38 @@ ${build_path}/variant/${S?groups[1]}.S.o: ${file}
<#list libraries_srcs as file> <#list libraries_srcs as file>
<#assign cpp = file?matches("${libraries_path}/(.*?)/(.*)\\.cpp")> <#assign cpp = file?matches("${libraries_path}/(.*?)/(.*)\\.cpp")>
<#if !cpp> <#if !cpp>
<#assign cpp = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.cpp")> <#assign cpp = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.cpp")>
</#if> </#if>
<#if cpp> <#if cpp>
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o: ${file} ${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.o: ${file} libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_cpp_o_pattern} ${recipe_cpp_o_pattern}
${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d: ; libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d: ;
-include ${build_path}/libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d -include libraries/${cpp?groups[1]}/${cpp?groups[2]}.cpp.d
</#if> </#if>
<#assign c = file?matches("${libraries_path}/(.*?)/(.*)\\.c")> <#assign c = file?matches("${libraries_path}/(.*?)/(.*)\\.c")>
<#if !c> <#if !c>
<#assign c = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.c")> <#assign c = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.c")>
</#if> </#if>
<#if c> <#if c>
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.o: ${file} ${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.d libraries/${c?groups[1]}/${c?groups[2]}.c.o: ${file} libraries/${c?groups[1]}/${c?groups[2]}.c.d
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_c_o_pattern} ${recipe_c_o_pattern}
${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.d: ; libraries/${c?groups[1]}/${c?groups[2]}.c.d: ;
-include ${build_path}/libraries/${c?groups[1]}/${c?groups[2]}.c.d -include libraries/${c?groups[1]}/${c?groups[2]}.c.d
</#if> </#if>
<#assign S = file?matches("${libraries_path}/(.*?)/(.*)\\.S")> <#assign S = file?matches("${libraries_path}/(.*?)/(.*)\\.S")>
<#if !S> <#if !S>
<#assign S = file?matches("${platform_core_path}/libraries/(.*?)/(.*)\\.S")> <#assign S = file?matches("${platform_path}/libraries/(.*?)/(.*)\\.S")>
</#if> </#if>
<#if S> <#if S>
${build_path}/libraries/${S?groups[1]}/${S?groups[2]}.S.o: ${file} libraries/${S?groups[1]}/${S?groups[2]}.S.o: ${file}
@$(call mymkdir,$(dir $@)) @$(call mymkdir,$(dir $@))
${recipe_S_o_pattern} ${recipe_S_o_pattern}

View file

@ -1,4 +1,5 @@
<templateManifest> <templateManifest>
<file src="/templates/cppsketch/arduino.cpp" <file open="true"
src="/templates/cppsketch/arduino.cpp"
dest="/${projectName}/${projectName}.cpp"/> dest="/${projectName}/${projectName}.cpp"/>
</templateManifest> </templateManifest>

View file

@ -7,8 +7,13 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.downloads; package org.eclipse.cdt.arduino.ui.internal.downloads;
import java.io.File;
import java.io.IOException;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jface.wizard.WizardPage;
@ -19,7 +24,9 @@ import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
public class ArduinoDownloadsManager extends WizardDialog { public class ArduinoDownloadsManager extends WizardDialog {
@ -84,7 +91,32 @@ public class ArduinoDownloadsManager extends WizardDialog {
protected void createButtonsForButtonBar(Composite parent) { protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent); super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.CANCEL_ID).setVisible(false); getButton(IDialogConstants.CANCEL_ID).setVisible(false);
getButton(IDialogConstants.FINISH_ID).setText("OK"); Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText("Done");
// make sure it's far right
finishButton.moveBelow(null);
}
static boolean checkLicense(Shell shell) {
File acceptedFile = ArduinoPreferences.getArduinoHome().resolve(".accepted").toFile(); //$NON-NLS-1$
if (!acceptedFile.exists()) {
String message = "Do you accept the licenses for the platforms and libraries you are downloading?";
MessageDialog dialog = new MessageDialog(shell, "Arduino Licensing", null, message,
MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0);
int rc = dialog.open();
if (rc == 0) {
try {
acceptedFile.createNewFile();
} catch (IOException e) {
Activator.log(e);
}
return true;
} else {
return false;
}
} else {
return true;
}
} }
} }

View file

@ -199,7 +199,7 @@ public class LibrariesTabControl extends Composite {
try { try {
container.run(true, true, monitor -> { container.run(true, true, monitor -> {
try { try {
for (ArduinoLibrary available : manager.getAvailableLibraries(monitor)) { for (ArduinoLibrary available : manager.getLibraryUpdates(monitor)) {
ArduinoLibrary installed = manager.getInstalledLibrary(available.getName()); ArduinoLibrary installed = manager.getInstalledLibrary(available.getName());
if (installed != null) { if (installed != null) {
if (ArduinoManager.compareVersions(available.getVersion(), installed.getVersion()) > 0) { if (ArduinoManager.compareVersions(available.getVersion(), installed.getVersion()) > 0) {
@ -263,14 +263,16 @@ public class LibrariesTabControl extends Composite {
SelectLibrariesDialog selectDialog = new SelectLibrariesDialog(getShell()); SelectLibrariesDialog selectDialog = new SelectLibrariesDialog(getShell());
selectDialog.setLibraries(availableLibraries); selectDialog.setLibraries(availableLibraries);
if (selectDialog.open() == Window.OK) { if (selectDialog.open() == Window.OK) {
Collection<ArduinoLibrary> selectedLibraries = selectDialog.getChecked(); if (ArduinoDownloadsManager.checkLicense(getShell())) {
container.run(true, true, monitor -> { Collection<ArduinoLibrary> selectedLibraries = selectDialog.getChecked();
try { container.run(true, true, monitor -> {
manager.installLibraries(selectedLibraries, monitor); try {
} catch (CoreException e) { manager.installLibraries(selectedLibraries, monitor);
Activator.log(e); } catch (CoreException e) {
} Activator.log(e);
}); }
});
}
} }
populateTable(); populateTable();
} catch (InterruptedException | InvocationTargetException e) { } catch (InterruptedException | InvocationTargetException e) {

View file

@ -197,7 +197,7 @@ public class PlatformsTabControl extends Composite {
try { try {
container.run(true, true, monitor -> { container.run(true, true, monitor -> {
try { try {
for (ArduinoPlatform available : manager.getAvailablePlatforms(monitor)) { for (ArduinoPlatform available : manager.getPlatformUpdates(monitor)) {
ArduinoPlatform installed = manager.getInstalledPlatform(available.getPackage().getName(), ArduinoPlatform installed = manager.getInstalledPlatform(available.getPackage().getName(),
available.getArchitecture()); available.getArchitecture());
if (installed != null) { if (installed != null) {
@ -257,14 +257,16 @@ public class PlatformsTabControl extends Composite {
SelectPlatformsDialog selectDialog = new SelectPlatformsDialog(getShell()); SelectPlatformsDialog selectDialog = new SelectPlatformsDialog(getShell());
selectDialog.setPlatforms(availablePlatforms); selectDialog.setPlatforms(availablePlatforms);
if (selectDialog.open() == Window.OK) { if (selectDialog.open() == Window.OK) {
Collection<ArduinoPlatform> selectedPlatforms = selectDialog.getSelectedPlatforms(); if (ArduinoDownloadsManager.checkLicense(getShell())) {
container.run(true, true, monitor -> { Collection<ArduinoPlatform> selectedPlatforms = selectDialog.getSelectedPlatforms();
try { container.run(true, true, monitor -> {
manager.installPlatforms(selectedPlatforms, monitor); try {
} catch (CoreException e) { manager.installPlatforms(selectedPlatforms, monitor);
Activator.log(e); } catch (CoreException e) {
} Activator.log(e);
}); }
});
}
} }
populateTable(); populateTable();
} catch (InterruptedException | InvocationTargetException e) { } catch (InterruptedException | InvocationTargetException e) {

View file

@ -10,14 +10,21 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.preferences; package org.eclipse.cdt.arduino.ui.internal.preferences;
import java.nio.file.Paths;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchPreferencePage;
@ -25,6 +32,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private Text urlsText; private Text urlsText;
private Text homeText;
@Override @Override
public void init(IWorkbench workbench) { public void init(IWorkbench workbench) {
@ -35,6 +43,33 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
Composite control = new Composite(parent, SWT.NONE); Composite control = new Composite(parent, SWT.NONE);
control.setLayout(new GridLayout()); control.setLayout(new GridLayout());
Composite homeComp = new Composite(control, SWT.NONE);
homeComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
homeComp.setLayout(new GridLayout(3, false));
Label label = new Label(homeComp, SWT.NONE);
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
label.setText("Arduino home:");
homeText = new Text(homeComp, SWT.BORDER);
homeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
homeText.setText(ArduinoPreferences.getArduinoHome().toString());
Button browse = new Button(homeComp, SWT.NONE);
browse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
browse.setText("Browse...");
browse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage("Select directory for the Arduino SDKs and toolchains.");
String dir = dialog.open();
if (dir != null) {
homeText.setText(dir);
}
}
});
Text desc = new Text(control, SWT.READ_ONLY | SWT.WRAP); Text desc = new Text(control, SWT.READ_ONLY | SWT.WRAP);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
layoutData.widthHint = 500; layoutData.widthHint = 500;
@ -52,14 +87,20 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
@Override @Override
public boolean performOk() { public boolean performOk() {
ArduinoPreferences.setBoardUrls(urlsText.getText()); ArduinoPreferences.setBoardUrls(urlsText.getText());
ArduinoPreferences.setArduinoHome(Paths.get(homeText.getText()));
return true; return true;
} }
@Override @Override
protected void performDefaults() { protected void performDefaults() {
String defaultHome = ArduinoPreferences.getDefaultArduinoHome();
homeText.setText(defaultHome);
ArduinoPreferences.setArduinoHome(Paths.get(defaultHome));
String defaultBoardUrl = ArduinoPreferences.getDefaultBoardUrls(); String defaultBoardUrl = ArduinoPreferences.getDefaultBoardUrls();
urlsText.setText(defaultBoardUrl); urlsText.setText(defaultBoardUrl);
ArduinoPreferences.setBoardUrls(defaultBoardUrl); ArduinoPreferences.setBoardUrls(defaultBoardUrl);
super.performDefaults(); super.performDefaults();
} }

View file

@ -7,29 +7,14 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.project; package org.eclipse.cdt.arduino.ui.internal.project;
import org.eclipse.tools.templates.ui.TemplateSelectionPage; import org.eclipse.tools.templates.ui.NewWizard;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
public class NewArduinoProjectWizard extends BasicNewProjectResourceWizard { public class NewArduinoProjectWizard extends NewWizard {
private static final String ARDUINO_TAG_ID = "org.eclipse.cdt.arduino.ui.tag"; //$NON-NLS-1$ private static final String ARDUINO_TAG_ID = "org.eclipse.cdt.arduino.ui.tag"; //$NON-NLS-1$
private TemplateSelectionPage templateSelectionPage;
public NewArduinoProjectWizard() { public NewArduinoProjectWizard() {
setForcePreviousAndNextButtons(true); super(ARDUINO_TAG_ID);
}
@Override
public void addPages() {
templateSelectionPage = new TemplateSelectionPage("templateSelection", ARDUINO_TAG_ID); //$NON-NLS-1$
templateSelectionPage.setTitle("Template for New Arduino Project");
this.addPage(templateSelectionPage);
}
@Override
public boolean performFinish() {
return true;
} }
} }

View file

@ -17,8 +17,6 @@ import java.util.Map.Entry;
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard; import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPackage;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection; import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
@ -49,6 +47,9 @@ public class BoardPropertyControl extends Composite {
private List<SelectionListener> listeners = Collections.synchronizedList(new ArrayList<SelectionListener>()); private List<SelectionListener> listeners = Collections.synchronizedList(new ArrayList<SelectionListener>());
private List<Control> menuControls = new ArrayList<>(); private List<Control> menuControls = new ArrayList<>();
private Label programmerLabel;
private Combo programmerCombo;
public BoardPropertyControl(Composite parent, int style) { public BoardPropertyControl(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -158,6 +159,28 @@ public class BoardPropertyControl extends Composite {
combo.select(0); combo.select(0);
} }
} }
try {
HierarchicalProperties programmers = board.getPlatform().getProgrammers();
if (programmers != null && programmers.getChildren() != null) {
programmerLabel = new Label(this, SWT.NONE);
programmerLabel.setText("Programmer:");
programmerCombo = new Combo(this, SWT.READ_ONLY);
programmerCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
List<String> ids = new ArrayList<>();
for (Entry<String, HierarchicalProperties> programmer : programmers.getChildren().entrySet()) {
ids.add(programmer.getKey());
String name = programmer.getValue().getChild("name").getValue(); //$NON-NLS-1$
programmerCombo.add(name);
}
programmerCombo.setData(ids);
programmerCombo.select(0);
}
} catch (CoreException e) {
Activator.log(e);
}
} }
private void boardChanged() { private void boardChanged() {
@ -169,6 +192,10 @@ public class BoardPropertyControl extends Composite {
control.dispose(); control.dispose();
} }
menuControls.clear(); menuControls.clear();
if (programmerLabel != null) {
programmerLabel.dispose();
programmerCombo.dispose();
}
board = newBoard; board = newBoard;
updateBoardMenu(); updateBoardMenu();
@ -205,6 +232,12 @@ public class BoardPropertyControl extends Composite {
} }
} }
} }
if (programmerCombo != null && !programmerCombo.isDisposed()) {
@SuppressWarnings("unchecked")
String programmer = ((List<String>) programmerCombo.getData()).get(programmerCombo.getSelectionIndex());
ArduinoRemoteConnection.setProgrammer(workingCopy, programmer);
}
} }
} }