
org.jerkar.tool.JkSlaveBuilds Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Build simpler, stronger, faster
package org.jerkar.tool;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.jerkar.api.depmanagement.JkDependencies;
import org.jerkar.api.depmanagement.JkScopedDependency;
import org.jerkar.api.system.JkLog;
import org.jerkar.api.utils.JkUtilsFile;
import org.jerkar.api.utils.JkUtilsIterable;
/**
* Defines slaves of a given master build.
*
* @author Jerome Angibaud
*/
public final class JkSlaveBuilds {
static JkSlaveBuilds of(File masterRootDir, List builds) {
return new JkSlaveBuilds(masterRootDir, new ArrayList(builds));
}
private final List directSlaves;
private List resolvedTransitiveBuilds;
private final File masterBuildRoot;
private JkSlaveBuilds(File masterDir, List buildDeps) {
super();
this.masterBuildRoot = masterDir;
this.directSlaves = Collections.unmodifiableList(buildDeps);
}
/**
* Returns a {@link JkSlaveBuilds} identical to this one but augmented with
* specified slave builds.
*/
@SuppressWarnings("unchecked")
public JkSlaveBuilds and(List slaves) {
return new JkSlaveBuilds(this.masterBuildRoot, JkUtilsIterable.concatLists(
this.directSlaves, slaves));
}
/**
* Returns a {@link JkSlaveBuilds} identical to this one but augmented with
* the {@link BuildDependency} contained in the the specified dependencies.
*/
public JkSlaveBuilds and(JkDependencies dependencies) {
final List list = projectBuildDependencies(dependencies);
return this.and(list);
}
/**
* Returns only the direct slave of this master build.
*/
public List directs() {
return Collections.unmodifiableList(directSlaves);
}
/**
* Returns direct and transitive slaves. Transitive slaves are resolved by
* invoking recursively JkBuildDependencySupport#slaves()
on
* direct slaves.
*
*/
public List all() {
if (resolvedTransitiveBuilds == null) {
resolvedTransitiveBuilds = resolveTransitiveBuilds(new HashSet());
}
return resolvedTransitiveBuilds;
}
/**
* Execute the doDefault
on all slaves.
*/
public void invokeDoDefaultMethodOnAll() {
this.invokeOnAll(JkConstants.DEFAULT_METHOD);
}
/**
* Executes the specified methods on all slaves.
*/
public void invokeOnAll(String... methods) {
this.executeOnAll(JkModelMethod.normals(methods));
}
private void executeOnAll(Iterable methods) {
JkLog.startln("Invoke " + methods + " on all dependents projects");
for (final JkBuild build : all()) {
build.execute(methods, this.masterBuildRoot);
}
JkLog.done("invoking " + methods + " on all dependents projects");
}
private List resolveTransitiveBuilds(Set files) {
final List result = new LinkedList();
for (final JkBuild build : directSlaves) {
final File dir = JkUtilsFile.canonicalFile(build.baseDir().root());
if (!files.contains(dir)) {
if (build instanceof JkBuildDependencySupport) {
final JkBuildDependencySupport buildDependencySupport = (JkBuildDependencySupport) build;
result.addAll(buildDependencySupport.slaves().resolveTransitiveBuilds(files));
}
result.add(build);
files.add(dir);
}
}
return result;
}
private static List projectBuildDependencies(JkDependencies dependencies) {
final List result = new LinkedList();
for (final JkScopedDependency scopedDependency : dependencies) {
if (scopedDependency.dependency() instanceof BuildDependency) {
final BuildDependency projectDependency = (BuildDependency) scopedDependency
.dependency();
result.add(projectDependency.projectBuild());
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy