Skip to content
This repository has been archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
Add a bit of documentation and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Feb 15, 2021
1 parent f156a2a commit e484e7a
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.URLClassLoader;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Level;
Expand All @@ -33,9 +34,12 @@ public final class PluginDependencyManager
@NotNull
private final Logger logger;

PluginDependencyManager(@NotNull final Function<String, Logger> loggerFactory, @Nullable final InputStream dependenciesResource,
@NotNull final File rootDirectory, @NotNull final URLClassLoader classLoader,
@NotNull final String applicationName, @NotNull final String applicationVersion,
PluginDependencyManager(@NotNull final Function<String, Logger> loggerFactory,
@Nullable final InputStream dependenciesResource,
@NotNull final File rootDirectory,
@NotNull final URLClassLoader classLoader,
@NotNull final String applicationName,
@NotNull final String applicationVersion,
@NotNull final CacheConfiguration cacheConfiguration)
{
this.logger = loggerFactory.apply(getClass().getName());
Expand Down Expand Up @@ -63,11 +67,23 @@ public static Builder builder()
return new Builder();
}

/**
* Add a dependency that should be downloaded and loaded into the classpath
*
* @param dependency The dependency to add to the required dependencies
*/
public void addRequiredDependency(@NotNull final Artifact dependency)
{
requiredDependencies.add(dependency);
}

/**
* Add a new Repository url that will be queried when searching for dependencies
* This should be a standard Maven Repository.
*
* @param alias A <b>unique</b> alias for this Repository.
* @param repositoryUrl the root url of the Repository
*/
public void addRepository(@NotNull final String alias, @NotNull final String repositoryUrl)
{
manager.getRepositoryManager().addRepository(alias, manager.getRepositoryFactory().create(repositoryUrl));
Expand All @@ -76,7 +92,6 @@ public void addRepository(@NotNull final String alias, @NotNull final String rep
private void loadDependenciesFromFile(@NotNull final InputStream dependenciesResource)
{
final JSONDependencies jsonDependencies;

try (final Reader reader = new InputStreamReader(dependenciesResource))
{
jsonDependencies = Constants.GSON.fromJson(reader, JSONDependencies.class);
Expand Down Expand Up @@ -130,7 +145,7 @@ private void loadDependenciesFromFile(@NotNull final InputStream dependenciesRes
* which is completed once all dependencies have been downloaded (if applicable), loaded into the classpath, or failed.
* <p>
* Because of the non blocking nature, important parts of initialization (that require classes from dependencies) should
* typically either block, or
* typically either block, or use a callback such as {@link CompletableFuture#whenComplete(BiConsumer)}
*
* @return a {@link CompletableFuture} that is completed when dependency loading finishes.
* @since 0.0.1
Expand All @@ -142,7 +157,7 @@ public CompletableFuture<Void> loadAllDependencies()
{
logger.warning("There were no dependencies to load! This might be intentional, but if not, check your dependencies configuration!");
}

//Each dependency is loaded concurrently
return CompletableFuture.allOf(requiredDependencies.stream()
.map(manager::downloadAndLoad)
.toArray(CompletableFuture[]::new));
Expand Down

0 comments on commit e484e7a

Please sign in to comment.