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;
}
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);
}
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, '.');
}
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;
}
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());
}
}
Aggregations