@Override
public ProjectStructureModel load( final Repository repository, boolean includeModules ) {
if ( repository == null ) return null;
ProjectStructureModel model = new ProjectStructureModel();
Path path = repository.getRoot();
final Project project = projectService.resolveToParentProject( path );
if ( project != null ) {
model.setPOM( pomService.load( project.getPomXMLPath() ) );
model.setPOMMetaData( metadataService.getMetadata( project.getPomXMLPath() ) );
model.setPathToPOM( project.getPomXMLPath() );
model.setModules( new ArrayList<String>( project.getModules() ) );
if ( includeModules && project.getModules() != null ) {
org.uberfire.java.nio.file.Path parentPath = Paths.convert( project.getRootPath() );
Project moduleProject;
for ( String module : project.getModules() ) {
moduleProject = projectService.resolveProject( Paths.convert( parentPath.resolve( module ) ) );
model.getModulesProject().put( module, moduleProject );
}
}
} else {
//if no parent pom.xml present we must check if there are orphan projects for this repository.
List<Project> repositoryProjects = getProjects( repository );
if ( !repositoryProjects.isEmpty() ) {
model.setOrphanProjects( repositoryProjects );
POM pom;
for ( Project orphanProject : repositoryProjects ) {
pom = pomService.load( orphanProject.getPomXMLPath() );
model.getOrphanProjectsPOM().put( orphanProject.getSignatureId(), pom );
}
} else {
model = null;
}
}