Skip to content

Commit

Permalink
ROO-120: Support multi module Maven projects
Browse files Browse the repository at this point in the history
  • Loading branch information
James Tyrrell committed Oct 20, 2011
1 parent 4ff8bb1 commit 91b7f04
Show file tree
Hide file tree
Showing 232 changed files with 6,333 additions and 3,848 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class BackupOperationsImpl implements BackupOperations {
@Reference private ProjectOperations projectOperations;

public boolean isBackupAvailable() {
return projectOperations.isProjectAvailable();
return projectOperations.isFocusedProjectAvailable();
}

public String backup() {
Expand All @@ -63,8 +63,8 @@ public String backup() {

ZipOutputStream zos = null;
try {
File projectDirectory = new File(projectOperations.getPathResolver().getIdentifier(Path.ROOT, "."));
MutableFile file = fileManager.createFile(FileDetails.getCanonicalPath(new File(projectDirectory, projectOperations.getProjectMetadata().getProjectName() + "_" + df.format(new Date()) + ".zip")));
File projectDirectory = new File(projectOperations.getPathResolver().getFocusedIdentifier(Path.ROOT, "."));
MutableFile file = fileManager.createFile(FileDetails.getCanonicalPath(new File(projectDirectory, projectOperations.getFocusedProjectName() + "_" + df.format(new Date()) + ".zip")));
zos = new ZipOutputStream(file.getOutputStream());
zip(projectDirectory, projectDirectory, zos);
} catch (FileNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.roo.classpath.itd.AbstractItdTypeDetailsProvidingMetadataItem;
import org.springframework.roo.metadata.MetadataIdentificationUtils;
import org.springframework.roo.model.JavaType;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.ContextualPath;
import org.springframework.roo.support.style.ToStringCreator;
import org.springframework.roo.support.util.Assert;

Expand Down Expand Up @@ -65,15 +65,15 @@ public static String getMetadataIdentiferType() {
return PROVIDES_TYPE;
}

public static String createIdentifier(final JavaType javaType, final Path path) {
public static String createIdentifier(final JavaType javaType, final ContextualPath path) {
return PhysicalTypeIdentifierNamingUtils.createIdentifier(PROVIDES_TYPE_STRING, javaType, path);
}

public static JavaType getJavaType(final String metadataIdentificationString) {
return PhysicalTypeIdentifierNamingUtils.getJavaType(PROVIDES_TYPE_STRING, metadataIdentificationString);
}

public static Path getPath(final String metadataIdentificationString) {
public static ContextualPath getPath(final String metadataIdentificationString) {
return PhysicalTypeIdentifierNamingUtils.getPath(PROVIDES_TYPE_STRING, metadataIdentificationString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.roo.classpath.itd.AbstractItdMetadataProvider;
import org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem;
import org.springframework.roo.model.JavaType;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.ContextualPath;
/**
* Implementation of {@link ConfigurableMetadataProvider}.
*
Expand Down Expand Up @@ -43,12 +43,12 @@ public String getItdUniquenessFilenameSuffix() {
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
JavaType javaType = ConfigurableMetadata.getJavaType(metadataIdentificationString);
Path path = ConfigurableMetadata.getPath(metadataIdentificationString);
ContextualPath path = ConfigurableMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}

@Override
protected String createLocalIdentifier(final JavaType javaType, final Path path) {
protected String createLocalIdentifier(final JavaType javaType, final ContextualPath path) {
return ConfigurableMetadata.createIdentifier(javaType, path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private enum Type {

// Fields
@Reference private FileManager fileManager;
@Reference private PathResolver pathResolver;
@Reference private ProjectOperations projectOperations;
@Reference private UrlInputStreamService httpService;

Expand All @@ -91,7 +92,7 @@ protected void activate(final ComponentContext context) {
}

public boolean isCommandAvailable() {
return !projectOperations.isProjectAvailable();
return !projectOperations.isFocusedProjectAvailable();
}

public void createAdvancedAddon(final JavaPackage topLevelPackage, final String description, final String projectName) {
Expand Down Expand Up @@ -206,20 +207,18 @@ public void createI18nAddon(final JavaPackage topLevelPackage, String language,

install("assembly.xml", topLevelPackage, Path.ROOT, Type.I18N, projectName);

PathResolver pathResolver = projectOperations.getPathResolver();

try {
FileCopyUtils.copy(new FileInputStream(messageBundle), fileManager.createFile(pathResolver.getIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + messageBundle.getName())).getOutputStream());
FileCopyUtils.copy(new FileInputStream(messageBundle), fileManager.createFile(pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + messageBundle.getName())).getOutputStream());
if (flagGraphic != null) {
FileCopyUtils.copy(new FileInputStream(flagGraphic), fileManager.createFile(pathResolver.getIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + flagGraphic.getName())).getOutputStream());
FileCopyUtils.copy(new FileInputStream(flagGraphic), fileManager.createFile(pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + flagGraphic.getName())).getOutputStream());
} else {
installFlagGraphic(locale, packagePath);
}
} catch (IOException e) {
throw new IllegalStateException("Could not copy addon resources into project", e);
}

String destinationFile = pathResolver.getIdentifier(Path.SRC_MAIN_JAVA, packagePath + separatorChar + languageName + "Language.java");
String destinationFile = pathResolver.getFocusedIdentifier(Path.SRC_MAIN_JAVA, packagePath + separatorChar + languageName + "Language.java");

if (!fileManager.exists(destinationFile)) {
InputStream templateInputStream = TemplateUtils.getTemplate(getClass(), Type.I18N.name().toLowerCase() + "/Language.java-template");
Expand Down Expand Up @@ -294,7 +293,7 @@ private void createProject(final JavaPackage topLevelPackage, final Type type, f
* @param pom the POM to write (required)
*/
private void writePomFile(final Document pom) {
final MutableFile pomFile = fileManager.createFile(projectOperations.getPathResolver().getIdentifier(Path.ROOT, POM_XML));
final MutableFile pomFile = fileManager.createFile(pathResolver.getFocusedIdentifier(Path.ROOT, POM_XML));
XmlUtils.writeXml(pomFile.getOutputStream(), pom);
}

Expand All @@ -305,18 +304,18 @@ private void install(final String targetFilename, final JavaPackage topLevelPack
String topLevelPackageName = topLevelPackage.getFullyQualifiedPackageName();
String packagePath = topLevelPackageName.replace('.', separatorChar);
String destinationFile = "";
PathResolver pathResolver = projectOperations.getPathResolver();

if (targetFilename.endsWith(".java")) {
destinationFile = pathResolver.getIdentifier(path, packagePath + separatorChar + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + targetFilename);
destinationFile = pathResolver.getFocusedIdentifier(path, packagePath + separatorChar + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + targetFilename);
} else {
destinationFile = pathResolver.getIdentifier(path, packagePath + separatorChar + targetFilename);
destinationFile = pathResolver.getFocusedIdentifier(path, packagePath + separatorChar + targetFilename);
}

// Different destination for assembly.xml
if ("assembly.xml".equals(targetFilename)) {
destinationFile = pathResolver.getIdentifier(path, "src" + separatorChar + "main" + separatorChar + "assembly" + separatorChar + targetFilename);
destinationFile = pathResolver.getFocusedIdentifier(path, "src" + separatorChar + "main" + separatorChar + "assembly" + separatorChar + targetFilename);
} else if (targetFilename.startsWith("RooAnnotation")) { // Adjust name for Roo Annotation
destinationFile = pathResolver.getIdentifier(path, packagePath + separatorChar + "Roo" + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + ".java");
destinationFile = pathResolver.getFocusedIdentifier(path, packagePath + separatorChar + "Roo" + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + ".java");
}

if (!fileManager.exists(destinationFile)) {
Expand All @@ -341,7 +340,7 @@ private void install(final String targetFilename, final JavaPackage topLevelPack
private void writeTextFile(final String fullPathFromRoot, final String message) {
Assert.hasText(fullPathFromRoot, "Text file name to write is required");
Assert.hasText(message, "Message required");
String path = projectOperations.getPathResolver().getIdentifier(Path.ROOT, fullPathFromRoot);
String path = pathResolver.getFocusedIdentifier(Path.ROOT, fullPathFromRoot);
MutableFile mutableFile = fileManager.exists(path) ? fileManager.updateFile(path) : fileManager.createFile(path);
byte[] input = message.getBytes();
try {
Expand All @@ -367,7 +366,7 @@ private void installFlagGraphic(final Locale locale, final String packagePath) {
if (entry.getName().equals(expectedEntryName)) {
int size;
byte[] buffer = new byte[2048];
MutableFile target = fileManager.createFile(projectOperations.getPathResolver().getIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + "/" + countryCode + ".png"));
MutableFile target = fileManager.createFile(pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + "/" + countryCode + ".png"));
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(target.getOutputStream(), buffer.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.springframework.roo.model.JavaType;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.ProjectMetadata;
import org.springframework.roo.project.PathResolver;
import org.springframework.roo.project.ProjectOperations;
import org.springframework.roo.shell.Shell;
import org.springframework.roo.support.util.Assert;
Expand Down Expand Up @@ -77,10 +77,12 @@ public class DbreDatabaseListenerImpl extends AbstractHashCodeTrackingMetadataNo
@Reference private DbreModelService dbreModelService;
@Reference private FileManager fileManager;
@Reference private IntegrationTestOperations integrationTestOperations;
@Reference private PathResolver pathResolver;
@Reference private ProjectOperations projectOperations;
@Reference private TypeLocationService typeLocationService;
@Reference private TypeManagementService typeManagementService;
@Reference private Shell shell;

private Map<JavaType, List<Identifier>> identifierResults;

public void onFileEvent(final FileEvent fileEvent) {
Expand Down Expand Up @@ -145,7 +147,7 @@ private void reverseEngineer(final Database database) {
schemaPackage = new JavaPackage(destinationPackage.getFullyQualifiedPackageName() + "." + DbreTypeUtils.suggestPackageName(table.getSchema().getName()));
}
final JavaType javaType = DbreTypeUtils.suggestTypeNameForNewTable(table.getName(), schemaPackage);
if (typeLocationService.findClassOrInterface(javaType) == null) {
if (typeLocationService.getTypeDetails(javaType) == null) {
table.setIncludeNonPortableAttributes(database.isIncludeNonPortableAttributes());
newEntities.add(createNewManagedEntityFromTable(javaType, table, database.isActiveRecord()));
}
Expand Down Expand Up @@ -200,8 +202,7 @@ private JavaPackage getDestinationPackage(final Database database, final Set<Cla

// Fall back to project's top level package
if (destinationPackage == null) {
final ProjectMetadata projectMetadata = projectOperations.getProjectMetadata();
destinationPackage = projectMetadata.getTopLevelPackage();
destinationPackage = projectOperations.getFocusedTopLevelPackage();
}
return destinationPackage;
}
Expand Down Expand Up @@ -340,7 +341,7 @@ private ClassOrInterfaceTypeDetails createNewManagedEntityFromTable(final JavaTy
extendsTypes.add(superclass);

// Create entity class
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(javaType, Path.SRC_MAIN_JAVA);
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(javaType, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
final ClassOrInterfaceTypeDetailsBuilder typeDetailsBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, javaType, PhysicalTypeCategory.CLASS);
typeDetailsBuilder.setExtendsTypes(extendsTypes);
typeDetailsBuilder.setAnnotations(annotations);
Expand Down Expand Up @@ -412,7 +413,7 @@ private void createIdentifierClass(final JavaType identifierType) {
identifierAnnotations.add(identifierBuilder);

// Produce identifier itself
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(identifierType, Path.SRC_MAIN_JAVA);
final String declaredByMetadataId = typeLocationService.getPhysicalTypeIdentifier(identifierType);
final ClassOrInterfaceTypeDetailsBuilder identifierTypeDetailsBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC | Modifier.FINAL, identifierType, PhysicalTypeCategory.CLASS);
identifierTypeDetailsBuilder.setAnnotations(identifierAnnotations);
typeManagementService.createOrUpdateTypeOnDisk(identifierTypeDetailsBuilder.build());
Expand Down Expand Up @@ -465,7 +466,7 @@ private void deleteManagedType(final ClassOrInterfaceTypeDetails managedEntity,
}

private boolean isEntityDeletable(final ClassOrInterfaceTypeDetails managedEntity) {
final String declaredByMetadataId = DbreMetadata.createIdentifier(managedEntity.getName(), Path.SRC_MAIN_JAVA);
final String declaredByMetadataId = DbreMetadata.createIdentifier(managedEntity.getName(), PhysicalTypeIdentifier.getPath(managedEntity.getDeclaredByMetadataId()));
final DbreMetadata dbreMetadata = (DbreMetadata) metadataService.get(declaredByMetadataId);
if (dbreMetadata == null || !dbreMetadata.isAutomaticallyDelete()) {
return false;
Expand Down Expand Up @@ -563,7 +564,7 @@ private JavaType getIdentifierType(final JavaType entity) {
}

private PhysicalTypeMetadata getPhysicalTypeMetadata(final JavaType javaType) {
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(javaType, Path.SRC_MAIN_JAVA);
final String declaredByMetadataId = typeLocationService.getPhysicalTypeIdentifier(javaType);
return (PhysicalTypeMetadata) metadataService.get(declaredByMetadataId);
}
}
Loading

0 comments on commit 91b7f04

Please sign in to comment.