Search in sources :

Example 1 with XmiResourceManager

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;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 2 with XmiResourceManager

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject) IRepositoryService(org.talend.repository.model.IRepositoryService) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) FolderItem(org.talend.core.model.properties.FolderItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with XmiResourceManager

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IOException(java.io.IOException) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with XmiResourceManager

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;
//
}
Also used : Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) ChangeProjectTechinicalNameMigrationTask(org.talend.repository.model.migration.ChangeProjectTechinicalNameMigrationTask) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 5 with XmiResourceManager

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);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Aggregations

XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)11 PersistenceException (org.talend.commons.exception.PersistenceException)9 IProject (org.eclipse.core.resources.IProject)8 Resource (org.eclipse.emf.ecore.resource.Resource)8 IResource (org.eclipse.core.resources.IResource)7 IWorkspace (org.eclipse.core.resources.IWorkspace)5 CoreException (org.eclipse.core.runtime.CoreException)4 IFile (org.eclipse.core.resources.IFile)3 IProjectDescription (org.eclipse.core.resources.IProjectDescription)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 Project (org.talend.core.model.general.Project)3 Project (org.talend.core.model.properties.Project)3 Property (org.talend.core.model.properties.Property)3 User (org.talend.core.model.properties.User)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Item (org.talend.core.model.properties.Item)2