use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class ProjectConverter method sanitizeClonePath.
private String sanitizeClonePath(String clonePath) throws DevfileException {
URI uri = clonePathToURI(clonePath);
if (uri.isAbsolute()) {
throw new DevfileException("The clonePath must be a relative path. This seems to be an URI with a scheme: " + clonePath);
}
uri = uri.normalize();
String path = uri.getPath();
if (path.isEmpty()) {
// the user tried to trick us with something like "blah/.."
throw new DevfileException("Cloning directly into projects root is not allowed." + " The clonePath that resolves to empty path: " + clonePath);
}
if (path.startsWith("/")) {
// user-authored. Just don't give the user impression we can support absolute paths.
throw new DevfileException("The clonePath must be a relative. This seems to be an absolute path: " + clonePath);
}
if (path.startsWith("..")) {
// an attempt to escape the projects root, e.g. "ich/../muss/../../raus". That's a no-no.
throw new DevfileException("The clonePath cannot escape the projects root. Don't use .. to try and do that." + " The invalid path was: " + clonePath);
}
return path;
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException 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.exception.DevfileException in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
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);
}
}
Aggregations