use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ExtensionCasesTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
new File(root, "/project1").mkdir();
List<ProjectConfig> projects = new ArrayList<>();
projects.add(DtoFactory.newDto(ProjectConfigDto.class).withPath("/project1").withName("project1Name").withType("primary1"));
workspaceHolder = new TestWorkspaceHolder(projects);
ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
projectTypeRegistry.registerProjectType(new PT1());
//projectTypeRegistry.registerProjectType(new PT3());
//ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
projectRegistry.initProjects();
pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, null, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
pm.initWatcher();
projectHandlerRegistry.register(new ProjectInitHandler() {
@Override
public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder) throws ServerException, NotFoundException, ConflictException, ForbiddenException {
projectFolder.createFile("generated", "test".getBytes());
projectFolder.createFolder("project2");
projectRegistry.setProjectType("/project1/project2", BaseProjectType.ID, false);
//System.out.println(">>S>>> "+projectRegistry);
}
@Override
public String getProjectType() {
return "primary1";
}
});
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class PlainJavaInitHandler method initializeClasspath.
@Override
protected void initializeClasspath(IJavaProject javaProject) throws ServerException {
IClasspathEntry[] projectClasspath;
try {
projectClasspath = javaProject.getRawClasspath();
} catch (JavaModelException e) {
LOG.warn("Can't get classpath for: " + javaProject.getProject().getFullPath().toOSString(), e);
throw new ServerException(e);
}
//default classpath
IClasspathEntry[] defaultClasspath = new IClasspathEntry[] { JavaCore.newSourceEntry(javaProject.getPath()) };
if (!Arrays.equals(defaultClasspath, projectClasspath)) {
//classpath is already initialized
return;
}
RegisteredProject project = projectRegistryProvider.get().getProject(javaProject.getPath().toOSString());
List<String> sourceFolders = project.getAttributes().get(Constants.SOURCE_FOLDER);
List<String> library = project.getAttributes().get(LIBRARY_FOLDER);
classpathBuilder.generateClasspath(javaProject, sourceFolders, library);
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ProjectService method uploadProjectFromZip.
@POST
@Path("/upload/zipproject/{path:.*}")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Upload zip project", notes = "Upload project from local zip", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = ""), @ApiResponse(code = 401, message = "User not authorized to call this operation"), @ApiResponse(code = 403, message = "Forbidden operation"), @ApiResponse(code = 409, message = "Resource already exists"), @ApiResponse(code = 500, message = "Unsupported source type") })
public List<SourceEstimation> uploadProjectFromZip(@ApiParam(value = "Path in the project", required = true) @PathParam("path") String path, @ApiParam(value = "Force rewrite existing project", allowableValues = "true,false") @QueryParam("force") boolean force, Iterator<FileItem> formData) throws ServerException, IOException, ConflictException, ForbiddenException, NotFoundException, BadRequestException {
// Not all importers uses virtual file system API. In this case virtual file system API doesn't get events and isn't able to set
final FolderEntry baseProjectFolder = (FolderEntry) getVirtualFile(path, force);
int stripNumber = 0;
String projectName = "";
String projectDescription = "";
FileItem contentItem = null;
while (formData.hasNext()) {
FileItem item = formData.next();
if (!item.isFormField()) {
if (contentItem == null) {
contentItem = item;
} else {
throw new ServerException("More then one upload file is found but only one is expected. ");
}
} else {
switch(item.getFieldName()) {
case ("name"):
projectName = item.getString().trim();
break;
case ("description"):
projectDescription = item.getString().trim();
break;
case ("skipFirstLevel"):
stripNumber = Boolean.parseBoolean(item.getString().trim()) ? 1 : 0;
break;
}
}
}
if (contentItem == null) {
throw new ServerException("Cannot find zip file for upload.");
}
try (InputStream zip = contentItem.getInputStream()) {
baseProjectFolder.getVirtualFile().unzip(zip, true, stripNumber);
}
return resolveSources(path);
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ProjectService method uploadZip.
private static Response uploadZip(VirtualFile parent, Iterator<FileItem> formData) throws ForbiddenException, ConflictException, ServerException {
try {
FileItem contentItem = null;
boolean overwrite = false;
boolean skipFirstLevel = false;
while (formData.hasNext()) {
FileItem item = formData.next();
if (!item.isFormField()) {
if (contentItem == null) {
contentItem = item;
} else {
throw new ServerException("More then one upload file is found but only one should be. ");
}
} else if ("overwrite".equals(item.getFieldName())) {
overwrite = Boolean.parseBoolean(item.getString().trim());
} else if ("skipFirstLevel".equals(item.getFieldName())) {
skipFirstLevel = Boolean.parseBoolean(item.getString().trim());
}
}
if (contentItem == null) {
throw new ServerException("Cannot find file for upload. ");
}
try {
importZip(parent, contentItem.getInputStream(), overwrite, skipFirstLevel);
} catch (IOException ioe) {
throw new ServerException(ioe.getMessage(), ioe);
}
return Response.ok("", MediaType.TEXT_HTML).build();
} catch (ForbiddenException | ConflictException | ServerException e) {
HtmlErrorFormatter.sendErrorAsHTML(e);
// never thrown
throw e;
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LuceneSearcher method doInit.
protected final synchronized void doInit() throws ServerException {
try {
luceneIndexWriter = new IndexWriter(makeDirectory(), new IndexWriterConfig(makeAnalyzer()));
searcherManager = new SearcherManager(luceneIndexWriter, true, new SearcherFactory());
closed = false;
} catch (IOException e) {
throw new ServerException(e);
}
}
Aggregations