com.prezi.pride.vcs.VcsManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pride-core Show documentation
Show all versions of pride-core Show documentation
Pride manages multiple Gradle modules as a single Gradle project
package com.prezi.pride.vcs;
import com.prezi.pride.PrideException;
import com.prezi.pride.vcs.file.FileVcsSupportFactory;
import org.apache.commons.configuration.Configuration;
import java.io.File;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
public final class VcsManager {
private final Map vcss = new LinkedHashMap();
public VcsManager() {
for (VcsSupportFactory factory : ServiceLoader.load(VcsSupportFactory.class)) {
vcss.put(factory.getType(), factory);
}
// Make sure file support is always the last VCS tried
VcsSupportFactory fileSupport = new FileVcsSupportFactory();
vcss.put(fileSupport.getType(), fileSupport);
}
public Vcs getVcs(final String type, Configuration configuration) {
VcsSupportFactory vcsFactory = vcss.get(type);
if (vcsFactory == null) {
throw new PrideException("No support for VCS type \"" + type + "\"");
}
return new Vcs(type, vcsFactory.createVcsSupport(configuration));
}
public Vcs findSupportingVcs(File directory, Configuration configuration) {
for (VcsSupportFactory factory : vcss.values()) {
if (factory.canSupport(directory)) {
return new Vcs(factory.getType(), factory.createVcsSupport(configuration));
}
}
throw new PrideException("No VCS support found for local repository in directory \"" + directory + "\"");
}
public Set getSupportedTypes() {
return Collections.unmodifiableSet(vcss.keySet());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy