use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class URLFileContentProvider method fetchContent.
@Override
public String fetchContent(String fileURL) throws IOException, DevfileException {
URI fileURI;
String requestURL;
try {
fileURI = new URI(fileURL);
} catch (URISyntaxException e) {
throw new DevfileException(e.getMessage(), e);
}
if (fileURI.isAbsolute()) {
requestURL = fileURL;
} else {
if (devfileLocation == null) {
throw new DevfileException(format("It is unable to fetch a file %s as relative to devfile, since devfile location" + " is unknown. Try specifying absolute URL.", fileURL));
}
requestURL = devfileLocation.resolve(fileURI).toString();
}
try {
return urlFetcher.fetch(requestURL);
} catch (IOException e) {
throw new IOException(format("Failed to fetch a file from URL %s. Make sure the URL" + " of the devfile points to the raw content of it (e.g. not to the webpage" + " showing it but really just its contents). Additionally, if you're using " + " relative form, make sure the referenced files are actually stored" + " relative to the devfile on the same host," + " or try to specify URL in absolute form. The current attempt to download" + " the file failed with the following error message: %s", fileURL, e.getMessage()), e);
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException 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.exception.DevfileException in project che-server by eclipse-che.
the class DefaultEditorProvisioner method provisionAsyncStoragePlugin.
/**
* Provision the for async storage service, it will provide ability backup and restore project
* source using special storage. Will torn on only if workspace start in Ephemeral mode and has
* attribute 'asyncPersist = true'
*
* @param components The set of components currently present in the Devfile
* @param contentProvider content provider for plugin references retrieval
* @throws DevfileException - A DevfileException containing any caught InfrastructureException
*/
private void provisionAsyncStoragePlugin(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
try {
Map<String, String> missingPluginsIdToRef = Collections.singletonMap(componentFQNParser.getPluginPublisherAndName(asyncStoragePluginRef), asyncStoragePluginRef);
addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DefaultEditorProvisioner method provisionDefaultPlugins.
/**
* Provision the default editor plugins and add them to the the Devfile's component list
*
* @param components The set of components currently present in the Devfile
* @param contentProvider content provider for plugin references retrieval
* @throws DevfileException - A DevfileException containing any caught InfrastructureException
*/
private void provisionDefaultPlugins(List<ComponentImpl> components, FileContentProvider contentProvider) throws DevfileException {
Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsToRefs);
removeAlreadyAddedPlugins(components, contentProvider, missingPluginsIdToRef);
try {
addMissingPlugins(components, contentProvider, missingPluginsIdToRef);
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DevfileConverter method devFileToWorkspaceConfig.
/**
* Converts given {@link Devfile} into {@link WorkspaceConfigImpl workspace config}.
*
* @param devfile initial devfile
* @param contentProvider content provider for recipe-type component or plugin references
* @return constructed workspace config
* @throws DevfileException when general devfile error occurs
* @throws DevfileException when devfile requires additional files content but the specified
* content provider does not support it
* @throws DevfileFormatException when devfile format is invalid
* @throws DevfileRecipeFormatException when content of the file specified in recipe type
* component is empty or its format is invalid
*/
public WorkspaceConfigImpl devFileToWorkspaceConfig(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
checkArgument(contentProvider != null, "Content provider must not be null");
// make copy to avoid modification of original devfile
devfile = new DevfileImpl(devfile);
validateCurrentVersion(devfile);
defaultEditorProvisioner.apply(devfile, contentProvider);
WorkspaceConfigImpl config = new WorkspaceConfigImpl();
config.setName(devfile.getName());
for (Command command : devfile.getCommands()) {
CommandImpl com = commandConverter.toWorkspaceCommand(command, contentProvider);
if (com != null) {
config.getCommands().add(com);
}
}
// so, commands should be already converted
for (ComponentImpl component : devfile.getComponents()) {
ComponentToWorkspaceApplier applier = componentTypeToApplier.get(component.getType());
if (applier == null) {
throw new DevfileException(String.format("Devfile contains component `%s` with type `%s` that can not be converted to workspace", getIdentifiableComponentName(component), component.getType()));
}
applier.apply(config, component, contentProvider);
}
for (ProjectImpl project : devfile.getProjects()) {
ProjectConfigImpl projectConfig = projectConverter.toWorkspaceProject(project);
config.getProjects().add(projectConfig);
}
config.getAttributes().putAll(devfile.getAttributes());
config.setDevfile(devfile);
return config;
}
Aggregations