diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgAddCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgAddCommand.java new file mode 100644 index 0000000000..aec21d87ad --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgAddCommand.java @@ -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); + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgBranchCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgBranchCommand.java new file mode 100644 index 0000000000..74d1b1f742 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgBranchCommand.java @@ -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()); + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgCommitCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgCommitCommand.java new file mode 100644 index 0000000000..aa611a8ba4 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgCommitCommand.java @@ -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; + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgPushCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgPushCommand.java new file mode 100644 index 0000000000..47144dad35 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgPushCommand.java @@ -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); + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRemoveCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRemoveCommand.java new file mode 100644 index 0000000000..88d6ef04a8 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRemoveCommand.java @@ -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); + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientFactoryProvider.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientFactoryProvider.java new file mode 100644 index 0000000000..ad83abc97b --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientFactoryProvider.java @@ -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; + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientProvider.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientProvider.java new file mode 100644 index 0000000000..353e6a5b46 --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgRepositoryClientProvider.java @@ -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 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 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(); + } +} diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgTagCommand.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgTagCommand.java new file mode 100644 index 0000000000..3aa448bfca --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/client/spi/HgTagCommand.java @@ -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); + } + +} diff --git a/scm-plugins/scm-hg-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider b/scm-plugins/scm-hg-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider new file mode 100644 index 0000000000..ebb411a4fe --- /dev/null +++ b/scm-plugins/scm-hg-plugin/src/test/resources/META-INF/services/sonia.scm.repository.client.spi.RepositoryClientFactoryProvider @@ -0,0 +1 @@ +sonia.scm.repository.client.spi.HgRepositoryClientFactoryProvider \ No newline at end of file diff --git a/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java b/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java index 60bf5d4aa9..4c5b3ec951 100644 --- a/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java +++ b/scm-webapp/src/test/java/sonia/scm/it/RepositoryHookITCase.java @@ -57,6 +57,7 @@ import sonia.scm.repository.Repository; import sonia.scm.repository.RepositoryTestData; import sonia.scm.repository.client.api.RepositoryClient; import sonia.scm.repository.client.api.RepositoryClientFactory; +import sonia.scm.util.IOUtil; /** * Integration tests for repository hooks. @@ -198,10 +199,10 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase Collection params = Lists.newArrayList(); params.add(new String[] { "git" }); // params.add(new String[] { "svn" }); - // if (IOUtil.search("hg") != null) - // { - // params.add(new String[] { "hg" }); - // } + if (IOUtil.search("hg") != null) + { + params.add(new String[] { "hg" }); + } return params; }