use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-git by JetBrains.
the class GitBuildParametersProvider method getParameters.
@NotNull
@Override
public Map<String, String> getParameters(@NotNull SBuild build, boolean emulationMode) {
Map<String, String> params = new HashMap<String, String>();
if (emulationMode)
return params;
for (BuildRevision revision : build.getRevisions()) {
RepositoryVersion repositoryVersion = revision.getRepositoryVersion();
VcsRootInstance root = revision.getRoot();
if (!Constants.VCS_NAME.equals(root.getVcsName()))
continue;
String vcsBranch = repositoryVersion.getVcsBranch();
if (vcsBranch != null)
params.put(GitUtils.getGitRootBranchParamName(root), vcsBranch);
}
return params;
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-git by JetBrains.
the class GitDiagnosticsTab method runTestConnectionForAllProjectRoots.
private void runTestConnectionForAllProjectRoots(@NotNull SProject project, @NotNull List<VcsRootInstance> vcsRootInstances, @NotNull Date timestamp) {
final String externalId = project.getExternalId();
boolean canceled = false;
try {
final Map<Integer, String> cachedResults = new HashMap<>();
final long start = System.currentTimeMillis();
int processed = 0;
int cacheHits = 0;
for (VcsRootInstance ri : vcsRootInstances) {
++processed;
if (!isGitRoot(ri) || ri.getUsages().isEmpty()) {
continue;
}
String error = null;
final Integer key = getKey(ri);
if (cachedResults.containsKey(key)) {
++cacheHits;
error = cachedResults.get(key);
// cached success
if (error == null)
continue;
} else {
boolean jGitSucceeded = true;
try {
IOGuard.allowNetworkAndCommandLine(() -> myVcsSupport.getRemoteRefs(ri, false));
} catch (VcsException e) {
jGitSucceeded = false;
cachedResults.put(key, null);
}
// if jgit fails, no need to check native git
if (jGitSucceeded) {
try {
IOGuard.allowNetworkAndCommandLine(() -> myVcsSupport.getRemoteRefs(ri, true));
cachedResults.put(key, null);
} catch (Throwable e) {
error = e.getMessage();
cachedResults.put(key, error);
}
}
}
final Lock lock = myLocks.get(externalId);
lock.lock();
try {
final VcsRootLink vcsRootLink = new VcsRootLink(ri.getParent());
final TestConnectionTask task = myTestConnectionsInProgress.get(externalId);
if (task == null) {
canceled = true;
break;
}
task.setRootsProcessed(processed);
if (error == null)
continue;
final List<TestConnectionError> rootErrors = task.getRootErrors(vcsRootLink);
rootErrors.add(new TestConnectionError(error, ri.getUsages().keySet().stream().map(bt -> new BuildTypeLink(bt)).collect(Collectors.toSet())));
} finally {
lock.unlock();
}
}
final long duration = System.currentTimeMillis() - start;
LOG.info("Native git TestConnection for " + LogUtil.describe(project) + (canceled ? " was canceled," : " finished") + " took " + TimeUnit.MILLISECONDS.toSeconds(duration) + "sec, cache size: " + cachedResults.size() + ", cache hits: " + cacheHits);
if (canceled)
return;
if (project.isRootProject()) {
FileUtil.delete(getTestConnectionResultsFolder());
final File storedFile = getStoredTestConnectionErrorsFile(timestamp);
deleteFile(storedFile);
FileUtil.createParentDirs(storedFile);
FileWriter writer = null;
try {
final Map<VcsRootLink, List<TestConnectionError>> errors;
final Lock lock = myLocks.get(externalId);
lock.lock();
try {
errors = myTestConnectionsInProgress.get(externalId).getErrors();
} finally {
lock.unlock();
}
writer = new FileWriter(storedFile);
GSON.toJson(errors, Map.class, writer);
} catch (Throwable e) {
LOG.warnAndDebugDetails("Exception while saving native git Test Connection results for " + LogUtil.describe(project) + " to " + storedFile, e);
deleteFile(storedFile);
} finally {
FileUtil.close(writer);
}
}
} finally {
final Lock lock = myLocks.get(externalId);
lock.lock();
try {
finishTask(externalId);
} finally {
lock.unlock();
}
}
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-git by JetBrains.
the class SpaceExternalChangeViewerExtension method getAvailableProperties.
@Nullable
@Override
public Map<String, String> getAvailableProperties(@NotNull VcsRoot vcs) {
final VcsRootInstance vcsRoot = (VcsRootInstance) vcs;
if (!Constants.VCS_NAME.equals(vcsRoot.getVcsName()))
return null;
String url = vcsRoot.getProperty(Constants.FETCH_URL);
if (url == null)
return null;
URIish uri;
try {
uri = new URIish(url);
} catch (URISyntaxException e) {
return null;
}
final String gitPath = uri.getPath();
if (uri.getHost().endsWith(".jetbrains.space")) {
// Space is on the Jetbrains side
final String[] strings = gitPath.substring(1).split("/");
if (strings.length == 3) {
final String orgName = strings[0];
final String project = strings[1];
final String repository = strings[2].replaceFirst("\\.git$", "");
final String repositoryUrl = String.format("https://%s.jetbrains.space/p/%s/repositories/%s", orgName, project, repository);
return createResponse(repositoryUrl);
}
} else {
final SVcsRoot vcsRootParent = vcsRoot.getParent();
final List<OAuthConnectionDescriptor> connections = myOAuthConnectionsManager.getAvailableConnectionsOfType(vcsRootParent.getProject(), SpaceOAuthProvider.TYPE);
if (connections.isEmpty())
return null;
for (OAuthConnectionDescriptor connection : connections) {
final SpaceConnectDescriber spaceConnectDescriber = new SpaceConnectDescriber(connection);
final String spaceAddress = spaceConnectDescriber.getAddress();
if (uri.getHost().contains(spaceAddress)) {
// Selfhosted Space
final String[] strings = gitPath.substring(1).split("/");
if (strings.length == 2) {
final String project = strings[0];
final String repository = strings[1].replaceFirst("\\.git$", "");
final String repositoryUrl = String.format("https://%s/p/%s/repositories/%s", spaceAddress, project, repository);
return createResponse(repositoryUrl);
}
}
}
}
return null;
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-git by JetBrains.
the class SGitVcsRoot method getOrRefreshToken.
@Nullable
protected ExpiringAccessToken getOrRefreshToken(@NotNull String tokenId) {
VcsRoot vcsRoot = getOriginalRoot();
if (myTokenRefresher == null)
return null;
SVcsRoot parentRoot = vcsRoot instanceof SVcsRoot ? (SVcsRoot) vcsRoot : vcsRoot instanceof VcsRootInstance ? ((VcsRootInstance) vcsRoot).getParent() : null;
if (parentRoot == null) {
return myTokenRefresher.getRefreshableToken(vcsRoot.getExternalId(), tokenId);
} else {
return myTokenRefresher.getRefreshableToken(parentRoot.getProject(), tokenId);
}
}
use of jetbrains.buildServer.vcs.VcsRootInstance in project teamcity-rest by JetBrains.
the class BuildTypeTest method testBranchesCaseDiff.
// TW-49294
@Test
public void testBranchesCaseDiff() throws ExecutionException, InterruptedException {
final BuildTypeEx bt = getRootProject().createProject("Project1", "Project test 1").createBuildType("testBT", "My test build type");
final BuildTypeRequest buildTypeRequest = new BuildTypeRequest();
buildTypeRequest.setInTests(myBuildTypeFinder, myBranchFinder, myBeanContext);
MockVcsSupport vcs = vcsSupport().withName("vcs").dagBased(true).register();
BuildFinderTestBase.MockCollectRepositoryChangesPolicy collectChangesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
vcs.setCollectChangesPolicy(collectChangesPolicy);
final SVcsRoot vcsRoot = bt.getProject().createVcsRoot("vcs", "extId", "name");
bt.addVcsRoot(vcsRoot);
final VcsRootInstance vcsRootInstance = bt.getVcsRootInstances().get(0);
collectChangesPolicy.setCurrentState(vcsRootInstance, createVersionState("master", map("master", "1", "aaa", "2", "bbb", "2", "Aaa", "3")));
setBranchSpec(vcsRootInstance, "+:*");
myFixture.getVcsModificationChecker().checkForModifications(bt.getVcsRootInstances(), OperationRequestor.UNKNOWN);
Branches branches = buildTypeRequest.serveBranches("id:testBT", "policy:ALL_BRANCHES", Fields.ALL_NESTED.getFieldsSpec());
assertEquals("<default>", branches.branches.get(0).getInternalName());
assertEquals("Aaa", branches.branches.get(1).getInternalName());
assertEquals("aaa", branches.branches.get(2).getInternalName());
assertEquals("bbb", branches.branches.get(3).getInternalName());
}
Aggregations