Search in sources :

Example 6 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.

the class SimpleGeneratorStrategyTest method testGeneratingProject.

@Test
public void testGeneratingProject() throws Exception {
    prepareProject();
    final Path pomXml = Paths.get(Thread.currentThread().getContextClassLoader().getResource("test-pom.xml").toURI());
    Map<String, AttributeValue> attributeValues = new HashMap<>();
    attributeValues.put(MavenAttributes.ARTIFACT_ID, new AttributeValue("my_artifact"));
    attributeValues.put(MavenAttributes.GROUP_ID, new AttributeValue("my_group"));
    attributeValues.put(MavenAttributes.PACKAGING, new AttributeValue("jar"));
    attributeValues.put(MavenAttributes.VERSION, new AttributeValue("1.0-SNAPSHOT"));
    attributeValues.put(SOURCE_FOLDER, new AttributeValue("src/main/java"));
    attributeValues.put(MavenAttributes.TEST_SOURCE_FOLDER, new AttributeValue("src/test/java"));
    pm.getProject("my_project").getBaseFolder();
    simple.generateProject(org.eclipse.che.api.vfs.Path.of("my_project"), attributeValues, null);
    VirtualFileEntry pomFile = pm.getProject("my_project").getBaseFolder().getChild("pom.xml");
    Assert.assertTrue(pomFile.isFile());
    Assert.assertEquals(new String(((FileEntry) pomFile).contentAsBytes()), new String(Files.readAllBytes(pomXml)));
    VirtualFileEntry srcFolder = pm.getProject("my_project").getBaseFolder().getChild("src/main/java");
    Assert.assertTrue(srcFolder.isFolder());
    VirtualFileEntry testFolder = pm.getProject("my_project").getBaseFolder().getChild("src/test/java");
    Assert.assertTrue(testFolder.isFolder());
}
Also used : Path(java.nio.file.Path) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry) Test(org.junit.Test)

Example 7 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.

the class ComposerProjectGenerator method onCreateProject.

@Override
public void onCreateProject(Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    AttributeValue packageName = attributes.get(Constants.PACKAGE);
    if (packageName == null) {
        throw new ServerException("Missed some required options (package)");
    }
    VirtualFileSystem vfs = virtualFileSystemProvider.getVirtualFileSystem();
    String projectAbsolutePath = new File(vfs.getRoot().toIoFile(), projectPath.toString()).toString();
    String[] commandLine = { "composer", "create-project", packageName.getString(), projectAbsolutePath, "--no-install" };
    try {
        ComposerCommandExecutor.execute(commandLine, null);
    } catch (TimeoutException | IOException | InterruptedException e) {
        throw new ServerException(e);
    }
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) IOException(java.io.IOException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.

the class AntProjectGenerator method onCreateProject.

@Override
public void onCreateProject(FolderEntry baseFolder, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    final String buildXmlContent = new BuildFileGenerator(baseFolder.getName()).getBuildFileContent();
    baseFolder.createFile(AntAttributes.BUILD_FILE, buildXmlContent.getBytes(), "text/xml");
    AttributeValue sourceFolders = attributes.get(AntAttributes.SOURCE_FOLDER);
    if (sourceFolders != null) {
        baseFolder.createFolder(sourceFolders.getString());
    }
    AttributeValue testSourceFolders = attributes.get(AntAttributes.TEST_SOURCE_FOLDER);
    if (testSourceFolders != null) {
        baseFolder.createFolder(testSourceFolders.getString());
    }
}
Also used : BuildFileGenerator(org.eclipse.che.ide.ant.tools.buildfile.BuildFileGenerator) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue)

Example 9 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue 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 10 with AttributeValue

use of org.eclipse.che.api.project.server.type.AttributeValue in project che by eclipse.

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProject.

@Test
public void testCreateBatchProjectsWithInnerProject() throws Exception {
    final String rootProjectPath = "/testProject1";
    final String innerProjectPath = "/testProject1/innerProject";
    final String importType = "importType1";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final String[] paths2 = { "innerProject/", "innerProject/folder2/", "innerProject/folder2/file2.txt" };
    final List<String> children1 = Arrays.asList(paths1);
    final List<String> children2 = Arrays.asList(paths2);
    final List<String> children = new ArrayList<>(children1);
    children.addAll(children2);
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType);
    NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source);
    NewProjectConfigDto config2 = createProjectConfigObject("innerProject", innerProjectPath, innerProjectType, null);
    config2.setAttributes(attributes);
    List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(rootProject);
    assertTrue(rootProjectFolder.getVirtualFile().exists());
    assertEquals(rootProjectPath, rootProject.getPath());
    checkChildrenFor(rootProjectFolder, children1);
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(rootProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Aggregations

AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)16 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)8 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)7 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)5 File (java.io.File)2 Map (java.util.Map)2 ServerException (org.eclipse.che.api.core.ServerException)2 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)2 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)2 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 PathMatcher (java.nio.file.PathMatcher)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1