Search in sources :

Example 26 with Dependency

use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.

the class PomTest method testCanAddNewDependencyWhenOwnTypeIsNonStandard.

@Test
public void testCanAddNewDependencyWhenOwnTypeIsNonStandard() {
    // Set up
    final Dependency mockNewDependency = mock(Dependency.class);
    when(mockNewDependency.getType()).thenReturn(DependencyType.WAR);
    final Pom pom = getMinimalPom("custom");
    // Invoke and check
    assertTrue(pom.canAddDependency(mockNewDependency, true));
}
Also used : Dependency(org.springframework.roo.project.Dependency) Test(org.junit.Test)

Example 27 with Dependency

use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.

the class PomTest method testHasDependencyExcludingVersionWhenDependencyHasDifferentType.

@Test
public void testHasDependencyExcludingVersionWhenDependencyHasDifferentType() {
    // Set up
    final Dependency mockExistingDependency = getMockDependency(DEPENDENCY_GROUP_ID, DEPENDENCY_ARTIFACT_ID, "1.0", DependencyType.JAR);
    final Pom pom = getMinimalPom(JAR, mockExistingDependency);
    final Dependency mockOtherDependency = getMockDependency(DEPENDENCY_GROUP_ID, DEPENDENCY_ARTIFACT_ID, "1.0", DependencyType.OTHER);
    // Invoke and check
    assertFalse(pom.hasDependencyExcludingVersion(mockOtherDependency));
}
Also used : Dependency(org.springframework.roo.project.Dependency) Test(org.junit.Test)

Example 28 with Dependency

use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.

the class MailOperationsImpl method isInstalledInModule.

@Override
public boolean isInstalledInModule(String moduleName) {
    Pom currentPom = getProjectOperations().getPomFromModuleName(moduleName);
    List<Dependency> dependencies = new ArrayList<Dependency>();
    dependencies.add(DEPENDENCY_SPRING_BOOT_STARTER_MAIL);
    dependencies.add(DEPENDENCY_SPRINGLETS_STARTER_MAIL);
    return currentPom.isAllDependenciesRegistered(dependencies);
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.springframework.roo.project.Dependency) Pom(org.springframework.roo.project.maven.Pom)

Example 29 with Dependency

use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.

the class DtoOperationsImpl method addFieldsToProjection.

/**
 * Removes persistence annotations of provided fields and adds them to a
 * ClassOrInterfaceTypeDetailsBuilder representing a Projection in construction.
 * Also adds final modifier to fields if required.
 *
 * @param projectionBuilder the ClassOrInterfaceTypeDetailsBuilder for building the
 *            Projection class.
 * @param fieldsToAdd the List<FieldMetadata> to add.
 */
