use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.
the class PowerShellRunnerDiscovererTest method setUp.
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
m = new Mockery();
myBrowser = m.mock(Browser.class);
myRootElement = m.mock(Element.class, "root-element");
myDiscoverer = new PowerShellRunnerDiscoverer();
myBuildTypeSettings = m.mock(BuildTypeSettings.class);
}
use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.
the class PowerShellRunnerDiscovererTest method testDiscover_NoSuitableFiles.
@Test
public void testDiscover_NoSuitableFiles() {
final Element file1 = m.mock(Element.class, "file1.txt");
final Element dir1 = m.mock(Element.class, "dir1");
final Element file2 = m.mock(Element.class, "file2");
final Element dir2 = m.mock(Element.class, "dir2");
final List<Element> topLevel = new ArrayList<>(Arrays.asList(file1, dir1));
final List<Element> bottomLevel;
bottomLevel = new ArrayList<>(Arrays.asList(file2, dir2));
m.checking(new Expectations() {
{
oneOf(myBrowser).getRoot();
will(returnValue(myRootElement));
oneOf(myRootElement).getChildren();
will(returnValue(topLevel));
atLeast(1).of(file1).isLeaf();
will(returnValue(true));
atLeast(1).of(dir1).isLeaf();
will(returnValue(false));
oneOf(file1).getName();
will(returnValue("file1.txt"));
oneOf(dir1).getChildren();
will(returnValue(bottomLevel));
atLeast(1).of(file2).isLeaf();
will(returnValue(true));
atLeast(1).of(dir2).isLeaf();
will(returnValue(false));
oneOf(file2).getName();
will(returnValue("file2"));
}
});
final List<DiscoveredObject> runners = myDiscoverer.discover(myBuildTypeSettings, myBrowser);
assertNotNull(runners);
assertEquals(0, runners.size());
}
use of jetbrains.buildServer.util.browser.Element in project teamcity-powershell by JetBrains.
the class PowerShellRunnerDiscoverer method discoverRunnersInDirectory.
@NotNull
@Override
protected List<DiscoveredObject> discoverRunnersInDirectory(@NotNull final Element dir, @NotNull final List<Element> filesAndDirs) {
final List<DiscoveredObject> runners = new ArrayList<>();
for (Element e : filesAndDirs) {
if (e.isLeaf() && PS_EXT.equals(FileUtil.getExtension(e.getName()))) {
final Map<String, String> parameters = new HashMap<>();
parameters.put(PowerShellConstants.RUNNER_SCRIPT_FILE, e.getFullName());
parameters.put(PowerShellConstants.RUNNER_EXECUTION_MODE, PowerShellExecutionMode.PS1.getValue());
parameters.put(PowerShellConstants.RUNNER_SCRIPT_MODE, PowerShellScriptMode.FILE.getValue());
runners.add(new DiscoveredObject(PowerShellConstants.RUN_TYPE, parameters));
}
}
return runners;
}
use of jetbrains.buildServer.util.browser.Element in project teamcity-rest by JetBrains.
the class FilesSubResource method getChildren.
@GET
@Path(FilesSubResource.CHILDREN + "{path:(/.*)?}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@ApiOperation(value = "getChildren", hidden = true)
public Files getChildren(@PathParam("path") @DefaultValue("") final String path, @QueryParam("basePath") final String basePath, @QueryParam("locator") final String locator, @QueryParam("fields") String fields) {
if (!myArchiveBrowsingSupported && locator != null) {
final Boolean browseArchives = new Locator(locator).getSingleDimensionValueAsBoolean(BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME);
if (browseArchives != null && browseArchives) {
throw new BadRequestException("Archive browsing is not supported for this request, remove '" + BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME + "' dimension");
}
}
final FileApiUrlBuilder builder = fileApiUrlBuilder(locator, myUrlPrefix);
final Element rootElement = myProvider.getElement(myProvider.preprocess(StringUtil.removeLeadingSlash(path)));
return new Files(null, new Files.DefaultFilesProvider(builder, myBeanContext) {
@Override
@NotNull
public List<? extends Element> getItems() {
return BuildArtifactsFinder.getItems(rootElement, myProvider.preprocess(basePath), locator, builder, myBeanContext.getServiceLocator());
}
}, new Fields(fields), myBeanContext);
}
use of jetbrains.buildServer.util.browser.Element in project teamcity-rest by JetBrains.
the class FilesSubResource method getContent.
@GET
@Path(FilesSubResource.CONTENT + "{path:(/.*)?}")
@Produces({ MediaType.WILDCARD })
@ApiOperation(value = "getContent", hidden = true)
public Response getContent(@PathParam("path") final String path, @QueryParam("responseBuilder") final String responseBuilder, @Context HttpServletRequest request, @Context HttpServletResponse response) {
final String preprocessedPath = myProvider.preprocess(StringUtil.removeLeadingSlash(path));
final Element initialElement = myProvider.getElement(preprocessedPath);
if (!initialElement.isContentAvailable()) {
throw new NotFoundException("Cannot provide content for '" + initialElement.getFullName() + "'. To get children use '" + fileApiUrlBuilder(null, myUrlPrefix).getChildrenHref(initialElement) + "'.");
}
String contentResponseBuilder = getSetting("rest.files.contentResponseBuilder", "coreWithDownloadProcessor", "responseBuilder", responseBuilder, true, "rest", "core", "coreWithDownloadProcessor");
if ("rest".equals(contentResponseBuilder)) {
// pre-2017.1 way of downloading files
final Response.ResponseBuilder builder = getContent(initialElement, request);
myProvider.fileContentServed(preprocessedPath, request);
setCacheControl(request, response);
return builder.build();
} else if ("core".equals(contentResponseBuilder)) {
processCoreDownload(initialElement, request, response);
} else if ("coreWithDownloadProcessor".equals(contentResponseBuilder)) {
if (!(myProvider instanceof DownloadProcessor) || !((DownloadProcessor) myProvider).processDownload(initialElement, request, response)) {
processCoreDownload(initialElement, request, response);
}
} else {
throw new BadRequestException("Unknown responseBuilder: '" + contentResponseBuilder + "'. Supported values are: '" + "rest" + "', '" + "core" + "', '" + "coreWithDownloadProcessor" + "'");
}
// todo: register only if no errors occurred?
myProvider.fileContentServed(preprocessedPath, request);
if (!response.isCommitted()) {
// let Jersey know what the response should be, otherwise 304 responses can turn to 204
return Response.status(response.getStatus()).build();
}
return null;
}
Aggregations