Skip to content
Snippets Groups Projects

Added folder handling to Tpd import

Merged Miklos Magyari requested to merge folders into main
4 files
+ 179
20
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -353,8 +353,18 @@ public class TpdImporter {
final URI mainProjectFileFolderURI = mainProjectFileFolderPath.toUri();
final List<String> projectsCreated = new ArrayList<>();
if (projectsToImport.get(resolvedProjectFileURI) != null) {
final List<Node> packedProjects = loadPackedProjects(projectsToImport.get(resolvedProjectFileURI));
final File a = new File(resolvedProjectFileURI);
File absolute = null;
try {
absolute = a.getCanonicalFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if (projectsToImport.get(absolute.toURI()) != null) {
final List<Node> packedProjects = loadPackedProjects(projectsToImport.get(absolute.toURI()));
for (final Node node : packedProjects) {
// final IProject project = createProject(node, false);
// if (project == null) {
@@ -366,11 +376,18 @@ public class TpdImporter {
}
projectsToImport.entrySet().stream().forEach((x) -> {
final NodeList referencedProjectsList = x.getValue().getDocumentElement().getChildNodes();
final Node node = getNodebyName(referencedProjectsList, ProjectFormatConstants.FILES_NODE);
loadFilesData(node, projectFile, mainProjectFileFolderURI);
loadFileList(node, projectFile, x.getKey());
final Node folderNode = getNodebyName(referencedProjectsList, ProjectFormatConstants.FOLDERS_NODE);
if (folderNode != null) {
loadFoldersData(folderNode, mainProjectFileFolderURI);
loadFileList(folderNode, projectFile, x.getKey());
}
final Node node = getNodebyName(referencedProjectsList, ProjectFormatConstants.FILES_NODE);
if (node != null) {
loadFilesData(node, projectFile, mainProjectFileFolderURI);
loadFileList(node, projectFile, x.getKey());
}
});
return islimitImportProcesses;
@@ -410,7 +427,17 @@ public class TpdImporter {
* @return true if there were no errors, false otherwise.
* */
private boolean loadURIDocuments(final URI file, final Validator validator) {
if (projectsToImport.containsKey(file)) {
final File a = new File(file);
final Document document = getDocumentFromFile(file.getPath());
File absolute = null;
try {
absolute = a.getCanonicalFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
if (projectsToImport.containsKey(absolute.toURI())) {
return true;
}
@@ -420,7 +447,6 @@ public class TpdImporter {
return false;
}
final Document document = getDocumentFromFile(file.getPath());
if (document == null) {
final StringBuilder builder = new StringBuilder("It was not possible to load the imported project file: '" + file.toString()
+ "'\n");
@@ -444,17 +470,8 @@ public class TpdImporter {
// ProjectFileHandler.clearNode(document);
final File a = new File(file);
File absolute;
try {
absolute = a.getCanonicalFile();
projectsToImport.put(absolute.toURI(), document);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
projectsToImport.put(absolute.toURI(), document);
final Element mainElement = document.getDocumentElement();
final NodeList mainNodes = mainElement.getChildNodes();
final Node referencedProjectsNode = getNodebyName(mainNodes, ProjectFormatConstants.REFERENCED_PROJECTS_NODE);
@@ -583,6 +600,93 @@ public class TpdImporter {
return result;
}
/**
* Load the information describing folders.
*
* @param foldersNode
* the node to load from.
* @param project
* the project to set this information on.
* @param projectFileFolderURI
* the location of the project file's folder.
*
* @return true if the import was successful, false otherwise.
* */
private boolean loadFoldersData(final Node foldersNode, final URI projectFileFolderURI) {
final NodeList folderNodeList = foldersNode.getChildNodes();
for (int i = 0, size = folderNodeList.getLength(); i < size; i++) {
final Node folderItem = folderNodeList.item(i);
if (folderItem.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final NamedNodeMap attributeMap = folderItem.getAttributes();
if (attributeMap == null) {
continue;
}
final Node projectRelativePathNode = attributeMap.getNamedItem(ProjectFormatConstants.FOLDER_ECLIPSE_LOCATION_NODE);
if (projectRelativePathNode == null) {
// displayError("Import failed", "Error while importing project " + project.getName()
// + " the project relative path attribute of the " + i + " th folder is missing");
return false;
}
final String projectRelativePath = projectRelativePathNode.getTextContent();
final Node relativeURINode = attributeMap.getNamedItem(ProjectFormatConstants.FOLDER_RELATIVE_LOCATION);
final Node rawURINode = attributeMap.getNamedItem(ProjectFormatConstants.FOLDER_RAW_LOCATION);
// final IFolder folder = project.getFolder(projectRelativePath);
// if (!folder.exists()) {
// try {
// if (relativeURINode != null) {
// final String relativeLocation = relativeURINode.getTextContent();
// //if relativeLocation == "virtual:/virtual" then
// //create a workaround according to the rawURI branch
// if( "virtual:/virtual".equals(relativeLocation) ) {
// folder.createLink(URI.create(relativeLocation), IResource.ALLOW_MISSING_LOCAL, null);
// continue;
// }
//
// final URI absoluteURI = TITANPathUtilities.resolvePathURI(relativeLocation, URIUtil.toPath(projectFileFolderURI).toOSString());
// if (absoluteURI == null) {
// // The URI cannot be resolved - for example it
// // contains not existing environment variables
// continue;
// }
// if (TitanURIUtil.isPrefix(projectLocationURI, absoluteURI)) {
// folder.create(false, true, null);
// } else {
// final File tmpFolder = new File(absoluteURI);
// if (tmpFolder.exists()) {
// folder.createLink(absoluteURI, IResource.ALLOW_MISSING_LOCAL, null);
// } else {
// ErrorReporter.logError("Error while importing folders into project `" + project.getName() + "'. Folder `"
// + absoluteURI + "' does not exist");
// continue;
// }
// }
// } else if (rawURINode != null) {
// final String rawLocation = rawURINode.getTextContent();
// folder.createLink(URI.create(rawLocation), IResource.ALLOW_MISSING_LOCAL, null);
// } else {
// TITANDebugConsole.println("Cannot create the resource " + folder.getFullPath().toString()
// + " the location information is missing or corrupted");
// }
// } catch (CoreException e) {
// ErrorReporter.logError("Error while importing folders into project: " + e );
// //be silent, it can happen normally
// }
// } else {
// ErrorReporter.logWarning("Folder to be imported `" + folder.getName() + "' already exists in project `" + project.getName()
// + "'");
// }
}
return true;
}
/**
* Load the information describing files.
*
Loading