use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.
the class ServiceOperationsImpl method createServiceInterface.
/**
* Method that creates the service interface
*
* @param domainType
* @param interfaceType
*/
private void createServiceInterface(final JavaType domainType, final JavaType interfaceType) {
Validate.notNull(interfaceType.getModule(), "JavaType %s does not have a module", domainType);
// Checks if new service interface already exists.
final String interfaceIdentifier = pathResolver.getCanonicalPath(interfaceType.getModule(), Path.SRC_MAIN_JAVA, interfaceType);
if (fileManager.exists(interfaceIdentifier)) {
// Type already exists - nothing to do
return;
}
// Validate that user provides a valid entity
Validate.notNull(domainType, "ERROR: Domain type required to generate service");
ClassOrInterfaceTypeDetails entityDetails = typeLocationService.getTypeDetails(domainType);
Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "ERROR: Provided entity should be annotated with @RooJpaEntity");
// Generating @RooService annotation
final AnnotationMetadataBuilder interfaceAnnotationMetadata = new AnnotationMetadataBuilder(ROO_SERVICE);
interfaceAnnotationMetadata.addAttribute(new ClassAttributeValue(new JavaSymbolName("entity"), domainType));
// Creating interface builder
final String interfaceMid = PhysicalTypeIdentifier.createIdentifier(interfaceType, pathResolver.getPath(interfaceIdentifier));
final ClassOrInterfaceTypeDetailsBuilder interfaceTypeBuilder = new ClassOrInterfaceTypeDetailsBuilder(interfaceMid, PUBLIC, interfaceType, PhysicalTypeCategory.INTERFACE);
// Adding @RooService annotation to current interface
interfaceTypeBuilder.addAnnotation(interfaceAnnotationMetadata.build());
// Write service interface on disk
typeManagementService.createOrUpdateTypeOnDisk(interfaceTypeBuilder.build());
// Add dependencies between modules
projectOperations.addModuleDependency(interfaceType.getModule(), domainType.getModule());
// Add springlets-data-commons dependency
projectOperations.addDependency(interfaceType.getModule(), new Dependency("io.springlets", "springlets-data-commons", null));
}
use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.
the class ControllerOperationsImpl method setup.
/**
* This operation will setup Spring MVC on generated project.
*
* @param module
* Pom module where Spring MVC should be included
* @param usesDefaultModule
* boolean that indicates if the setup command is using the
* default application module
*/
@Override
public void setup(Pom module, boolean usesDefaultModule) {
// If provided module is null, use the focused one
if (module == null) {
module = getProjectOperations().getFocusedModule();
}
// Checks that provided module matches with Application properties
// modules
Validate.isTrue(getTypeLocationService().hasModuleFeature(module, ModuleFeatureName.APPLICATION), "ERROR: You are trying to install Spring MVC inside module that doesn't match with APPLICATION modules features. " + "Use --module parameter to specify a valid APPLICATION module where install Spring MVC.");
// message
if (isInstalledInModule(module.getModuleName())) {
String message = "";
if (usesDefaultModule) {
message = String.format("the default module '%s'.", module.getModuleName());
} else {
message = String.format("the provided module '%s'.", module.getModuleName());
}
LOGGER.log(Level.INFO, String.format("INFO: Spring MVC is already installed in %s", message));
return;
}
// Add Spring MVC dependency
getProjectOperations().addDependency(module.getModuleName(), new Dependency("org.springframework.boot", "spring-boot-starter-web", null));
// Add DateTime dependency
getProjectOperations().addDependency(module.getModuleName(), new Dependency("joda-time", "joda-time", null));
// Add TracEE dependency and property
getProjectOperations().addProperty("", TRACEE_PROPERTY);
getProjectOperations().addDependency(module.getModuleName(), TRACEE_SPRINGMVC);
// Include Springlets Starter project dependencies and properties
getProjectOperations().addProperty("", SPRINGLETS_VERSION_PROPERTY);
getProjectOperations().addDependency(module.getModuleName(), SPRINGLETS_WEB_STARTER);
// Create WebMvcConfiguration.java class
JavaType webMvcConfiguration = new JavaType(String.format("%s.config.WebMvcConfiguration", getTypeLocationService().getTopLevelPackageForModule(module)), module.getModuleName());
Validate.notNull(webMvcConfiguration.getModule(), "ERROR: Module name is required to generate a valid JavaType");
// Checks if new service interface already exists.
final String webMvcConfigurationIdentifier = getPathResolver().getCanonicalPath(webMvcConfiguration.getModule(), Path.SRC_MAIN_JAVA, webMvcConfiguration);
if (!getFileManager().exists(webMvcConfigurationIdentifier)) {
// Creating class builder
final String mid = PhysicalTypeIdentifier.createIdentifier(webMvcConfiguration, getPathResolver().getPath(webMvcConfigurationIdentifier));
final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, webMvcConfiguration, PhysicalTypeCategory.CLASS);
// Generating @RooWebMvcConfiguration annotation
final AnnotationMetadataBuilder annotationMetadata = new AnnotationMetadataBuilder(RooJavaType.ROO_WEB_MVC_CONFIGURATION);
typeBuilder.addAnnotation(annotationMetadata.build());
// Write new class disk
getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
}
// Create JSON configuration class
createDomainModelModule(module);
// Adding spring.jackson.serialization.indent-output property
getApplicationConfigService().addProperty(module.getModuleName(), "spring.jackson.serialization.indent-output", "true", "dev", true);
}
use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.
the class JspOperationsImpl method updateConfiguration.
/**
* Adds Tiles Maven dependencies and updates the MVC config to include Tiles
* view support
*/
private void updateConfiguration() {
// Add tiles dependencies to pom
final Element configuration = XmlUtils.getRootElement(getClass(), "tiles/configuration.xml");
final List<Dependency> dependencies = new ArrayList<Dependency>();
final List<Element> springDependencies = XmlUtils.findElements("/configuration/tiles/dependencies/dependency", configuration);
for (final Element dependencyElement : springDependencies) {
dependencies.add(new Dependency(dependencyElement));
}
getProjectOperations().addDependencies(getProjectOperations().getFocusedModuleName(), dependencies);
// Add config to MVC app context
final String mvcConfig = getPathResolver().getFocusedIdentifier(SRC_MAIN_WEBAPP, "WEB-INF/spring/webmvc-config.xml");
final Document mvcConfigDocument = XmlUtils.readXml(fileManager.getInputStream(mvcConfig));
final Element beans = mvcConfigDocument.getDocumentElement();
if (XmlUtils.findFirstElement("/beans/bean[@id = 'tilesViewResolver']", beans) != null || XmlUtils.findFirstElement("/beans/bean[@id = 'tilesConfigurer']", beans) != null) {
// Tiles is already configured, nothing to do
return;
}
final Document configDoc = getDocumentTemplate("tiles/tiles-mvc-config-template.xml");
final Element configElement = configDoc.getDocumentElement();
final List<Element> tilesConfig = XmlUtils.findElements("/config/bean", configElement);
for (final Element bean : tilesConfig) {
final Node importedBean = mvcConfigDocument.importNode(bean, true);
beans.appendChild(importedBean);
}
fileManager.createOrUpdateTextFileIfRequired(mvcConfig, XmlUtils.nodeToString(mvcConfigDocument), true);
}
use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.
the class ThymeleafControllerTestCreator method createIntegrationTest.
@Override
public void createIntegrationTest(JavaType type, Pom module) {
Validate.notNull(type, "Class to produce an integration test class for is required");
// Check if provided JavaType is a Thymeleaf Controller
ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type);
Validate.notNull(cid.getAnnotation(RooJavaType.ROO_CONTROLLER), "Type must be a Roo controller.");
Validate.notNull(cid.getAnnotation(RooJavaType.ROO_THYMELEAF), "Type must be a Roo Thymeleaf controller.");
// Add springlets-boot-starter-test dependency
projectOperations.addProperty("", SPRINGLETS_VERSION_PROPERTY);
projectOperations.addDependency(module.getModuleName(), SPRINGLETS_BOOT_STARTER_TEST_DEPENDENCY);
// Get the controller managed entity
ControllerAnnotationValues controllerAnnotationValues = new ControllerAnnotationValues(cid);
JavaType managedEntity = controllerAnnotationValues.getEntity();
// Workaround to get a JavaType with not null module when recovering it
// from a ClassAttributeValue
managedEntity = new JavaType(managedEntity.getFullyQualifiedTypeName(), managedEntity.getArray(), managedEntity.getDataType(), managedEntity.getArgName(), managedEntity.getParameters(), typeLocationService.getTypeDetails(managedEntity).getType().getModule());
// Create Data On Demand artifacts for managed entity
List<DataOnDemandCreatorProvider> dodCreators = getValidDataOnDemandCreatorsForType(managedEntity);
Validate.isTrue(!dodCreators.isEmpty(), "Couldn't find any 'DataOnDemandCreatorProvider' for Thymeleaf controllers.");
Validate.isTrue(dodCreators.size() == 1, "More than 1 valid 'DataOnDemandCreatorProvider' found for Thymeleaf controllers. %s can't decide which one to use.", this.getClass().getName());
DataOnDemandCreatorProvider creator = dodCreators.get(0);
creator.createDataOnDemand(managedEntity);
// Add module dependency with test-jar dependency
if (projectOperations.isMultimoduleProject()) {
String managedEntityModuleName = managedEntity.getModule();
Pom managedEntityModule = projectOperations.getPomFromModuleName(managedEntityModuleName);
projectOperations.addDependency(module.getModuleName(), new Dependency(managedEntityModule.getGroupId(), managedEntityModule.getArtifactId(), "${project.version}", DependencyType.valueOfTypeCode("test-jar"), DependencyScope.TEST), true, true);
}
// Create integration test class
final JavaType name = new JavaType(type + "IT", module.getModuleName());
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, Path.SRC_TEST_JAVA.getModulePathId(module.getModuleName()));
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
// Add @RooThymeleafControllerIntegrationTest to source file
AnnotationMetadataBuilder rooIntegrationTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_THYMELEAF_CONTROLLER_INTEGRATION_TEST);
rooIntegrationTestAnnotation.addClassAttribute("targetClass", type);
// Create integration test class
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS);
cidBuilder.addAnnotation(rooIntegrationTestAnnotation);
// Write changes to disk
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
Aggregations