Search in sources :

Example 1 with ProjectImporter

use of org.eclipse.che.api.project.server.importer.ProjectImporter in project che by eclipse.

the class SubversionProjectImporterTest method setUp.

@Before
public void setUp() throws Exception {
    // Bind components
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            Multibinder.newSetBinder(binder(), ProjectImporter.class).addBinding().to(SubversionProjectImporter.class);
            Multibinder.newSetBinder(binder(), ProjectTypeDef.class).addBinding().to(SubversionProjectType.class);
            Multibinder.newSetBinder(binder(), ValueProviderFactory.class).addBinding().to(SubversionValueProviderFactory.class);
            bind(SshKeyProvider.class).toInstance(sshKeyProvider);
            bind(ProfileDao.class).toInstance(userProfileDao);
            bind(RepositoryUrlProvider.class).toInstance(repositoryUrlProvider);
        }
    });
    // Init virtual file system
    VirtualFileSystem virtualFileSystem = TestUtils.createVirtualFileSystem();
    root = virtualFileSystem.getRoot();
    // Create the test user
    TestUtils.createTestUser(userProfileDao);
    // Create the Subversion repository
    repoRoot = TestUtils.createGreekTreeRepository();
    projectImporter = injector.getInstance(SubversionProjectImporter.class);
}
Also used : VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) Injector(com.google.inject.Injector) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ValueProviderFactory(org.eclipse.che.api.project.server.type.ValueProviderFactory) AbstractModule(com.google.inject.AbstractModule) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) Before(org.junit.Before)

Example 2 with ProjectImporter

use of org.eclipse.che.api.project.server.importer.ProjectImporter in project che by eclipse.

the class ProjectServiceTest method registerImporter.

private void registerImporter(String importType, InputStream zip) throws Exception {
    final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
    importerRegistry.register(new ProjectImporter() {

        @Override
        public String getId() {
            return importType;
        }

        @Override
        public boolean isInternal() {
            return false;
        }

        @Override
        public String getDescription() {
            return "Chuck importer";
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
            importSources(baseFolder, storage, LineConsumerFactory.NULL);
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
            // Don't really use location in this test.
            baseFolder.getVirtualFile().unzip(zip, true, 0);
            folderHolder.set(baseFolder);
        }

        @Override
        public ImporterCategory getCategory() {
            return ImporterCategory.ARCHIVE;
        }
    });
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Example 3 with ProjectImporter

use of org.eclipse.che.api.project.server.importer.ProjectImporter in project che by eclipse.

the class ProjectManagerWriteTest method registerImporter.

private void registerImporter(String importType, InputStream zip) throws Exception {
    final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
    importerRegistry.register(new ProjectImporter() {

        @Override
        public String getId() {
            return importType;
        }

        @Override
        public boolean isInternal() {
            return false;
        }

        @Override
        public String getDescription() {
            return "importer";
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
            importSources(baseFolder, storage, LineConsumerFactory.NULL);
        }

        @Override
        public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
            // Don't really use location in this test.
            baseFolder.getVirtualFile().unzip(zip, true, 0);
            folderHolder.set(baseFolder);
        }

        @Override
        public ImporterCategory getCategory() {
            return ProjectImporter.ImporterCategory.ARCHIVE;
        }
    });
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) ValueHolder(org.eclipse.che.api.core.util.ValueHolder) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Example 4 with ProjectImporter

use of org.eclipse.che.api.project.server.importer.ProjectImporter in project che by eclipse.

