use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class TestOperationsImpl method addIntegrationTestDependencies.
/**
* Add needed dependencies and plugins to run created integration tests.
*
* @param module {@link String} the module name where add dependencies.
*/
private void addIntegrationTestDependencies(String moduleName) {
// Add dependencies if needed
projectOperations.addDependency(moduleName, JUNIT_DEPENDENCY);
projectOperations.addDependency(moduleName, ASSERTJ_CORE_DEPENDENCY);
projectOperations.addDependency(moduleName, SPRING_TEST_DEPENDENCY);
projectOperations.addDependency(moduleName, SPRING_BOOT_TEST_DEPENDENCY);
// Add plugin maven-failsafe-plugin
Pom module = projectOperations.getPomFromModuleName(moduleName);
// Stop if the plugin is already installed
for (final Plugin plugin : module.getBuildPlugins()) {
if (plugin.getArtifactId().equals("maven-failsafe-plugin")) {
return;
}
}
final Element configuration = XmlUtils.getConfiguration(getClass());
final Element plugin = XmlUtils.findFirstElement("/configuration/plugin", configuration);
// Now install the plugin itself
if (plugin != null) {
projectOperations.addBuildPlugin(moduleName, new Plugin(plugin));
}
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class ControllerCommands method getInstalledControllerMVCResponseTypes.
/**
* This method gets all implementations of ControllerMVCResponseService
* interface to be able to locate all installed ControllerMVCResponseService
*
* @return Map with responseTypes identifier and the
* ControllerMVCResponseService implementation
*/
public Map<String, ControllerMVCResponseService> getInstalledControllerMVCResponseTypes() {
try {
ServiceReference<?>[] references = this.context.getAllServiceReferences(ControllerMVCResponseService.class.getName(), null);
for (ServiceReference<?> ref : references) {
ControllerMVCResponseService responseTypeService = (ControllerMVCResponseService) this.context.getService(ref);
boolean isInstalled = false;
for (Pom module : getProjectOperations().getPoms()) {
if (responseTypeService.isInstalledInModule(module.getModuleName())) {
isInstalled = true;
break;
}
}
if (isInstalled) {
responseTypes.put(responseTypeService.getResponseType(), responseTypeService);
}
}
return responseTypes;
} catch (InvalidSyntaxException e) {
LOGGER.warning("Cannot load ControllerMVCResponseService on ControllerCommands.");
return null;
}
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class DefaultSecurityProvider method isInstalledInModule.
@Override
public boolean isInstalledInModule(String moduleName) {
boolean isInstalledInModule = false;
Pom module = getProjectOperations().getPomFromModuleName(moduleName);
Set<Dependency> starter = module.getDependenciesExcludingVersion(SPRING_SECURITY_STARTER);
if (!starter.isEmpty()) {
isInstalledInModule = true;
}
return isInstalledInModule;
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class SpringletsJpaSecurityProvider method isInstalledInModule.
@Override
public boolean isInstalledInModule(String moduleName) {
boolean isInstalledInModule = false;
Pom module = getProjectOperations().getPomFromModuleName(moduleName);
Set<Dependency> starter = module.getDependenciesExcludingVersion(SPRINGLETS_SECURITY_AUTHENTICATION_STARTER);
if (!starter.isEmpty()) {
isInstalledInModule = true;
}
return isInstalledInModule;
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class JsonControllerTestCreator 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 JSON 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_JSON), "Type must be a Roo JSON 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 JSON controllers.");
Validate.isTrue(dodCreators.size() == 1, "More than 1 valid 'DataOnDemandCreatorProvider' found for JSON 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 @RooJsonControllerIntegrationTest to source file
AnnotationMetadataBuilder rooIntegrationTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JSON_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