28
28
*/
29
29
package processing .app .packages ;
30
30
31
- import static processing .app .I18n .format ;
32
- import static processing .app .I18n .tr ;
33
-
34
31
import java .io .File ;
35
- import java .io .IOException ;
36
- import java .nio .file .Files ;
37
- import java .nio .file .Paths ;
38
32
import java .util .ArrayList ;
39
33
import java .util .Collection ;
40
- import java .util .LinkedList ;
41
34
import java .util .List ;
42
- import java .util .Optional ;
43
-
44
- import com .github .zafarkhaja .semver .Version ;
45
35
46
- import cc .arduino .Constants ;
47
- import cc .arduino .contributions .VersionHelper ;
48
36
import cc .arduino .contributions .libraries .ContributedLibraryDependency ;
49
- import processing .app .helpers .PreferencesMap ;
50
37
51
38
public class UserLibrary {
52
39
@@ -72,115 +59,6 @@ public class UserLibrary {
72
59
public static final String LOCATION_REF_CORE = "ref-platform" ;
73
60
protected String location ;
74
61
75
- public static UserLibrary create (File libFolder , String location ) throws IOException {
76
- // Parse metadata
77
- File propertiesFile = new File (libFolder , "library.properties" );
78
- PreferencesMap properties = new PreferencesMap ();
79
- properties .load (propertiesFile );
80
-
81
- // Library sanity checks
82
- // ---------------------
83
-
84
- // Compatibility with 1.5 rev.1 libraries:
85
- // "email" field changed to "maintainer"
86
- if (!properties .containsKey ("maintainer" ) && properties .containsKey ("email" )) {
87
- properties .put ("maintainer" , properties .get ("email" ));
88
- }
89
-
90
- // Compatibility with 1.5 rev.1 libraries:
91
- // "arch" folder no longer supported
92
- File archFolder = new File (libFolder , "arch" );
93
- if (archFolder .isDirectory ())
94
- throw new IOException ("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information" );
95
-
96
- // Check mandatory properties
97
- for (String p : Constants .LIBRARY_MANDATORY_PROPERTIES )
98
- if (!properties .containsKey (p ))
99
- throw new IOException ("Missing '" + p + "' from library" );
100
-
101
- // Check layout
102
- String layout ;
103
- File srcFolder = new File (libFolder , "src" );
104
-
105
- if (srcFolder .exists () && srcFolder .isDirectory ()) {
106
- // Layout with a single "src" folder and recursive compilation
107
- layout = "recursive" ;
108
- } else {
109
- // Layout with source code on library's root and "utility" folders
110
- layout = "flat" ;
111
- }
112
-
113
- // Warn if root folder contains development leftovers
114
- File [] files = libFolder .listFiles ();
115
- if (files == null ) {
116
- throw new IOException ("Unable to list files of library in " + libFolder );
117
- }
118
-
119
- // Extract metadata info
120
- String architectures = properties .get ("architectures" );
121
- if (architectures == null )
122
- architectures = "*" ; // defaults to "any"
123
- List <String > archs = new ArrayList <>();
124
- for (String arch : architectures .split ("," ))
125
- archs .add (arch .trim ());
126
-
127
- String category = properties .get ("category" );
128
- if (category == null ) {
129
- category = "Uncategorized" ;
130
- }
131
- if (!Constants .LIBRARY_CATEGORIES .contains (category )) {
132
- category = "Uncategorized" ;
133
- }
134
-
135
- String license = properties .get ("license" );
136
- if (license == null ) {
137
- license = "Unspecified" ;
138
- }
139
-
140
- String types = properties .get ("types" );
141
- if (types == null ) {
142
- types = "Contributed" ;
143
- }
144
- List <String > typesList = new LinkedList <>();
145
- for (String type : types .split ("," )) {
146
- typesList .add (type .trim ());
147
- }
148
-
149
- List <String > includes = null ;
150
- if (properties .containsKey ("includes" ) && !properties .get ("includes" ).trim ().isEmpty ()) {
151
- includes = new ArrayList <>();
152
- for (String i : properties .get ("includes" ).split ("," ))
153
- includes .add (i .trim ());
154
- }
155
-
156
- String declaredVersion = properties .get ("version" ).trim ();
157
- Optional <Version > version = VersionHelper .valueOf (declaredVersion );
158
- if (!version .isPresent ()) {
159
- System .out .println (
160
- format (tr ("Invalid version '{0}' for library in: {1}" ), declaredVersion , libFolder .getAbsolutePath ()));
161
- }
162
-
163
- UserLibrary res = new UserLibrary ( //
164
- libFolder , //
165
- properties .get ("name" ).trim (), //
166
- version .isPresent () ? version .get ().toString () : declaredVersion , //
167
- properties .get ("author" ).trim (), //
168
- properties .get ("maintainer" ).trim (), //
169
- properties .get ("sentence" ).trim (), //
170
- properties .get ("paragraph" ).trim (), //
171
- properties .get ("url" ).trim (), //
172
- category .trim (), //
173
- license .trim (), //
174
- archs , //
175
- layout , //
176
- typesList , //
177
- Files .exists (Paths .get (libFolder .getAbsolutePath (), Constants .LIBRARY_DEVELOPMENT_FLAG_FILE )), //
178
- includes , //
179
- location //
180
- );
181
- return res ;
182
- }
183
-
184
62
public UserLibrary (File installedFolder , String name , String version ,
185
63
String author , String maintainer , String sentence ,
186
64
String paraghraph , String website , String category ,
0 commit comments