From e67974ccc9ec76ce9cce8c5899ed4b011d143ad4 Mon Sep 17 00:00:00 2001 From: jcagarcia Date: Fri, 29 Apr 2016 09:40:31 +0200 Subject: [PATCH] ROO-3741: Including banner.txt on project generation --- .../roo/project/MavenOperationsImpl.java | 43 +++++++++++++++++++ .../roo/project/banner/banner.txt | 9 ++++ 2 files changed, 52 insertions(+) create mode 100644 runtime/project/src/main/resources/org/springframework/roo/project/banner/banner.txt diff --git a/runtime/project/src/main/java/org/springframework/roo/project/MavenOperationsImpl.java b/runtime/project/src/main/java/org/springframework/roo/project/MavenOperationsImpl.java index 3940b8b26f..1b55e1346e 100644 --- a/runtime/project/src/main/java/org/springframework/roo/project/MavenOperationsImpl.java +++ b/runtime/project/src/main/java/org/springframework/roo/project/MavenOperationsImpl.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -27,6 +29,7 @@ import org.springframework.roo.project.packaging.PackagingProvider; import org.springframework.roo.project.packaging.PackagingProviderRegistry; import org.springframework.roo.support.logging.HandlerUtils; +import org.springframework.roo.support.osgi.OSGiUtils; import org.springframework.roo.support.util.DomUtils; import org.springframework.roo.support.util.FileUtils; import org.springframework.roo.support.util.XmlUtils; @@ -193,6 +196,9 @@ public void createMultimoduleProject(final JavaPackage topLevelPackage, final St createSpringBootApplicationClass(topLevelPackage, projectName); createApplicationTestsClass(topLevelPackage, projectName); + // ROO-3741: Including banner.txt on application module + addBannerFile(getPomFromModuleName("application")); + // Create standard project modules if (multimodule == Multimodule.STANDARD) { createModule(pom, "model", jarPackagingProvider, "model"); @@ -256,6 +262,43 @@ public void createProject(final JavaPackage topLevelPackage, final String projec // ROO-3687: Generates necessary Spring Boot artifacts createSpringBootApplicationClass(topLevelPackage, projectName); createApplicationTestsClass(topLevelPackage, projectName); + + // ROO-3741: Including banner.txt + addBannerFile(getPomFromModuleName("")); + } + + /** + * This method creates a banner.txt file inside generated project that + * will be displayed when the generated Spring Boot application starts. + * + * @param Pom module where banner.txt should be generated + */ + private void addBannerFile(Pom module) { + + LogicalPath resourcesPath = + LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName()); + + String sourceAntPath = "banner/banner.txt"; + String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); + + if (!getFileManager().exists(targetDirectory)) { + getFileManager().createDirectory(targetDirectory); + } + + final String path = FileUtils.getPath(getClass(), sourceAntPath); + final Iterable urls = OSGiUtils.findEntriesByPattern(context, path); + Validate.notNull(urls, "Could not search bundles for resources for Ant Path '%s'", path); + for (final URL url : urls) { + final String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1); + try { + String contents = IOUtils.toString(url); + getFileManager().createOrUpdateTextFileIfRequired(targetDirectory + fileName, contents, + false); + } catch (final Exception e) { + throw new IllegalStateException(e); + } + + } } /** diff --git a/runtime/project/src/main/resources/org/springframework/roo/project/banner/banner.txt b/runtime/project/src/main/resources/org/springframework/roo/project/banner/banner.txt new file mode 100644 index 0000000000..182afc09ea --- /dev/null +++ b/runtime/project/src/main/resources/org/springframework/roo/project/banner/banner.txt @@ -0,0 +1,9 @@ +${AnsiColor.GREEN} _ + ___ _ __ _ __(_)_ __ __ _ _ __ ___ ___ +/ __| '_ \| '__| | '_ \ / _` | '__/ _ \ / _ \ +\__ \ |_) | | | | | | | (_| | | | (_) | (_) | +|___/ .__/|_| |_|_| |_|\__, |_| \___/ \___/ + |_| |___/ + +${AnsiColor.BRIGHT_RED}Spring application made with Spring Roo 2.0 +Doubts? http://projects.spring.io/spring-roo/${AnsiColor.DEFAULT}