use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class MetadataCommands method metadataForModule.
@CliCommand(value = METADATA_FOR_MODULE_COMMAND, help = "Shows the ProjectMetadata for the indicated project module.")
public String metadataForModule(@CliOption(key = { "", "module" }, mandatory = false, optionContext = INCLUDE_CURRENT_MODULE, help = "The module for which to retrieve the metadata. " + "Default if option not present: the Roo Shell focused module.") final Pom pom) {
final Pom targetPom = ObjectUtils.defaultIfNull(pom, projectOperations.getFocusedModule());
if (targetPom == null) {
return "This project has no modules";
}
final String projectMID = ProjectMetadata.getProjectIdentifier(targetPom.getModuleName());
return metadataService.get(projectMID).toString();
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class TypeLocationServiceImpl method getProposedJavaType.
private String getProposedJavaType(final String fileCanonicalPath) {
Validate.notBlank(fileCanonicalPath, "File canonical path required");
// Determine the JavaType for this file
String relativePath = "";
final Pom moduleForFileIdentifier = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath);
if (moduleForFileIdentifier == null) {
return relativePath;
}
for (final PhysicalPath physicalPath : moduleForFileIdentifier.getPhysicalPaths()) {
final String moduleCanonicalPath = FileUtils.ensureTrailingSeparator(FileUtils.getCanonicalPath(physicalPath.getLocation()));
if (fileCanonicalPath.startsWith(moduleCanonicalPath)) {
relativePath = File.separator + StringUtils.replace(fileCanonicalPath, moduleCanonicalPath, "", 1);
break;
}
}
Validate.notBlank(relativePath, "Could not determine compilation unit name for file '%s'", fileCanonicalPath);
Validate.isTrue(relativePath.startsWith(File.separator), "Relative path unexpectedly dropped the '%s' prefix (received '%s' from '%s')", File.separator, relativePath, fileCanonicalPath);
relativePath = relativePath.substring(1);
Validate.isTrue(relativePath.endsWith(".java"), "The relative path unexpectedly dropped the .java extension for file '%s'", fileCanonicalPath);
relativePath = relativePath.substring(0, relativePath.lastIndexOf(".java"));
return relativePath.replace(File.separatorChar, '.');
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class TypeLocationServiceImpl method getPhysicalTypeIdentifier.
public String getPhysicalTypeIdentifier(final String fileCanonicalPath) {
Validate.notBlank(fileCanonicalPath, "File canonical path required");
if (!doesPathIndicateJavaType(fileCanonicalPath)) {
return null;
}
String physicalTypeIdentifier = getTypeCache().getTypeIdFromTypeFilePath(fileCanonicalPath);
if (physicalTypeIdentifier != null) {
return physicalTypeIdentifier;
}
final String typeDirectory = FileUtils.getFirstDirectory(fileCanonicalPath);
final String simpleTypeName = StringUtils.replace(fileCanonicalPath, typeDirectory + File.separator, "", 1).replace(".java", "");
final JavaPackage javaPackage = getTypeResolutionService().getPackage(fileCanonicalPath);
if (javaPackage == null) {
return null;
}
final Pom module = getProjectOperations().getModuleForFileIdentifier(fileCanonicalPath);
Validate.notNull(module, "The module for the file '" + fileCanonicalPath + "' could not be located");
final JavaType javaType = new JavaType(javaPackage.getFullyQualifiedPackageName() + "." + simpleTypeName, module.getModuleName());
getTypeCache().cacheTypeAgainstModule(module, javaType);
String reducedPath = fileCanonicalPath.replace(javaType.getRelativeFileName(), "");
reducedPath = StringUtils.stripEnd(reducedPath, File.separator);
for (final PhysicalPath physicalPath : module.getPhysicalPaths()) {
if (physicalPath.getLocationPath().startsWith(reducedPath)) {
final LogicalPath path = physicalPath.getLogicalPath();
physicalTypeIdentifier = MetadataIdentificationUtils.create(PhysicalTypeIdentifier.class.getName(), path.getName() + "?" + javaType.getFullyQualifiedTypeName());
break;
}
}
getTypeCache().cacheFilePathAgainstTypeIdentifier(fileCanonicalPath, physicalTypeIdentifier);
return physicalTypeIdentifier;
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class AbstractProjectOperations method addBuildPlugins.
@Override
public void addBuildPlugins(final String moduleName, final Collection<? extends Plugin> newPlugins, boolean addToPluginManagement) {
Validate.isTrue(isProjectAvailable(moduleName), "Plugin modification prohibited at this time");
Validate.notNull(newPlugins, "Plugins required");
if (CollectionUtils.isEmpty(newPlugins)) {
return;
}
final Pom parentPom = getPomFromModuleName("");
boolean isSamePom = false;
Pom pom = null;
if ("".equals(moduleName)) {
isSamePom = true;
pom = parentPom;
} else {
pom = getPomFromModuleName(moduleName);
}
Validate.notNull(parentPom, "The parentPom is not available, so plugin addition cannot be performed");
Validate.notNull(pom, "The pom is not available, so plugin addition cannot be performed");
final Document parentDocument = XmlUtils.readXml(fileManager.getInputStream(parentPom.getPath()));
Document document = null;
if (isSamePom) {
document = parentDocument;
} else {
document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath()));
}
writePluginInPom(newPlugins, parentPom, pom, parentDocument, document, parentDocument.getDocumentElement(), document.getDocumentElement(), addToPluginManagement, isSamePom);
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class AbstractProjectOperations method addModuleDependency.
public void addModuleDependency(final String moduleName, final String moduleToDependUpon, boolean testDependency) {
Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited at this time");
Validate.notNull(moduleToDependUpon, "Dependency required");
if (StringUtils.isBlank(moduleToDependUpon)) {
// No need to ever add a dependency upon the root POM
return;
}
final Pom module = getPomFromModuleName(moduleName);
if (module != null && StringUtils.isNotBlank(module.getModuleName()) && !moduleToDependUpon.equals(module.getModuleName())) {
final ProjectMetadata dependencyProject = getProjectMetadata(moduleToDependUpon);
if (dependencyProject != null) {
final Pom dependencyPom = dependencyProject.getPom();
if (!dependencyPom.getPath().equals(module.getPath())) {
if (testDependency) {
// Add as test-type dependency
final Dependency dependency = dependencyPom.asDependency(DependencyScope.TEST, DependencyType.valueOfTypeCode("test-jar"));
detectCircularDependency(module, dependencyPom);
addDependency(module.getModuleName(), dependency);
} else {
// Add as "normal" dependency
final Dependency dependency = dependencyPom.asDependency(COMPILE);
if (!module.hasDependencyExcludingVersion(dependency)) {
detectCircularDependency(module, dependencyPom);
addDependency(module.getModuleName(), dependency);
}
}
}
}
}
}
Aggregations