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));
}
}
}
Aggregations