private void addFieldsToProjection(ClassOrInterfaceTypeDetailsBuilder projectionBuilder, Map<String, FieldMetadata> fieldsToAdd) {
    Iterator<Entry<String, FieldMetadata>> iterator = fieldsToAdd.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, FieldMetadata> entry = iterator.next();
        FieldMetadata field = entry.getValue();
        // List and Set types require special management
        FieldMetadataBuilder fieldBuilder = null;
        FieldDetails fieldDetails = null;
        if (field.getFieldType().getFullyQualifiedTypeName().equals("java.util.Set")) {
            JavaType fieldType = field.getFieldType().getParameters().get(0);
            fieldDetails = new SetField(projectionBuilder.getDeclaredByMetadataId(), new JavaType(JdkJavaType.SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), field.getFieldName(), fieldType, null, null, true);
            fieldBuilder = new FieldMetadataBuilder(fieldDetails);
            fieldBuilder.setModifier(field.getModifier());
            fieldBuilder.setAnnotations(field.getAnnotations());
        } else if (field.getFieldType().getFullyQualifiedTypeName().equals("java.util.List")) {
            JavaType fieldType = field.getFieldType().getParameters().get(0);
            fieldDetails = new ListField(projectionBuilder.getDeclaredByMetadataId(), new JavaType(JdkJavaType.LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), field.getFieldName(), fieldType, null, null, true);
            fieldBuilder = new FieldMetadataBuilder(fieldDetails);
            fieldBuilder.setModifier(field.getModifier());
            fieldBuilder.setAnnotations(field.getAnnotations());
        } else {
            // Can't just copy FieldMetadata because field.declaredByMetadataId will be the same
            fieldBuilder = new FieldMetadataBuilder(projectionBuilder.getDeclaredByMetadataId(), field);
        }
        // Add dependency between modules
        typeLocationService.addModuleDependency(projectionBuilder.getName().getModule(), field.getFieldType());
        // Set new fieldName
        fieldBuilder.setFieldName(new JavaSymbolName(entry.getKey()));
        // If it is a CollectionField it needs an initializer
        String initializer = null;
        if (fieldDetails instanceof CollectionField) {
            final CollectionField collectionField = (CollectionField) fieldDetails;
            initializer = "new " + collectionField.getInitializer() + "()";
        } else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
            initializer = "new Date()";
        }
        fieldBuilder.setFieldInitializer(initializer);
        // Remove persistence annotations
        List<AnnotationMetadata> annotations = field.getAnnotations();
        for (AnnotationMetadata annotation : annotations) {
            if (annotation.getAnnotationType().getFullyQualifiedTypeName().contains("javax.persistence")) {
                fieldBuilder.removeAnnotation(annotation.getAnnotationType());
            } else if (annotation.getAnnotationType().getFullyQualifiedTypeName().startsWith("javax.validation")) {
                // Add validation dependency
                projectOperations.addDependency(projectionBuilder.getName().getModule(), new Dependency("javax.validation", "validation-api", null));
            } else if (annotation.getAnnotationType().equals(RooJavaType.ROO_JPA_RELATION)) {
                fieldBuilder.removeAnnotation(annotation.getAnnotationType());
            }
        }
        fieldBuilder.setModifier(Modifier.PRIVATE);
        // Build field
        FieldMetadata projectionField = fieldBuilder.build();
        // Add field to DTO
        projectionBuilder.addField(projectionField);
    }
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) ListField(org.springframework.roo.classpath.operations.jsr303.ListField) Dependency(org.springframework.roo.project.Dependency) SetField(org.springframework.roo.classpath.operations.jsr303.SetField) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder) Entry(java.util.Map.Entry) JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) DateField(org.springframework.roo.classpath.operations.jsr303.DateField) CollectionField(org.springframework.roo.classpath.operations.jsr303.CollectionField)

Example 30 with Dependency

use of org.springframework.roo.project.Dependency in project spring-roo by spring-projects.

the class RepositoryJpaTestCreator 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 Repository
    ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type);
    Validate.notNull(cid.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA), "Type must be a Roo JPA Repository type.");
    // Get the repository managed entity
    RepositoryJpaAnnotationValues repositoryAnnotationValues = new RepositoryJpaAnnotationValues(cid);
    JavaType managedEntity = repositoryAnnotationValues.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 JPA repositories.");
    Validate.isTrue(dodCreators.size() == 1, "More than 1 valid 'DataOnDemandCreatorProvider' found for JPA repositories. %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 @RooRepositoryJpaIntegrationTest to source file
    AnnotationMetadataBuilder rooIntegrationTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_REPOSITORY_JPA_INTEGRATION_TEST);
    rooIntegrationTestAnnotation.addClassAttribute("targetClass", type);
    rooIntegrationTestAnnotation.addClassAttribute("dodConfigurationClass", creator.getDataOnDemandConfiguration());
    rooIntegrationTestAnnotation.addClassAttribute("dodClass", creator.getDataOnDemand(managedEntity));
    // 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());
}
Also used : RepositoryJpaAnnotationValues(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaAnnotationValues) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) Dependency(org.springframework.roo.project.Dependency) DataOnDemandCreatorProvider(org.springframework.roo.addon.test.providers.DataOnDemandCreatorProvider) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) Pom(org.springframework.roo.project.maven.Pom)

Aggregations

Dependency (org.springframework.roo.project.Dependency)34 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 JavaType (org.springframework.roo.model.JavaType)10 RooJavaType (org.springframework.roo.model.RooJavaType)10 ArrayList (java.util.ArrayList)9 Pom (org.springframework.roo.project.maven.Pom)9 Test (org.junit.Test)8 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)8 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)7 Element (org.w3c.dom.Element)6 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)4 DataOnDemandCreatorProvider (org.springframework.roo.addon.test.providers.DataOnDemandCreatorProvider)3 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)3 JdkJavaType (org.springframework.roo.model.JdkJavaType)3 JpaJavaType (org.springframework.roo.model.JpaJavaType)3 SpringJavaType (org.springframework.roo.model.SpringJavaType)3 ControllerAnnotationValues (org.springframework.roo.addon.web.mvc.controller.addon.ControllerAnnotationValues)2 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)2 Property (org.springframework.roo.project.Property)2 Node (org.w3c.dom.Node)2