Search in sources :

Example 1 with PhysicalPath

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

the class TypeLocationServiceImpl method getPhysicalPath.

private PhysicalPath getPhysicalPath(final JavaType javaType) {
    Validate.notNull(javaType, "Java type required");
    final String parentPath = getParentPath(javaType);
    if (parentPath == null) {
        return null;
    }
    for (final Pom pom : getProjectOperations().getPoms()) {
        for (final PhysicalPath physicalPath : pom.getPhysicalPaths()) {
            if (physicalPath.isSource()) {
                final String pathLocation = FileUtils.ensureTrailingSeparator(physicalPath.getLocationPath());
                if (pathLocation.startsWith(parentPath)) {
                    getTypeCache().cacheTypeAgainstModule(pom, javaType);
                    return physicalPath;
                }
            }
        }
    }
    return null;
}
Also used : PhysicalPath(org.springframework.roo.project.PhysicalPath) Pom(org.springframework.roo.project.maven.Pom)

Example 2 with PhysicalPath

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

the class TypeLocationServiceImpl method getPhysicalTypeIdentifier.

public String getPhysicalTypeIdentifier(final JavaType type) {
    final PhysicalPath containingPhysicalPath = getPhysicalPath(type);
    if (containingPhysicalPath == null) {
        return null;
    }
    final LogicalPath logicalPath = containingPhysicalPath.getLogicalPath();
    return PhysicalTypeIdentifier.createIdentifier(type, logicalPath);
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath) PhysicalPath(org.springframework.roo.project.PhysicalPath)

Example 3 with PhysicalPath

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

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

use of org.springframework.roo.project.PhysicalPath 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)

Aggregations

PhysicalPath (org.springframework.roo.project.PhysicalPath)5 LogicalPath (org.springframework.roo.project.LogicalPath)3 Pom (org.springframework.roo.project.maven.Pom)3 File (java.io.File)1 Test (org.junit.Test)1 JavaPackage (org.springframework.roo.model.JavaPackage)1 JavaType (org.springframework.roo.model.JavaType)1 Path (org.springframework.roo.project.Path)1