You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Guillaume Nodet (Jira)" <ji...@apache.org> on 2024/10/24 10:16:00 UTC

[jira] [Assigned] (MNG-8350) Improve storage and computation of locations in model objects

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

Guillaume Nodet reassigned MNG-8350:
------------------------------------

    Assignee: Guillaume Nodet

> 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
>
> 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)