diff --git a/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java index 1e170d999e..528c93eef9 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/PullCommandBuilder.java @@ -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); diff --git a/scm-core/src/main/java/sonia/scm/repository/api/PushCommandBuilder.java b/scm-core/src/main/java/sonia/scm/repository/api/PushCommandBuilder.java index 5737997442..fabe938ff7 100644 --- a/scm-core/src/main/java/sonia/scm/repository/api/PushCommandBuilder.java +++ b/scm-core/src/main/java/sonia/scm/repository/api/PushCommandBuilder.java @@ -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 */ diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java index be1305b4db..274e124f5e 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/PullCommandRequest.java @@ -33,7 +33,8 @@ package sonia.scm.repository.spi; /** - * + * Request object for {@link PullCommand}. + * * @author Sebastian Sdorra * @since 1.31 */ diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/PushCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/PushCommandRequest.java index d1f51e427e..679e93f1bb 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/PushCommandRequest.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/PushCommandRequest.java @@ -33,6 +33,7 @@ package sonia.scm.repository.spi; /** + * Request object for {@link PushCommand}. * * @author Sebastian Sdorra * @since 1.31 diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/RemoteCommandRequest.java b/scm-core/src/main/java/sonia/scm/repository/spi/RemoteCommandRequest.java index 949b56efa7..0f3cd909d9 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/RemoteCommandRequest.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/RemoteCommandRequest.java @@ -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; }