mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +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
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user