merge with branch 1.x

This commit is contained in:
Sebastian Sdorra
2017-01-14 13:25:25 +01:00
22 changed files with 260 additions and 377 deletions

View File

@@ -35,8 +35,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -164,7 +162,7 @@ public class AbstractHgHandler
*/
protected Map<String, String> createEnvironment(String revision, String path)
{
Map<String, String> env = new HashMap<String, String>();
Map<String, String> env = new HashMap<>();
env.put(ENV_REVISION, HgUtil.getRevision(revision));
env.put(ENV_PATH, Util.nonNull(path));
@@ -300,29 +298,15 @@ public class AbstractHgHandler
throws IOException, RepositoryException
{
Process p = createScriptProcess(script, extraEnv);
T result = null;
InputStream input = null;
try
{
handleErrorStream(p.getErrorStream());
input = p.getInputStream();
result =
(T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
input.close();
}
catch (JAXBException ex)
{
handleErrorStream(p.getErrorStream());
try (InputStream input = p.getInputStream()) {
return (T) handler.getJaxbContext().createUnmarshaller().unmarshal(input);
} catch (JAXBException ex) {
logger.error("could not parse result", ex);
throw new RepositoryException("could not parse result", ex);
}
finally
{
Closeables.close(input, true);
}
return result;
}
//~--- methods --------------------------------------------------------------

View File

@@ -34,7 +34,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
import com.google.common.io.Resources;
import org.junit.Rule;
@@ -109,20 +108,13 @@ public class HgWindowsPackageFixTest
*/
private File createHgBat(String number) throws IOException
{
URL url =
Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
URL url = Resources.getResource("sonia/scm/repository/hg.bat.".concat(number));
File file = tempFolder.newFile(number);
FileOutputStream fos = null;
try
try (FileOutputStream fos = new FileOutputStream(file))
{
fos = new FileOutputStream(file);
Resources.copy(url, fos);
}
finally
{
Closeables.close(fos, true);
}
return file;
}

View File

@@ -31,7 +31,9 @@
package sonia.scm.repository.client.spi;
import com.aragost.javahg.Repository;
import com.aragost.javahg.commands.ExecutionException;
import java.io.IOException;
import sonia.scm.repository.client.api.RepositoryClientException;
/**
* Mercurial implementation of the {@link PushCommand}.
@@ -55,7 +57,11 @@ public class HgPushCommand implements PushCommand
{
com.aragost.javahg.commands.PushCommand cmd = com.aragost.javahg.commands.PushCommand.on(repository);
cmd.cmdAppend("--new-branch");
cmd.execute(url);
try {
cmd.execute(url);
} catch (ExecutionException ex) {
throw new RepositoryClientException("push to repository failed", ex);
}
}
}

View File

@@ -32,6 +32,7 @@ package sonia.scm.repository.client.spi;
import com.aragost.javahg.Repository;
import com.aragost.javahg.RepositoryConfiguration;
import com.aragost.javahg.commands.ExecutionException;
import com.aragost.javahg.commands.PullCommand;
import com.google.common.base.Strings;
import java.io.File;
@@ -40,6 +41,7 @@ import java.net.URL;
import sonia.scm.io.INIConfiguration;
import sonia.scm.io.INIConfigurationWriter;
import sonia.scm.io.INISection;
import sonia.scm.repository.client.api.RepositoryClientException;
import sonia.scm.util.IOUtil;
/**
@@ -53,19 +55,17 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
private static final String TYPE = "hg";
@Override
public RepositoryClientProvider create(File main, File workingCopy) throws IOException
{
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
{
throws IOException {
RepositoryConfiguration configuration = new RepositoryConfiguration();
String binary = IOUtil.search("hg");
if (Strings.isNullOrEmpty(binary)){
throw new IOException("could not find mercurial binary (hg)");
throw new RepositoryClientException("could not find mercurial binary (hg)");
}
configuration.setHgBin(binary);
@@ -77,13 +77,18 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
}
Repository repository = Repository.create(configuration, workingCopy);
PullCommand.on(repository).execute(url);
try {
PullCommand command = PullCommand.on(repository);
command.cmdAppend("-u");
command.execute(url);
} catch (ExecutionException ex) {
throw new RepositoryClientException("failed to pull from remote repository", ex);
}
return new HgRepositoryClientProvider(repository, hgrc, url);
}
private File createHgrc(String url, String username, String password) throws IOException
{
private File createHgrc(String url, String username, String password) throws IOException {
URL repositoryUrl = new URL(url);
INIConfiguration hgConfig = new INIConfiguration();
@@ -101,8 +106,7 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
);
authSection.setParameter(prefix + "schemes", repositoryUrl.getProtocol());
authSection.setParameter(prefix + "username", username);
if (!Strings.isNullOrEmpty(password))
{
if (!Strings.isNullOrEmpty(password)) {
authSection.setParameter(prefix + "password", password);
}
hgConfig.addSection(authSection);
@@ -114,8 +118,7 @@ public class HgRepositoryClientFactoryProvider implements RepositoryClientFactor
}
@Override
public String getType()
{
public String getType() {
return TYPE;
}

View File

@@ -103,6 +103,11 @@ public class HgRepositoryClientProvider extends RepositoryClientProvider
return new HgPushCommand(repository, url);
}
@Override
public File getWorkingCopy() {
return repository.getDirectory();
}
@Override
public void close() throws IOException
{