Skip to content

Commit

Permalink
Add isLoaded method and some nullability annotations, change include …
Browse files Browse the repository at this point in the history
…logic a little bit
  • Loading branch information
Vankka committed Jul 20, 2024
1 parent 54f6494 commit a62fa0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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<Relocation> relocations) {
synchronized (dependencyManager) {
dependencyManager.addRelocations(relocations);
Expand All @@ -92,6 +94,7 @@ public ApplicationDependencyManager addRelocations(@NotNull Collection<Relocatio
* @param relocation the relocation
* @see #addRelocations(Collection)
*/
@NotNull
public ApplicationDependencyManager addRelocation(@NotNull Relocation relocation) {
synchronized (dependencyManager) {
dependencyManager.addRelocation(relocation);
Expand All @@ -111,6 +114,7 @@ public ApplicationDependencyManager addRelocation(@NotNull Relocation relocation
* @throws IOException if reading the file from the {@link URL} fails
*/
@CheckReturnValue
@NotNull
public DependencyManager includeResource(@NotNull URL resourceURL) throws IOException {
DependencyDownloadResource resource = new DependencyDownloadResource(resourceURL);
return includeResource(resource);
Expand All @@ -127,6 +131,7 @@ public DependencyManager includeResource(@NotNull URL resourceURL) throws IOExce
* @return the {@link DependencyManager} to load in the dependencies
*/
@CheckReturnValue
@NotNull
public DependencyManager includeResource(@NotNull String resourceContent) {
DependencyDownloadResource resource = new DependencyDownloadResource(resourceContent);
return includeResource(resource);
Expand All @@ -143,6 +148,7 @@ public DependencyManager includeResource(@NotNull String resourceContent) {
* @return the {@link DependencyManager} to load in the dependencies
*/
@CheckReturnValue
@NotNull
public DependencyManager includeResource(@NotNull List<String> resourceLines) {
DependencyDownloadResource resource = new DependencyDownloadResource(resourceLines);
return includeResource(resource);
Expand All @@ -157,6 +163,8 @@ public DependencyManager includeResource(@NotNull List<String> 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());
}
Expand All @@ -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<Dependency> dependencies, @NotNull List<Relocation> relocations) {
addRelocations(relocations);
return include(dependencies);
Expand All @@ -187,6 +196,7 @@ public DependencyManager include(@NotNull List<Dependency> dependencies, @NotNul
* @return the {@link DependencyManager} to load in the dependencies
*/
@CheckReturnValue
@NotNull
public DependencyManager include(@NotNull Dependency... dependencies) {
return include(Arrays.asList(dependencies));
}
Expand All @@ -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<Dependency> dependencies) {
dependencies = addMissingDependencies(dependencies);

Expand All @@ -219,12 +230,15 @@ public DependencyManager include(@NotNull Collection<Dependency> 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<Dependency> dependencies = addMissingDependencies(manager.getDependencies());
if (manager.isLoaded()) {
return dependencyManager;
}

DependencyManager dependencyManager = new DependencyManager(manager.getDependencyPathProvider());
dependencyManager.addDependencies(dependencies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit a62fa0a

Please sign in to comment.