Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
ROO-3741: Including banner.txt on project generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcagarcia committed Apr 29, 2016
1 parent 57a196a commit e67974c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<URL> 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);
}

}
}

/**
Expand Down
@@ -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}

0 comments on commit e67974c

Please sign in to comment.