eclipse-sirius / sirius-desktop

Sirius Desktop: desktop-based graphical modelers for dedicated DSLs
https://eclipse.dev/sirius/
Eclipse Public License 2.0
15 stars 13 forks source link

Reduce (ideally remove) Guava usage #146

Open pcdavid opened 1 year ago

pcdavid commented 1 year ago

Guava can cause issues when a single Eclipse runtime has multiple different versions. A long time ago we already tried to isolate our use of it to internals, and not expose Guava-provided values in our APIs to reduce the risk.

There is no urgency, and this can be done progressively over many versions, but it would be nice if we could reduce our usage to the minimum.

At the time of this writing we have lots of uses:

% git grep -h '^import com.google.common' -- '**/*.java' | wc -l
1526

If we look at the details:

% git grep -h '^import com.google.common' -- '**/*.java' | sort | uniq -c | sort -rn
    437 import com.google.common.collect.Iterables;
    230 import com.google.common.base.Predicate;
    175 import com.google.common.collect.Lists;
    113 import com.google.common.base.Predicates;
     98 import com.google.common.collect.Iterators;
     80 import com.google.common.base.Function;
     77 import com.google.common.collect.Sets;
     46 import com.google.common.base.Preconditions;
     37 import com.google.common.collect.Multimap;
     28 import com.google.common.collect.Collections2;
     22 import com.google.common.collect.Ordering;
     22 import com.google.common.collect.HashMultimap;
     16 import com.google.common.collect.UnmodifiableIterator;
     15 import com.google.common.base.Objects;
     15 import com.google.common.base.Joiner;
     13 import com.google.common.collect.Maps;
     13 import com.google.common.collect.LinkedHashMultimap;
     11 import com.google.common.collect.ImmutableSet;
      9 import com.google.common.collect.Sets.SetView;
      6 import com.google.common.collect.ArrayListMultimap;
      6 import com.google.common.cache.CacheBuilder;
      5 import com.google.common.collect.Multiset;
      5 import com.google.common.collect.BiMap;
      5 import com.google.common.cache.LoadingCache;
      5 import com.google.common.cache.CacheLoader;
      4 import com.google.common.collect.ListMultimap;
      4 import com.google.common.collect.ImmutableList;
      4 import com.google.common.collect.HashBiMap;
      4 import com.google.common.base.Functions;
      2 import com.google.common.collect.HashMultiset;
      1 import com.google.common.primitives.Primitives;
      1 import com.google.common.primitives.Ints;
      1 import com.google.common.collect.SetMultimap;
      1 import com.google.common.collect.Multimaps;
      1 import com.google.common.collect.MapMaker;
      1 import com.google.common.collect.LinkedListMultimap;
      1 import com.google.common.collect.LinkedHashMultiset;
      1 import com.google.common.collect.ImmutableSortedSet;
      1 import com.google.common.collect.ImmutableMultiset;
      1 import com.google.common.collect.ImmutableMap;
      1 import com.google.common.collect.ConcurrentHashMultiset;
      1 import com.google.common.collect.AbstractIterator;
      1 import com.google.common.cache.Weigher;
      1 import com.google.common.cache.RemovalNotification;
      1 import com.google.common.cache.RemovalListener;
      1 import com.google.common.cache.Cache;
      1 import com.google.common.base.Throwables;
      1 import com.google.common.base.Stopwatch;
      1 import com.google.common.base.Splitter;

Quite a few of these are helpers which used to make sense in the pre-Java 8 times, but could be replaced by now standard Java APIs (sometimes the replacement is trivial, even mechanical; sometimes it's more invovled like converting the many uses of Iterables into equivalent stream operations).

There are two categories where current Java version (we're on Java 17 at the moment) do not provide an alternative by defaults com.google.common.cache and com.google.common.collect.BiMap.

com.google.common.cache is only used in a limited set of types, and Guava itself considers it mostly deprecated now, recommending to switch to https://github.com/ben-manes/caffeine instead. Note that caffeine has recently been added to Orbit: https://github.com/eclipse-orbit/orbit-simrel/issues/22

com.google.common.collect.BiMap is quite useful, so it'll probably be the last remnant, but depending on each use case it may be possible to get rid of it too.

pcdavid commented 1 year ago

It might be the occasion to test OpenRewrite, which has a recipe to replace some uses of Guava with standard Java APIs: https://docs.openrewrite.org/recipes/java/migrate/guava/noguava