allow multiple provider implementations

This commit is contained in:
Sebastian Sdorra
2012-07-15 16:20:18 +02:00
parent d2955dcc6d
commit ac5fab3e8d
3 changed files with 75 additions and 9 deletions

View File

@@ -38,6 +38,7 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.client.api.RepositoryClientException;
//~--- JDK imports ------------------------------------------------------------
@@ -118,4 +119,18 @@ public class GitRepositoryClientFactoryProvider
return new GitRepositoryClientProvider(git, credentialsProvider);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getType()
{
return GitRepositoryHandler.TYPE_NAME;
}
}

View File

@@ -53,10 +53,13 @@ public final class RepositoryClientFactory
*
*
* @param provider
*
* @param providers
*/
public RepositoryClientFactory(RepositoryClientFactoryProvider provider)
public RepositoryClientFactory(
Iterable<RepositoryClientFactoryProvider> providers)
{
this.provider = provider;
this.providers = providers;
}
//~--- methods --------------------------------------------------------------
@@ -65,6 +68,8 @@ public final class RepositoryClientFactory
* Method description
*
*
*
* @param type
* @param main
* @param workingCopy
*
@@ -72,16 +77,19 @@ public final class RepositoryClientFactory
*
* @throws IOException
*/
public RepositoryClient create(File main, File workingCopy) throws IOException
public RepositoryClient create(String type, File main, File workingCopy)
throws IOException
{
return new RepositoryClient(provider.create(main, workingCopy));
return new RepositoryClient(getProvider(type).create(main, workingCopy));
}
/**
* Method description
*
*
*
* @param type
* @param url
* @param username
* @param password
@@ -91,16 +99,49 @@ public final class RepositoryClientFactory
*
* @throws IOException
*/
public RepositoryClient create(String url, String username, String password,
File workingCopy)
public RepositoryClient create(String type, String url, String username,
String password, File workingCopy)
throws IOException
{
return new RepositoryClient(provider.create(url, username, password,
workingCopy));
return new RepositoryClient(getProvider(type).create(url, username,
password, workingCopy));
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param type
*
* @return
*/
private RepositoryClientFactoryProvider getProvider(String type)
{
RepositoryClientFactoryProvider provider = null;
for (RepositoryClientFactoryProvider p : providers)
{
if (p.getType().equalsIgnoreCase(type))
{
provider = p;
break;
}
}
if (provider == null)
{
throw new RuntimeException(
"could not find provider for type ".concat(type));
}
return provider;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private RepositoryClientFactoryProvider provider;
private Iterable<RepositoryClientFactoryProvider> providers;
}

View File

@@ -74,4 +74,14 @@ public interface RepositoryClientFactoryProvider
public RepositoryClientProvider create(String url, String username,
String password, File workingCopy)
throws IOException;
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public String getType();
}