From 4ed78dfa7c16b1dbff089fe65afdb36fc06ddf9d Mon Sep 17 00:00:00 2001 From: Eugene Ivantsov Date: Tue, 27 Sep 2016 10:50:49 +0300 Subject: [PATCH] Auto crete files with hello world content when creating C, C++, and Python projects from scratch Signed-off-by: Eugene Ivantsov --- .../che-plugin-cpp-lang-server/pom.xml | 4 ++ .../cpp/generator/CProjectGenerator.java | 39 ++++++++++++++++++ .../cpp/generator/CppProjectGenerator.java | 40 +++++++++++++++++++ .../che/plugin/cpp/inject/CppModule.java | 10 +++++ .../main/resources/files/default_c_content | 9 +++++ .../main/resources/files/default_cpp_content | 9 +++++ .../generator/NodeJsProjectGenerator.java | 3 +- .../{default_content => default_node_content} | 0 .../generator/PythonProjectGenerator.java | 9 ++++- .../resources/files/default_python_content | 1 + 10 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CProjectGenerator.java create mode 100644 plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CppProjectGenerator.java create mode 100644 plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_c_content create mode 100644 plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_cpp_content rename plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/resources/files/{default_content => default_node_content} (100%) create mode 100644 plugins/plugin-python/che-plugin-python-lang-server/src/main/resources/files/default_python_content diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/pom.xml b/plugins/plugin-cpp/che-plugin-cpp-lang-server/pom.xml index 2e7d47f0ab..c3a53e02a2 100644 --- a/plugins/plugin-cpp/che-plugin-cpp-lang-server/pom.xml +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/pom.xml @@ -32,6 +32,10 @@ com.google.inject.extensions guice-multibindings + + org.eclipse.che.core + che-core-api-core + org.eclipse.che.core che-core-api-project diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CProjectGenerator.java b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CProjectGenerator.java new file mode 100644 index 0000000000..a3f21e85be --- /dev/null +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CProjectGenerator.java @@ -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 attributes, + Map 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; + } +} diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CppProjectGenerator.java b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CppProjectGenerator.java new file mode 100644 index 0000000000..054c2d2f00 --- /dev/null +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/generator/CppProjectGenerator.java @@ -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 attributes, + Map 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; + } +} + diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/inject/CppModule.java b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/inject/CppModule.java index 86f4d92858..139340c156 100644 --- a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/inject/CppModule.java +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/java/org/eclipse/che/plugin/cpp/inject/CppModule.java @@ -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 projectTypeMultibinder = Multibinder.newSetBinder(binder(), ProjectTypeDef.class); projectTypeMultibinder.addBinding().to(CProjectType.class); projectTypeMultibinder.addBinding().to(CppProjectType.class); + + Multibinder projectHandlerMultibinder = newSetBinder(binder(), ProjectHandler.class); + projectHandlerMultibinder.addBinding().to(CppProjectGenerator.class); + projectHandlerMultibinder.addBinding().to(CProjectGenerator.class); } } diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_c_content b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_c_content new file mode 100644 index 0000000000..5aab458ec9 --- /dev/null +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_c_content @@ -0,0 +1,9 @@ +/* Hello World program */ + +#include + +main() +{ + printf("Hello World"); + +} diff --git a/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_cpp_content b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_cpp_content new file mode 100644 index 0000000000..cabf6a12ac --- /dev/null +++ b/plugins/plugin-cpp/che-plugin-cpp-lang-server/src/main/resources/files/default_cpp_content @@ -0,0 +1,9 @@ +/* Hello World program */ + +#include + +main() +{ + cout << "Hello World!"; + return 0; +} diff --git a/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/java/org/eclipse/che/plugin/nodejs/generator/NodeJsProjectGenerator.java b/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/java/org/eclipse/che/plugin/nodejs/generator/NodeJsProjectGenerator.java index 1c0d47c0e7..26ebc6fa3b 100644 --- a/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/java/org/eclipse/che/plugin/nodejs/generator/NodeJsProjectGenerator.java +++ b/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/java/org/eclipse/che/plugin/nodejs/generator/NodeJsProjectGenerator.java @@ -33,7 +33,7 @@ public class NodeJsProjectGenerator implements CreateProjectHandler { public void onCreateProject(FolderEntry baseFolder, Map attributes, Map 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; } } + diff --git a/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/resources/files/default_content b/plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/resources/files/default_node_content similarity index 100% rename from plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/resources/files/default_content rename to plugins/plugin-nodejs/che-plugin-nodejs-lang-server/src/main/resources/files/default_node_content diff --git a/plugins/plugin-python/che-plugin-python-lang-server/src/main/java/org/eclipse/che/plugin/python/generator/PythonProjectGenerator.java b/plugins/plugin-python/che-plugin-python-lang-server/src/main/java/org/eclipse/che/plugin/python/generator/PythonProjectGenerator.java index 94a5546f65..b09bdfac01 100644 --- a/plugins/plugin-python/che-plugin-python-lang-server/src/main/java/org/eclipse/che/plugin/python/generator/PythonProjectGenerator.java +++ b/plugins/plugin-python/che-plugin-python-lang-server/src/main/java/org/eclipse/che/plugin/python/generator/PythonProjectGenerator.java @@ -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 attributes, Map options) - throws ForbiddenException, ConflictException, ServerException { + public void onCreateProject(FolderEntry baseFolder, + Map attributes, + Map options) throws ForbiddenException, ConflictException, ServerException { + baseFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/default_python_content")); } @Override diff --git a/plugins/plugin-python/che-plugin-python-lang-server/src/main/resources/files/default_python_content b/plugins/plugin-python/che-plugin-python-lang-server/src/main/resources/files/default_python_content new file mode 100644 index 0000000000..f4da9afa4b --- /dev/null +++ b/plugins/plugin-python/che-plugin-python-lang-server/src/main/resources/files/default_python_content @@ -0,0 +1 @@ +print "Hello World!"