the class ProjectServiceTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    WorkspaceProjectsSyncer workspaceHolder = new WsAgentTestBase.TestWorkspaceHolder();
    File root = new File(FS_PATH);
    if (root.exists()) {
        IoUtil.deleteRecursive(root);
    }
    root.mkdir();
    File indexDir = new File(INDEX_PATH);
    if (indexDir.exists()) {
        IoUtil.deleteRecursive(indexDir);
    }
    indexDir.mkdir();
    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> {
        for (java.nio.file.Path pathElement : path) {
            if (pathElement == null || EXCLUDE_SEARCH_PATH.equals(pathElement.toString())) {
                return true;
            }
        }
        return false;
    });
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
    vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    final EventService eventService = new EventService();
    // PTs for test
    ProjectTypeDef chuck = new ProjectTypeDef("chuck_project_type", "chuck_project_type", true, false) {

        {
            addConstantDefinition("x", "attr description", new AttributeValue(Arrays.asList("a", "b")));
        }
    };
    Set<ProjectTypeDef> projectTypes = new HashSet<>();
    final LocalProjectType myProjectType = new LocalProjectType("my_project_type", "my project type");
    projectTypes.add(myProjectType);
    projectTypes.add(new LocalProjectType("module_type", "module type"));
    projectTypes.add(chuck);
    ptRegistry = new ProjectTypeRegistry(projectTypes);
    phRegistry = new ProjectHandlerRegistry(new HashSet<>());
    importerRegistry = new ProjectImporterRegistry(Collections.<ProjectImporter>emptySet());
    projectServiceLinksInjector = new ProjectServiceLinksInjector();
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, ptRegistry, phRegistry, eventService);
    projectRegistry.initProjects();
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
    pm = new ProjectManager(vfsProvider, ptRegistry, projectRegistry, phRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
    pm.initWatcher();
    HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
    //List<ProjectConfigDto> modules = new ArrayList<>();
    projects = new ArrayList<>();
    addMockedProjectConfigDto(myProjectType, "my_project");
    when(httpJsonRequestFactory.fromLink(any())).thenReturn(httpJsonRequest);
    when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
    when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
    when(workspaceConfigMock.getProjects()).thenReturn(projects);
    //        verify(httpJsonRequestFactory).fromLink(eq(DtoFactory.newDto(Link.class)
    //                                                             .withHref(apiEndpoint + "/workspace/" + workspace + "/project")
    //                                                             .withMethod(PUT)));
    DependencySupplierImpl dependencies = new DependencySupplierImpl();
    dependencies.addInstance(ProjectTypeRegistry.class, ptRegistry);
    dependencies.addInstance(UserDao.class, userDao);
    dependencies.addInstance(ProjectManager.class, pm);
    dependencies.addInstance(ProjectImporterRegistry.class, importerRegistry);
    dependencies.addInstance(ProjectHandlerRegistry.class, phRegistry);
    dependencies.addInstance(EventService.class, eventService);
    dependencies.addInstance(ProjectServiceLinksInjector.class, projectServiceLinksInjector);
    ResourceBinder resources = new ResourceBinderImpl();
    ProviderBinder providers = ProviderBinder.getInstance();
    EverrestProcessor processor = new EverrestProcessor(new EverrestConfiguration(), dependencies, new RequestHandlerImpl(new RequestDispatcher(resources), providers), null);
    launcher = new ResourceLauncher(processor);
    processor.addApplication(new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return java.util.Collections.<Class<?>>singleton(ProjectService.class);
        }

        @Override
        public Set<Object> getSingletons() {
            return new HashSet<>(Arrays.asList(new ApiExceptionMapper()));
        }
    });
    ApplicationContext.setCurrent(anApplicationContext().withProviders(providers).build());
    env = org.eclipse.che.commons.env.EnvironmentContext.getCurrent();
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) DependencySupplierImpl(org.everrest.core.tools.DependencySupplierImpl) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ResourceLauncher(org.everrest.core.tools.ResourceLauncher) EverrestConfiguration(org.everrest.core.impl.EverrestConfiguration) EverrestProcessor(org.everrest.core.impl.EverrestProcessor) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) EventService(org.eclipse.che.api.core.notification.EventService) RequestDispatcher(org.everrest.core.impl.RequestDispatcher) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) ProviderBinder(org.everrest.core.impl.ProviderBinder) PathMatcher(java.nio.file.PathMatcher) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) RequestHandlerImpl(org.everrest.core.impl.RequestHandlerImpl) ResourceBinderImpl(org.everrest.core.impl.ResourceBinderImpl) ResourceBinder(org.everrest.core.ResourceBinder) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File) Application(javax.ws.rs.core.Application) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ProjectImporter

use of org.eclipse.che.api.project.server.importer.ProjectImporter in project che by eclipse.

the class ProjectManager method doImportProject.

/** Note: Use {@link FileWatcherManager#suspend()} and {@link FileWatcherManager#resume()} while importing source code */
private RegisteredProject doImportProject(String path, SourceStorage sourceStorage, boolean rewrite, LineConsumerFactory lineConsumerFactory) throws ServerException, IOException, ForbiddenException, UnauthorizedException, ConflictException, NotFoundException {
    final ProjectImporter importer = importers.getImporter(sourceStorage.getType());
    if (importer == null) {
        throw new NotFoundException(format("Unable import sources project from '%s'. Sources type '%s' is not supported.", sourceStorage.getLocation(), sourceStorage.getType()));
    }
    String normalizePath = (path.startsWith("/")) ? path : "/".concat(path);
    FolderEntry folder = asFolder(normalizePath);
    if (folder != null && !rewrite) {
        throw new ConflictException(format("Project %s already exists ", path));
    }
    if (folder == null) {
        folder = getProjectsRoot().createFolder(normalizePath);
    }
    try {
        importer.importSources(folder, sourceStorage, lineConsumerFactory);
    } catch (final Exception e) {
        folder.remove();
        throw e;
    }
    final String name = folder.getPath().getName();
    for (ProjectConfig project : workspaceProjectsHolder.getProjects()) {
        if (normalizePath.equals(project.getPath())) {
            // TODO Needed for factory project importing with keepDir. It needs to find more appropriate solution
            List<String> innerProjects = projectRegistry.getProjects(normalizePath);
            for (String innerProject : innerProjects) {
                RegisteredProject registeredProject = projectRegistry.getProject(innerProject);
                projectRegistry.putProject(registeredProject, asFolder(registeredProject.getPath()), true, false);
            }
            RegisteredProject rp = projectRegistry.putProject(project, folder, true, false);
            workspaceProjectsHolder.sync(projectRegistry);
            return rp;
        }
    }
    RegisteredProject rp = projectRegistry.putProject(new NewProjectConfigImpl(normalizePath, name, BaseProjectType.ID, sourceStorage), folder, true, false);
    workspaceProjectsHolder.sync(projectRegistry);
    return rp;
}
Also used : ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) BadRequestException(org.eclipse.che.api.core.BadRequestException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter)

Aggregations

ProjectImporter (org.eclipse.che.api.project.server.importer.ProjectImporter)5 ConflictException (org.eclipse.che.api.core.ConflictException)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)3 ServerException (org.eclipse.che.api.core.ServerException)3 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)2 LineConsumerFactory (org.eclipse.che.api.core.util.LineConsumerFactory)2 ValueHolder (org.eclipse.che.api.core.util.ValueHolder)2 ProjectTypeDef (org.eclipse.che.api.project.server.type.ProjectTypeDef)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 File (java.io.File)1 IOException (java.io.IOException)1 PathMatcher (java.nio.file.PathMatcher)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Application (javax.ws.rs.core.Application)1 BadRequestException (org.eclipse.che.api.core.BadRequestException)1 NotFoundException (org.eclipse.che.api.core.NotFoundException)1 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)1