* @param repository is the repository, where the source file is automatically added or updated,
* when the source file is registered.
* @return a RobotItem that has been created or updated in the repository.
*/
private RobotItem register(URL sourceFileUrl, IRepositoryRoot root, IRepository repository) {
RobotItem item = null;
// Check if the source file is already registered in the repository with a project URL
if (root instanceof ClasspathRoot) {
String projectUrl = ((ClasspathRoot) root).getFriendlyProjectURL(sourceFileUrl);
if (projectUrl != null) {
IRepositoryItem repositoryItem = repository.getItem(projectUrl);
if (repositoryItem instanceof RobotItem) {
item = (RobotItem) repositoryItem;
}
}
}
// If no project URL was registered with the source file then check if the source file is registered
// in the repository.
if (item == null) {
String friendlyUrl = UrlUtil.removeFileExtension(sourceFileUrl.toString());
IRepositoryItem repositoryItem = repository.getItem(friendlyUrl);
if (repositoryItem instanceof RobotItem) {
item = (RobotItem) repositoryItem;
}
}
// If the source file has not been registered then create a new RobotItem based on the source file URL
if (item == null) {
item = new RobotItem(sourceFileUrl, root);
}
// Add the root URL as source path with the RobotIteam
item.addSourcePathURL(root.getURL());
// Add or update the item in the repository and return it
repository.addOrUpdateItem(item);
return item;
}