use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class EditorComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified editor component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param editorComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from cheEditor
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(editorComponent != null, "Component must not be null");
checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
final String editorComponentAlias = editorComponent.getAlias();
final String editorId = editorComponent.getId();
final String registryUrl = editorComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
}
workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
editorComponent.setId(fqn.getId());
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
the class EditorComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified editor component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param editorComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from cheEditor
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(editorComponent != null, "Component must not be null");
checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
final String editorComponentAlias = editorComponent.getAlias();
final String editorId = editorComponent.getId();
final String registryUrl = editorComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
}
workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
editorComponent.setId(fqn.getId());
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
the class URLFactoryBuilderTest method checkThatDtoHasCorrectNames.
@Test(dataProvider = "devfiles")
public void checkThatDtoHasCorrectNames(DevfileImpl devfile, String expectedGenerateName) throws ApiException, IOException, OverrideParameterException, DevfileException {
DefaultFactoryUrl defaultFactoryUrl = mock(DefaultFactoryUrl.class);
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
when(defaultFactoryUrl.devfileFileLocations()).thenReturn(singletonList(new DevfileLocation() {
@Override
public Optional<String> filename() {
return Optional.empty();
}
@Override
public String location() {
return "http://foo.bar/anything";
}
}));
when(fileContentProvider.fetchContent(anyString())).thenReturn("anything");
when(devfileParser.parseYamlRaw("anything")).thenReturn(new ObjectNode(JsonNodeFactory.instance));
when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
FactoryDto factory = (FactoryDto) urlFactoryBuilder.createFactoryFromDevfile(defaultFactoryUrl, fileContentProvider, emptyMap()).get();
assertNull(factory.getDevfile().getMetadata().getName());
assertEquals(factory.getDevfile().getMetadata().getGenerateName(), expectedGenerateName);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
the class URLFactoryBuilderTest method checkCorrectExceptionThrownDependingOnCause.
@Test(dataProvider = "devfileExceptions")
public void checkCorrectExceptionThrownDependingOnCause(Throwable cause, Class expectedClass, String expectedMessage, Map<String, String> expectedAttributes) throws IOException, DevfileException {
DefaultFactoryUrl defaultFactoryUrl = mock(DefaultFactoryUrl.class);
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
when(defaultFactoryUrl.devfileFileLocations()).thenReturn(singletonList(new DevfileLocation() {
@Override
public Optional<String> filename() {
return Optional.empty();
}
@Override
public String location() {
return "http://foo.bar/anything";
}
}));
when(fileContentProvider.fetchContent(anyString())).thenThrow(new DevfileException("", cause));
// when
try {
urlFactoryBuilder.createFactoryFromDevfile(defaultFactoryUrl, fileContentProvider, emptyMap());
} catch (ApiException e) {
assertTrue(e.getClass().isAssignableFrom(expectedClass));
assertEquals(e.getMessage(), expectedMessage);
if (e.getServiceError() instanceof ExtendedError)
assertEquals(((ExtendedError) e.getServiceError()).getAttributes(), expectedAttributes);
}
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
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