io.bdeploy.api.product.v1.impl.MultiLocalDependencyFetcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
package io.bdeploy.api.product.v1.impl;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import io.bdeploy.api.product.v1.DependencyFetcher;
import io.bdeploy.bhive.BHive;
import io.bdeploy.bhive.model.Manifest;
import io.bdeploy.bhive.model.Manifest.Key;
import io.bdeploy.bhive.model.ObjectId;
import io.bdeploy.bhive.op.CopyOperation;
import io.bdeploy.bhive.op.ObjectListOperation;
import io.bdeploy.common.util.OsHelper.OperatingSystem;
public class MultiLocalDependencyFetcher implements DependencyFetcher {
private final List sources;
public MultiLocalDependencyFetcher(List sources) {
this.sources = sources;
}
@Override
public SortedSet fetch(BHive target, SortedSet specs, OperatingSystem os) {
SortedSet smks = new TreeSet<>();
// make sure all dependencies are satisfied
for (String dep : specs) {
smks.add(this.resolveDependency(target, dep, os));
}
return smks;
}
private Key resolveDependency(BHive target, String dep, OperatingSystem os) {
// check if dependency is in the target
Key resolved = LocalDependencyFetcher.resolveSingleLocal(target, dep, os);
if (resolved != null) {
return resolved;
}
// check if dependency is in some source
for (BHive source : sources) {
resolved = LocalDependencyFetcher.resolveSingleLocal(source, dep, os);
if (resolved != null) {
// copy found dependency into target
copyDependency(source, target, resolved);
return resolved;
}
}
throw new IllegalStateException("Cannot resolve dependency " + dep + " for " + os);
}
private static void copyDependency(BHive source, BHive target, Key resolved) {
Set objectIds = source.execute(new ObjectListOperation().addManifest(resolved));
CopyOperation op = new CopyOperation().setDestinationHive(target).addManifest(resolved).addObject(objectIds);
source.execute(op);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy