use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class GenericRepositoryContentHandler method create.
private Resource create(IProject project, GenericConnectionItem item, IPath path) throws PersistenceException {
XmiResourceManager xmiResourceManager = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager();
ERepositoryObjectType repObjType = getRepositoryObjectType(item);
Resource itemResource = null;
if (repObjType != null) {
itemResource = xmiResourceManager.createItemResource(project, item, path, repObjType, false);
MetadataManager.addContents(item, itemResource);
itemResource.getContents().add(item.getConnection());
}
return itemResource;
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class RemoveBinFolderMigrationTask method execute.
@Override
public ExecutionResult execute(Project project) {
XmiResourceManager xmiResourceManager = new XmiResourceManager();
IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
for (ERepositoryObjectType type : getTypes()) {
IFolder folder = null;
if (type != null && type.hasFolder()) {
try {
IProject fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
if (!fsProject.getFolder(ERepositoryObjectType.getFolderName(type)).exists()) {
continue;
}
folder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource current : ResourceUtils.getMembers(folder)) {
if ((current instanceof IFolder) && ((IFolder) current).getName().equals("bin")) {
for (IResource fileCurrent : ResourceUtils.getMembers((IFolder) current)) {
if (fileCurrent instanceof IFile) {
if (xmiResourceManager.isPropertyFile((IFile) fileCurrent)) {
Property property = null;
try {
property = xmiResourceManager.loadProperty(fileCurrent);
} catch (RuntimeException e) {
// property will be null
ExceptionHandler.process(e);
}
if (property != null) {
// restore folder if doesn't exist anymore.
Item propertyItem = property.getItem();
propertyItem.getState().setDeleted(true);
EmfHelper.saveResource(propertyItem.eResource());
String oldPath = propertyItem.getState().getPath();
IPath path = new Path(oldPath);
factory.createParentFoldersRecursively(project, type, path, true);
FolderItem folderItem = factory.getFolderItem(project, type, path);
propertyItem.setParent(folderItem);
String name = fileCurrent.getName().replace(".properties", "");
// take all the files starting by the same name
IFolder typeRootFolder = ResourceUtils.getFolder(fsProject, ERepositoryObjectType.getFolderName(type), true);
for (IResource filesToMove : ResourceUtils.getMembers((IFolder) current)) {
if (filesToMove.getName().startsWith(name)) {
IPath originalPath = filesToMove.getFullPath();
IPath finalPath = typeRootFolder.getFullPath().append(path).append(originalPath.lastSegment());
if (fsProject.getWorkspace().getRoot().getFile(finalPath).exists()) {
// if the file exists in both bin and target directory, delete
// the one from bin.
filesToMove.delete(true, new NullProgressMonitor());
} else {
ResourceUtils.moveResource(filesToMove, finalPath);
}
}
}
}
}
}
}
IResource[] binFolder = ResourceUtils.getMembers((IFolder) current);
if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
try {
((IFolder) current).delete(true, null);
} catch (CoreException e) {
// not catched, not important if can delete or not
}
}
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
} catch (CoreException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
}
// }
return ExecutionResult.SUCCESS_NO_ALERT;
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class ImportProjectsUtilities method afterImportAs.
/**
* DOC smallet Comment method "afterImportAs".
*
* @param newName
* @param technicalName
* @throws InvocationTargetException
*/
private static Project afterImportAs(String newName, String technicalName) throws InvocationTargetException {
// Rename in ".project" and "talendProject" or "talend.project"
// TODO SML Optimize
final IWorkspace workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
IContainer containers = (IProject) workspace.getRoot().findMember(new Path(technicalName));
IResource file2 = containers.findMember(IProjectDescription.DESCRIPTION_FILE_NAME);
try {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
replaceInFile("<name>.*</name>", file2.getLocation().toOSString(), "<name>" + technicalName + "</name>");
// TDI-19269
final IProject project = workspace.getRoot().getProject(technicalName);
XmiResourceManager xmiManager = new XmiResourceManager();
try {
final Project loadProject = xmiManager.loadProject(project);
loadProject.setTechnicalLabel(technicalName);
loadProject.setLabel(newName);
loadProject.setLocal(true);
loadProject.setId(0);
loadProject.setUrl(null);
loadProject.setCreationDate(null);
loadProject.setDescription("");
loadProject.setType(null);
// ADD xqliu 2012-03-12 TDQ-4771 clear the list of Folders
if (loadProject.getFolders() != null) {
loadProject.getFolders().clear();
}
// ~ TDQ-4771
xmiManager.saveResource(loadProject.eResource());
return loadProject;
} catch (PersistenceException e) {
//
}
} catch (IOException e) {
throw new InvocationTargetException(e);
}
return null;
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class TalendWizardProjectsImportPage method createProjects.
@SuppressWarnings("restriction")
@Override
public boolean createProjects() {
// TDI-19269
final boolean created = super.createProjects();
//
final Object[] selected = getProjectsList().getCheckedElements();
XmiResourceManager xmiManager = new XmiResourceManager();
try {
for (Object element : selected) {
final ProjectRecord record = (ProjectRecord) element;
String projectName = record.getProjectName();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProject project = workspace.getRoot().getProject(projectName);
try {
final Project loadProject = xmiManager.loadProject(project);
loadProject.setLocal(true);
loadProject.setId(0);
loadProject.setUrl(null);
loadProject.setCreationDate(null);
//loadProject.setDescription(""); //$NON-NLS-1$
loadProject.setType(null);
xmiManager.saveResource(loadProject.eResource());
// FIXME TDI-22786, migrate the project name.
if (ProjectManager.enableSpecialTechnicalProjectName()) {
ChangeProjectTechinicalNameMigrationTask migrationTask = new ChangeProjectTechinicalNameMigrationTask();
migrationTask.migrateTalendProject(project, loadProject, xmiManager);
}
} catch (PersistenceException e) {
//
}
}
} finally {
xmiManager.unloadResources();
}
return created;
//
}
use of org.talend.core.repository.utils.XmiResourceManager in project tdi-studio-se by Talend.
the class DemosImportTest method createTempDemoProject.
protected void createTempDemoProject(String demoName) throws CoreException, PersistenceException {
Project projectInfor = new Project();
projectInfor.setLabel(demoName);
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
tempDemoProject = new Project();
// Fill project object
tempDemoProject.setLabel(projectInfor.getLabel());
tempDemoProject.setDescription(projectInfor.getDescription());
tempDemoProject.setLanguage(projectInfor.getLanguage());
tempDemoProject.setAuthor(projectInfor.getAuthor());
tempDemoProject.setLocal(true);
tempDemoProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(tempDemoProject.getEmfProject());
projectResource.getContents().add(tempDemoProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
Aggregations