use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class EqualsMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = EqualsMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = EqualsMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class ToStringMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = ToStringMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = ToStringMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class JpaEntityMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = getType(metadataIdentificationString);
final LogicalPath path = PhysicalTypeIdentifierNamingUtils.getPath(PROVIDES_TYPE_STRING, metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class SeleniumOperationsImpl method generateTest.
/**
* Creates a new Selenium testcase
*
* @param controller the JavaType of the controller under test (required)
* @param name the name of the test case (optional)
* @param serverURL the URL of the Selenium server (optional)
*/
@Override
public void generateTest(final JavaType controller, String name, String serverURL) {
Validate.notNull(controller, "Controller type required");
final ClassOrInterfaceTypeDetails controllerTypeDetails = typeLocationService.getTypeDetails(controller);
Validate.notNull(controllerTypeDetails, "Class or interface type details for type '%s' could not be resolved", controller);
final LogicalPath path = PhysicalTypeIdentifier.getPath(controllerTypeDetails.getDeclaredByMetadataId());
final String webScaffoldMetadataIdentifier = WebScaffoldMetadata.createIdentifier(controller, path);
final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService.get(webScaffoldMetadataIdentifier);
Validate.notNull(webScaffoldMetadata, "Web controller '%s' does not appear to be an automatic, scaffolded controller", controller.getFullyQualifiedTypeName());
// allow the creation of new instances for the form backing object
if (!webScaffoldMetadata.getAnnotationValues().isCreate()) {
LOGGER.warning("The controller you specified does not allow the creation of new instances of the form backing object. No Selenium tests created.");
return;
}
if (!serverURL.endsWith("/")) {
serverURL = serverURL + "/";
}
final JavaType formBackingType = webScaffoldMetadata.getAnnotationValues().getFormBackingObject();
final String relativeTestFilePath = "selenium/test-" + formBackingType.getSimpleTypeName().toLowerCase() + ".xhtml";
final String seleniumPath = pathResolver.getFocusedIdentifier(Path.SRC_MAIN_WEBAPP, relativeTestFilePath);
final InputStream templateInputStream = FileUtils.getInputStream(getClass(), "selenium-template.xhtml");
Validate.notNull(templateInputStream, "Could not acquire selenium.xhtml template");
final Document document = XmlUtils.readXml(templateInputStream);
final Element root = (Element) document.getLastChild();
if (root == null || !"html".equals(root.getNodeName())) {
throw new IllegalArgumentException("Could not parse selenium test case template file!");
}
name = name != null ? name : "Selenium test for " + controller.getSimpleTypeName();
XmlUtils.findRequiredElement("/html/head/title", root).setTextContent(name);
XmlUtils.findRequiredElement("/html/body/table/thead/tr/td", root).setTextContent(name);
final Element tbody = XmlUtils.findRequiredElement("/html/body/table/tbody", root);
tbody.appendChild(openCommand(document, serverURL + projectOperations.getProjectName(projectOperations.getFocusedModuleName()) + "/" + webScaffoldMetadata.getAnnotationValues().getPath() + "?form"));
final ClassOrInterfaceTypeDetails formBackingTypeDetails = typeLocationService.getTypeDetails(formBackingType);
Validate.notNull(formBackingType, "Class or interface type details for type '%s' could not be resolved", formBackingType);
final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(getClass().getName(), formBackingTypeDetails);
// Add composite PK identifier fields if needed
for (final FieldMetadata field : persistenceMemberLocator.getEmbeddedIdentifierFields(formBackingType)) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(field);
final String fieldName = field.getFieldName().getSymbolName();
fieldBuilder.setFieldName(new JavaSymbolName(fieldName + "." + fieldName));
tbody.appendChild(typeCommand(document, fieldBuilder.build()));
}
}
// Add all other fields
final List<FieldMetadata> fields = webMetadataService.getScaffoldEligibleFieldMetadata(formBackingType, memberDetails, null);
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(typeCommand(document, field));
}
}
tbody.appendChild(clickAndWaitCommand(document, "//input[@id = 'proceed']"));
// Add verifications for all other fields
for (final FieldMetadata field : fields) {
final JavaType fieldType = field.getFieldType();
if (!fieldType.isCommonCollectionType() && !isSpecialType(fieldType)) {
tbody.appendChild(verifyTextCommand(document, formBackingType, field));
}
}
fileManager.createOrUpdateTextFileIfRequired(seleniumPath, XmlUtils.nodeToString(document), false);
manageTestSuite(relativeTestFilePath, name, serverURL);
// Install selenium-maven-plugin
installMavenPlugin();
}
use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.
the class WebFlowOperationsImpl method addLocalizedMessages.
/**
* Add this add-on localized messages from its message bundles to the project's
* message bundles, for each installed language, plus English. Existing messages
* will be replaced.
*
* @param moduleName the module name where the message bundles are.
* @param flowName the name/id of the flow to prefix the messages.
*/
private void addLocalizedMessages(String moduleName) {
// Install localized messages for each installed language
for (I18n i18n : i18nSupport.getSupportedLanguages()) {
if (i18n.getLanguage().equals(new EnglishLanguage().getLanguage())) {
continue;
}
// Get theme specific messages
InputStream themeMessagesInputStream = null;
try {
themeMessagesInputStream = FileUtils.getInputStream(getClass(), String.format("messages_%s.properties", i18n.getLocale()));
} catch (NullPointerException ex) {
LOGGER.warning(String.format("There aren't translations for %1$s language. Adding english messages to messages_%1$s.properties instead.", i18n.getLocale()));
themeMessagesInputStream = FileUtils.getInputStream(getClass(), String.format("messages.properties", i18n.getLocale()));
}
final Properties loadedProperties = propFilesManagerService.loadProperties(themeMessagesInputStream);
// Add theme messages to localized message bundle
final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName);
final String targetDirectory = pathResolver.getIdentifier(resourcesPath, "");
String bundlePath = String.format("%s%smessages_%s.properties", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, i18n.getLocale());
if (fileManager.exists(bundlePath)) {
Map<String, String> newProperties = new HashMap<String, String>();
for (Entry<Object, Object> entry : loadedProperties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
// Prefix with flow name
key = String.format("%s_%s", this.flowName.toLowerCase(), key);
newProperties.put(key, value);
newProperties.put("label_".concat(this.flowName.toLowerCase()), StringUtils.capitalize(this.flowName));
}
propFilesManagerService.addProperties(resourcesPath, String.format("messages_%s.properties", i18n.getLocale()), newProperties, true, true);
}
// Close InputStream
try {
themeMessagesInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Always install english messages
InputStream themeMessagesInputStream = FileUtils.getInputStream(getClass(), "messages.properties");
EnglishLanguage english = new EnglishLanguage();
final Properties loadedProperties = propFilesManagerService.loadProperties(themeMessagesInputStream);
// Add theme messages to localized message bundle
final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName);
final String targetDirectory = pathResolver.getIdentifier(resourcesPath, "");
String bundlePath = String.format("%s%smessages.properties", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, english.getLocale());
if (fileManager.exists(bundlePath)) {
Map<String, String> newProperties = new HashMap<String, String>();
for (Entry<Object, Object> entry : loadedProperties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
// Prefix with flow name
key = String.format("%s_%s", this.flowName.toLowerCase(), key);
newProperties.put(key, value);
newProperties.put("label_".concat(this.flowName.toLowerCase()), StringUtils.capitalize(this.flowName));
}
propFilesManagerService.addProperties(resourcesPath, "messages.properties", newProperties, true, true);
}
// Close InputStream
try {
themeMessagesInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations