Search in sources :

Example 61 with LogicalPath

use of org.springframework.roo.project.LogicalPath 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 62 with LogicalPath

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

the class AbstractItdMetadataProvider method getParentMetadata.

/**
 * Looks up the given type's inheritance hierarchy for metadata of the given
 * type, starting with the given type's parent and going upwards until the
 * first such instance is found (i.e. lower level metadata takes priority
 * over higher level metadata)
 *
 * @param <T> the type of metadata to look for
 * @param child the child type whose parents to search (required)
 * @return <code>null</code> if there is no such metadata
 */
@SuppressWarnings("unchecked")
protected <T extends MetadataItem> T getParentMetadata(final ClassOrInterfaceTypeDetails child) {
    T parentMetadata = null;
    ClassOrInterfaceTypeDetails superCid = child.getSuperclass();
    while (parentMetadata == null && superCid != null) {
        final String superCidPhysicalTypeIdentifier = superCid.getDeclaredByMetadataId();
        final LogicalPath path = PhysicalTypeIdentifier.getPath(superCidPhysicalTypeIdentifier);
        final String superCidLocalIdentifier = createLocalIdentifier(superCid.getName(), path);
        parentMetadata = (T) getMetadataService().get(superCidLocalIdentifier);
        superCid = superCid.getSuperclass();
    }
    // Could be null
    return parentMetadata;
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 63 with LogicalPath

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

the class AbstractItdMetadataProvider method getLocalMid.

/**
 * Assists creating a local metadata identification string (MID) from any
 * presented {@link MemberHoldingTypeDetails} implementation. This is
 * achieved by extracting the
 * {@link IdentifiableJavaStructure#getDeclaredByMetadataId()} and
 * converting it into a {@link JavaType} and {@link Path}, then calling
 * {@link #createLocalIdentifier(JavaType, Path)}.
 *
 * @param memberHoldingTypeDetails the member holder from which the
 *            declaring type information should be extracted (required)
 * @return a MID produced by {@link #createLocalIdentifier(JavaType, Path)}
 *         for the extracted Java type in the extract Path (never null)
 */
protected String getLocalMid(final MemberHoldingTypeDetails memberHoldingTypeDetails) {
    final JavaType governorType = memberHoldingTypeDetails.getName();
    // Extract out the metadata provider class (we need this later to
    // extract just the Path it is located in)
    final String providesType = MetadataIdentificationUtils.getMetadataClass(memberHoldingTypeDetails.getDeclaredByMetadataId());
    final LogicalPath path = PhysicalTypeIdentifierNamingUtils.getPath(providesType, memberHoldingTypeDetails.getDeclaredByMetadataId());
    // Produce the local MID we're going to use to make the request
    return createLocalIdentifier(governorType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 64 with LogicalPath

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

the class PomTest method testGetModulePathsForMinimalJarPom.

@Test
public void testGetModulePathsForMinimalJarPom() {
    // Set up
    final Pom pom = getMinimalPom(DEFAULT_PACKAGING);
    final Path[] expectedPaths = { ROOT };
    // Invoke and check
    assertEquals(expectedPaths.length, pom.getPhysicalPaths().size());
    for (final Path path : expectedPaths) {
        final PhysicalPath modulePath = pom.getPhysicalPath(path);
        assertEquals(new File(PROJECT_ROOT, path.getDefaultLocation()), modulePath.getLocation());
        assertEquals(path.isJavaSource(), modulePath.isSource());
        final LogicalPath moduelPathId = modulePath.getLogicalPath();
        assertEquals(path, moduelPathId.getPath());
        assertEquals(ROOT_MODULE, moduelPathId.getModule());
    }
}
Also used : Path(org.springframework.roo.project.Path) LogicalPath(org.springframework.roo.project.LogicalPath) PhysicalPath(org.springframework.roo.project.PhysicalPath) LogicalPath(org.springframework.roo.project.LogicalPath) File(java.io.File) PhysicalPath(org.springframework.roo.project.PhysicalPath) Test(org.junit.Test)

Example 65 with LogicalPath

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

the class DbreMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = DbreMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = DbreMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Aggregations

LogicalPath (org.springframework.roo.project.LogicalPath)85 JavaType (org.springframework.roo.model.JavaType)62 RooJavaType (org.springframework.roo.model.RooJavaType)55 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)13 JpaJavaType (org.springframework.roo.model.JpaJavaType)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 SpringJavaType (org.springframework.roo.model.SpringJavaType)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)5 BufferedInputStream (java.io.BufferedInputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 I18n (org.springframework.roo.addon.web.mvc.i18n.components.I18n)4 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3