All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.prezi.pride.vcs.VcsManager Maven / Gradle / Ivy

There is a newer version: 0.12.3
Show newest version
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