Skip to content

Commit

Permalink
Work on dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
HttpMarco committed Dec 31, 2024
1 parent caa076d commit 1d06ac1
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 9 deletions.
1 change: 1 addition & 0 deletions polocloud-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

dependencies {
compileOnlyApi(libs.annotations)
annotationProcessor(libs.lombok)
compileOnly(libs.lombok)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public ModifiableClassloader() {
}

@SneakyThrows
public void attach(String file) {
super.addURL(new File(file).toURI().toURL());
public void attach(File file) {
super.addURL(file.toURI().toURL());
}

public static ModifiableClassloader defaultClassLoader() {
return new ModifiableClassloader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dev.httpmarco.polocloud.api.groups.ClusterGroupProvider;
import dev.httpmarco.polocloud.node.components.ComponentProvider;
import dev.httpmarco.polocloud.node.components.impl.ComponentProviderImpl;
import dev.httpmarco.polocloud.node.dependencies.DependencyProvider;
import dev.httpmarco.polocloud.node.dependencies.impl.DependencyProviderImpl;
import dev.httpmarco.polocloud.node.group.ClusterGroupProviderImpl;
import lombok.Getter;
import lombok.experimental.Accessors;
Expand All @@ -14,13 +16,15 @@
@Accessors(fluent = true)
public final class Node extends PolocloudAPI {

private final DependencyProvider dependencyProvider;
private final ComponentProvider componentProvider;
private final ClusterGroupProvider groupProvider;


public Node() {
log.info("Starting Polocloud Node...");

this.dependencyProvider = new DependencyProviderImpl();
this.componentProvider = new ComponentProviderImpl();
this.groupProvider = new ClusterGroupProviderImpl();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dev.httpmarco.polocloud.node.dependencies;

import dev.httpmarco.polocloud.api.Version;
import dev.httpmarco.polocloud.api.Available;

public class Dependency {
import java.io.File;

private String groupId;
private String artifactId;
private Version version;
public interface Dependency extends Available {

File file();

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
package dev.httpmarco.polocloud.node.dependencies;

import dev.httpmarco.polocloud.common.ModifiableClassloader;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Log4j2
@RequiredArgsConstructor
public final class DependencySlot {

private final ModifiableClassloader classloader;
private final List<Dependency> dependencies = new CopyOnWriteArrayList<>();

public void bindDependencies(Dependency dependency) {
if(!dependency.available()) {
log.warn("Cannot bind dependencies for {}", dependency);
return;
}

this.classloader.attach(dependency.file());
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.httpmarco.polocloud.node.dependencies.impl;

import dev.httpmarco.polocloud.common.ModifiableClassloader;
import dev.httpmarco.polocloud.node.dependencies.DependencyProvider;
import dev.httpmarco.polocloud.node.dependencies.DependencySlot;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;

Expand All @@ -13,7 +13,10 @@
@Accessors(fluent = true)
public class DependencyProviderImpl implements DependencyProvider {

private final DependencySlot originalSlot = new DependencySlot();
private final DependencySlot originalSlot = new DependencySlot(ModifiableClassloader.defaultClassLoader());
private final List<DependencySlot> slots = new ArrayList<>();




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dev.httpmarco.polocloud.node.dependencies.impl;

import dev.httpmarco.polocloud.api.Version;
import dev.httpmarco.polocloud.node.dependencies.Dependency;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.Nullable;

import java.io.File;

@Getter
@ToString
@Accessors(fluent = true)
@AllArgsConstructor
public final class RepositoryDependency implements Dependency {

private final String groupId;
private final String artifactId;
private final Version version;

private @Nullable File file;

@Override
public boolean available() {
return file != null && file.exists();
}
}

0 comments on commit 1d06ac1

Please sign in to comment.