use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class BuildTypeRequest method updateVcsRootEntry.
@PUT
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Update a VCS root of the matching build configuration.", nickname = "updateBuildTypeVcsRoot")
public VcsRootEntry updateVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, VcsRootEntry entry, @QueryParam("fields") String fields) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
final SVcsRoot resultVcsRoot = entry.replaceIn(buildType.get(), vcsRoot, myVcsRootFinder);
buildType.persist("VCS root replaced");
return new VcsRootEntry(resultVcsRoot, buildType, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class VcsRootRequest method deleteAllProperties.
@DELETE
@Path("/{vcsRootLocator}/properties")
@ApiOperation(value = "Delete all properties of the matching VCS root.", nickname = "deleteAllVcsRootProperties")
public void deleteAllProperties(@ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
vcsRoot.setProperties(new HashMap<String, String>());
vcsRoot.schedulePersisting("All VCS root properties removed");
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class BuildTypeRequest method deleteVcsRootEntry.
@DELETE
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@ApiOperation(value = "Remove a VCS root of the matching build configuration.", nickname = "deleteVcsRoot")
public void deleteVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
// todo: extract builType/VCS root id retrieving logic into single method
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
// this assumes VCS root id are unique throughout the server
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
}
buildType.get().removeVcsRoot(vcsRoot);
buildType.persist("VCS root detached");
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class BuildTypeRequest method getVcsRootEntry.
@GET
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}")
@Produces({ "application/xml", "application/json" })
@ApiOperation(value = "Get a VCS root of the matching build configuration.", nickname = "getVcsRoot")
public VcsRootEntry getVcsRootEntry(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator, @QueryParam("fields") String fields) {
final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
}
return new VcsRootEntry(vcsRoot, buildType, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-rest by JetBrains.
the class ProjectFinder method findSingleItem.
@Nullable
@Override
public SProject findSingleItem(@NotNull final Locator locator) {
if (locator.isSingleValue()) {
// no dimensions found, assume it's a name or internal id or external id
SProject project = null;
@SuppressWarnings("ConstantConditions") @NotNull final String singleValue = locator.getSingleValue();
project = myProjectManager.findProjectByExternalId(singleValue);
if (project != null) {
return project;
}
final List<SProject> projectsByName = findProjectsByName(null, singleValue, true);
if (projectsByName.size() == 1) {
return projectsByName.get(0);
}
project = myProjectManager.findProjectById(singleValue);
if (project != null) {
return project;
}
throw new NotFoundException("No project found by name or internal/external id '" + singleValue + "'.");
}
String id = locator.getSingleDimensionValue(DIMENSION_ID);
if (id != null) {
SProject project = myProjectManager.findProjectByExternalId(id);
if (project == null) {
if (TeamCityProperties.getBoolean(APIController.REST_COMPATIBILITY_ALLOW_EXTERNAL_ID_AS_INTERNAL)) {
project = myProjectManager.findProjectById(id);
if (project == null) {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "' in compatibility mode. Project cannot be found by external or internal id '" + id + "'.");
}
} else {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by external id '" + id + "'.");
}
}
return project;
}
String internalId = locator.getSingleDimensionValue(DIMENSION_INTERNAL_ID);
if (internalId != null) {
SProject project = myProjectManager.findProjectById(internalId);
if (project == null) {
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by internal id '" + internalId + "'.");
}
return project;
}
String uuid = locator.getSingleDimensionValue(DIMENSION_UUID);
if (!StringUtil.isEmpty(uuid)) {
SProject project = myProjectManager.findProjectByConfigId(uuid);
if (project == null) {
// protecting against brute force uuid guessing
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
throw new NotFoundException("No project found by locator '" + locator.getStringRepresentation() + "'. Project cannot be found by uuid '" + uuid + "'.");
}
return project;
}
String buildLocator = locator.getSingleDimensionValue(BUILD);
if (!StringUtil.isEmpty(buildLocator)) {
BuildPromotion build = myServiceLocator.getSingletonService(BuildPromotionFinder.class).getItem(buildLocator);
SBuildType buildType = build.getBuildType();
if (buildType != null) {
return buildType.getProject();
}
}
String buildTypeLocator = locator.getSingleDimensionValue(BUILD_TYPE);
if (!StringUtil.isEmpty(buildTypeLocator)) {
BuildTypeOrTemplate buildType = myServiceLocator.getSingletonService(BuildTypeFinder.class).getItem(buildTypeLocator);
return buildType.getProject();
}
String vcsRootLocator = locator.getSingleDimensionValue(VCS_ROOT);
if (!StringUtil.isEmpty(vcsRootLocator)) {
SVcsRoot vcsRoot = myServiceLocator.getSingletonService(VcsRootFinder.class).getItem(vcsRootLocator);
return vcsRoot.getProject();
}
return null;
}
Aggregations