use of jetbrains.buildServer.util.Converter in project teamcity-rest by JetBrains.
the class ProblemFinder method getProblemsByBuilds.
@NotNull
private Set<ProblemWrapper> getProblemsByBuilds(@NotNull final String buildLocator) {
LinkedHashSet<ProblemWrapper> result = new LinkedHashSet<>();
List<BuildPromotion> builds = myBuildPromotionFinder.getItems(buildLocator).myEntries;
for (BuildPromotion build : builds) {
result.addAll(CollectionsUtil.convertCollection(ProblemOccurrenceFinder.getProblemOccurrences(build), new Converter<ProblemWrapper, BuildProblem>() {
@Override
public ProblemWrapper createFrom(@NotNull final BuildProblem buildProblem) {
return new ProblemWrapper(buildProblem.getId(), buildProblem.getBuildProblemData(), myServiceLocator);
}
}));
}
return result;
}
use of jetbrains.buildServer.util.Converter in project teamcity-rest by JetBrains.
the class Build method getBuildToTrigger.
private BuildPromotion getBuildToTrigger(@Nullable final SUser user, @NotNull final ServiceLocator serviceLocator, @NotNull final Map<Long, Long> buildPromotionIdReplacements) {
SVcsModification changeToUse = null;
SVcsModification personalChangeToUse = null;
if (submittedLastChanges != null) {
List<SVcsModification> lastChanges = submittedLastChanges.getChangesFromPosted(serviceLocator.getSingletonService(ChangeFinder.class));
if (lastChanges.size() > 0) {
boolean changeProcessed = false;
boolean personalChangeProcessed = false;
for (SVcsModification change : lastChanges) {
if (!change.isPersonal()) {
if (!changeProcessed) {
changeToUse = change;
changeProcessed = true;
} else {
throw new BadRequestException("Several non-personal changes are submitted, only one can be present");
}
} else {
if (!personalChangeProcessed) {
personalChangeToUse = change;
personalChangeProcessed = true;
} else {
throw new BadRequestException("Several personal changes are submitted, only one can be present");
}
}
}
}
}
final SBuildType submittedBuildType = getSubmittedBuildType(serviceLocator, personalChangeToUse, user);
final BuildCustomizer customizer = serviceLocator.getSingletonService(BuildCustomizerFactory.class).createBuildCustomizer(submittedBuildType, user);
if (changeToUse != null) {
// might need to rework after comparison to code in jetbrains.buildServer.controllers.RunBuildBean.setupBuildCustomizer: customizer.setNodeRevisions, etc.
customizer.setChangesUpTo(changeToUse);
}
if (submittedComment != null) {
if (submittedComment.text != null) {
customizer.setBuildComment(submittedComment.text);
} else {
throw new BadRequestException("Submitted comment does not have 'text' set.");
}
}
if (submittedProperties != null) {
customizer.setParameters(submittedProperties.getMap());
}
// this should ideally be used only when defaultBranc flag is not set. If set to false, should use customizer.setDesiredBranchName(submittedBranchName, false)
if (submittedBranchName != null)
customizer.setDesiredBranchName(submittedBranchName);
if (submittedPersonal != null)
customizer.setPersonal(submittedPersonal);
if (submittedBuildDependencies != null) {
try {
customizer.setSnapshotDependencyNodes(submittedBuildDependencies.getFromPosted(serviceLocator, buildPromotionIdReplacements));
} catch (IllegalArgumentException e) {
throw new BadRequestException("Error trying to use specified snapshot dependencies" + getRelatedBuildDescription() + ":" + e.getMessage());
} catch (NotFoundException e) {
throw new BadRequestException("Error searching for snapshot dependency" + getRelatedBuildDescription() + ": " + e.getMessage(), e);
}
}
if (submittedTriggeringOptions != null) {
if (submittedTriggeringOptions.cleanSources != null) {
customizer.setCleanSources(submittedTriggeringOptions.cleanSources);
}
if (submittedTriggeringOptions.cleanSourcesInAllDependencies != null) {
((BuildCustomizerEx) customizer).setApplyCleanSourcesToDependencies(submittedTriggeringOptions.cleanSourcesInAllDependencies);
}
if (submittedTriggeringOptions.freezeSettings != null) {
((BuildCustomizerEx) customizer).setFreezeSettings(submittedTriggeringOptions.freezeSettings);
}
if (submittedTriggeringOptions.tagDependencies != null) {
((BuildCustomizerEx) customizer).setApplyTagsToDependencies(submittedTriggeringOptions.tagDependencies);
}
if (submittedTriggeringOptions.rebuildAllDependencies != null) {
customizer.setRebuildDependencies(submittedTriggeringOptions.rebuildAllDependencies);
}
if (submittedTriggeringOptions.rebuildFailedOrIncompleteDependencies != null && submittedTriggeringOptions.rebuildFailedOrIncompleteDependencies) {
((BuildCustomizerEx) customizer).setRebuildDependencies(BuildCustomizerEx.RebuildDependenciesMode.FAILED_OR_INCOMPLETE);
}
if (submittedTriggeringOptions.rebuildDependencies != null) {
customizer.setRebuildDependencies(CollectionsUtil.convertCollection(submittedTriggeringOptions.rebuildDependencies.getFromPosted(serviceLocator.getSingletonService(BuildTypeFinder.class)), new Converter<String, BuildTypeOrTemplate>() {
public String createFrom(@NotNull final BuildTypeOrTemplate source) {
if (source.getBuildType() == null) {
// noinspection ConstantConditions
throw new BadRequestException("Template is specified instead of a build type. Template id: '" + source.getTemplate().getExternalId() + "'");
}
return source.getBuildType().getInternalId();
}
}));
}
}
List<BuildPromotion> artifactDepsBuildsPosted = null;
try {
artifactDepsBuildsPosted = submittedBuildArtifactDependencies == null ? null : submittedBuildArtifactDependencies.getFromPosted(serviceLocator, buildPromotionIdReplacements);
} catch (NotFoundException e) {
throw new BadRequestException("Error searching for artifact dependency" + getRelatedBuildDescription() + ": " + e.getMessage(), e);
}
if (submittedCustomBuildArtifactDependencies != null) {
// todo: investigate if OK: here new dependencies are created and set into the build. Custom run build dialog onthe contrary, sets artifact deps with the same IDs into the build
final List<SArtifactDependency> customDeps = submittedCustomBuildArtifactDependencies.getFromPosted(submittedBuildType.getArtifactDependencies(), serviceLocator);
if (artifactDepsBuildsPosted == null) {
setDepsWithNullCheck(customizer, customDeps);
} else {
// patch with "artifact-dependencies"
setDepsWithNullCheck(customizer, getBuildPatchedDeps(customDeps, true, serviceLocator, artifactDepsBuildsPosted));
}
} else {
if (artifactDepsBuildsPosted != null) {
// use "artifact-dependencies" as the only dependencies as this allows to repeat a build
setDepsWithNullCheck(customizer, getBuildPatchedDeps(submittedBuildType.getArtifactDependencies(), false, serviceLocator, artifactDepsBuildsPosted));
} else {
// no artifact dependencies customizations necessary
}
}
if (submittedTags != null) {
customizer.setTagDatas(new HashSet<TagData>(submittedTags.getFromPosted(serviceLocator.getSingletonService(UserFinder.class))));
}
if (submittedAttributes != null) {
customizer.setAttributes(submittedAttributes.getMap());
}
final BuildPromotion result;
try {
result = customizer.createPromotion();
} catch (IllegalStateException e) {
// IllegalStateException is thrown e.g. when we try to create a personal build in a build type which does not allow this
throw new BadRequestException("Cannot trigger build: " + e.getMessage());
} catch (RevisionsNotFoundException e) {
throw new BadRequestException("Cannot trigger build, if the changes are specified, they should be visible on the build configuration Change Log under the requested branch. Original error: " + e.getMessage());
}
BuildTypeEx modifiedBuildType = getCustomizedSubmittedBuildType(serviceLocator);
if (modifiedBuildType != null) {
// it's core's responsibility to check permissions here
try {
((BuildPromotionEx) result).freezeSettings(modifiedBuildType, "rest");
} catch (IOException e) {
// include nested erorr or it can expose too much data?
throw new OperationException("Error while freezing promotion settings", e);
}
}
return result;
}
use of jetbrains.buildServer.util.Converter in project teamcity-rest by JetBrains.
the class ProjectFinderTest method testProjectBean.
@Test
public void testProjectBean() throws Exception {
final SProject project10 = createProject("p1", "project 1");
final SProject project20 = createProject("p2", "project 2");
final SProject project10_10 = project10.createProject("p10_10", "p1_child1");
final SProject project10_20 = project10.createProject("p10_20", "xxx");
final SProject project10_10_10 = project10_10.createProject("p10_10_10", "xxx");
final SProject project30 = createProject(project10.getProjectId(), "p3");
Project project = new Project(project10, new Fields("projects($long)"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_10.getExternalId(), project10_20.getExternalId());
project = new Project(project10, new Fields("projects($long,$locator(name:xxx))"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_20.getExternalId());
project = new Project(project10, new Fields("projects($long,$locator(project:$any,affectedProject:(" + project10.getExternalId() + ")))"), getBeanContext(myServer));
assertNotNull(project.projects.projects);
checkOrderedCollection(CollectionsUtil.convertCollection(project.projects.projects, new Converter<String, Project>() {
public String createFrom(@NotNull final Project source) {
return source.id;
}
}), project10_10.getExternalId(), project10_20.getExternalId(), project10_10_10.getExternalId());
ProjectFeatureDescriptorFactory featureDescriptorFactory = myFixture.findSingletonService(ProjectFeatureDescriptorFactory.class);
assert featureDescriptorFactory != null;
project10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId10", "type10", asMap("a", "b", "c", "d"), project10.getProjectId()));
project10_10.addFeature(featureDescriptorFactory.createProjectFeature("uniqueId20", "type20", asMap("a", "b", "c", "d"), project10_10.getProjectId()));
project = new Project(project10_10, new Fields("$long"), getBeanContext(myServer));
assertEquals(project.id, project10_10.getExternalId());
assertNotNull(project.projectFeatures);
assertEquals(Integer.valueOf(1), project.projectFeatures.count);
List<PropEntityProjectFeature> propEntities = project.projectFeatures.propEntities;
assertEquals(1, propEntities.size());
PropEntityProjectFeature feature = propEntities.get(0);
assertEquals("uniqueId20", feature.id);
assertEquals("type20", feature.type);
assertEquals(Integer.valueOf(2), feature.properties.count);
assertEquals("a", feature.properties.properties.get(0).name);
assertEquals("b", feature.properties.properties.get(0).value);
assertEquals("c", feature.properties.properties.get(1).name);
assertEquals("d", feature.properties.properties.get(1).value);
}
Aggregations