28
28
*/
29
29
package cc .arduino .contributions .libraries ;
30
30
31
- import static processing .app .I18n ._ ;
32
-
33
- import java .io .File ;
34
- import java .io .FileInputStream ;
35
- import java .io .IOException ;
36
- import java .io .InputStream ;
37
- import java .util .List ;
38
-
31
+ import com .fasterxml .jackson .databind .DeserializationFeature ;
32
+ import com .fasterxml .jackson .databind .ObjectMapper ;
33
+ import com .fasterxml .jackson .module .mrbean .MrBeanModule ;
39
34
import processing .app .BaseNoGui ;
40
35
import processing .app .I18n ;
41
36
import processing .app .helpers .FileUtils ;
44
39
import processing .app .packages .LibraryList ;
45
40
import processing .app .packages .UserLibrary ;
46
41
47
- import com .fasterxml .jackson .databind .DeserializationFeature ;
48
- import com .fasterxml .jackson .databind .ObjectMapper ;
49
- import com .fasterxml .jackson .module .mrbean .MrBeanModule ;
42
+ import java .io .File ;
43
+ import java .io .FileInputStream ;
44
+ import java .io .IOException ;
45
+ import java .io .InputStream ;
46
+ import java .util .Arrays ;
47
+ import java .util .List ;
48
+
49
+ import static processing .app .I18n ._ ;
50
50
51
51
public class LibrariesIndexer {
52
52
@@ -60,7 +60,7 @@ public class LibrariesIndexer {
60
60
public LibrariesIndexer (File preferencesFolder ) {
61
61
indexFile = new File (preferencesFolder , "library_index.json" );
62
62
stagingFolder = new File (preferencesFolder , "staging" + File .separator +
63
- "libraries" );
63
+ "libraries" );
64
64
}
65
65
66
66
public void parseIndex () throws IOException {
@@ -109,31 +109,28 @@ private void scanInstalledLibraries(File folder) {
109
109
for (File subfolder : list ) {
110
110
if (!BaseNoGui .isSanitaryName (subfolder .getName ())) {
111
111
String mess = I18n .format (_ ("The library \" {0}\" cannot be used.\n "
112
- + "Library names must contain only basic letters and numbers.\n "
113
- + "(ASCII only and no spaces, and it cannot start with a number)" ),
114
- subfolder .getName ());
112
+ + "Library names must contain only basic letters and numbers.\n "
113
+ + "(ASCII only and no spaces, and it cannot start with a number)" ),
114
+ subfolder .getName ());
115
115
BaseNoGui .showMessage (_ ("Ignoring bad library name" ), mess );
116
116
continue ;
117
117
}
118
118
119
119
try {
120
120
scanLibrary (subfolder );
121
121
} catch (IOException e ) {
122
- System .out .println (I18n .format (_ ("Invalid library found in {0}: {1}" ),
123
- subfolder , e .getMessage ()));
122
+ System .out .println (I18n .format (_ ("Invalid library found in {0}: {1}" ), subfolder , e .getMessage ()));
124
123
}
125
124
}
126
125
}
127
126
128
127
private void scanLibrary (File folder ) throws IOException {
129
- boolean readOnly = !FileUtils
130
- .isSubDirectory (sketchbookLibrariesFolder , folder );
128
+ boolean readOnly = !FileUtils .isSubDirectory (sketchbookLibrariesFolder , folder );
131
129
132
130
// A library is considered "legacy" if it doesn't contains
133
131
// a file called "library.properties"
134
132
File check = new File (folder , "library.properties" );
135
133
if (!check .exists () || !check .isFile ()) {
136
-
137
134
// Create a legacy library and exit
138
135
LegacyUserLibrary lib = LegacyUserLibrary .create (folder );
139
136
lib .setReadOnly (readOnly );
@@ -148,12 +145,20 @@ private void scanLibrary(File folder) throws IOException {
148
145
149
146
// Check if we can find the same library in the index
150
147
// and mark it as installed
151
- String libName = folder .getName (); // XXX: lib.getName()?
152
- ContributedLibrary foundLib = index .find (libName , lib .getVersion ());
148
+ ContributedLibrary foundLib = index .find (lib .getName (), lib .getVersion ());
153
149
if (foundLib != null ) {
154
150
foundLib .setInstalled (true );
155
151
foundLib .setInstalledFolder (folder );
156
152
foundLib .setReadOnly (readOnly );
153
+ lib .setTypes (foundLib .getTypes ());
154
+ }
155
+
156
+ if (lib .isReadOnly () && lib .getTypes () == null && !lib .getDeclaredTypes ().isEmpty ()) {
157
+ lib .setTypes (lib .getDeclaredTypes ());
158
+ }
159
+
160
+ if (lib .getTypes () == null ) {
161
+ lib .setTypes (Arrays .asList ("Contributed" ));
157
162
}
158
163
}
159
164
0 commit comments