Search in sources :

Example 1 with Repository

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

the class RepositoryJpaOperationsImpl method generateConfiguration.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void generateConfiguration(JavaType interfaceType, JavaType domainType) {
    final Element configuration = XmlUtils.getConfiguration(getClass());
    // Add querydsl dependency
    final List<Element> dependencies;
    final List<Element> plugins;
    if (getProjectOperations().isMultimoduleProject()) {
        dependencies = XmlUtils.findElements("/configuration/multimodule/dependencies/dependency", configuration);
        plugins = XmlUtils.findElements("/configuration/multimodule/plugins/plugin", configuration);
        // Add database test dependency
        getJpaOperations().addDatabaseDependencyWithTestScope(interfaceType.getModule(), null, null);
    } else {
        dependencies = XmlUtils.findElements("/configuration/monomodule/dependencies/dependency", configuration);
        plugins = XmlUtils.findElements("/configuration/monomodule/plugins/plugin", configuration);
    }
    for (final Element dependencyElement : dependencies) {
        getProjectOperations().addDependency(interfaceType.getModule(), new Dependency(dependencyElement));
    }
    // Add querydsl plugin
    Plugin queryDslPlugin = null;
    for (final Element pluginElement : plugins) {
        Plugin plugin = new Plugin(pluginElement);
        if (plugin.getArtifactId().equals("querydsl-maven-plugin")) {
            queryDslPlugin = plugin;
        }
        getProjectOperations().addBuildPlugin(interfaceType.getModule(), plugin);
    }
    if (getProjectOperations().isMultimoduleProject()) {
        if (queryDslPlugin == null) {
            throw new RuntimeException("Error: Missing QueryDSL plugin");
        }
        // Add entity package to find Q classes.
        Set<String> packages = new HashSet();
        for (ClassOrInterfaceTypeDetails cid : getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_REPOSITORY_JPA)) {
            if (cid.getType().getModule().equals(interfaceType.getModule())) {
                JavaType relatedEntity = (JavaType) cid.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA).getAttribute("entity").getValue();
                String module = getTypeLocationService().getTypeDetails(relatedEntity).getType().getModule();
                if (!packages.contains(module)) {
                    packages.add(module);
                    getProjectOperations().addPackageToPluginExecution(interfaceType.getModule(), queryDslPlugin, "generate-qtypes", getProjectOperations().getTopLevelPackage(module).getFullyQualifiedPackageName());
                }
            }
        }
        getProjectOperations().addPackageToPluginExecution(interfaceType.getModule(), queryDslPlugin, "generate-qtypes", getProjectOperations().getTopLevelPackage(domainType.getModule()).getFullyQualifiedPackageName());
    } else {
        // Add querydsl processor repository
        List<Element> repositories = XmlUtils.findElements("/configuration/monomodule/repositories/repository", configuration);
        for (final Element repositoryElement : repositories) {
            getProjectOperations().addRepository(interfaceType.getModule(), new Repository(repositoryElement));
        }
    }
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) Repository(org.springframework.roo.project.Repository) Element(org.w3c.dom.Element) Dependency(org.springframework.roo.project.Dependency) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) Plugin(org.springframework.roo.project.Plugin) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 JavaType (org.springframework.roo.model.JavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1 SpringJavaType (org.springframework.roo.model.SpringJavaType)1 Dependency (org.springframework.roo.project.Dependency)1 Plugin (org.springframework.roo.project.Plugin)1 Repository (org.springframework.roo.project.Repository)1 Element (org.w3c.dom.Element)1