@@ -59,9 +59,9 @@ impl Lock {
5959 metadata. projects . push ( EnvProject {
6060 publisher : project. publisher ,
6161 name : project. name ,
62- identifiers : project. identifiers ,
6362 version : project. version ,
6463 path,
64+ identifiers : project. identifiers ,
6565 usages,
6666 editable : false ,
6767 files : None ,
@@ -81,9 +81,9 @@ impl Lock {
8181 metadata. projects . push ( EnvProject {
8282 publisher : project. publisher ,
8383 name : project. name ,
84- identifiers : project. identifiers ,
8584 version : project. version ,
8685 path : editable. as_str ( ) . into ( ) ,
86+ identifiers : project. identifiers ,
8787 usages,
8888 editable : true ,
8989 files : Some ( files) ,
@@ -98,6 +98,7 @@ impl Lock {
9898#[ derive( Debug , Deserialize ) ]
9999pub struct EnvMetadata {
100100 pub version : String ,
101+ #[ serde( rename = "project" , skip_serializing_if = "Vec::is_empty" , default ) ]
101102 pub projects : Vec < EnvProject > ,
102103}
103104
@@ -189,6 +190,17 @@ impl EnvMetadata {
189190 }
190191 }
191192
193+ pub fn remove_project < S : AsRef < str > , V : AsRef < str > > ( & mut self , iri : S , version : Option < V > ) {
194+ if let Some ( v) = version {
195+ self . projects . retain ( |p| {
196+ p. version != v. as_ref ( ) || !p. identifiers . iter ( ) . any ( |i| i == iri. as_ref ( ) )
197+ } ) ;
198+ } else {
199+ self . projects
200+ . retain ( |p| !p. identifiers . iter ( ) . any ( |i| i == iri. as_ref ( ) ) ) ;
201+ }
202+ }
203+
192204 /// Add `LocalSrcProject` to env. Must have `nominal_path` set.
193205 pub fn add_local_project (
194206 & mut self ,
@@ -202,11 +214,11 @@ impl EnvMetadata {
202214 let project = EnvProject {
203215 publisher : info. publisher ,
204216 name : Some ( info. name ) ,
205- identifiers,
206217 version : info. version ,
207218 path : project
208219 . nominal_path
209220 . expect ( "expected nominal path for project" ) ,
221+ identifiers,
210222 usages : info. usage . into_iter ( ) . map ( |u| u. resource ) . collect ( ) ,
211223 editable,
212224 files : None ,
@@ -230,24 +242,27 @@ pub struct EnvProject {
230242 pub publisher : Option < String > ,
231243 /// Name of the project. Intended for display purposes.
232244 pub name : Option < String > ,
233- /// List of identifiers (IRIs) used for the project.
234- /// The first identifier is to. be considered the canonical
235- /// identifier, and if the project is not `editable` this
236- /// is the IRI it is installed as. The rest are considered
237- /// as aliases. Can only be empty for `editable` projects.
238- pub identifiers : Vec < String > ,
239245 /// Version of the project.
240246 pub version : String ,
241247 /// Path to the root directory of the project.
242248 /// If the project is not `editable` this should be relative
243249 /// to the env directory and otherwise it should be relative
244250 /// to the workspace root.
245251 pub path : Utf8PathBuf ,
252+ /// List of identifiers (IRIs) used for the project.
253+ /// The first identifier is to. be considered the canonical
254+ /// identifier, and if the project is not `editable` this
255+ /// is the IRI it is installed as. The rest are considered
256+ /// as aliases. Can only be empty for `editable` projects.
257+ #[ serde( skip_serializing_if = "Vec::is_empty" , default ) ]
258+ pub identifiers : Vec < String > ,
246259 /// Usages of the project. Intended for tools needing to
247260 /// track the interdependence of project in the environment.
261+ #[ serde( skip_serializing_if = "Vec::is_empty" , default ) ]
248262 pub usages : Vec < String > ,
249263 /// Indicator of wether the project is fully installed in
250264 /// the environment or located elsewhere.
265+ #[ serde( skip_serializing_if = "bool::is_false" , default ) ]
251266 pub editable : bool ,
252267 /// In case of an `editable` project these are the files
253268 /// belonging to the project. Intended for tools that
@@ -266,14 +281,14 @@ impl EnvProject {
266281 if let Some ( name) = & self . name {
267282 table. insert ( "name" , value ( name) ) ;
268283 }
284+ table. insert ( "version" , value ( & self . version ) ) ;
285+ table. insert ( "path" , value ( self . path . as_str ( ) ) ) ;
269286 if !self . identifiers . is_empty ( ) {
270287 table. insert (
271288 "identifiers" ,
272289 value ( multiline_array ( self . identifiers . iter ( ) ) ) ,
273290 ) ;
274291 }
275- table. insert ( "version" , value ( & self . version ) ) ;
276- table. insert ( "path" , value ( self . path . as_str ( ) ) ) ;
277292 if !self . usages . is_empty ( ) {
278293 table. insert ( "usages" , value ( multiline_array ( self . usages . iter ( ) ) ) ) ;
279294 }
0 commit comments