Search in sources :

Example 56 with Pom

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();
}
Also used : Pom(org.springframework.roo.project.maven.Pom) CliCommand(org.springframework.roo.shell.CliCommand)

Example 57 with Pom

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, '.');
}
Also used : PhysicalPath(org.springframework.roo.project.PhysicalPath) Pom(org.springframework.roo.project.maven.Pom)

Example 58 with Pom

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;
}
Also used : JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath) JavaPackage(org.springframework.roo.model.JavaPackage) PhysicalPath(org.springframework.roo.project.PhysicalPath) Pom(org.springframework.roo.project.maven.Pom)

Example 59 with Pom

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);
}
Also used : Document(org.w3c.dom.Document) Pom(org.springframework.roo.project.maven.Pom)

Example 60 with Pom

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);
                    }
                }
            }
        }
    }
}
Also used : Pom(org.springframework.roo.project.maven.Pom)

Aggregations

Pom (org.springframework.roo.project.maven.Pom)86 Element (org.w3c.dom.Element)19 JavaType (org.springframework.roo.model.JavaType)16 Document (org.w3c.dom.Document)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)9 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 Dependency (org.springframework.roo.project.Dependency)9 RooJavaType (org.springframework.roo.model.RooJavaType)7 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ServiceReference (org.osgi.framework.ServiceReference)5 ControllerMVCResponseService (org.springframework.roo.addon.web.mvc.controller.addon.responses.ControllerMVCResponseService)5 JavaPackage (org.springframework.roo.model.JavaPackage)5 List (java.util.List)4 Plugin (org.springframework.roo.project.Plugin)4 Completion (org.springframework.roo.shell.Completion)4 HashMap (java.util.HashMap)3 DataOnDemandCreatorProvider (org.springframework.roo.addon.test.providers.DataOnDemandCreatorProvider)3