diff --git a/runtime/src/main/java/dev/vankka/dependencydownload/ApplicationDependencyManager.java b/runtime/src/main/java/dev/vankka/dependencydownload/ApplicationDependencyManager.java index 6002bd4..288b3c4 100644 --- a/runtime/src/main/java/dev/vankka/dependencydownload/ApplicationDependencyManager.java +++ b/runtime/src/main/java/dev/vankka/dependencydownload/ApplicationDependencyManager.java @@ -69,6 +69,7 @@ public ApplicationDependencyManager(@NotNull DependencyPathProvider dependencyPa * @param relocations the relocations to add * @see #addRelocation(Relocation) */ + @NotNull public ApplicationDependencyManager addRelocations(@NotNull Relocation... relocations) { return addRelocations(Arrays.asList(relocations)); } @@ -79,6 +80,7 @@ public ApplicationDependencyManager addRelocations(@NotNull Relocation... reloca * @param relocations the relocations to add * @see #addRelocation(Relocation) */ + @NotNull public ApplicationDependencyManager addRelocations(@NotNull Collection relocations) { synchronized (dependencyManager) { dependencyManager.addRelocations(relocations); @@ -92,6 +94,7 @@ public ApplicationDependencyManager addRelocations(@NotNull Collection resourceLines) { DependencyDownloadResource resource = new DependencyDownloadResource(resourceLines); return includeResource(resource); @@ -157,6 +163,8 @@ public DependencyManager includeResource(@NotNull List resourceLines) { * @param resource the resource to get dependencies and relocations from * @return the {@link DependencyManager} to load in the dependencies */ + @CheckReturnValue + @NotNull public DependencyManager includeResource(@NotNull DependencyDownloadResource resource) { return include(resource.getDependencies(), resource.getRelocations()); } @@ -172,6 +180,7 @@ public DependencyManager includeResource(@NotNull DependencyDownloadResource res * @return the {@link DependencyManager} to load in the dependencies */ @CheckReturnValue + @NotNull public DependencyManager include(@NotNull List dependencies, @NotNull List relocations) { addRelocations(relocations); return include(dependencies); @@ -187,6 +196,7 @@ public DependencyManager include(@NotNull List dependencies, @NotNul * @return the {@link DependencyManager} to load in the dependencies */ @CheckReturnValue + @NotNull public DependencyManager include(@NotNull Dependency... dependencies) { return include(Arrays.asList(dependencies)); } @@ -201,6 +211,7 @@ public DependencyManager include(@NotNull Dependency... dependencies) { * @return the {@link DependencyManager} to load in the dependencies */ @CheckReturnValue + @NotNull public DependencyManager include(@NotNull Collection dependencies) { dependencies = addMissingDependencies(dependencies); @@ -219,12 +230,15 @@ public DependencyManager include(@NotNull Collection dependencies) { * and will include all the relocations from this manager. * * @param manager the manager to get dependencies and relocations from - * @return a new {@link DependencyManager} to load in the dependencies + * @return a new {@link DependencyManager} to load in the dependencies, or the same manager if it already loaded */ - @CheckReturnValue + @NotNull public DependencyManager include(@NotNull DependencyManager manager) { addRelocations(manager.getRelocations()); List dependencies = addMissingDependencies(manager.getDependencies()); + if (manager.isLoaded()) { + return dependencyManager; + } DependencyManager dependencyManager = new DependencyManager(manager.getDependencyPathProvider()); dependencyManager.addDependencies(dependencies); diff --git a/runtime/src/main/java/dev/vankka/dependencydownload/DependencyManager.java b/runtime/src/main/java/dev/vankka/dependencydownload/DependencyManager.java index 914d9b6..f3e4df3 100644 --- a/runtime/src/main/java/dev/vankka/dependencydownload/DependencyManager.java +++ b/runtime/src/main/java/dev/vankka/dependencydownload/DependencyManager.java @@ -182,6 +182,14 @@ public DependencyPathProvider getDependencyPathProvider() { return dependencyPathProvider; } + /** + * Are this {@link DependencyManager}s dependencies already loaded. + * @return {@code true} if {@link #load(Executor, ClasspathAppender)} has already been loaded + */ + public boolean isLoaded() { + return step.get() == 3; + } + /** * Loads dependencies and relocations from the resource generated by the gradle plugin. *