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());
}
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);
}
}
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());
}
}
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();
}
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);
}
Aggregations