mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
remove deprecated classes
This commit is contained in:
@@ -1,483 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.client;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import sonia.scm.url.UrlProvider;
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated use {@link UrlProvider} instead. For example:
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* URLProvider provider = URLProviderFactory.createUrlProvider(
|
|
||||||
* baseUrl,
|
|
||||||
* UrlProviderFactory.TYPE_RESTAPI_XML
|
|
||||||
* );
|
|
||||||
* String authUrl = provider.getAuthenticationUrl();
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public class ScmUrlProvider
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String API_PATH = "/api/rest/";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_AUTHENTICATION = "authentication";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_AUTHENTICATION_LOGIN =
|
|
||||||
"authentication/login";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_GROUP = "groups/";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_GROUPS = "groups";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_REPOSITORIES = "repositories";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_REPOSITORY = "repositories/";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_USER = "users/";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPART_USERS = "users";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPATTERN_BLAME = "repositories/{0}/blame";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPATTERN_BROWSE = "repositories/{0}/browse";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPATTERN_CHANGESETS =
|
|
||||||
"repositories/{0}/changesets";
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
public static final String URLPATTERN_CONTENT = "repositories/{0}/content";
|
|
||||||
|
|
||||||
/** the logger for classVar */
|
|
||||||
private static final Logger logger =
|
|
||||||
LoggerFactory.getLogger(ScmUrlProvider.class);
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param baseUrl
|
|
||||||
*/
|
|
||||||
public ScmUrlProvider(String baseUrl)
|
|
||||||
{
|
|
||||||
if (!baseUrl.endsWith(API_PATH))
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl.concat(API_PATH);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("create new url provider with baseurl {}", this.baseUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getAuthenticationLoginUrl()
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_AUTHENTICATION_LOGIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getAuthenticationUrl()
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_AUTHENTICATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getBaseUrl()
|
|
||||||
{
|
|
||||||
return baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryId
|
|
||||||
* @param path
|
|
||||||
* @param revision
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getBlameUrl(String repositoryId, String path, String revision)
|
|
||||||
{
|
|
||||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_BLAME),
|
|
||||||
repositoryId);
|
|
||||||
|
|
||||||
return appendParameter(url, path, revision);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getExtension()
|
|
||||||
{
|
|
||||||
return extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getGroupUrl(String name)
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_GROUP.concat(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getGroupsUrl()
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_GROUPS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoriesUrl()
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_REPOSITORIES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryId
|
|
||||||
* @param revision
|
|
||||||
* @param path
|
|
||||||
* @since 1.8
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryBrowseUrl(String repositoryId, String path,
|
|
||||||
String revision)
|
|
||||||
{
|
|
||||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_BROWSE),
|
|
||||||
repositoryId);
|
|
||||||
|
|
||||||
return appendParameter(url, path, revision);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryId
|
|
||||||
* @since 1.8
|
|
||||||
*
|
|
||||||
* @param path
|
|
||||||
* @param revision
|
|
||||||
* @param start
|
|
||||||
* @param limit
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryChangesetUrl(String repositoryId, String path,
|
|
||||||
String revision, int start, int limit)
|
|
||||||
{
|
|
||||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_CHANGESETS),
|
|
||||||
repositoryId);
|
|
||||||
String s = "?";
|
|
||||||
|
|
||||||
if (start >= 0)
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("start=").concat(String.valueOf(start));
|
|
||||||
s = "&";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (limit > 0)
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("limit=").concat(String.valueOf(limit));
|
|
||||||
s = "&";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path != null)
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("path=").concat(path);
|
|
||||||
s = "&";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (revision != null)
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("revision=").concat(revision);
|
|
||||||
s = "&";
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryId
|
|
||||||
* @since 1.8
|
|
||||||
*
|
|
||||||
* @param start
|
|
||||||
* @param limit
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryChangesetUrl(String repositoryId, int start,
|
|
||||||
int limit)
|
|
||||||
{
|
|
||||||
return getRepositoryChangesetUrl(repositoryId, null, null, start, limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param repositoryId
|
|
||||||
* @param path
|
|
||||||
* @param revision
|
|
||||||
* @since 1.8
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryContentUrl(String repositoryId, String path,
|
|
||||||
String revision)
|
|
||||||
{
|
|
||||||
String url = MessageFormat.format(getResourceUrl(URLPATTERN_CONTENT,
|
|
||||||
false), repositoryId);
|
|
||||||
|
|
||||||
url = url.concat("?path=").concat(path);
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(revision))
|
|
||||||
{
|
|
||||||
url = url.concat("&revision=").concat(revision);
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRepositoryUrl(String id)
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_REPOSITORY.concat(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param urlPart
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getResourceUrl(String urlPart)
|
|
||||||
{
|
|
||||||
return getResourceUrl(urlPart, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param urlPart
|
|
||||||
* @param appendExtension
|
|
||||||
* @since 1.8
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getResourceUrl(String urlPart, boolean appendExtension)
|
|
||||||
{
|
|
||||||
String resourceUrl = baseUrl.concat(urlPart);
|
|
||||||
|
|
||||||
if (appendExtension)
|
|
||||||
{
|
|
||||||
resourceUrl = resourceUrl.concat(extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger.isTraceEnabled())
|
|
||||||
{
|
|
||||||
logger.trace("return resourceurl {}", resourceUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resourceUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUserUrl(String name)
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_USER.concat(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUsersUrl()
|
|
||||||
{
|
|
||||||
return getResourceUrl(URLPART_USERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param baseUrl
|
|
||||||
*/
|
|
||||||
public void setBaseUrl(String baseUrl)
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param extension
|
|
||||||
*/
|
|
||||||
public void setExtension(String extension)
|
|
||||||
{
|
|
||||||
this.extension = extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @param path
|
|
||||||
* @param revision
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String appendParameter(String url, String path, String revision)
|
|
||||||
{
|
|
||||||
String s = "?";
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(path))
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("path=").concat(path);
|
|
||||||
s = "&";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Util.isNotEmpty(revision))
|
|
||||||
{
|
|
||||||
url = url.concat(s).concat("revision=").concat(revision);
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String baseUrl;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String extension = ".xml";
|
|
||||||
}
|
|
||||||
@@ -52,34 +52,6 @@
|
|||||||
<version>${slf4j.version}</version>
|
<version>${slf4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- jgit -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.jgit</groupId>
|
|
||||||
<artifactId>org.eclipse.jgit</artifactId>
|
|
||||||
<version>${jgit.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- svnkit -->
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>sonia.svnkit</groupId>
|
|
||||||
<artifactId>svnkit</artifactId>
|
|
||||||
<version>${svnkit.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- for jgit -->
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>jgit-repository</id>
|
|
||||||
<name>jgit release repository</name>
|
|
||||||
<url>http://download.eclipse.org/jgit/maven</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class AbstractRepositoryClient implements RepositoryClient
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
*/
|
|
||||||
public AbstractRepositoryClient(File localRepository, String remoteRepository)
|
|
||||||
{
|
|
||||||
this.localRepository = localRepository;
|
|
||||||
this.remoteRepository = remoteRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public File getLocalRepository()
|
|
||||||
{
|
|
||||||
return localRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRemoteRepository()
|
|
||||||
{
|
|
||||||
return remoteRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
protected File localRepository;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
protected String remoteRepository;
|
|
||||||
}
|
|
||||||
@@ -1,548 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.eclipse.jgit.api.AddCommand;
|
|
||||||
import org.eclipse.jgit.api.CommitCommand;
|
|
||||||
import org.eclipse.jgit.api.Git;
|
|
||||||
import org.eclipse.jgit.api.GitCommand;
|
|
||||||
import org.eclipse.jgit.dircache.DirCache;
|
|
||||||
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
|
||||||
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
|
|
||||||
import org.eclipse.jgit.errors.NotSupportedException;
|
|
||||||
import org.eclipse.jgit.errors.TransportException;
|
|
||||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
|
||||||
import org.eclipse.jgit.lib.Ref;
|
|
||||||
import org.eclipse.jgit.lib.RefComparator;
|
|
||||||
import org.eclipse.jgit.lib.RefUpdate;
|
|
||||||
import org.eclipse.jgit.lib.TextProgressMonitor;
|
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
|
||||||
import org.eclipse.jgit.transport.CredentialsProvider;
|
|
||||||
import org.eclipse.jgit.transport.FetchResult;
|
|
||||||
import org.eclipse.jgit.transport.PushResult;
|
|
||||||
import org.eclipse.jgit.transport.RefSpec;
|
|
||||||
import org.eclipse.jgit.transport.RemoteConfig;
|
|
||||||
import org.eclipse.jgit.transport.RemoteRefUpdate;
|
|
||||||
import org.eclipse.jgit.transport.TrackingRefUpdate;
|
|
||||||
import org.eclipse.jgit.transport.Transport;
|
|
||||||
import org.eclipse.jgit.transport.URIish;
|
|
||||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
|
||||||
|
|
||||||
import sonia.scm.util.Util;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class GitRepositoryClient extends AbstractRepositoryClient
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws URISyntaxException
|
|
||||||
*/
|
|
||||||
GitRepositoryClient(File localRepository, String remoteRepository,
|
|
||||||
String username, String password)
|
|
||||||
throws URISyntaxException, IOException
|
|
||||||
{
|
|
||||||
super(localRepository, remoteRepository);
|
|
||||||
uri = new URIish(remoteRepository);
|
|
||||||
|
|
||||||
if ((username != null) && (password != null))
|
|
||||||
{
|
|
||||||
uri.setUser(username);
|
|
||||||
uri.setPass(password);
|
|
||||||
credentialsProvider = new UsernamePasswordCredentialsProvider(username,
|
|
||||||
password);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.repository = new FileRepository(new File(localRepository,
|
|
||||||
Constants.DOT_GIT));
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @param others
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void add(String file, String... others)
|
|
||||||
throws RepositoryClientException
|
|
||||||
{
|
|
||||||
AddCommand cmd = new Git(repository).add();
|
|
||||||
|
|
||||||
cmd.addFilepattern(file);
|
|
||||||
|
|
||||||
if (others != null)
|
|
||||||
{
|
|
||||||
for (String f : others)
|
|
||||||
{
|
|
||||||
cmd.addFilepattern(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callCommand(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void checkout() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final FetchResult r = runFetch();
|
|
||||||
|
|
||||||
if (r != null)
|
|
||||||
{
|
|
||||||
for (TrackingRefUpdate ru : r.getTrackingRefUpdates())
|
|
||||||
{
|
|
||||||
switch (ru.getResult())
|
|
||||||
{
|
|
||||||
case IO_FAILURE :
|
|
||||||
case LOCK_FAILURE :
|
|
||||||
case REJECTED :
|
|
||||||
case REJECTED_CURRENT_BRANCH :
|
|
||||||
throw new RepositoryClientException("could not checkout, status "
|
|
||||||
+ ru.getResult().name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref branch = guessHEAD(r);
|
|
||||||
|
|
||||||
doCheckout(branch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (RepositoryClientException ex)
|
|
||||||
{
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void commit(String message) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CommitCommand cmd = new Git(repository).commit();
|
|
||||||
|
|
||||||
cmd.setMessage(message);
|
|
||||||
callCommand(cmd);
|
|
||||||
|
|
||||||
List<Transport> transports = Transport.openAll(repository, "origin",
|
|
||||||
Transport.Operation.PUSH);
|
|
||||||
|
|
||||||
for (Transport transport : transports)
|
|
||||||
{
|
|
||||||
List<RefSpec> refSpecs = new ArrayList<RefSpec>();
|
|
||||||
RefSpec rs = new RefSpec("+refs/heads/master:refs/heads/master");
|
|
||||||
|
|
||||||
refSpecs.add(rs);
|
|
||||||
|
|
||||||
if (credentialsProvider != null)
|
|
||||||
{
|
|
||||||
transport.setCredentialsProvider(credentialsProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<RemoteRefUpdate> toPush =
|
|
||||||
transport.findRemoteRefUpdatesFor(refSpecs);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PushResult result = transport.push(new TextProgressMonitor(), toPush);
|
|
||||||
Collection<RemoteRefUpdate> refUpdates = result.getRemoteUpdates();
|
|
||||||
|
|
||||||
if (Util.isEmpty(refUpdates))
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException("no ref updated");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (RemoteRefUpdate refUpdate : refUpdates)
|
|
||||||
{
|
|
||||||
switch (refUpdate.getStatus())
|
|
||||||
{
|
|
||||||
case OK :
|
|
||||||
case UP_TO_DATE :
|
|
||||||
case NON_EXISTING :
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NOT_ATTEMPTED :
|
|
||||||
case AWAITING_REPORT :
|
|
||||||
case REJECTED_NODELETE :
|
|
||||||
case REJECTED_NONFASTFORWARD :
|
|
||||||
case REJECTED_REMOTE_CHANGED :
|
|
||||||
case REJECTED_OTHER_REASON :
|
|
||||||
throw new RepositoryClientException(
|
|
||||||
"could not update ref ".concat(refUpdate.getSrcRef()).concat(
|
|
||||||
" status ".concat(refUpdate.getStatus().toString())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
transport.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (RepositoryClientException ex)
|
|
||||||
{
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
repository.create(false);
|
|
||||||
addRemote("origin", new URIish(remoteRepository), "master", null, true,
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param remoteName
|
|
||||||
* @param uri
|
|
||||||
* @param branchName
|
|
||||||
* @param tagName
|
|
||||||
* @param allSelected
|
|
||||||
* @param selectedBranches
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws URISyntaxException
|
|
||||||
*/
|
|
||||||
private void addRemote(final String remoteName, final URIish uri,
|
|
||||||
final String branchName, final String tagName, final boolean allSelected,
|
|
||||||
final Collection<Ref> selectedBranches)
|
|
||||||
throws URISyntaxException, IOException
|
|
||||||
{
|
|
||||||
|
|
||||||
// add remote configuration
|
|
||||||
final RemoteConfig rc = new RemoteConfig(repository.getConfig(),
|
|
||||||
remoteName);
|
|
||||||
|
|
||||||
rc.addURI(uri);
|
|
||||||
|
|
||||||
final String dst = Constants.R_REMOTES + rc.getName();
|
|
||||||
RefSpec wcrs = new RefSpec();
|
|
||||||
|
|
||||||
wcrs = wcrs.setForceUpdate(true);
|
|
||||||
wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst + "/*");
|
|
||||||
|
|
||||||
if (allSelected)
|
|
||||||
{
|
|
||||||
rc.addFetchRefSpec(wcrs);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (final Ref ref : selectedBranches)
|
|
||||||
{
|
|
||||||
if (wcrs.matchSource(ref))
|
|
||||||
{
|
|
||||||
rc.addFetchRefSpec(wcrs.expandFromSource(ref));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rc.update(repository.getConfig());
|
|
||||||
repository.getConfig().save();
|
|
||||||
|
|
||||||
// setup the default remote branch for branchName
|
|
||||||
repository.getConfig().setString("branch", branchName, "remote",
|
|
||||||
remoteName);
|
|
||||||
|
|
||||||
if (branchName != null)
|
|
||||||
{
|
|
||||||
repository.getConfig().setString("branch", branchName, "merge",
|
|
||||||
Constants.R_HEADS + branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tagName != null)
|
|
||||||
{
|
|
||||||
repository.getConfig().setString("branch", branchName, "merge",
|
|
||||||
Constants.R_TAGS + branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
repository.getConfig().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param cmd
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
private void callCommand(GitCommand cmd) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cmd.call();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param branch
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private void doCheckout(final Ref branch) throws IOException
|
|
||||||
{
|
|
||||||
if (!Constants.HEAD.equals(branch.getName()))
|
|
||||||
{
|
|
||||||
RefUpdate u = repository.updateRef(Constants.HEAD);
|
|
||||||
|
|
||||||
u.disableRefLog();
|
|
||||||
u.link(branch.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
RevCommit commit = parseCommit(branch);
|
|
||||||
RefUpdate u = repository.updateRef(Constants.HEAD);
|
|
||||||
|
|
||||||
u.setNewObjectId(commit);
|
|
||||||
u.forceUpdate();
|
|
||||||
|
|
||||||
DirCache dc = repository.lockDirCache();
|
|
||||||
DirCacheCheckout co = new DirCacheCheckout(repository, dc,
|
|
||||||
commit.getTree());
|
|
||||||
|
|
||||||
co.checkout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param result
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Ref guessHEAD(final FetchResult result)
|
|
||||||
{
|
|
||||||
final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
|
|
||||||
final List<Ref> availableRefs = new ArrayList<Ref>();
|
|
||||||
Ref head = null;
|
|
||||||
|
|
||||||
for (final Ref r : result.getAdvertisedRefs())
|
|
||||||
{
|
|
||||||
final String n = r.getName();
|
|
||||||
|
|
||||||
if (!n.startsWith(Constants.R_HEADS))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
availableRefs.add(r);
|
|
||||||
|
|
||||||
if ((idHEAD == null) || (head != null))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r.getObjectId().equals(idHEAD.getObjectId()))
|
|
||||||
{
|
|
||||||
head = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(availableRefs, RefComparator.INSTANCE);
|
|
||||||
|
|
||||||
if ((idHEAD != null) && (head == null))
|
|
||||||
{
|
|
||||||
head = idHEAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
return head;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param branch
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* @throws IncorrectObjectTypeException
|
|
||||||
* @throws MissingObjectException
|
|
||||||
*/
|
|
||||||
private RevCommit parseCommit(Ref branch)
|
|
||||||
throws MissingObjectException, IncorrectObjectTypeException, IOException
|
|
||||||
{
|
|
||||||
try (RevWalk rw = new RevWalk(repository))
|
|
||||||
{
|
|
||||||
return rw.parseCommit(branch.getObjectId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws NotSupportedException
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
* @throws TransportException
|
|
||||||
* @throws URISyntaxException
|
|
||||||
*/
|
|
||||||
private FetchResult runFetch()
|
|
||||||
throws NotSupportedException, URISyntaxException, TransportException,
|
|
||||||
RepositoryClientException
|
|
||||||
{
|
|
||||||
FetchResult r = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Transport tn = Transport.open(repository, "origin");
|
|
||||||
|
|
||||||
if (credentialsProvider != null)
|
|
||||||
{
|
|
||||||
tn.setCredentialsProvider(credentialsProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<RefSpec> refSpecs = new ArrayList<RefSpec>();
|
|
||||||
RefSpec rs = new RefSpec("+refs/heads/master:refs/heads/master");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
r = tn.fetch(new TextProgressMonitor(), refSpecs);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
tn.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (NoRemoteRepositoryException ex)
|
|
||||||
{
|
|
||||||
|
|
||||||
// empty repository, call init
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private CredentialsProvider credentialsProvider;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private RemoteConfig remoteConfig;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private FileRepository repository;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private URIish uri;
|
|
||||||
}
|
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import sonia.scm.io.SimpleCommand;
|
|
||||||
import sonia.scm.io.SimpleCommandResult;
|
|
||||||
import sonia.scm.util.IOUtil;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class HgRepositoryClient extends AbstractRepositoryClient
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*/
|
|
||||||
HgRepositoryClient(File localRepository, String remoteRepository,
|
|
||||||
String username, String password)
|
|
||||||
{
|
|
||||||
super(localRepository, remoteRepository);
|
|
||||||
|
|
||||||
if ((username != null) && (password != null))
|
|
||||||
{
|
|
||||||
String scheme = remoteRepository.substring(0,
|
|
||||||
remoteRepository.indexOf("://") + 3);
|
|
||||||
StringBuilder buffer = new StringBuilder(scheme);
|
|
||||||
|
|
||||||
buffer.append(username).append(":").append(password).append("@");
|
|
||||||
buffer.append(remoteRepository.substring(scheme.length()));
|
|
||||||
remoteURL = buffer.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
remoteURL = remoteRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
hg = IOUtil.search("hg");
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @param others
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void add(String file, String... others)
|
|
||||||
throws RepositoryClientException
|
|
||||||
{
|
|
||||||
addFile(file);
|
|
||||||
|
|
||||||
if (others != null)
|
|
||||||
{
|
|
||||||
for (String o : others)
|
|
||||||
{
|
|
||||||
addFile(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void checkout() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
if (!isInitialized())
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleCommand cmd = new SimpleCommand(hg, "-R",
|
|
||||||
localRepository.getAbsolutePath(), "pull", "-u",
|
|
||||||
remoteURL);
|
|
||||||
|
|
||||||
execute(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void commit(String message) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
SimpleCommand cmd = null;
|
|
||||||
|
|
||||||
if (pendingCommit)
|
|
||||||
{
|
|
||||||
cmd = new SimpleCommand(hg, "-R", localRepository.getAbsolutePath(),
|
|
||||||
"commit", "-m", message);
|
|
||||||
execute(cmd);
|
|
||||||
pendingCommit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = new SimpleCommand(hg, "-R", localRepository.getAbsolutePath(),
|
|
||||||
"push", remoteURL);
|
|
||||||
execute(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
SimpleCommand cmd = new SimpleCommand(hg, "init",
|
|
||||||
localRepository.getAbsolutePath());
|
|
||||||
|
|
||||||
execute(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
private void addFile(String file) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
SimpleCommand cmd = new SimpleCommand(hg, "-R",
|
|
||||||
localRepository.getAbsolutePath(), "add",
|
|
||||||
new File(localRepository, file).getAbsolutePath());
|
|
||||||
|
|
||||||
execute(cmd);
|
|
||||||
pendingCommit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param cmd
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
private void execute(SimpleCommand cmd) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SimpleCommandResult result = cmd.execute();
|
|
||||||
|
|
||||||
if (!result.isSuccessfull())
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(result.getOutput());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean isInitialized()
|
|
||||||
{
|
|
||||||
return new File(localRepository, ".hg").exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String hg;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private boolean pendingCommit = false;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private String remoteURL;
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated use {@link sonia.scm.repository.client.api.RepositoryClient}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface RepositoryClient
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @param others
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public void add(String file, String... others)
|
|
||||||
throws RepositoryClientException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public void checkout() throws RepositoryClientException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public void commit(String message) throws RepositoryClientException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public void init() throws RepositoryClientException;
|
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public File getLocalRepository();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getRemoteRepository();
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class RepositoryClientException extends Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private static final long serialVersionUID = -6017272751596608450L;
|
|
||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public RepositoryClientException() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public RepositoryClientException(String message)
|
|
||||||
{
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param throwable
|
|
||||||
*/
|
|
||||||
public RepositoryClientException(Throwable throwable)
|
|
||||||
{
|
|
||||||
super(throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
* @param throwable
|
|
||||||
*/
|
|
||||||
public RepositoryClientException(String message, Throwable throwable)
|
|
||||||
{
|
|
||||||
super(message, throwable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
* @deprecated use {@link sonia.scm.repository.client.api.RepositoryClientFactory}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public final class RepositoryClientFactory
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private RepositoryClientFactory() {}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public static RepositoryClient createClient(String type,
|
|
||||||
File localRepository, String remoteRepository)
|
|
||||||
throws RepositoryClientException
|
|
||||||
{
|
|
||||||
return createClient(type, localRepository, remoteRepository, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
public static RepositoryClient createClient(String type,
|
|
||||||
File localRepository, String remoteRepository, String username,
|
|
||||||
String password)
|
|
||||||
throws RepositoryClientException
|
|
||||||
{
|
|
||||||
RepositoryClient client = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if ("git".equals(type))
|
|
||||||
{
|
|
||||||
client = new GitRepositoryClient(localRepository, remoteRepository,
|
|
||||||
username, password);
|
|
||||||
}
|
|
||||||
else if ("svn".equals(type))
|
|
||||||
{
|
|
||||||
client = new SvnRepositoryClient(localRepository, remoteRepository,
|
|
||||||
username, password);
|
|
||||||
}
|
|
||||||
else if ("hg".equals(type))
|
|
||||||
{
|
|
||||||
client = new HgRepositoryClient(localRepository, remoteRepository,
|
|
||||||
username, password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,242 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2010, Sebastian Sdorra
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* http://bitbucket.org/sdorra/scm-manager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.repository.client;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
|
||||||
|
|
||||||
import org.tmatesoft.svn.core.SVNCommitInfo;
|
|
||||||
import org.tmatesoft.svn.core.SVNDepth;
|
|
||||||
import org.tmatesoft.svn.core.SVNErrorMessage;
|
|
||||||
import org.tmatesoft.svn.core.SVNException;
|
|
||||||
import org.tmatesoft.svn.core.SVNURL;
|
|
||||||
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
|
|
||||||
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
|
|
||||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
|
||||||
import org.tmatesoft.svn.core.wc.SVNCommitClient;
|
|
||||||
import org.tmatesoft.svn.core.wc.SVNRevision;
|
|
||||||
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
|
|
||||||
import org.tmatesoft.svn.core.wc.SVNWCClient;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.tmatesoft.svn.core.internal.util.SVNURLUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SvnRepositoryClient extends AbstractRepositoryClient
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs ...
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param localRepository
|
|
||||||
* @param remoteRepository
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
*
|
|
||||||
* @throws SVNException
|
|
||||||
*/
|
|
||||||
SvnRepositoryClient(File localRepository, String remoteRepository,
|
|
||||||
String username, String password)
|
|
||||||
throws SVNException
|
|
||||||
{
|
|
||||||
super(localRepository, remoteRepository);
|
|
||||||
|
|
||||||
DefaultSVNOptions options = new DefaultSVNOptions();
|
|
||||||
|
|
||||||
options.setAuthStorageEnabled(false);
|
|
||||||
options.setUseAutoProperties(false);
|
|
||||||
|
|
||||||
if ((username != null) && (password != null))
|
|
||||||
{
|
|
||||||
client = SVNClientManager.newInstance(options, username, password);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
client = SVNClientManager.newInstance(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteRepositoryURL = SVNURL.parseURIEncoded(remoteRepository);
|
|
||||||
DAVRepositoryFactory.setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @param others
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void add(String file, String... others)
|
|
||||||
throws RepositoryClientException
|
|
||||||
{
|
|
||||||
checkout();
|
|
||||||
|
|
||||||
List<File> files = new ArrayList<File>();
|
|
||||||
|
|
||||||
files.add(new File(localRepository, file));
|
|
||||||
|
|
||||||
if (others != null)
|
|
||||||
{
|
|
||||||
for (String f : others)
|
|
||||||
{
|
|
||||||
files.add(new File(localRepository, f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addFiles(files);
|
|
||||||
pendingFiles.addAll(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void checkout() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SVNUpdateClient updateClient = client.getUpdateClient();
|
|
||||||
|
|
||||||
updateClient.doCheckout(remoteRepositoryURL, localRepository,
|
|
||||||
SVNRevision.UNDEFINED, SVNRevision.HEAD,
|
|
||||||
SVNDepth.FILES, false);
|
|
||||||
}
|
|
||||||
catch (SVNException ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void commit(String message) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
checkout();
|
|
||||||
|
|
||||||
SVNCommitClient cc = client.getCommitClient();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SVNCommitInfo info = cc.doCommit(pendingFiles.toArray(new File[0]), true,
|
|
||||||
message, null, null, true, true,
|
|
||||||
SVNDepth.INFINITY);
|
|
||||||
SVNErrorMessage msg = info.getErrorMessage();
|
|
||||||
|
|
||||||
if (msg != null)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(msg.getFullMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingFiles.clear();
|
|
||||||
}
|
|
||||||
catch (SVNException ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void init() throws RepositoryClientException
|
|
||||||
{
|
|
||||||
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param files
|
|
||||||
*
|
|
||||||
* @throws RepositoryClientException
|
|
||||||
*/
|
|
||||||
private void addFiles(List<File> files) throws RepositoryClientException
|
|
||||||
{
|
|
||||||
SVNWCClient wClient = client.getWCClient();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
wClient.doAdd(files.toArray(new File[0]), true, false, false,
|
|
||||||
SVNDepth.INFINITY, false, false, false);
|
|
||||||
}
|
|
||||||
catch (SVNException ex)
|
|
||||||
{
|
|
||||||
throw new RepositoryClientException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
List<File> pendingFiles = new ArrayList<File>();
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private SVNClientManager client;
|
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private SVNURL remoteRepositoryURL;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user