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