Search in sources :

Example 1 with LineAwareByteArrayOutputStream

use of jetbrains.buildServer.LineAwareByteArrayOutputStream in project teamcity-git by JetBrains.

the class GitPatchBuilderDispatcher method buildPatchInSeparateProcess.

private void buildPatchInSeparateProcess() throws Exception {
    final String rootStr = LogUtil.describe(myGitRoot);
    final ProcessXmxProvider xmxProvider = new ProcessXmxProvider(new RepositoryXmxStorage(myContext.getRepository(), "patch"), myConfig, "patch", "(root: " + rootStr + ")");
    Integer xmx = xmxProvider.getNextXmx();
    while (xmx != null) {
        final GeneralCommandLine patchCmd = createPatchCommandLine(xmx);
        final File patchFile = FileUtil.createTempFile("git", "patch");
        final File internalProperties = getPatchPropertiesFile();
        try {
            final ByteArrayOutputStream stdout = new LineAwareByteArrayOutputStream(Charset.forName("UTF-8"), new NoOpLineListener(), false);
            final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
            final GitProcessExecutor.GitExecResult gitResult = new GitProcessExecutor(patchCmd).runProcess(getInput(patchFile, internalProperties), myConfig.getPatchProcessIdleTimeoutSeconds(), stdout, stderr, new GitProcessExecutor.ProcessExecutorAdapter());
            VcsException patchError = CommandLineUtil.getCommandLineError("build patch", gitResult.getExecResult());
            if (patchError != null) {
                if (gitResult.isOutOfMemoryError()) {
                    final Integer nextXmx = xmxProvider.getNextXmx();
                    if (nextXmx != null) {
                        xmx = nextXmx;
                        FileUtil.delete(patchFile);
                        continue;
                    }
                    throw new VcsException("There is not enough memory for git patch (last attempted -Xmx" + xmx + "M). Please contact your system administrator", patchError);
                } else if (gitResult.isTimeout()) {
                    throw new VcsException("git patch for root " + rootStr + " was idle for more than " + myConfig.getFetchTimeout() + " second(s), try increasing the timeout using the " + PluginConfigImpl.TEAMCITY_GIT_IDLE_TIMEOUT_SECONDS + " property", patchError);
                }
                throw patchError;
            }
            new LowLevelPatcher(new FileInputStream(patchFile)).applyPatch(new NoExitLowLevelPatchTranslator(((PatchBuilderEx) myBuilder).getLowLevelBuilder()));
            break;
        } finally {
            FileUtil.delete(patchFile);
            FileUtil.delete(internalProperties);
        }
    }
}
Also used : RepositoryXmxStorage(jetbrains.buildServer.buildTriggers.vcs.git.process.RepositoryXmxStorage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LineAwareByteArrayOutputStream(jetbrains.buildServer.LineAwareByteArrayOutputStream) FileInputStream(java.io.FileInputStream) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) LineAwareByteArrayOutputStream(jetbrains.buildServer.LineAwareByteArrayOutputStream) VcsException(jetbrains.buildServer.vcs.VcsException) GitProcessExecutor(jetbrains.buildServer.buildTriggers.vcs.git.process.GitProcessExecutor) File(java.io.File)

Example 2 with LineAwareByteArrayOutputStream

use of jetbrains.buildServer.LineAwareByteArrayOutputStream in project teamcity-git by JetBrains.

the class GitCommandLine method createStderrBuffer.

@NotNull
public ByteArrayOutputStream createStderrBuffer() {
    LineAwareByteArrayOutputStream buffer = new LineAwareByteArrayOutputStream(Charset.forName("UTF-8"), new GitProgressListener(myLogger));
    buffer.setCREndsLine(true);
    return buffer;
}
Also used : GitProgressListener(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitProgressListener) LineAwareByteArrayOutputStream(jetbrains.buildServer.LineAwareByteArrayOutputStream) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LineAwareByteArrayOutputStream (jetbrains.buildServer.LineAwareByteArrayOutputStream)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 GitProgressListener (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitProgressListener)1 GitProcessExecutor (jetbrains.buildServer.buildTriggers.vcs.git.process.GitProcessExecutor)1 RepositoryXmxStorage (jetbrains.buildServer.buildTriggers.vcs.git.process.RepositoryXmxStorage)1 VcsException (jetbrains.buildServer.vcs.VcsException)1 NotNull (org.jetbrains.annotations.NotNull)1