use of jetbrains.buildServer.vcs.patches.PatchBuilderImpl in project teamcity-git by JetBrains.
the class GitPatchProcess method main.
public static void main(String... args) throws Exception {
Map<String, String> properties = VcsUtil.stringToProperties(GitServerUtil.readInput());
GitPatchProcessSettings settings = new GitPatchProcessSettings(properties);
GitServerUtil.configureInternalProperties(settings.getInternalProperties());
GitServerUtil.configureStreamFileThreshold(Integer.MAX_VALUE);
GitServerUtil.configureExternalProcessLogger(settings.isDebugEnabled());
GitServerUtil.setupMemoryMappedIndexReading();
JSchConfigInitializer.initJSchConfig(JSch.class);
PluginConfigImpl config = new PluginConfigImpl(new ConstantCachePaths(settings.getGitCachesDir()));
RepositoryManager repositoryManager = new RepositoryManagerImpl(config, new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl()));
GitMapFullPath mapFullPath = new GitMapFullPath(config, new RevisionsCache(config));
VcsRootSshKeyManager sshKeyManager = new ConstantSshKeyManager(settings.getKeyBytes());
TransportFactory transportFactory = new TransportFactoryImpl(config, sshKeyManager, settings.getGitTrustStoreProvider());
FetcherProperties fetcherProperties = new FetcherProperties(config);
FetchCommand fetchCommand = new FetchCommandImpl(config, transportFactory, fetcherProperties, sshKeyManager, settings.getGitTrustStoreProvider());
GitRepoOperations repoOperations = new GitRepoOperationsImpl(config, transportFactory, sshKeyManager, fetchCommand);
CommitLoader commitLoader = new CommitLoaderImpl(repositoryManager, repoOperations, mapFullPath, config);
OperationContext context = new OperationContext(commitLoader, repositoryManager, settings.getRoot(), "build patch", GitProgress.NO_OP, config, null);
OutputStream fos = new BufferedOutputStream(new FileOutputStream(settings.getPatchFile()));
try {
PatchBuilderImpl patchBuilder = new PatchBuilderImpl(fos);
new GitPatchBuilder(context, patchBuilder, settings.getFromRevision(), settings.getToRevision(), settings.getCheckoutRules(), settings.isVerboseTreeWalkLog(), new PrintFile(), transportFactory).buildPatch();
patchBuilder.close();
} catch (Throwable t) {
if (settings.isDebugEnabled() || isImportant(t)) {
System.err.println(t.getMessage());
t.printStackTrace(System.err);
} else {
String msg = t.getMessage();
boolean printStackTrace = false;
if (t instanceof SubmoduleFetchException) {
Throwable cause = t.getCause();
printStackTrace = cause != null && isImportant(cause);
}
System.err.println(msg);
if (printStackTrace)
t.printStackTrace(System.err);
}
System.exit(1);
} finally {
fos.close();
}
}
use of jetbrains.buildServer.vcs.patches.PatchBuilderImpl in project teamcity-git by JetBrains.
the class GitPatchTest method checkPatch.
private void checkPatch(@NotNull VcsRoot root, String name, @Nullable String fromVersion, @NotNull String toVersion, @NotNull CheckoutRules rules) throws IOException, VcsException {
setName(name);
GitVcsSupport support = getSupport();
ByteArrayOutputStream output = new ByteArrayOutputStream();
PatchBuilderImpl builder = new PatchBuilderImpl(output);
support.buildPatch(root, fromVersion, toVersion, builder, rules);
builder.close();
checkPatchResult(output.toByteArray());
}
use of jetbrains.buildServer.vcs.patches.PatchBuilderImpl in project teamcity-git by JetBrains.
the class MapFullPathTest method fetchAction.
@DataProvider
public Object[][] fetchAction() {
return new Object[][] { new Object[] { new FetchAction("collect changes") {
@Override
public void run() throws Exception {
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("9ef3a588831557040e81e4063ecf27d5442837f4");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
}
} }, new Object[] { new FetchAction("build patch") {
@Override
public void run() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PatchBuilderImpl builder = new PatchBuilderImpl(output);
myGit.buildPatch(myRoot, null, "add81050184d3c818560bdd8839f50024c188586", builder, CheckoutRules.DEFAULT);
}
} }, new Object[] { new FetchAction("get content") {
@Override
public void run() throws Exception {
myGit.getContentProvider().getContent("readme", myRoot, "add81050184d3c818560bdd8839f50024c188586");
}
} } };
}
use of jetbrains.buildServer.vcs.patches.PatchBuilderImpl in project teamcity-git by JetBrains.
the class GitPatchTest method build_patch_several_roots.
@Test(dataProvider = "patchInSeparateProcess")
public void build_patch_several_roots(boolean patchInSeparateProcess) throws Exception {
myConfigBuilder.setSeparateProcessForPatch(patchInSeparateProcess);
// A build configuration can have several VCS roots, TeamCity builds patches in them one by one
// in unspecified order and then combines them into a single patch. That means a patch for
// individual VCS root should never delete the root directory, because this action could delete
// sources of another VCS root. Also patches should not contain an 'EXIT' command, otherwise
// when agent applies a combined patch it will stop after first 'EXIT'.
// patch8 is combination of patch1 and patch6
setName("patch8");
// patch1
GitVcsSupport support = getSupport();
VcsRoot root1 = getRoot("patch-tests", false);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PatchBuilderImpl builder = new PatchBuilderImpl(output);
support.buildPatch(root1, null, "0dd03338d20d2e8068fbac9f24899d45d443df38", builder, CheckoutRules.DEFAULT);
// patch6
VcsRoot root2 = getRoot("rename-test", false);
// pass an unknown fromRevision 'a...a' to ensure we don't remove the root dir if the fromRevision is not found
support.buildPatch(root2, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "2eed4ae6732536f76a65136a606f635e8ada63b9", builder, CheckoutRules.DEFAULT);
builder.close();
checkPatchResult(output.toByteArray());
}
use of jetbrains.buildServer.vcs.patches.PatchBuilderImpl in project teamcity-git by JetBrains.
the class GitPatchTest method checkPatch.
private void checkPatch(String name, @NotNull String branchName, @Nullable String fromVersion, @NotNull String toVersion, boolean enableSubmodules) throws IOException, VcsException {
setName(name);
GitVcsSupport support = getSupport();
VcsRoot root = getRoot(branchName, enableSubmodules);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PatchBuilderImpl builder = new PatchBuilderImpl(output);
support.buildPatch(root, fromVersion, toVersion, builder, CheckoutRules.DEFAULT);
builder.close();
checkPatchResult(output.toByteArray());
}
Aggregations