added support for remote urls to push and pull api

This commit is contained in:
Sebastian Sdorra
2014-10-29 21:35:10 +01:00
parent 6256cea4ce
commit 4436d14a5f
5 changed files with 131 additions and 6 deletions

View File

@@ -50,6 +50,7 @@ import sonia.scm.security.RepositoryPermission;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.net.URL;
/**
* The pull command pull changes from a other repository.
@@ -83,6 +84,38 @@ public final class PullCommandBuilder
//~--- methods --------------------------------------------------------------
/**
* Pull all changes from the given remote url.
*
*
* @param url remote url
*
* @return informations over the executed pull command
*
* @throws IOException
* @throws RepositoryException
*
* @since 1.43
*/
public PullResponse pull(String url)
throws IOException, RepositoryException
{
Subject subject = SecurityUtils.getSubject();
//J-
subject.checkPermission(
new RepositoryPermission(localRepository, PermissionType.WRITE)
);
//J+
URL remoteUrl = new URL(url);
request.reset();
request.setRemoteUrl(remoteUrl);
logger.info("pull changes from url {}", url);
return command.pull(request);
}
/**
* Pull all changes from the given remote repository.
*
@@ -108,6 +141,7 @@ public final class PullCommandBuilder
);
//J+
request.reset();
request.setRemoteRepository(remoteRepository);
logger.info("pull changes from {}", remoteRepository);

View File

@@ -30,6 +30,7 @@
*/
package sonia.scm.repository.api;
//~--- non-JDK imports --------------------------------------------------------
@@ -37,6 +38,9 @@ package sonia.scm.repository.api;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.PermissionType;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException;
@@ -48,15 +52,25 @@ import sonia.scm.security.RepositoryPermission;
import java.io.IOException;
import java.net.URL;
/**
* The push command push changes to a other repository.
*
*
* @author Sebastian Sdorra
* @since 1.31
*/
public final class PushCommandBuilder
{
/**
* the logger for PushCommandBuilder
*/
private static final Logger logger =
LoggerFactory.getLogger(PushCommandBuilder.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new PushCommandBuilder.
*
@@ -90,11 +104,39 @@ public final class PushCommandBuilder
);
//J+
logger.info("push changes to repository {}", remoteRepository.getId());
request.reset();
request.setRemoteRepository(remoteRepository);
return command.push(request);
}
/**
* Push all changes to the given remote url.
*
* @param url url of a remote repository
*
* @return informations of the executed push command
*
* @throws IOException
* @throws RepositoryException
*
* @since 1.43
*/
public PushResponse push(String url) throws IOException, RepositoryException
{
URL remoteUrl = new URL(url);
logger.info("push changes to url {}", url);
request.reset();
request.setRemoteUrl(remoteUrl);
return command.push(request);
}
//~--- fields ---------------------------------------------------------------
/** push command implementation */

View File

@@ -33,7 +33,8 @@
package sonia.scm.repository.spi;
/**
*
* Request object for {@link PullCommand}.
*
* @author Sebastian Sdorra
* @since 1.31
*/

View File

@@ -33,6 +33,7 @@
package sonia.scm.repository.spi;
/**
* Request object for {@link PushCommand}.
*
* @author Sebastian Sdorra
* @since 1.31

View File

@@ -30,6 +30,7 @@
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -38,12 +39,16 @@ import com.google.common.base.Objects;
import sonia.scm.repository.Repository;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
/**
*
* @author Sebastian Sdorra
* @since 1.31
*/
public abstract class RemoteCommandRequest
public abstract class RemoteCommandRequest implements Resetable
{
/**
@@ -64,7 +69,8 @@ public abstract class RemoteCommandRequest
final RemoteCommandRequest other = (RemoteCommandRequest) obj;
return Objects.equal(remoteRepository, other.remoteRepository);
return Objects.equal(remoteRepository, other.remoteRepository)
&& Objects.equal(remoteUrl, other.remoteUrl);
}
/**
@@ -73,7 +79,19 @@ public abstract class RemoteCommandRequest
@Override
public int hashCode()
{
return Objects.hashCode(remoteRepository);
return Objects.hashCode(remoteRepository, remoteUrl);
}
/**
* Resets the request object.
*
* @since 1.43
*/
@Override
public void reset()
{
remoteRepository = null;
remoteUrl = null;
}
/**
@@ -82,10 +100,10 @@ public abstract class RemoteCommandRequest
@Override
public String toString()
{
//J-
return Objects.toStringHelper(this)
.add("remoteRepository", remoteRepository)
.add("remoteUrl", remoteUrl)
.toString();
//J+
}
@@ -102,6 +120,19 @@ public abstract class RemoteCommandRequest
this.remoteRepository = remoteRepository;
}
/**
* Method description
*
*
* @param remoteUrl
*
* @since 1.43
*/
public void setRemoteUrl(URL remoteUrl)
{
this.remoteUrl = remoteUrl;
}
//~--- get methods ----------------------------------------------------------
/**
@@ -115,8 +146,24 @@ public abstract class RemoteCommandRequest
return remoteRepository;
}
/**
* Method description
*
*
* @return
*
* @since 1.43
*/
URL getRemoteUrl()
{
return remoteUrl;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
protected Repository remoteRepository;
/** remote url */
protected URL remoteUrl;
}