use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DevfileConverterTest method shouldInvokeDefaultEditorProvisionerDuringConvertingDevfileToWorkrspaceConfig.
@Test
public void shouldInvokeDefaultEditorProvisionerDuringConvertingDevfileToWorkrspaceConfig() throws Exception {
// given
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
DevfileImpl devfile = newDevfile("petclinic");
// when
devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
// then
verify(defaultEditorToolApplier).apply(devfile, fileContentProvider);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DevfileConverterTest method shouldConvertProjectsDuringConvertingDevfileToWorkspaceConfig.
@Test
public void shouldConvertProjectsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
// given
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
DevfileImpl devfile = newDevfile("petclinic");
ProjectImpl devfileProject = mock(ProjectImpl.class);
devfile.getProjects().add(devfileProject);
ProjectConfigImpl workspaceProject = mock(ProjectConfigImpl.class);
when(projectConverter.toWorkspaceProject(any())).thenReturn(workspaceProject);
// when
WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
// then
assertEquals(workspaceConfig.getProjects().size(), 1);
assertSame(workspaceConfig.getProjects().get(0), workspaceProject);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DefaultEditorProvisioner method apply.
/**
* Provision default editor if there is no editor. Also provisions default plugins for default
* editor regardless whether it is provisioned or set by user.
*
* @param devfile devfile where editor and plugins should be provisioned
* @param contentProvider content provider for plugin references retrieval
*/
public void apply(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
if (defaultEditorRef == null) {
// there is no default editor configured
return;
}
if ("true".equals(devfile.getAttributes().get(EDITOR_FREE_DEVFILE_ATTRIBUTE))) {
return;
}
List<ComponentImpl> components = devfile.getComponents();
Optional<ComponentImpl> editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();
boolean isDefaultEditorUsed;
if (!editorOpt.isPresent()) {
components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef));
isDefaultEditorUsed = true;
} else {
Component editor = editorOpt.get();
String editorPublisherAndName = getPluginPublisherAndName(editor, contentProvider);
isDefaultEditorUsed = defaultEditor.equals(editorPublisherAndName);
}
if (isDefaultEditorUsed) {
provisionDefaultPlugins(components, contentProvider);
}
if ("false".equals(devfile.getAttributes().get(PERSIST_VOLUMES_ATTRIBUTE)) && "true".equals(devfile.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
provisionAsyncStoragePlugin(components, contentProvider);
}
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class GithubAuthorizingFileContentProviderTest method shouldThrowNotFoundForPublicRepos.
@Test(expectedExceptions = FileNotFoundException.class)
public void shouldThrowNotFoundForPublicRepos() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
when(urlFetcher.fetch(eq(url))).thenThrow(FileNotFoundException.class);
when(urlFetcher.fetch(eq("https://api.github.com/repos/eclipse/che"))).thenReturn("OK");
GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
fileContentProvider.fetchContent(url);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class GitlabAuthorizingFileContentProviderTest method shouldExpandRelativePaths.
@Test
public void shouldExpandRelativePaths() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
GitlabUrl gitlabUrl = new GitlabUrl().withHostName("https://gitlab.net").withUsername("eclipse").withProject("che");
FileContentProvider fileContentProvider = new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, gitCredentialsManager, personalAccessTokenManager);
fileContentProvider.fetchContent("devfile.yaml");
verify(urlFetcher).fetch(eq("https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw"));
}
Aggregations