@Override public String getViewsFolder(String moduleName) { return pathResolver.getIdentifier(moduleName, Path.SRC_MAIN_RESOURCES, "/templates"); }
@Override public String getTemplatesLocation() { String thymeleafTemplatesLocation = projectSettings.getProperty(SPRING_ROO_THYMELEAF_TEMPLATES_LOCATION); if (thymeleafTemplatesLocation != null) { return pathResolver.getIdentifier("", Path.ROOT_ROO_CONFIG, thymeleafTemplatesLocation); } return pathResolver.getIdentifier("", Path.ROOT_ROO_CONFIG, "templates/thymeleaf/default"); }
@Override public String getSpringConfigLocation(String moduleName, String profile) { return pathResolver.getIdentifier(getApplicationConfigFileLocation(moduleName), getAppliCationConfigFileName(profile)); }
public String createArtifacts(final JavaPackage topLevelPackage, final String nullableProjectName, final String javaVersion, final GAV parentPom, final String module, final ProjectOperations projectOperations) { // Already created by the creator addon return projectOperations.getPathResolver().getIdentifier( LogicalPath.getInstance(Path.ROOT, ""), "pom.xml"); }
@Override public String getSpringConfigLocation(String moduleName) { return pathResolver.getIdentifier(getApplicationConfigFileLocation(moduleName), getAppliCationConfigFileName(null)); }
@Override public Map<String, String> getProperties(final LogicalPath propertyFilePath, final String propertyFilename) { Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties(); try { if (getFileManager().exists(filePath)) { loadProperties(props, new BufferedInputStream(new FileInputStream(filePath))); } else { throw new IllegalStateException(String.format( "ERROR: '%s' properties file doesn't exists.", filePath)); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } final Map<String, String> result = new HashMap<String, String>(); for (final Object key : props.keySet()) { result.put(key.toString(), props.getProperty(key.toString())); } return Collections.unmodifiableMap(result); }
private void writeTextFile(final String fullPathFromRoot, final String message, String folder) { Validate.notBlank(fullPathFromRoot, "Text file name to write is required"); Validate.notBlank(message, "Message required"); MutableFile mutableFile; if (folder != null) { LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + fullPathFromRoot)); } else { LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, fullPathFromRoot)); } OutputStream outputStream = null; try { outputStream = mutableFile.getOutputStream(); IOUtils.write(message, outputStream); } catch (final IOException ioe) { throw new IllegalStateException(ioe); } finally { IOUtils.closeQuietly(outputStream); } }
private void copyFile(String fileName, String folder) { String file; LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); if (folder != null) { file = pathResolver.getIdentifier(rootPath, folder + "/src/main/resources/" + fileName); } else { file = pathResolver.getIdentifier(rootPath, fileName); } InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = FileUtils.getInputStream(getClass(), "resources/" + fileName); if (!fileManager.exists(file)) { outputStream = fileManager.createFile(file).getOutputStream(); } if (outputStream != null) { IOUtils.copy(inputStream, outputStream); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } finally { IOUtils.closeQuietly(inputStream); if (outputStream != null) { IOUtils.closeQuietly(outputStream); } } }
getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties();
@Override public String getProperty(LogicalPath propertyFilePath, String propertyFilename, String prefix, String key) { Validate.notNull(prefix, "Prefix could be blank but not null"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); Validate.notBlank(key, "Key required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); MutableFile mutableFile = null; final Properties props = new Properties(); if (getFileManager().exists(filePath)) { mutableFile = getFileManager().updateFile(filePath); loadProperties(props, mutableFile.getInputStream()); } else { return null; } // Including prefix if needed if (StringUtils.isNotBlank(prefix)) { key = prefix.concat(".").concat(key); } return props.getProperty(key); }
@Override public void removePropertiesByPrefix(LogicalPath propertyFilePath, String propertyFilename, String prefix) { Validate.notBlank(prefix, "Prefix required"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); MutableFile mutableFile = null; final Properties props = new Properties(); if (getFileManager().exists(filePath)) { mutableFile = getFileManager().updateFile(filePath); loadProperties(props, mutableFile.getInputStream()); } else { throw new IllegalStateException(String.format("ERROR: '%s' properties file doesn't exists.", filePath)); } for (Entry property : props.entrySet()) { String key = (String) property.getKey(); if (key != null && key.startsWith(prefix)) { props.remove(key); } } storeProps(props, mutableFile.getOutputStream(), "Updated at " + new Date()); }
@Override public void removeProperty(LogicalPath propertyFilePath, String propertyFilename, String prefix, String key) { Validate.notNull(prefix, "Prefix could be blank but not null"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); Validate.notBlank(key, "Key required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); MutableFile mutableFile = null; final Properties props = new Properties(); if (getFileManager().exists(filePath)) { mutableFile = getFileManager().updateFile(filePath); loadProperties(props, mutableFile.getInputStream()); } else { throw new IllegalStateException(String.format("ERROR: '%s' properties file doesn't exists.", filePath)); } // Including prefix if needed if (StringUtils.isNotBlank(prefix)) { key = prefix.concat(".").concat(key); } if (props.containsKey(key)) { props.remove(key); storeProps(props, mutableFile.getOutputStream(), "Updated at " + new Date()); } }
/** * Writes the given Maven POM to disk * * @param pom the POM to write (required) */ private void writePomFile(final Document pom, String folder) { MutableFile pomFile; if (folder != null) { LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); pomFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + POM_XML)); } else { LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); pomFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, POM_XML)); } XmlUtils.writeXml(pomFile.getOutputStream(), pom); }
LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName()); String filePath = getPathResolver().getIdentifier(resourcesPath, "application-dev.properties"); MutableFile appDevMutableFile = null; final Properties props = new Properties();
/** * Return a list of installed languages in the provided application module. * * @param moduleName * the module name to search for installed languages. * @return a list with the available languages. */ @Override public List<I18n> getInstalledLanguages(String moduleName) { final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); // Create list for installed languages List<I18n> installedLanguages = new ArrayList<I18n>(); // Get all available languages Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages(); for (I18n i18n : supportedLanguages) { String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage()); String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle); if (getFileManager().exists(bundlePath)) { installedLanguages.add(i18n); } } // Always add English language as default installedLanguages.add(new EnglishLanguage()); return Collections.unmodifiableList(installedLanguages); }
pathResolver.getIdentifier(moduleName, Path.SRC_MAIN_RESOURCES, "/templates/".concat(this.flowName)); if (fileManager.exists(targetDirectory)) {
/** * 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); } } }
fileManager.createFile(pathResolver.getIdentifier(rootPath, "src/main/assembly/repo-assembly.xml"));
/** * Writes a label with a default exception message on messages.properties files * * @param exception * @param moduleName */ private void addExceptionLabel(JavaType exception, String moduleName) { if (getProjectOperations().isMultimoduleProject()) { Validate.notBlank(moduleName, "Module name is required"); } final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); final String exceptionName = exception.getSimpleTypeName(); final String labelKey = LABEL_PREFIX.concat(exceptionName.toLowerCase()); Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages(); for (I18n i18n : supportedLanguages) { String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage()); String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle); if (getFileManager().exists(bundlePath)) { getPropFilesManager().addPropertyIfNotExists(resourcesPath, messageBundle, labelKey, String.format(LABEL_MESSAGE, exceptionName), true); } } // Always update english message bundles getPropFilesManager().addPropertyIfNotExists(resourcesPath, "messages.properties", labelKey, String.format(LABEL_MESSAGE, exceptionName), true); }
/** * Add labels to all installed languages * * @param moduleName * @param labels */ @Override public void addOrUpdateLabels(String moduleName, final Map<String, String> labels) { final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages(); for (I18n i18n : supportedLanguages) { String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage()); String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle); if (getFileManager().exists(bundlePath)) { // Adding labels if not exists already getPropFilesManager().addPropertiesIfNotExists(resourcesPath, messageBundle, labels, true, false); } } // Allways update english message bundles if label not exists already getPropFilesManager().addPropertiesIfNotExists(resourcesPath, "messages.properties", labels, true, false); }