Skip to content

Commit

Permalink
Use weak references for dep cache (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
kageiit authored Jan 15, 2020
1 parent 81358ed commit 1b74e2b
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import com.uber.okbuck.extension.ExternalDependenciesExtension;
import com.uber.okbuck.extension.JetifierExtension;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.WeakHashMap;
import javax.annotation.Nullable;
import org.apache.commons.io.FilenameUtils;
import org.gradle.api.artifacts.ExternalDependency;
Expand All @@ -22,12 +23,11 @@ public final class DependencyFactory {

private static final String LOCAL_DEP_VERSION = "1.0.0-LOCAL";

// Use instance of Dependency Factory and clean it up b/w runs
private static HashMap<ExternalDependency, Set<VersionlessDependency>> unresolvedToVersionless =
new HashMap<>();
private static Map<ExternalDependency, Set<VersionlessDependency>> unresolvedToVersionless =
new WeakHashMap<>();

private static HashMap<OResolvedDependency, OExternalDependency> externalDependencyCache =
new HashMap<>();
private static Map<OResolvedDependency, OExternalDependency> externalDependencyCache =
new WeakHashMap<>();

private DependencyFactory() {}

Expand Down Expand Up @@ -129,7 +129,8 @@ public static synchronized Set<VersionlessDependency> fromDependency(
vDependencyBuilder.setGroup(group);
}

Set<VersionlessDependency> vDeps = new HashSet<>();
Set<VersionlessDependency> vDeps = Collections.newSetFromMap(
new WeakHashMap<VersionlessDependency, Boolean>());

if (dependency.getArtifacts().size() > 0) {
vDeps.addAll(
Expand Down Expand Up @@ -196,7 +197,7 @@ private static boolean isLocalDependency(String dependencyFilePath) {
}

public static void cleanup() {
unresolvedToVersionless = new HashMap<>();
externalDependencyCache = new HashMap<>();
unresolvedToVersionless.clear();
externalDependencyCache.clear();
}
}

0 comments on commit 1b74e2b

Please sign in to comment.