Search in sources :

Example 1 with ResetCacheHandler

use of jetbrains.buildServer.util.cache.ResetCacheHandler in project teamcity-git by JetBrains.

the class GitSupportBuilder method build.

@NotNull
public GitVcsSupport build() {
    if (myPluginConfigBuilder == null && myServerPaths == null && myPluginConfig == null)
        throw new IllegalStateException("Plugin config or server paths should be set");
    if (myPluginConfig == null)
        myPluginConfig = myPluginConfigBuilder != null ? myPluginConfigBuilder.build() : new PluginConfigImpl(myServerPaths);
    if (myTransportFactory == null)
        myTransportFactory = new TransportFactoryImpl(myPluginConfig, myVcsRootSSHKeyManager);
    Mockery context = new Mockery();
    if (myFetchCommand == null) {
        if (myBeforeFetchHook == null) {
            myFetchCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
        } else {
            final FetchCommand originalCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
            myFetchCommand = (db, fetchURI, settings) -> {
                myBeforeFetchHook.run();
                originalCommand.fetch(db, fetchURI, settings);
            };
        }
    }
    MirrorManager mirrorManager = new MirrorManagerImpl(myPluginConfig, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    myRepositoryManager = new RepositoryManagerImpl(myPluginConfig, mirrorManager);
    final ResetCacheRegister resetCacheManager;
    if (myResetCacheManager == null) {
        context.setImposteriser(ClassImposteriser.INSTANCE);
        resetCacheManager = context.mock(ResetCacheRegister.class);
        context.checking(new Expectations() {

            {
                allowing(resetCacheManager).registerHandler(with(any(ResetCacheHandler.class)));
            }
        });
    } else {
        resetCacheManager = myResetCacheManager;
    }
    RevisionsCache revisionsCache = new RevisionsCache(myPluginConfig);
    myMapFullPath = new GitMapFullPath(myPluginConfig, revisionsCache);
    final GitRepoOperationsImpl gitRepoOperations = new GitRepoOperationsImpl(myPluginConfig, myTransportFactory, myVcsRootSSHKeyManager, myFetchCommand);
    myCommitLoader = new CommitLoaderImpl(myRepositoryManager, gitRepoOperations, myMapFullPath, myPluginConfig);
    GitResetCacheHandler resetCacheHandler = new GitResetCacheHandler(myRepositoryManager, new GcErrors());
    ResetRevisionsCacheHandler resetRevisionsCacheHandler = new ResetRevisionsCacheHandler(revisionsCache);
    TokenRefresher tokenRefresher = new TokenRefresher() {

        @Nullable
        @Override
        public OAuthToken getRefreshableToken(@NotNull String vcsRootExtId, @NotNull String tokenFullId) {
            return null;
        }

        @Nullable
        @Override
        public OAuthToken getRefreshableToken(@NotNull SProject project, @NotNull String tokenFullId) {
            return null;
        }
    };
    GitVcsSupport git = new GitVcsSupport(gitRepoOperations, myPluginConfig, resetCacheManager, myTransportFactory, myRepositoryManager, myMapFullPath, myCommitLoader, myVcsRootSSHKeyManager, new MockVcsOperationProgressProvider(), resetCacheHandler, resetRevisionsCacheHandler, tokenRefresher, myTestConnectionSupport);
    git.addExtensions(myExtensions);
    git.setExtensionHolder(myExtensionHolder);
    return git;
}
Also used : TokenRefresher(jetbrains.buildServer.serverSide.oauth.TokenRefresher) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) SProject(jetbrains.buildServer.serverSide.SProject) Mockery(org.jmock.Mockery) NotNull(org.jetbrains.annotations.NotNull) Expectations(org.jmock.Expectations) MockVcsOperationProgressProvider(jetbrains.buildServer.vcs.MockVcsOperationProgressProvider) ResetCacheHandler(jetbrains.buildServer.util.cache.ResetCacheHandler) ResetCacheRegister(jetbrains.buildServer.util.cache.ResetCacheRegister) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResetCacheHandler

use of jetbrains.buildServer.util.cache.ResetCacheHandler in project teamcity-git by JetBrains.

the class CollectChangesTest method collect_changes_after_cache_reset.

public void collect_changes_after_cache_reset() throws Exception {
    GitVcsSupport git = git();
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).build();
    git.collectChanges(root, "2c7e90053e0f7a5dd25ea2a16ef8909ba71826f6", "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", CheckoutRules.DEFAULT);
    ServerPluginConfig config = myConfig.build();
    MirrorManager mirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    RepositoryManager repositoryManager = new RepositoryManagerImpl(config, mirrorManager);
    ResetCacheHandler resetHandler = new GitResetCacheHandler(repositoryManager, new GcErrors());
    for (String cache : resetHandler.listCaches()) resetHandler.resetCache(cache);
    try {
        git.collectChanges(root, "2c7e90053e0f7a5dd25ea2a16ef8909ba71826f6", "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", CheckoutRules.DEFAULT);
    } catch (VcsException e) {
        fail("Reset of caches breaks repository");
    }
}
Also used : ResetCacheHandler(jetbrains.buildServer.util.cache.ResetCacheHandler)

Aggregations

ResetCacheHandler (jetbrains.buildServer.util.cache.ResetCacheHandler)2 GitRepoOperationsImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl)1 SProject (jetbrains.buildServer.serverSide.SProject)1 TokenRefresher (jetbrains.buildServer.serverSide.oauth.TokenRefresher)1 ResetCacheRegister (jetbrains.buildServer.util.cache.ResetCacheRegister)1 MockVcsOperationProgressProvider (jetbrains.buildServer.vcs.MockVcsOperationProgressProvider)1 NotNull (org.jetbrains.annotations.NotNull)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1