Auto crete files with hello world content when creating C, C++, and Python projects from scratch

Signed-off-by: Eugene Ivantsov <eivantsov@codenvy.com>
6.19.x
Eugene Ivantsov 2016-09-27 10:50:49 +03:00
parent 6e3aa1c49e
commit 4ed78dfa7c
10 changed files with 121 additions and 3 deletions

View File

@ -32,6 +32,10 @@
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project</artifactId>

View File

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.cpp.generator;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.project.server.FolderEntry;
import org.eclipse.che.api.project.server.handlers.CreateProjectHandler;
import org.eclipse.che.api.project.server.type.AttributeValue;
import org.eclipse.che.plugin.cpp.shared.Constants;
import java.util.Map;
public class CProjectGenerator implements CreateProjectHandler {
private static final String FILE_NAME = "hello.c";
@Override
public void onCreateProject(FolderEntry baseFolder,
Map<String, AttributeValue> attributes,
Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_c_content"));
}
@Override
public String getProjectType() {
return Constants.C_PROJECT_TYPE_ID;
}
}

View File

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.cpp.generator;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.ForbiddenException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.project.server.FolderEntry;
import org.eclipse.che.api.project.server.handlers.CreateProjectHandler;
import org.eclipse.che.api.project.server.type.AttributeValue;
import org.eclipse.che.plugin.cpp.shared.Constants;
import java.util.Map;
public class CppProjectGenerator implements CreateProjectHandler {
private static final String FILE_NAME = "hello.cpp";
@Override
public void onCreateProject(FolderEntry baseFolder,
Map<String, AttributeValue> attributes,
Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_cpp_content"));
}
@Override
public String getProjectType() {
return Constants.CPP_PROJECT_TYPE_ID;
}
}

View File

@ -12,11 +12,17 @@ package org.eclipse.che.plugin.cpp.inject;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import org.eclipse.che.api.project.server.handlers.ProjectHandler;
import org.eclipse.che.api.project.server.type.ProjectTypeDef;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.cpp.generator.CProjectGenerator;
import org.eclipse.che.plugin.cpp.generator.CppProjectGenerator;
import org.eclipse.che.plugin.cpp.projecttype.CProjectType;
import org.eclipse.che.plugin.cpp.projecttype.CppProjectType;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
/**
* @author Vitaly Parfonov
*/
@ -27,5 +33,9 @@ public class CppModule extends AbstractModule {
Multibinder<ProjectTypeDef> projectTypeMultibinder = Multibinder.newSetBinder(binder(), ProjectTypeDef.class);
projectTypeMultibinder.addBinding().to(CProjectType.class);
projectTypeMultibinder.addBinding().to(CppProjectType.class);
Multibinder<ProjectHandler> projectHandlerMultibinder = newSetBinder(binder(), ProjectHandler.class);
projectHandlerMultibinder.addBinding().to(CppProjectGenerator.class);
projectHandlerMultibinder.addBinding().to(CProjectGenerator.class);
}
}

View File

@ -0,0 +1,9 @@
/* Hello World program */
#include<stdio.h>
main()
{
printf("Hello World");
}

View File

@ -0,0 +1,9 @@
/* Hello World program */
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}

View File

@ -33,7 +33,7 @@ public class NodeJsProjectGenerator implements CreateProjectHandler {
public void onCreateProject(FolderEntry baseFolder,
Map<String, AttributeValue> attributes,
Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_content"));
baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_node_content"));
}
@Override
@ -41,3 +41,4 @@ public class NodeJsProjectGenerator implements CreateProjectHandler {
return Constants.NODE_JS_PROJECT_TYPE_ID;
}
}

View File

@ -24,9 +24,14 @@ import java.util.Map;
* @author Valeriy Svydenko
*/
public class PythonProjectGenerator implements CreateProjectHandler {
private static final String FILE_NAME = "main.py";
@Override
public void onCreateProject(FolderEntry baseFolder, Map<String, AttributeValue> attributes, Map<String, String> options)
throws ForbiddenException, ConflictException, ServerException {
public void onCreateProject(FolderEntry baseFolder,
Map<String, AttributeValue> attributes,
Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_python_content"));
}
@Override