mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Added Contributed Platforms.
- TargetPackage / TargetPlatform / TargetBoard are now interfaces - Contributions installed are detected during init time - Tools must be referenced through "path" property (automatically set by the IDE to the contributed tool path)
This commit is contained in:
committed by
Federico Fissore
parent
183c386e8c
commit
100dd21bd0
@ -91,6 +91,15 @@ public class Base {
|
|||||||
|
|
||||||
splashScreenHelper.splashText(_("Loading configuration..."));
|
splashScreenHelper.splashText(_("Loading configuration..."));
|
||||||
|
|
||||||
|
try {
|
||||||
|
guardedMain(args);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
System.exit(255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void guardedMain(String args[]) throws Exception {
|
||||||
BaseNoGui.initLogger();
|
BaseNoGui.initLogger();
|
||||||
|
|
||||||
BaseNoGui.notifier = new GUIUserNotifier();
|
BaseNoGui.notifier = new GUIUserNotifier();
|
||||||
|
@ -19,7 +19,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
targetPackage = new TargetPackage("arduino", new File(".", "hardware/arduino/"));
|
targetPackage = new LegacyTargetPackage("arduino", new File(".", "hardware/arduino/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
public interface ContributedBoard {
|
||||||
|
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ContributedPackage {
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract String getMaintainer();
|
||||||
|
|
||||||
|
public abstract String getWebsiteURL();
|
||||||
|
|
||||||
|
public abstract String getEmail();
|
||||||
|
|
||||||
|
public abstract List<ContributedPlatform> getPlatforms();
|
||||||
|
|
||||||
|
public abstract List<ContributedTool> getTools();
|
||||||
|
|
||||||
|
public ContributedPlatform findPlatform(String architecture, String version) {
|
||||||
|
for (ContributedPlatform platform : getPlatforms()) {
|
||||||
|
if (platform.getArchitecture().equals(architecture) &&
|
||||||
|
platform.getVersion().equals(version))
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContributedTool findTool(String name, String version) {
|
||||||
|
for (ContributedTool tool : getTools()) {
|
||||||
|
if (tool.getName().equals(name) && tool.getVersion().equals(version))
|
||||||
|
return tool;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String res;
|
||||||
|
res = "Package name : " + getName() + "\n";
|
||||||
|
res += " maintaner : " + getMaintainer() + " (" + getEmail() + ")\n";
|
||||||
|
if (getPlatforms() != null) {
|
||||||
|
for (ContributedPlatform plat : getPlatforms()) {
|
||||||
|
res += "\n Plaform : name : " + plat.getName();
|
||||||
|
if (plat.isInstalled()) {
|
||||||
|
res += "\n " + ((DownloadableContribution) plat);
|
||||||
|
}
|
||||||
|
res += "\n category : " + plat.getCategory();
|
||||||
|
res += "\n architecture : " +
|
||||||
|
plat.getArchitecture() + " " + plat.getVersion() + "\n";
|
||||||
|
if (plat.getToolsDependencies() != null)
|
||||||
|
for (ContributedToolReference t : plat.getToolsDependencies()) {
|
||||||
|
res += " tool dep : " + t.getName() + " " +
|
||||||
|
t.getVersion() + "\n";
|
||||||
|
}
|
||||||
|
if (plat.getBoards() != null)
|
||||||
|
for (ContributedBoard board : plat.getBoards())
|
||||||
|
res += " board : " + board.getName() +
|
||||||
|
"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getTools() != null) {
|
||||||
|
for (ContributedTool tool : getTools())
|
||||||
|
res += tool + "\n";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ContributedPlatform extends DownloadableContribution {
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract String getVersion();
|
||||||
|
|
||||||
|
public abstract String getCategory();
|
||||||
|
|
||||||
|
public abstract String getArchitecture();
|
||||||
|
|
||||||
|
public abstract String getChecksum();
|
||||||
|
|
||||||
|
public abstract List<ContributedToolReference> getToolsDependencies();
|
||||||
|
|
||||||
|
public abstract List<ContributedBoard> getBoards();
|
||||||
|
|
||||||
|
private List<ContributedTool> resolvedTools = null;
|
||||||
|
|
||||||
|
private ContributedPackage parentPackage;
|
||||||
|
|
||||||
|
public List<ContributedTool> getResolvedTools() {
|
||||||
|
return resolvedTools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ContributedTool> resolveToolsDependencies(Collection<ContributedPackage> packages) {
|
||||||
|
resolvedTools = new ArrayList<ContributedTool>();
|
||||||
|
|
||||||
|
// If there are no dependencies return empty list
|
||||||
|
if (getToolsDependencies() == null)
|
||||||
|
return resolvedTools;
|
||||||
|
|
||||||
|
// For each tool dependency
|
||||||
|
for (ContributedToolReference dep : getToolsDependencies()) {
|
||||||
|
// Search the referenced tool
|
||||||
|
ContributedTool tool = dep.resolve(packages);
|
||||||
|
if (tool == null) {
|
||||||
|
System.err
|
||||||
|
.println("Index error: could not find referenced tool " + dep);
|
||||||
|
}
|
||||||
|
resolvedTools.add(tool);
|
||||||
|
}
|
||||||
|
return resolvedTools;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContributedPackage getParentPackage() {
|
||||||
|
return parentPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentPackage(ContributedPackage parentPackage) {
|
||||||
|
this.parentPackage = parentPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import processing.app.debug.TargetPackage;
|
||||||
|
import processing.app.debug.TargetPlatform;
|
||||||
|
|
||||||
|
public class ContributedTargetPackage implements TargetPackage {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private Map<String, TargetPlatform> platforms;
|
||||||
|
|
||||||
|
public ContributedTargetPackage(String _id) {
|
||||||
|
id = _id;
|
||||||
|
platforms = new HashMap<String, TargetPlatform>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addPlatform(TargetPlatform p) {
|
||||||
|
platforms.put(p.getId(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasPlatforms() {
|
||||||
|
return platforms.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, TargetPlatform> getPlatforms() {
|
||||||
|
return platforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<TargetPlatform> platforms() {
|
||||||
|
return platforms.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetPlatform get(String platform) {
|
||||||
|
return platforms.get(platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TargetPackage: " + getId();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
import static processing.app.I18n.format;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import processing.app.debug.LegacyTargetPlatform;
|
||||||
|
import processing.app.debug.TargetPackage;
|
||||||
|
import processing.app.debug.TargetPlatformException;
|
||||||
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
|
public class ContributedTargetPlatform extends LegacyTargetPlatform {
|
||||||
|
|
||||||
|
public ContributedTargetPlatform(String _name, File _folder,
|
||||||
|
TargetPackage parent,
|
||||||
|
ContributionsIndex index)
|
||||||
|
throws TargetPlatformException {
|
||||||
|
super(_name, _folder, parent);
|
||||||
|
|
||||||
|
// Populate tools
|
||||||
|
PreferencesMap toolsPrefs = preferences.subTree("tools");
|
||||||
|
Set<String> names = toolsPrefs.firstLevelMap().keySet();
|
||||||
|
for (String name : names) {
|
||||||
|
String version = toolsPrefs.get(name + ".version");
|
||||||
|
if (version == null) {
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Tool {0} must define a version property ({1})"), //
|
||||||
|
name, "tools." + name + ".version"));
|
||||||
|
}
|
||||||
|
|
||||||
|
String packageName = getContainerPackage().getId();
|
||||||
|
ContributedTool tool = index.findTool(packageName, name, version);
|
||||||
|
if (tool == null) {
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Tool {0} not found in package {1}"),
|
||||||
|
name + ":" + version, packageName));
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadableContribution download = tool.getDownloadableContribution();
|
||||||
|
if (!download.isInstalled()) {
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Tool {0} is required but it's not installed."), //
|
||||||
|
name + ":" + version));
|
||||||
|
}
|
||||||
|
preferences.put("tools." + name + ".path", //
|
||||||
|
download.getInstalledFolder().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ContributedTool {
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract String getVersion();
|
||||||
|
|
||||||
|
public abstract List<HostDependentDownloadableContribution> getSystems();
|
||||||
|
|
||||||
|
public DownloadableContribution getDownloadableContribution() {
|
||||||
|
for (HostDependentDownloadableContribution c : getSystems()) {
|
||||||
|
if (c.isCompatible())
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String res;
|
||||||
|
res = "Tool name : " + getName() + " " + getVersion() + "\n";
|
||||||
|
for (HostDependentDownloadableContribution sys : getSystems()) {
|
||||||
|
res += " sys";
|
||||||
|
res += sys.isCompatible() ? "*" : " ";
|
||||||
|
res += " : " + sys + "\n";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class ContributedToolReference {
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract String getVersion();
|
||||||
|
|
||||||
|
public abstract String getPackager();
|
||||||
|
|
||||||
|
public ContributedTool resolve(Collection<ContributedPackage> packages) {
|
||||||
|
for (ContributedPackage pack : packages) {
|
||||||
|
for (ContributedTool tool : pack.getTools())
|
||||||
|
if (tool.getName().equals(getName()) &&
|
||||||
|
tool.getVersion().equals(getVersion()) &&
|
||||||
|
pack.getName().equals(getPackager()))
|
||||||
|
return tool;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "name=" + getName() + " version=" + getVersion() + " packager=" +
|
||||||
|
getPackager();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ContributionsIndex {
|
||||||
|
|
||||||
|
public abstract List<ContributedPackage> getPackages();
|
||||||
|
|
||||||
|
public ContributedPackage findPackage(String packageName) {
|
||||||
|
for (ContributedPackage pack : getPackages()) {
|
||||||
|
if (pack.getName().equals(packageName))
|
||||||
|
return pack;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContributedTool findTool(String packageName, String name,
|
||||||
|
String version) {
|
||||||
|
ContributedPackage pack = findPackage(packageName);
|
||||||
|
if (pack == null)
|
||||||
|
return null;
|
||||||
|
return pack.findTool(name, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> categories = new ArrayList<String>();
|
||||||
|
|
||||||
|
public List<String> getCategories() {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillCategories() {
|
||||||
|
categories.clear();
|
||||||
|
for (ContributedPackage pack : getPackages()) {
|
||||||
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
|
if (!categories.contains(platform.getCategory()))
|
||||||
|
categories.add(platform.getCategory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String res = "";
|
||||||
|
res += "Categories: ";
|
||||||
|
for (String c : getCategories())
|
||||||
|
res += "'" + c + "' ";
|
||||||
|
res += "\n";
|
||||||
|
for (ContributedPackage pack : getPackages())
|
||||||
|
res += pack + "\n";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import processing.app.debug.TargetPackage;
|
||||||
|
import processing.app.debug.TargetPlatform;
|
||||||
|
import processing.app.debug.TargetPlatformException;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||||
|
|
||||||
|
public class ContributionsIndexer {
|
||||||
|
|
||||||
|
private File preferencesFolder;
|
||||||
|
private File packagesFolder;
|
||||||
|
private ContributionsIndex index;
|
||||||
|
|
||||||
|
public ContributionsIndexer(File _preferencesFolder) {
|
||||||
|
preferencesFolder = _preferencesFolder;
|
||||||
|
packagesFolder = new File(preferencesFolder, "packages");
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void main(String args[]) throws Exception {
|
||||||
|
// File indexFile = new File(args[0]);
|
||||||
|
//
|
||||||
|
// // VerifyResult verify = ClearSignedVerifier.verify(indexFile,
|
||||||
|
// // new PackagersPublicKeys());
|
||||||
|
// // if (!verify.verified)
|
||||||
|
// // throw new Exception("Invalid index file!");
|
||||||
|
//
|
||||||
|
// ContributionsIndexer indexer = new ContributionsIndexer(null);
|
||||||
|
// // indexer.parse(new ByteArrayInputStream(verify.clearText));
|
||||||
|
// indexer.parseIndex(indexFile);
|
||||||
|
// indexer.syncWithFilesystem();
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void parseIndex() throws JsonParseException, IOException {
|
||||||
|
// Parse index file
|
||||||
|
parseIndex(new File(preferencesFolder, "package_index.json"));
|
||||||
|
|
||||||
|
List<ContributedPackage> packages = index.getPackages();
|
||||||
|
for (ContributedPackage pack : packages) {
|
||||||
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
|
// Set a reference to parent packages
|
||||||
|
platform.setParentPackage(pack);
|
||||||
|
|
||||||
|
// Resolve tools dependencies (works also as a check for file integrity)
|
||||||
|
platform.resolveToolsDependencies(packages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index.fillCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseIndex(File indexFile) throws JsonParseException,
|
||||||
|
IOException {
|
||||||
|
InputStream indexIn = new FileInputStream(indexFile);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.registerModule(new MrBeanModule());
|
||||||
|
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
|
mapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
||||||
|
index = mapper.readValue(indexIn, ContributionsIndex.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncWithFilesystem() {
|
||||||
|
if (!packagesFolder.isDirectory())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Scan all hardware folders and mark as installed all the
|
||||||
|
// platforms found.
|
||||||
|
for (File folder : packagesFolder.listFiles(ONLY_DIRS)) {
|
||||||
|
ContributedPackage pack = index.findPackage(folder.getName());
|
||||||
|
if (pack != null)
|
||||||
|
syncPackageWithFilesystem(pack, folder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncPackageWithFilesystem(ContributedPackage pack, File root) {
|
||||||
|
// Scan all hardware folders and mark as installed all the tools found.
|
||||||
|
File hardwareFolder = new File(root, "hardware");
|
||||||
|
if (hardwareFolder.isDirectory()) {
|
||||||
|
for (File platformFolder : hardwareFolder.listFiles(ONLY_DIRS)) {
|
||||||
|
for (File versionFolder : platformFolder.listFiles(ONLY_DIRS))
|
||||||
|
syncHardwareWithFilesystem(pack, platformFolder, versionFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan all tools folders and mark as installed all the tools found.
|
||||||
|
File toolsFolder = new File(root, "tools");
|
||||||
|
if (toolsFolder.isDirectory()) {
|
||||||
|
for (File toolFolder : toolsFolder.listFiles(ONLY_DIRS)) {
|
||||||
|
for (File versionFolder : toolFolder.listFiles(ONLY_DIRS))
|
||||||
|
syncToolWithFilesystem(pack, toolFolder, versionFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncToolWithFilesystem(ContributedPackage pack, File toolFolder,
|
||||||
|
File versionFolder) {
|
||||||
|
ContributedTool tool = pack.findTool(toolFolder.getName(),
|
||||||
|
versionFolder.getName());
|
||||||
|
if (tool == null)
|
||||||
|
return;
|
||||||
|
DownloadableContribution contrib = tool.getDownloadableContribution();
|
||||||
|
if (contrib == null) {
|
||||||
|
System.err.println(tool +
|
||||||
|
" seems to have no downloadable contributions for your " +
|
||||||
|
"operating system, but it is installed in\n" + versionFolder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contrib.setInstalled(true);
|
||||||
|
contrib.setInstalledFolder(versionFolder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncHardwareWithFilesystem(ContributedPackage pack,
|
||||||
|
File platformFolder,
|
||||||
|
File versionFolder) {
|
||||||
|
String architecture = platformFolder.getName();
|
||||||
|
String version = versionFolder.getName();
|
||||||
|
ContributedPlatform platform = pack.findPlatform(architecture, version);
|
||||||
|
if (platform != null) {
|
||||||
|
platform.setInstalled(true);
|
||||||
|
platform.setInstalledFolder(versionFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return index.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TargetPackage> createTargetPackages() {
|
||||||
|
List<TargetPackage> res = new ArrayList<TargetPackage>();
|
||||||
|
|
||||||
|
for (ContributedPackage pack : index.getPackages()) {
|
||||||
|
ContributedTargetPackage targetPackage;
|
||||||
|
targetPackage = new ContributedTargetPackage(pack.getName());
|
||||||
|
|
||||||
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
|
if (!platform.isInstalled())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String arch = platform.getArchitecture();
|
||||||
|
File folder = platform.getInstalledFolder();
|
||||||
|
|
||||||
|
try {
|
||||||
|
TargetPlatform targetPlatform;
|
||||||
|
targetPlatform = new ContributedTargetPlatform(arch, folder,
|
||||||
|
targetPackage, index);
|
||||||
|
targetPackage.addPlatform(targetPlatform);
|
||||||
|
} catch (TargetPlatformException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetPackage.hasPlatforms())
|
||||||
|
res.add(targetPackage);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public abstract class DownloadableContribution {
|
||||||
|
|
||||||
|
private boolean installed;
|
||||||
|
private File installedFolder;
|
||||||
|
|
||||||
|
private boolean downloaded;
|
||||||
|
private File downloadedFile;
|
||||||
|
|
||||||
|
public abstract String getUrl();
|
||||||
|
|
||||||
|
public abstract String getChecksum();
|
||||||
|
|
||||||
|
public abstract long getSize();
|
||||||
|
|
||||||
|
public abstract String getArchiveFileName();
|
||||||
|
|
||||||
|
public boolean isDownloaded() {
|
||||||
|
return downloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloaded(boolean downloaded) {
|
||||||
|
this.downloaded = downloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDownloadedFile() {
|
||||||
|
return downloadedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadedFile(File downloadedFile) {
|
||||||
|
this.downloadedFile = downloadedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInstalled() {
|
||||||
|
return installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstalled(boolean installed) {
|
||||||
|
this.installed = installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getInstalledFolder() {
|
||||||
|
return installedFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstalledFolder(File installedFolder) {
|
||||||
|
this.installedFolder = installedFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String chk = getChecksum();
|
||||||
|
if (chk.length() > 14)
|
||||||
|
chk = getChecksum().substring(0, 14);
|
||||||
|
String res = "";
|
||||||
|
// res += getUrl() + " (" + chk + ") ";
|
||||||
|
if (installed) {
|
||||||
|
res += "installed on " + installedFolder.getAbsolutePath() + " (" +
|
||||||
|
getSize() + " bytes)";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Arduino.
|
||||||
|
*
|
||||||
|
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
|
||||||
|
*
|
||||||
|
* Arduino is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* As a special exception, you may use this file as part of a free software
|
||||||
|
* library without restriction. Specifically, if other files instantiate
|
||||||
|
* templates or use macros or inline functions from this file, or you compile
|
||||||
|
* this file and link it with other files to produce an executable, this
|
||||||
|
* file does not by itself cause the resulting executable to be covered by
|
||||||
|
* the GNU General Public License. This exception does not however
|
||||||
|
* invalidate any other reasons why the executable file might be covered by
|
||||||
|
* the GNU General Public License.
|
||||||
|
*/
|
||||||
|
package cc.arduino.packages.contributions;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public abstract class HostDependentDownloadableContribution extends
|
||||||
|
DownloadableContribution {
|
||||||
|
|
||||||
|
public abstract String getHost();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getHost() + " " + super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCompatible() {
|
||||||
|
// TODO: add missing host detections
|
||||||
|
|
||||||
|
Properties prop = System.getProperties();
|
||||||
|
String osName = prop.getProperty("os.name");
|
||||||
|
String osArch = prop.getProperty("os.arch");
|
||||||
|
// for (Object k : properties.keySet())
|
||||||
|
// System.out.println(k + " = " + properties.get(k));
|
||||||
|
|
||||||
|
String host = getHost();
|
||||||
|
|
||||||
|
if (osName.contains("Linux")) {
|
||||||
|
if (osArch.contains("amd64")) {
|
||||||
|
// os.arch = amd64
|
||||||
|
return host.matches("x86_64-.*linux-gnu");
|
||||||
|
} else {
|
||||||
|
// 32 bit systems
|
||||||
|
return host.matches("i[3456]86-.*linux-gnu");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (osName.contains("Windows")) {
|
||||||
|
if (host.matches("i[3456]86-.*mingw32"))
|
||||||
|
return true;
|
||||||
|
if (host.matches("i[3456]86-.*cygwin"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (osName.contains("Mac")) {
|
||||||
|
if (osArch.contains("86")) {
|
||||||
|
if (host.matches("i[3456]86-apple-darwin.*"))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -17,9 +17,10 @@ import org.apache.commons.logging.impl.NoOpLog;
|
|||||||
|
|
||||||
import cc.arduino.packages.DiscoveryManager;
|
import cc.arduino.packages.DiscoveryManager;
|
||||||
import cc.arduino.packages.Uploader;
|
import cc.arduino.packages.Uploader;
|
||||||
|
|
||||||
import processing.app.debug.Compiler;
|
import processing.app.debug.Compiler;
|
||||||
|
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||||
import processing.app.debug.TargetBoard;
|
import processing.app.debug.TargetBoard;
|
||||||
|
import processing.app.debug.LegacyTargetPackage;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
import processing.app.debug.TargetPlatform;
|
import processing.app.debug.TargetPlatform;
|
||||||
import processing.app.debug.TargetPlatformException;
|
import processing.app.debug.TargetPlatformException;
|
||||||
@ -421,7 +422,7 @@ public class BaseNoGui {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void init(String[] args) {
|
static public void init(String[] args) throws Exception {
|
||||||
getPlatform().init();
|
getPlatform().init();
|
||||||
|
|
||||||
String sketchbookPath = getSketchbookPath();
|
String sketchbookPath = getSketchbookPath();
|
||||||
@ -582,14 +583,16 @@ public class BaseNoGui {
|
|||||||
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
|
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void initPackages() {
|
static public void initPackages() throws Exception {
|
||||||
|
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||||
|
indexer.parseIndex();
|
||||||
|
indexer.syncWithFilesystem();
|
||||||
|
System.out.println(indexer);
|
||||||
|
|
||||||
packages = new HashMap<String, TargetPackage>();
|
packages = new HashMap<String, TargetPackage>();
|
||||||
loadHardware(getHardwareFolder());
|
loadHardware(getHardwareFolder());
|
||||||
loadHardware(getSketchbookHardwareFolder());
|
loadHardware(getSketchbookHardwareFolder());
|
||||||
if (packages.size() == 0) {
|
loadContributedHardware(indexer);
|
||||||
System.out.println(_("No valid configured cores found! Exiting..."));
|
|
||||||
System.exit(3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected void initPlatform() {
|
static protected void initPlatform() {
|
||||||
@ -649,7 +652,7 @@ public class BaseNoGui {
|
|||||||
File subfolder = new File(folder, target);
|
File subfolder = new File(folder, target);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
packages.put(target, new TargetPackage(target, subfolder));
|
packages.put(target, new LegacyTargetPackage(target, subfolder));
|
||||||
} catch (TargetPlatformException e) {
|
} catch (TargetPlatformException e) {
|
||||||
System.out.println("WARNING: Error loading hardware folder " + target);
|
System.out.println("WARNING: Error loading hardware folder " + target);
|
||||||
System.out.println(" " + e.getMessage());
|
System.out.println(" " + e.getMessage());
|
||||||
@ -714,6 +717,12 @@ public class BaseNoGui {
|
|||||||
populateImportToLibraryTable();
|
populateImportToLibraryTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static protected void loadContributedHardware(ContributionsIndexer indexer) {
|
||||||
|
for (TargetPackage pack : indexer.createTargetPackages()) {
|
||||||
|
packages.put(pack.getId(), pack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static public void populateImportToLibraryTable() {
|
static public void populateImportToLibraryTable() {
|
||||||
// Populate importToLibraryTable
|
// Populate importToLibraryTable
|
||||||
importToLibraryTable = new HashMap<String, Library>();
|
importToLibraryTable = new HashMap<String, Library>();
|
||||||
|
113
arduino-core/src/processing/app/debug/LegacyTargetBoard.java
Normal file
113
arduino-core/src/processing/app/debug/LegacyTargetBoard.java
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
TargetPackage - Represents a hardware package
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2014 Cristian Maglie
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
import static processing.app.I18n.format;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
|
public class LegacyTargetBoard implements TargetBoard {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private PreferencesMap prefs;
|
||||||
|
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
||||||
|
private TargetPlatform containerPlatform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TargetBoard based on preferences passed as argument.
|
||||||
|
*
|
||||||
|
* @param _prefs
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LegacyTargetBoard(String _id, PreferencesMap _prefs,
|
||||||
|
TargetPlatform parent) {
|
||||||
|
containerPlatform = parent;
|
||||||
|
id = _id;
|
||||||
|
prefs = new PreferencesMap(_prefs);
|
||||||
|
|
||||||
|
// Setup sub-menus
|
||||||
|
PreferencesMap menus = prefs.firstLevelMap().get("menu");
|
||||||
|
if (menus != null)
|
||||||
|
menuOptions = menus.firstLevelMap();
|
||||||
|
|
||||||
|
// Auto generate build.board if not set
|
||||||
|
if (!prefs.containsKey("build.board")) {
|
||||||
|
String board = containerPlatform.getId() + "_" + id;
|
||||||
|
board = board.toUpperCase();
|
||||||
|
prefs.put("build.board", board);
|
||||||
|
System.out
|
||||||
|
.println(format(_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
|
||||||
|
containerPlatform.getContainerPackage().getId(),
|
||||||
|
containerPlatform.getId(), id, board));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return prefs.get("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getPreferences() {
|
||||||
|
return prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasMenu(String menuId) {
|
||||||
|
return menuOptions.containsKey(menuId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getMenuLabels(String menuId) {
|
||||||
|
return menuOptions.get(menuId).topLevelMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMenuLabel(String menuId, String selectionId) {
|
||||||
|
return getMenuLabels(menuId).get(selectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getMenuIds() {
|
||||||
|
return menuOptions.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
|
||||||
|
return menuOptions.get(menuId).subTree(selectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetPlatform getContainerPlatform() {
|
||||||
|
return containerPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
TargetPackage - Represents a hardware package
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2011 Cristian Maglie
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import processing.app.I18n;
|
||||||
|
|
||||||
|
public class LegacyTargetPackage implements TargetPackage {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private Map<String, TargetPlatform> platforms;
|
||||||
|
|
||||||
|
public LegacyTargetPackage(String _id, File _folder) throws TargetPlatformException {
|
||||||
|
id = _id;
|
||||||
|
platforms = new LinkedHashMap<String, TargetPlatform>();
|
||||||
|
|
||||||
|
File[] folders = _folder.listFiles(ONLY_DIRS);
|
||||||
|
if (folders == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (File subFolder : folders) {
|
||||||
|
if (!subFolder.exists() || !subFolder.canRead())
|
||||||
|
continue;
|
||||||
|
String arch = subFolder.getName();
|
||||||
|
try {
|
||||||
|
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
|
||||||
|
platforms.put(arch, platform);
|
||||||
|
} catch (TargetPlatformException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platforms.size() == 0) {
|
||||||
|
throw new TargetPlatformException(I18n
|
||||||
|
.format(_("No valid hardware definitions found in folder {0}."),
|
||||||
|
_folder.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, TargetPlatform> getPlatforms() {
|
||||||
|
return platforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<TargetPlatform> platforms() {
|
||||||
|
return platforms.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetPlatform get(String platform) {
|
||||||
|
return platforms.get(platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
198
arduino-core/src/processing/app/debug/LegacyTargetPlatform.java
Normal file
198
arduino-core/src/processing/app/debug/LegacyTargetPlatform.java
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
TargetPlatform - Represents a hardware platform
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2009-2014 Arduino
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
import static processing.app.I18n.format;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
|
public class LegacyTargetPlatform implements TargetPlatform {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private File folder;
|
||||||
|
|
||||||
|
private TargetPackage containerPackage;
|
||||||
|
protected PreferencesMap preferences = new PreferencesMap();
|
||||||
|
|
||||||
|
private Map<String, TargetBoard> boards = new LinkedHashMap<String, TargetBoard>();
|
||||||
|
private TargetBoard defaultBoard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains preferences for every defined programmer
|
||||||
|
*/
|
||||||
|
private Map<String, PreferencesMap> programmers = new LinkedHashMap<String, PreferencesMap>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains labels for top level menus
|
||||||
|
*/
|
||||||
|
private PreferencesMap customMenus = new PreferencesMap();
|
||||||
|
|
||||||
|
public LegacyTargetPlatform(String _name, File _folder, TargetPackage parent)
|
||||||
|
throws TargetPlatformException {
|
||||||
|
|
||||||
|
id = _name;
|
||||||
|
folder = _folder;
|
||||||
|
containerPackage = parent;
|
||||||
|
|
||||||
|
// If there is no boards.txt, this is not a valid 1.5 hardware folder
|
||||||
|
File boardsFile = new File(folder, "boards.txt");
|
||||||
|
if (!boardsFile.exists() || !boardsFile.canRead())
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Could not find boards.txt in {0}. Is it pre-1.5?"),
|
||||||
|
folder.getAbsolutePath()));
|
||||||
|
|
||||||
|
// Load boards
|
||||||
|
try {
|
||||||
|
Map<String, PreferencesMap> boardsPreferences = new PreferencesMap(
|
||||||
|
boardsFile).firstLevelMap();
|
||||||
|
|
||||||
|
// Create custom menus for this platform
|
||||||
|
PreferencesMap menus = boardsPreferences.get("menu");
|
||||||
|
if (menus != null)
|
||||||
|
customMenus = menus.topLevelMap();
|
||||||
|
boardsPreferences.remove("menu");
|
||||||
|
|
||||||
|
// Create boards
|
||||||
|
Set<String> boardIds = boardsPreferences.keySet();
|
||||||
|
for (String boardId : boardIds) {
|
||||||
|
PreferencesMap preferences = boardsPreferences.get(boardId);
|
||||||
|
TargetBoard board = new LegacyTargetBoard(boardId, preferences, this);
|
||||||
|
boards.put(boardId, board);
|
||||||
|
|
||||||
|
// Pick the first board as default
|
||||||
|
if (defaultBoard == null)
|
||||||
|
defaultBoard = board;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TargetPlatformException(format(_("Error loading {0}"),
|
||||||
|
boardsFile.getAbsolutePath()), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File platformsFile = new File(folder, "platform.txt");
|
||||||
|
try {
|
||||||
|
if (platformsFile.exists() && platformsFile.canRead()) {
|
||||||
|
preferences.load(platformsFile);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Error loading {0}"), platformsFile.getAbsolutePath()), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow overriding values in platform.txt. This allows changing
|
||||||
|
// platform.txt (e.g. to use a system-wide toolchain), without
|
||||||
|
// having to modify platform.txt (which, when running from git,
|
||||||
|
// prevents files being marked as changed).
|
||||||
|
File localPlatformsFile = new File(folder, "platform.local.txt");
|
||||||
|
try {
|
||||||
|
if (localPlatformsFile.exists() && localPlatformsFile.canRead()) {
|
||||||
|
preferences.load(localPlatformsFile);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TargetPlatformException(
|
||||||
|
format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File progFile = new File(folder, "programmers.txt");
|
||||||
|
try {
|
||||||
|
if (progFile.exists() && progFile.canRead()) {
|
||||||
|
PreferencesMap prefs = new PreferencesMap();
|
||||||
|
prefs.load(progFile);
|
||||||
|
programmers = prefs.firstLevelMap();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TargetPlatformException(format(_("Error loading {0}"),
|
||||||
|
progFile.getAbsolutePath()), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFolder() {
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, TargetBoard> getBoards() {
|
||||||
|
return boards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getCustomMenus() {
|
||||||
|
return customMenus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getCustomMenuIds() {
|
||||||
|
return customMenus.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, PreferencesMap> getProgrammers() {
|
||||||
|
return programmers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getProgrammer(String programmer) {
|
||||||
|
return getProgrammers().get(programmer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getTool(String tool) {
|
||||||
|
return getPreferences().subTree("tools").subTree(tool);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreferencesMap getPreferences() {
|
||||||
|
return preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetBoard getBoard(String boardId) {
|
||||||
|
if (boards.containsKey(boardId)) {
|
||||||
|
return boards.get(boardId);
|
||||||
|
}
|
||||||
|
return defaultBoard;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetPackage getContainerPackage() {
|
||||||
|
return containerPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String res = "TargetPlatform: name=" + id + " boards={\n";
|
||||||
|
for (String boardId : boards.keySet())
|
||||||
|
res += " " + boardId + " = " + boards.get(boardId) + "\n";
|
||||||
|
return res + "}";
|
||||||
|
}
|
||||||
|
}
|
@ -1,76 +1,51 @@
|
|||||||
|
/*
|
||||||
|
TargetBoard - Represents a hardware board
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2014 Cristian Maglie
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
package processing.app.debug;
|
package processing.app.debug;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
import static processing.app.I18n.format;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
public class TargetBoard {
|
public interface TargetBoard {
|
||||||
|
|
||||||
private String id;
|
|
||||||
private PreferencesMap prefs;
|
|
||||||
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
|
||||||
private TargetPlatform containerPlatform;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TargetBoard based on preferences passed as argument.
|
|
||||||
*
|
|
||||||
* @param _prefs
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
|
|
||||||
containerPlatform = parent;
|
|
||||||
id = _id;
|
|
||||||
prefs = new PreferencesMap(_prefs);
|
|
||||||
|
|
||||||
// Setup sub-menus
|
|
||||||
PreferencesMap menus = prefs.firstLevelMap().get("menu");
|
|
||||||
if (menus != null)
|
|
||||||
menuOptions = menus.firstLevelMap();
|
|
||||||
|
|
||||||
// Auto generate build.board if not set
|
|
||||||
if (!prefs.containsKey("build.board")) {
|
|
||||||
String board = containerPlatform.getId() + "_" + id;
|
|
||||||
board = board.toUpperCase();
|
|
||||||
prefs.put("build.board", board);
|
|
||||||
System.out
|
|
||||||
.println(format(
|
|
||||||
_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
|
|
||||||
containerPlatform.getContainerPackage().getId(),
|
|
||||||
containerPlatform.getId(), id, board));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the board.
|
* Get the name of the board.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName();
|
||||||
return prefs.get("name");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the identifier of the board
|
* Get the identifier of the board
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public String getId();
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the full preferences map of the board with a given identifier
|
* Get the full preferences map of the board
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PreferencesMap getPreferences() {
|
public PreferencesMap getPreferences();
|
||||||
return prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the board has a sub menu.
|
* Check if the board has a sub menu.
|
||||||
@ -79,9 +54,7 @@ public class TargetBoard {
|
|||||||
* The menu ID to check
|
* The menu ID to check
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean hasMenu(String menuId) {
|
public boolean hasMenu(String menuId);
|
||||||
return menuOptions.containsKey(menuId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the options available on a specific menu
|
* Returns the options available on a specific menu
|
||||||
@ -90,9 +63,7 @@ public class TargetBoard {
|
|||||||
* The menu ID
|
* The menu ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PreferencesMap getMenuLabels(String menuId) {
|
public PreferencesMap getMenuLabels(String menuId);
|
||||||
return menuOptions.get(menuId).topLevelMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the label of the specified option in the specified menu
|
* Returns the label of the specified option in the specified menu
|
||||||
@ -103,13 +74,9 @@ public class TargetBoard {
|
|||||||
* The option ID
|
* The option ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getMenuLabel(String menuId, String selectionId) {
|
public String getMenuLabel(String menuId, String selectionId);
|
||||||
return getMenuLabels(menuId).get(selectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getMenuIds() {
|
public Set<String> getMenuIds();
|
||||||
return menuOptions.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration parameters to override (as a PreferenceMap) when
|
* Returns the configuration parameters to override (as a PreferenceMap) when
|
||||||
@ -121,12 +88,8 @@ public class TargetBoard {
|
|||||||
* The option ID
|
* The option ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
|
public PreferencesMap getMenuPreferences(String menuId, String selectionId);
|
||||||
return menuOptions.get(menuId).subTree(selectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetPlatform getContainerPlatform() {
|
public TargetPlatform getContainerPlatform();
|
||||||
return containerPlatform;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
||||||
/*
|
/*
|
||||||
TargetPackage - Represents a hardware package
|
TargetPackage - Represents a hardware package
|
||||||
Part of the Arduino project - http://www.arduino.cc/
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
Copyright (c) 2011 Cristian Maglie
|
Copyright (c) 2014 Cristian Maglie
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -21,61 +20,17 @@
|
|||||||
*/
|
*/
|
||||||
package processing.app.debug;
|
package processing.app.debug;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import processing.app.I18n;
|
public interface TargetPackage {
|
||||||
import processing.app.helpers.filefilters.OnlyDirs;
|
|
||||||
|
|
||||||
public class TargetPackage {
|
public String getId();
|
||||||
|
|
||||||
|
public Map<String, TargetPlatform> getPlatforms();
|
||||||
|
|
||||||
private String id;
|
public Collection<TargetPlatform> platforms();
|
||||||
|
|
||||||
Map<String, TargetPlatform> platforms = new LinkedHashMap<String, TargetPlatform>();
|
public TargetPlatform get(String platform);
|
||||||
|
|
||||||
public TargetPackage(String _id, File _folder) throws TargetPlatformException {
|
|
||||||
id = _id;
|
|
||||||
|
|
||||||
File[] folders = _folder.listFiles(new OnlyDirs());
|
|
||||||
if (folders == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (File subFolder : folders) {
|
|
||||||
if (!subFolder.exists() || !subFolder.canRead())
|
|
||||||
continue;
|
|
||||||
String arch = subFolder.getName();
|
|
||||||
try {
|
|
||||||
TargetPlatform platform = new TargetPlatform(arch, subFolder, this);
|
|
||||||
platforms.put(arch, platform);
|
|
||||||
} catch (TargetPlatformException e) {
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (platforms.size() == 0) {
|
|
||||||
throw new TargetPlatformException(I18n
|
|
||||||
.format(_("No valid hardware definitions found in folder {0}."),
|
|
||||||
_folder.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, TargetPlatform> getPlatforms() {
|
|
||||||
return platforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<TargetPlatform> platforms() {
|
|
||||||
return platforms.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetPlatform get(String platform) {
|
|
||||||
return platforms.get(platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
||||||
/*
|
/*
|
||||||
TargetPlatform - Represents a hardware platform
|
TargetPlatform - Represents a hardware platform
|
||||||
Part of the Arduino project - http://www.arduino.cc/
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
Copyright (c) 2009 David A. Mellis
|
Copyright (c) 2014 Arduino
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -21,174 +20,78 @@
|
|||||||
*/
|
*/
|
||||||
package processing.app.debug;
|
package processing.app.debug;
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
|
||||||
import static processing.app.I18n.format;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
public class TargetPlatform {
|
public interface TargetPlatform {
|
||||||
|
|
||||||
private String id;
|
public String getId();
|
||||||
private File folder;
|
|
||||||
private TargetPackage containerPackage;
|
public File getFolder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains preferences for every defined board
|
* Get TargetBoards under this TargetPlatform into a Map that maps the board
|
||||||
|
* id with the corresponding TargetBoard
|
||||||
|
*
|
||||||
|
* @return a Map<String, TargetBoard>
|
||||||
*/
|
*/
|
||||||
private Map<String, TargetBoard> boards = new LinkedHashMap<String, TargetBoard>();
|
public Map<String, TargetBoard> getBoards();
|
||||||
private TargetBoard defaultBoard;
|
|
||||||
|
public PreferencesMap getCustomMenus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains preferences for every defined programmer
|
* Return ids for top level menus
|
||||||
|
*
|
||||||
|
* @return a Set<String> with the ids of the top level custom menus
|
||||||
*/
|
*/
|
||||||
private Map<String, PreferencesMap> programmers = new LinkedHashMap<String, PreferencesMap>();
|
public Set<String> getCustomMenuIds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains preferences for platform
|
* Get preferences for all programmers
|
||||||
|
*
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private PreferencesMap preferences = new PreferencesMap();
|
public Map<String, PreferencesMap> getProgrammers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains labels for top level menus
|
* Get preferences for a specific programmer
|
||||||
|
*
|
||||||
|
* @param programmer
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private PreferencesMap customMenus = new PreferencesMap();
|
public PreferencesMap getProgrammer(String programmer);
|
||||||
|
|
||||||
public TargetPlatform(String _name, File _folder, TargetPackage parent)
|
/**
|
||||||
throws TargetPlatformException {
|
* Get preferences for a specific tool
|
||||||
|
*
|
||||||
|
* @param tool
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PreferencesMap getTool(String tool);
|
||||||
|
|
||||||
id = _name;
|
/**
|
||||||
folder = _folder;
|
* Return TargetPlatform preferences
|
||||||
containerPackage = parent;
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PreferencesMap getPreferences();
|
||||||
|
|
||||||
// If there is no boards.txt, this is not a valid 1.5 hardware folder
|
/**
|
||||||
File boardsFile = new File(folder, "boards.txt");
|
* Get a target board
|
||||||
if (!boardsFile.exists() || !boardsFile.canRead())
|
*
|
||||||
throw new TargetPlatformException(
|
* @param boardId
|
||||||
format(_("Could not find boards.txt in {0}. Is it pre-1.5?"),
|
* @return
|
||||||
folder.getAbsolutePath()));
|
*/
|
||||||
|
public TargetBoard getBoard(String boardId);
|
||||||
|
|
||||||
// Load boards
|
/**
|
||||||
try {
|
* Get the TargetPackage that contains this TargetPlatform
|
||||||
Map<String, PreferencesMap> boardsPreferences = new PreferencesMap(
|
*
|
||||||
boardsFile).firstLevelMap();
|
* @return
|
||||||
|
*/
|
||||||
|
public TargetPackage getContainerPackage();
|
||||||
|
|
||||||
// Create custom menus for this platform
|
|
||||||
PreferencesMap menus = boardsPreferences.get("menu");
|
|
||||||
if (menus != null)
|
|
||||||
customMenus = menus.topLevelMap();
|
|
||||||
boardsPreferences.remove("menu");
|
|
||||||
|
|
||||||
// Create boards
|
|
||||||
Set<String> boardIds = boardsPreferences.keySet();
|
|
||||||
for (String boardId : boardIds) {
|
|
||||||
PreferencesMap preferences = boardsPreferences.get(boardId);
|
|
||||||
TargetBoard board = new TargetBoard(boardId, preferences, this);
|
|
||||||
boards.put(boardId, board);
|
|
||||||
|
|
||||||
// Pick the first board as default
|
|
||||||
if (defaultBoard == null)
|
|
||||||
defaultBoard = board;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TargetPlatformException(format(_("Error loading {0}"),
|
|
||||||
boardsFile.getAbsolutePath()), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
File platformsFile = new File(folder, "platform.txt");
|
|
||||||
try {
|
|
||||||
if (platformsFile.exists() && platformsFile.canRead()) {
|
|
||||||
preferences.load(platformsFile);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TargetPlatformException(
|
|
||||||
format(_("Error loading {0}"), platformsFile.getAbsolutePath()), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow overriding values in platform.txt. This allows changing
|
|
||||||
// platform.txt (e.g. to use a system-wide toolchain), without
|
|
||||||
// having to modify platform.txt (which, when running from git,
|
|
||||||
// prevents files being marked as changed).
|
|
||||||
File localPlatformsFile = new File(folder, "platform.local.txt");
|
|
||||||
try {
|
|
||||||
if (localPlatformsFile.exists() && localPlatformsFile.canRead()) {
|
|
||||||
preferences.load(localPlatformsFile);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TargetPlatformException(
|
|
||||||
format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
File progFile = new File(folder, "programmers.txt");
|
|
||||||
try {
|
|
||||||
if (progFile.exists() && progFile.canRead()) {
|
|
||||||
PreferencesMap prefs = new PreferencesMap();
|
|
||||||
prefs.load(progFile);
|
|
||||||
programmers = prefs.firstLevelMap();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new TargetPlatformException(format(_("Error loading {0}"), progFile
|
|
||||||
.getAbsolutePath()), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFolder() {
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, TargetBoard> getBoards() {
|
|
||||||
return boards;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreferencesMap getCustomMenus() {
|
|
||||||
return customMenus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getCustomMenuIds() {
|
|
||||||
return customMenus.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, PreferencesMap> getProgrammers() {
|
|
||||||
return programmers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreferencesMap getProgrammer(String programmer) {
|
|
||||||
return getProgrammers().get(programmer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreferencesMap getTool(String tool) {
|
|
||||||
return getPreferences().subTree("tools").subTree(tool);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PreferencesMap getPreferences() {
|
|
||||||
return preferences;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetBoard getBoard(String boardId) {
|
|
||||||
if (boards.containsKey(boardId)) {
|
|
||||||
return boards.get(boardId);
|
|
||||||
}
|
|
||||||
return defaultBoard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetPackage getContainerPackage() {
|
|
||||||
return containerPackage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
String res = "TargetPlatform: name=" + id + " boards={\n";
|
|
||||||
for (String boardId : boards.keySet())
|
|
||||||
res += " " + boardId + " = " + boards.get(boardId) + "\n";
|
|
||||||
return res + "}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,17 @@ import java.io.FilenameFilter;
|
|||||||
*/
|
*/
|
||||||
public class OnlyDirs implements FilenameFilter {
|
public class OnlyDirs implements FilenameFilter {
|
||||||
|
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
if (name.charAt(0) == '.')
|
if (name.charAt(0) == '.')
|
||||||
return false;
|
return false;
|
||||||
if (name.equals("CVS"))
|
if (name.equals("CVS"))
|
||||||
return false;
|
return false;
|
||||||
return new File(dir, name).isDirectory();
|
return new File(dir, name).isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An handy pre-instantiated object
|
||||||
|
*/
|
||||||
|
public static final OnlyDirs ONLY_DIRS = new OnlyDirs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user