/** * Returns the {@link LogicalPath} for this path in the given module * * @param moduleName can be blank for the root or only module * @return a non-<code>null</code> instance */ public LogicalPath getModulePathId(final String moduleName) { return LogicalPath.getInstance(this, moduleName); }
/** * Method that get application config file location * * @return Path where application config file is located */ private LogicalPath getApplicationConfigFileLocation(String moduleName) { Validate.notNull(moduleName, "Module name is required"); LogicalPath location = LogicalPath.getInstance(DEFAULT_APPLICATION_CONFIG_FILE_LOCATION, moduleName); // ROO-3706: Check if exists some specific configuration to the // location of application config properties file String fileLocationShellConfig = settingsService.getProperty(CONFIG_FILE_LOCATION_SHELL_PROPERTY); if (fileLocationShellConfig != null && StringUtils.isNotBlank(fileLocationShellConfig)) { location = LogicalPath.getInstance(Path.ROOT, fileLocationShellConfig); } return location; }
public String getIdentifier(final String moduleName, final Path path, final String relativePath) { return getIdentifier(LogicalPath.getInstance(path, moduleName), relativePath); }
public LogicalPath convertFromText(final String value, final Class<?> targetType, final String optionContext) { LogicalPath logicalPath = LogicalPath.getInstance(value); if (logicalPath.getModule().equals("FOCUSED")) { logicalPath = LogicalPath.getInstance(logicalPath.getPath(), projectOperations.getFocusedModuleName()); } return logicalPath; }
/** * Returns the {@link LogicalPath} of the metadata item with the given id. * * @param metadataId must be a valid metadata instance id * @return a non-<code>null</code> path */ public static LogicalPath getPath(final String metadataId) { Validate.isTrue(MetadataIdentificationUtils.isIdentifyingInstance(metadataId), "Metadata id '%s' does not appear to be a valid identifier", metadataId); final String instanceKey = MetadataIdentificationUtils.getMetadataInstance(metadataId); final int index = instanceKey.indexOf("?"); return LogicalPath.getInstance(instanceKey.substring(0, index)); }
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"); }
/** * Parses the user project path from the given metadata ID. * * @param metadataClass the fully-qualified name of the metadata type * (required) * @param metadataId the ID of the metadata instance (must identify an * instance of the given metadata class) * @return a non-<code>null</code> path */ public static LogicalPath getPath(final String providesType, final String metadataIdentificationString) { Validate .isTrue( isValid(providesType, metadataIdentificationString), "Metadata identification string '%s' does not appear to be a valid physical type identifier", metadataIdentificationString); final String instance = MetadataIdentificationUtils.getMetadataInstance(metadataIdentificationString); final int index = instance.indexOf("?"); return LogicalPath.getInstance(instance.substring(0, index)); }
public String getFocusedIdentifier(final Path path, final String relativePath) { return getIdentifier( LogicalPath.getInstance(path, pomManagementService.getFocusedModuleName()), relativePath); }
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); } }
@Override public SortedSet<String> getPropertyKeys(boolean includeValues) { return getPropFilesManager().getPropertyKeys( LogicalPath.getInstance(PROJECT_CONFIG_FOLDER_LOCATION, ""), getProjectSettingsFileName(), includeValues); }
@Override public String getProperty(final String key) { return getPropFilesManager().getProperty( LogicalPath.getInstance(PROJECT_CONFIG_FOLDER_LOCATION, ""), getProjectSettingsFileName(), key); }
@Override public void addProperty(final String key, final String value, final boolean force) { getPropFilesManager().addPropertyIfNotExists( LogicalPath.getInstance(PROJECT_CONFIG_FOLDER_LOCATION, ""), getProjectSettingsFileName(), key, value, force); }
@Override public void removeProperty(final String key) { getPropFilesManager().removeProperty( LogicalPath.getInstance(PROJECT_CONFIG_FOLDER_LOCATION, ""), getProjectSettingsFileName(), key); }
@Override public Map<String, String> getProperties() { return getPropFilesManager().getProperties( LogicalPath.getInstance(PROJECT_CONFIG_FOLDER_LOCATION, ""), getProjectSettingsFileName()); }
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); } } }
/** * 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); }
/** * 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); }
/** * 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); }
@Override public JavaType createDataOnDemand(JavaType entity) { Validate.notNull(entity, "Entity to produce a data on demand provider for is required"); JavaType dodClass = getDataOnDemand(entity); if (dodClass != null) { return dodClass; } // Add plugin to generate test jar addMavenJarPlugin(entity.getModule()); // Create the JavaType for DoD class JavaType name = new JavaType(entity.getPackage().getFullyQualifiedPackageName().concat(".dod.") .concat(entity.getSimpleTypeName()).concat("DataOnDemand"), entity.getModule()); // Obatain test path for the module of the new class final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, name.getModule()); Validate.notNull(path, "Location of the new data on demand provider is required"); // Create DoD configuration class createDataOnDemandConfiguration(entity.getModule()); // Create entity factories for the given entity and its related entities createEntityFactory(entity); // Create data on demand class return newDataOnDemandClass(entity, name); }
/** * 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); }