Skip to content

Commit 0b9223c

Browse files
cmaglieFederico Fissore
authored andcommitted
Added Contributions for libraries
1 parent 75d1cb8 commit 0b9223c

File tree

12 files changed

+708
-200
lines changed

12 files changed

+708
-200
lines changed

app/src/processing/app/Base.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222

2323
package processing.app;
2424

25+
import java.awt.*;
26+
import java.awt.event.*;
27+
import java.io.*;
28+
import java.util.*;
29+
import java.util.List;
30+
31+
import javax.swing.*;
32+
33+
import cc.arduino.libraries.contributions.LibrariesIndexer;
2534
import cc.arduino.packages.DiscoveryManager;
2635
import cc.arduino.packages.contributions.ui.ContributionManagerUI;
2736
import cc.arduino.view.SplashScreenHelper;
@@ -34,8 +43,9 @@
3443
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
3544
import processing.app.legacy.PApplet;
3645
import processing.app.macosx.ThinkDifferent;
37-
import processing.app.packages.Library;
46+
import processing.app.legacy.PConstants;
3847
import processing.app.packages.LibraryList;
48+
import processing.app.packages.UserLibrary;
3949
import processing.app.tools.MenuScroller;
4050
import processing.app.tools.ZipDeflater;
4151

@@ -1083,29 +1093,21 @@ public void rebuildExamplesMenu(JMenu menu) {
10831093
// Add examples from libraries
10841094
LibraryList ideLibs = getIDELibs();
10851095
ideLibs.sort();
1086-
for (Library lib : ideLibs)
1096+
for (UserLibrary lib : ideLibs)
10871097
addSketchesSubmenu(menu, lib, false);
10881098

10891099
LibraryList userLibs = getUserLibs();
10901100
if (userLibs.size()>0) {
10911101
menu.addSeparator();
10921102
userLibs.sort();
1093-
for (Library lib : userLibs)
1103+
for (UserLibrary lib : userLibs)
10941104
addSketchesSubmenu(menu, lib, false);
10951105
}
10961106
} catch (IOException e) {
10971107
e.printStackTrace();
10981108
}
10991109
}
11001110

