[ 
https://issues.apache.org/jira/browse/MNG-8350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Guillaume Nodet closed MNG-8350.
--------------------------------
    Fix Version/s: 4.0.0-beta-6
       Resolution: Fixed

> Improve storage and computation of locations in model objects
> -------------------------------------------------------------
>
>                 Key: MNG-8350
>                 URL: https://issues.apache.org/jira/browse/MNG-8350
>             Project: Maven
>          Issue Type: Bug
>    Affects Versions: 4.0.0-beta-5
>            Reporter: Guillaume Nodet
>            Assignee: Guillaume Nodet
>            Priority: Major
>             Fix For: 4.0.0-beta-6
>
>
> The {{Build}} constructor has the following code:
> {code}
>         Map<Object, InputLocation> newlocs = builder.locations != null ? 
> builder.locations : Collections.emptyMap();
>         Map<Object, InputLocation> oldlocs = builder.base != null && 
> builder.base.locations != null ? builder.base.locations : 
> Collections.emptyMap();
>         Map<Object, InputLocation> mutableLocations = new 
> HashMap<>(super.locations);
>         mutableLocations.put("sourceDirectory", 
> newlocs.containsKey("sourceDirectory") ? newlocs.get("sourceDirectory") : 
> oldlocs.get("sourceDirectory"));
>         mutableLocations.put("scriptSourceDirectory", 
> newlocs.containsKey("scriptSourceDirectory") ? 
> newlocs.get("scriptSourceDirectory") : oldlocs.get("scriptSourceDirectory"));
>         mutableLocations.put("testSourceDirectory", 
> newlocs.containsKey("testSourceDirectory") ? 
> newlocs.get("testSourceDirectory") : oldlocs.get("testSourceDirectory"));
>         mutableLocations.put("outputDirectory", 
> newlocs.containsKey("outputDirectory") ? newlocs.get("outputDirectory") : 
> oldlocs.get("outputDirectory"));
>         mutableLocations.put("testOutputDirectory", 
> newlocs.containsKey("testOutputDirectory") ? 
> newlocs.get("testOutputDirectory") : oldlocs.get("testOutputDirectory"));
>         mutableLocations.put("extensions", newlocs.containsKey("extensions") 
> ? newlocs.get("extensions") : oldlocs.get("extensions"));
>         this.locations = Collections.unmodifiableMap(mutableLocations);
> {code}
> This is inefficient, especially when building models programmatically, in 
> which cases locations are usually not set.  The code will always store a 
> {{null}} value for each key, whereas an empty map could be sufficient if 
> there's no actual values.
> The generator code is located at:
> https://github.com/apache/maven/blob/b370e5e9299813e6df483bac049ec162b86fb7e8/src/mdo/model.vm#L174-L186



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to