mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
implement mercurial repository test client
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link AddCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public final class HgAddCommand implements AddCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
HgAddCommand(Repository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(String path) throws IOException
|
||||||
|
{
|
||||||
|
com.aragost.javahg.commands.AddCommand.on(repository).execute(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import java.io.IOException;
|
||||||
|
import sonia.scm.repository.Branch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link BranchCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgBranchCommand implements BranchCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
HgBranchCommand(Repository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Branch branch(String name) throws IOException
|
||||||
|
{
|
||||||
|
com.aragost.javahg.commands.BranchCommand.on(repository).set(name);
|
||||||
|
return new Branch(name, repository.tip().getNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import java.io.IOException;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.Modifications;
|
||||||
|
import sonia.scm.repository.Person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link CommitCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgCommitCommand implements CommitCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
HgCommitCommand(Repository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Changeset commit(CommitRequest request) throws IOException
|
||||||
|
{
|
||||||
|
com.aragost.javahg.Changeset c = com.aragost.javahg.commands.CommitCommand
|
||||||
|
.on(repository)
|
||||||
|
.user(request.getAuthor().toString())
|
||||||
|
.message(request.getMessage())
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
Changeset changeset = new Changeset(
|
||||||
|
c.getNode(),
|
||||||
|
c.getTimestamp().getDate().getTime(),
|
||||||
|
Person.toPerson(c.getUser()),
|
||||||
|
c.getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
changeset.setBranches(Lists.newArrayList(c.getBranch()));
|
||||||
|
changeset.setTags(c.tags());
|
||||||
|
changeset.setModifications(
|
||||||
|
new Modifications(c.getAddedFiles(), c.getModifiedFiles(), c.getDeletedFiles())
|
||||||
|
);
|
||||||
|
return changeset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link PushCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgPushCommand implements PushCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
private final String url;
|
||||||
|
|
||||||
|
HgPushCommand(Repository repository, String url)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void push() throws IOException
|
||||||
|
{
|
||||||
|
com.aragost.javahg.commands.PushCommand cmd = com.aragost.javahg.commands.PushCommand.on(repository);
|
||||||
|
cmd.cmdAppend("--new-branch");
|
||||||
|
cmd.execute(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link RemoveCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgRemoveCommand implements RemoveCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
HgRemoveCommand(Repository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(String path) throws IOException
|
||||||
|
{
|
||||||
|
com.aragost.javahg.commands.RemoveCommand.on(repository).execute(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import com.aragost.javahg.RepositoryConfiguration;
|
||||||
|
import com.aragost.javahg.commands.PullCommand;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import sonia.scm.io.INIConfiguration;
|
||||||
|
import sonia.scm.io.INIConfigurationWriter;
|
||||||
|
import sonia.scm.io.INISection;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link RepositoryClientFactoryProvider}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgRepositoryClientFactoryProvider implements RepositoryClientFactoryProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String TYPE = "hg";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepositoryClientProvider create(File main, File workingCopy) throws IOException
|
||||||
|
{
|
||||||
|
return create(main.toURI().toString(), null, null, workingCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RepositoryClientProvider create(String url, String username, String password, File workingCopy)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
RepositoryConfiguration configuration = new RepositoryConfiguration();
|
||||||
|
String binary = IOUtil.search("hg");
|
||||||
|
if (Strings.isNullOrEmpty(binary)){
|
||||||
|
throw new IOException("could not find mercurial binary (hg)");
|
||||||
|
}
|
||||||
|
configuration.setHgBin(binary);
|
||||||
|
|
||||||
|
File hgrc = null;
|
||||||
|
if (!Strings.isNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
hgrc = createHgrc(url, username, password);
|
||||||
|
configuration.setHgrcPath(hgrc.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
Repository repository = Repository.create(configuration, workingCopy);
|
||||||
|
PullCommand.on(repository).execute(url);
|
||||||
|
|
||||||
|
return new HgRepositoryClientProvider(repository, hgrc, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createHgrc(String url, String username, String password) throws IOException
|
||||||
|
{
|
||||||
|
URL repositoryUrl = new URL(url);
|
||||||
|
|
||||||
|
INIConfiguration hgConfig = new INIConfiguration();
|
||||||
|
|
||||||
|
INISection pathSection = new INISection("paths");
|
||||||
|
pathSection.setParameter(repositoryUrl.getHost(), url);
|
||||||
|
hgConfig.addSection(pathSection);
|
||||||
|
|
||||||
|
String prefix = repositoryUrl.getHost() + ".";
|
||||||
|
|
||||||
|
INISection authSection = new INISection("auth");
|
||||||
|
authSection.setParameter(
|
||||||
|
prefix + "prefix",
|
||||||
|
repositoryUrl.getHost() + ":" + repositoryUrl.getPort() + repositoryUrl.getPath()
|
||||||
|
);
|
||||||
|
authSection.setParameter(prefix + "schemes", repositoryUrl.getProtocol());
|
||||||
|
authSection.setParameter(prefix + "username", username);
|
||||||
|
if (!Strings.isNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
authSection.setParameter(prefix + "password", password);
|
||||||
|
}
|
||||||
|
hgConfig.addSection(authSection);
|
||||||
|
|
||||||
|
File hgrc = File.createTempFile("hgrc", ".temp");
|
||||||
|
INIConfigurationWriter writer = new INIConfigurationWriter();
|
||||||
|
writer.write(hgConfig, hgrc);
|
||||||
|
return hgrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
import sonia.scm.repository.client.api.ClientCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link RepositoryClientProvider}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgRepositoryClientProvider extends RepositoryClientProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final Set<ClientCommand> SUPPORTED_COMMANDS = ImmutableSet.of(
|
||||||
|
ClientCommand.ADD, ClientCommand.REMOVE, ClientCommand.COMMIT,
|
||||||
|
ClientCommand.TAG, ClientCommand.BANCH, ClientCommand.PUSH
|
||||||
|
);
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
private final File hgrc;
|
||||||
|
private final String url;
|
||||||
|
|
||||||
|
HgRepositoryClientProvider(Repository repository, File hgrc, String url)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
this.hgrc = hgrc;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<ClientCommand> getSupportedClientCommands()
|
||||||
|
{
|
||||||
|
return SUPPORTED_COMMANDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AddCommand getAddCommand()
|
||||||
|
{
|
||||||
|
return new HgAddCommand(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoveCommand getRemoveCommand()
|
||||||
|
{
|
||||||
|
return new HgRemoveCommand(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommitCommand getCommitCommand()
|
||||||
|
{
|
||||||
|
return new HgCommitCommand(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TagCommand getTagCommand()
|
||||||
|
{
|
||||||
|
return new HgTagCommand(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BranchCommand getBranchCommand()
|
||||||
|
{
|
||||||
|
return new HgBranchCommand(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PushCommand getPushCommand()
|
||||||
|
{
|
||||||
|
return new HgPushCommand(repository, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
if ( hgrc != null && hgrc.exists() && ! hgrc.delete() ){
|
||||||
|
throw new IOException("failed to remove hgrc file ".concat(hgrc.getPath()));
|
||||||
|
}
|
||||||
|
repository.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014, 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.spi;
|
||||||
|
|
||||||
|
import com.aragost.javahg.Repository;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import java.io.IOException;
|
||||||
|
import sonia.scm.repository.Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mercurial implementation of the {@link TagCommand}.
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
public class HgTagCommand implements TagCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
HgTagCommand(Repository repository)
|
||||||
|
{
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(TagRequest request) throws IOException
|
||||||
|
{
|
||||||
|
String rev = request.getRevision();
|
||||||
|
if ( Strings.isNullOrEmpty(rev) ){
|
||||||
|
rev = repository.tip().getNode();
|
||||||
|
}
|
||||||
|
com.aragost.javahg.commands.TagCommand.on(repository).rev(rev).execute(request.getName());
|
||||||
|
return new Tag(request.getName(), rev);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
sonia.scm.repository.client.spi.HgRepositoryClientFactoryProvider
|
||||||
@@ -57,6 +57,7 @@ import sonia.scm.repository.Repository;
|
|||||||
import sonia.scm.repository.RepositoryTestData;
|
import sonia.scm.repository.RepositoryTestData;
|
||||||
import sonia.scm.repository.client.api.RepositoryClient;
|
import sonia.scm.repository.client.api.RepositoryClient;
|
||||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||||
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for repository hooks.
|
* Integration tests for repository hooks.
|
||||||
@@ -198,10 +199,10 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
|
|||||||
Collection<String[]> params = Lists.newArrayList();
|
Collection<String[]> params = Lists.newArrayList();
|
||||||
params.add(new String[] { "git" });
|
params.add(new String[] { "git" });
|
||||||
// params.add(new String[] { "svn" });
|
// params.add(new String[] { "svn" });
|
||||||
// if (IOUtil.search("hg") != null)
|
if (IOUtil.search("hg") != null)
|
||||||
// {
|
{
|
||||||
// params.add(new String[] { "hg" });
|
params.add(new String[] { "hg" });
|
||||||
// }
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user