1101-
public LibraryList scanLibraries(List<File> folders) throws IOException {
1102-
return BaseNoGui.scanLibraries(folders);
1103-
}
1104-
1105-
public LibraryList scanLibraries(File folder) throws IOException {
1106-
return BaseNoGui.scanLibraries(folder);
1107-
}
1108-
11091111
public void onBoardOrPortChange() {
11101112
BaseNoGui.onBoardOrPortChange();
11111113

@@ -1431,10 +1433,10 @@ public int compare(File file, File file2) {
14311433
return ifound;
14321434
}
14331435

1434-
private boolean addSketchesSubmenu(JMenu menu, Library lib,
1436+
private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib,
14351437
boolean replaceExisting)
14361438
throws IOException {
1437-
return addSketchesSubmenu(menu, lib.getName(), lib.getFolder(),
1439+
return addSketchesSubmenu(menu, lib.getName(), lib.getInstalledFolder(),
14381440
replaceExisting);
14391441
}
14401442

@@ -1516,11 +1518,11 @@ protected void addLibraries(JMenu menu, LibraryList libs) throws IOException {
15161518
LibraryList list = new LibraryList(libs);
15171519
list.sort();
15181520

1519-
for (Library lib : list) {
1521+
for (UserLibrary lib : list) {
15201522
@SuppressWarnings("serial")
15211523
AbstractAction action = new AbstractAction(lib.getName()) {
15221524
public void actionPerformed(ActionEvent event) {
1523-
Library l = (Library) getValue("library");
1525+
UserLibrary l = (UserLibrary) getValue("library");
15241526
try {
15251527
activeEditor.getSketch().importLibrary(l);
15261528
} catch (IOException e) {

app/src/processing/app/Sketch.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
import processing.app.helpers.OSUtils;
3535
import processing.app.helpers.PreferencesMap;
3636
import processing.app.helpers.PreferencesMapException;
37-
import processing.app.packages.Library;
37+
import processing.app.packages.UserLibrary;
38+
import static processing.app.I18n._;
3839

3940
import javax.swing.*;
4041
import java.awt.*;
@@ -938,7 +939,7 @@ public boolean addFile(File sourceFile) {
938939
}
939940

940941

941-
public void importLibrary(Library lib) throws IOException {
942+
public void importLibrary(UserLibrary lib) throws IOException {
942943
importLibrary(lib.getSrcFolder());
943944
}
944945

app/src/processing/app/syntax/PdeKeywords.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
import processing.app.*;
2828
import processing.app.legacy.PApplet;
29-
import processing.app.packages.Library;
3029

3130
import java.io.*;
3231
import java.util.*;
3332

33+
import cc.arduino.libraries.contributions.ContributedLibrary;
34+
3435

3536
public class PdeKeywords extends CTokenMarker {
3637

@@ -61,8 +62,8 @@ static public KeywordMap getKeywords() {
6162
keywordColoring = new KeywordMap(false);
6263
keywordToReference = new Hashtable();
6364
getKeywords(Base.getLibStream("keywords.txt"));
64-
for (Library lib : Base.getLibraries()) {
65-
File keywords = new File(lib.getFolder(), "keywords.txt");
65+
for (ContributedLibrary lib : Base.getLibraries()) {
66+
File keywords = new File(lib.getInstalledFolder(), "keywords.txt");
6667
if (keywords.exists()) getKeywords(new FileInputStream(keywords));
6768
}
6869
} catch (Exception e) {
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
package cc.arduino.libraries.contributions;
30+
31+
import java.util.Comparator;
32+
import java.util.List;
33+
34+
import cc.arduino.packages.contributions.DownloadableContribution;
35+
36+
public abstract class ContributedLibrary extends DownloadableContribution {
37+
38+
public abstract String getName();
39+
40+
public abstract String getVersion();
41+
42+
public abstract String getMaintainer();
43+
44+
public abstract String getAuthor();
45+
46+
public abstract String getWebsite();
47+
48+
public abstract String getCategory();
49+
50+
public abstract String getLicense();
51+
52+
public abstract String getParagraph();
53+
54+
public abstract String getSentence();
55+
56+
public abstract String getSupportLevel();
57+
58+
public abstract List<String> getArchitectures();
59+
60+
public abstract List<ContributedLibraryReference> getRequires();
61+
62+
private boolean readOnly;
63+
64+
public boolean isReadOnly() {
65+
return readOnly;
66+
}
67+
68+
public void setReadOnly(boolean readOnly) {
69+
this.readOnly = readOnly;
70+
}
71+
72+
public static final Comparator<ContributedLibrary> CASE_INSENSITIVE_ORDER = new Comparator<ContributedLibrary>() {
73+
@Override
74+
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
75+
return o1.getName().compareToIgnoreCase(o2.getName());
76+
}
77+
};
78+
79+
/**
80+
* Returns <b>true</b> if the library declares to support the specified
81+
* architecture (through the "architectures" property field).
82+
*
83+
* @param reqArch
84+
* @return
85+
*/
86+
public boolean supportsArchitecture(String reqArch) {
87+
return getArchitectures().contains(reqArch) ||
88+
getArchitectures().contains("*");
89+
}
90+
91+
/**
92+
* Returns <b>true</b> if the library declares to support at least one of the
93+
* specified architectures.
94+
*
95+
* @param reqArchs
96+
* A List of architectures to check
97+
* @return
98+
*/
99+
public boolean supportsArchitecture(List<String> reqArchs) {
100+
if (reqArchs.contains("*"))
101+
return true;
102+
for (String reqArch : reqArchs)
103+
if (supportsArchitecture(reqArch))
104+
return true;
105+
return false;
106+
}
107+
108+
@Override
109+
public String toString() {
110+
String res = "";
111+
res += " ContributedLibrary : " + getName() + "\n";
112+
res += " author : " + getAuthor() + "\n";
113+
res += " maintainer : " + getMaintainer() + "\n";
114+
res += " version : " + getVersion() + "\n";
115+
res += " website : " + getUrl() + "\n";
116+
res += " category : " + getCategory() + "\n";
117+
res += " license : " + getLicense() + "\n";
118+
res += " descrip : " + getSentence() + "\n";
119+
if (getParagraph() != null && !getParagraph().isEmpty())
120+
res += " " + getParagraph() + "\n";
121+
res += " architectures : ";
122+
if (getArchitectures() != null)
123+
for (String a : getArchitectures()) {
124+
res += a + ",";
125+
}
126+
res += "\n";
127+
res += " requires :\n";
128+
if (getRequires() != null)
129+
for (ContributedLibraryReference r : getRequires()) {
130+
res += " " + r;
131+
}
132+
res += "\n";
133+
134+
// DownloadableContribution
135+
res += super.toString();
136+
137+
return res;
138+
}
139+
140+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
package cc.arduino.libraries.contributions;
30+
31+
public abstract class ContributedLibraryReference {
32+
33+
public abstract String getName();
34+
35+
public abstract String getMaintainer();
36+
37+
public abstract String getVersion();
38+
39+
@Override
40+
public String toString() {
41+
return getName() + " " + getVersion() + " (" + getMaintainer() + ")";
42+
}
43+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Copyright 2014 Arduino LLC (http://www.arduino.cc/)
5+
*
6+
* Arduino is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*
20+
* As a special exception, you may use this file as part of a free software
21+
* library without restriction. Specifically, if other files instantiate
22+
* templates or use macros or inline functions from this file, or you compile
23+
* this file and link it with other files to produce an executable, this
24+
* file does not by itself cause the resulting executable to be covered by
25+
* the GNU General Public License. This exception does not however
26+
* invalidate any other reasons why the executable file might be covered by
27+
* the GNU General Public License.
28+
*/
29+
package cc.arduino.libraries.contributions;
30+
31+
import java.util.List;
32+
33+
public abstract class LibrariesIndex {
34+
35+
public abstract List<ContributedLibrary> getLibraries();
36+
37+
public ContributedLibrary find(String name, String version) {
38+
for (ContributedLibrary lib : getLibraries()) {
39+
if (lib.getName().equals(name) && lib.getVersion().equals(version))
40+
return lib;
41+
}
42+
return null;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
String res = "";
48+
for (ContributedLibrary l : getLibraries())
49+
res += l.toString();
50+
return res;
51+
}
52+
}

0 commit comments

Comments
 (0)