Search in sources :

Example 1 with SBuildRunnerDescriptor

use of jetbrains.buildServer.serverSide.SBuildRunnerDescriptor in project teamcity-powershell by JetBrains.

the class PowerShellRunnerDiscovererTest method testExcludeAlreadyUsedFiles.

@Test
public void testExcludeAlreadyUsedFiles() {
    final SBuildRunnerDescriptor definedRunner = m.mock(SBuildRunnerDescriptor.class, "already-defined-descriptor");
    final String scriptFileName = "file1.ps1";
    final Map<String, String> definedRunnerParams = new HashMap<String, String>() {

        {
            put(PowerShellConstants.RUNNER_SCRIPT_FILE, scriptFileName);
            put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
        }
    };
    final Element file1 = m.mock(Element.class, "file1.ps1");
    final String file2Name = "file2.ps1";
    final Element file2 = m.mock(Element.class, file2Name);
    m.checking(new Expectations() {

        {
            oneOf(myBrowser).getRoot();
            will(returnValue(myRootElement));
            oneOf(myRootElement).getChildren();
            will(returnValue(Arrays.asList(file1, file2)));
            atLeast(1).of(file1).isLeaf();
            will(returnValue(true));
            atLeast(1).of(file2).isLeaf();
            will(returnValue(true));
            atLeast(1).of(file1).getName();
            will(returnValue(scriptFileName));
            atLeast(1).of(file2).getName();
            will(returnValue(file2Name));
            atLeast(1).of(file1).getFullName();
            will(returnValue(scriptFileName));
            atLeast(1).of(file2).getFullName();
            will(returnValue(file2Name));
            atLeast(1).of(myBuildTypeSettings).getBuildRunners();
            will(returnValue(Collections.singletonList(definedRunner)));
            oneOf(definedRunner).getType();
            will(returnValue(PowerShellConstants.RUN_TYPE));
            allowing(definedRunner).getParameters();
            will(returnValue(definedRunnerParams));
        }
    });
    final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
    assertNotNull(runners);
    assertEquals(1, runners.size());
    validateRunner(runners.get(0), file2Name);
}
Also used : Expectations(org.jmock.Expectations) SBuildRunnerDescriptor(jetbrains.buildServer.serverSide.SBuildRunnerDescriptor) Element(jetbrains.buildServer.util.browser.Element) DiscoveredObject(jetbrains.buildServer.serverSide.discovery.DiscoveredObject) Test(org.testng.annotations.Test)

Example 2 with SBuildRunnerDescriptor

use of jetbrains.buildServer.serverSide.SBuildRunnerDescriptor in project teamcity-rest by JetBrains.

the class PropEntityStep method addToInternalMain.

@NotNull
public SBuildRunnerDescriptor addToInternalMain(@NotNull final BuildTypeSettingsEx buildType, @NotNull final ServiceLocator serviceLocator) {
    if (StringUtil.isEmpty(type)) {
        throw new BadRequestException("Created step cannot have empty 'type'.");
    }
    SBuildRunnerDescriptor similar = getInheritedOrSameIdSimilar(buildType, serviceLocator);
    if (inherited != null && inherited && similar != null) {
        return similar;
    }
    if (similar != null && id != null && id.equals(similar.getId())) {
        // todo
        return similar;
    }
    @SuppressWarnings("ConstantConditions") final SBuildRunnerDescriptor runnerToCreate = buildType.addBuildRunner(StringUtil.isEmpty(name) ? "" : name, type, properties != null ? properties.getMap() : Collections.<String, String>emptyMap());
    return runnerToCreate;
}
Also used : SBuildRunnerDescriptor(jetbrains.buildServer.serverSide.SBuildRunnerDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SBuildRunnerDescriptor

use of jetbrains.buildServer.serverSide.SBuildRunnerDescriptor in project teamcity-rest by JetBrains.

the class PropEntitiesStep method setToBuildType.

public boolean setToBuildType(@NotNull final BuildTypeSettingsEx buildTypeSettings, @NotNull final ServiceLocator serviceLocator) {
    Storage original = new Storage(buildTypeSettings);
    try {
        removeAllSteps(buildTypeSettings);
        if (propEntities != null) {
            String[] runnersOrder = new String[propEntities.size()];
            boolean needToChangeOrder = false;
            int i = 0;
            for (PropEntityStep entity : propEntities) {
                SBuildRunnerDescriptor result = entity.addToInternal(buildTypeSettings, serviceLocator);
                runnersOrder[i] = result.getId();
                List<SBuildRunnerDescriptor> currentRunners = buildTypeSettings.getBuildRunners();
                if (!needToChangeOrder && (currentRunners.size() < i + 1 || !currentRunners.get(i).getId().equals(result.getId())))
                    needToChangeOrder = true;
                i++;
            }
            if (needToChangeOrder)
                buildTypeSettings.applyRunnersOrder(runnersOrder);
        }
        return true;
    } catch (Exception e) {
        // restore original settings
        original.apply(buildTypeSettings);
        throw new BadRequestException("Error replacing items", e);
    }
}
Also used : SBuildRunnerDescriptor(jetbrains.buildServer.serverSide.SBuildRunnerDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException)

Aggregations

SBuildRunnerDescriptor (jetbrains.buildServer.serverSide.SBuildRunnerDescriptor)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)2 DiscoveredObject (jetbrains.buildServer.serverSide.discovery.DiscoveredObject)1 Element (jetbrains.buildServer.util.browser.Element)1 NotNull (org.jetbrains.annotations.NotNull)1 Expectations (org.jmock.Expectations)1 Test (org.testng.annotations.Test)1