Search in sources :

Example 16 with IWorkspace

use of org.eclipse.core.resources.IWorkspace 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 17 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.

the class BuildJobHandler method build.

@Override
public void build(IProgressMonitor monitor) throws Exception {
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                buildDelegate(monitor);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        workspace.run(runnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with IWorkspace

use of org.eclipse.core.resources.IWorkspace 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 19 with IWorkspace

use of org.eclipse.core.resources.IWorkspace in project tesb-studio-se by Talend.

the class OpenWSDLPage method finish.

public boolean finish() {
    // changed by hqzhang for TDI-19527, label=displayName
    final String label = item.getProperty().getDisplayName();
    item.getProperty().setLabel(label);
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(final IProgressMonitor monitor) throws CoreException {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
                if (creation) {
                    item.getProperty().setId(factory.getNextId());
                    factory.create(item, getDestinationPath());
                    repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
                }
                ((ServiceConnection) item.getConnection()).setWSDLPath(path);
                ((ServiceConnection) item.getConnection()).getServicePort().clear();
                final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
                final InputStream is;
                if (null == path) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // create new WSDL file from template
                    TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
                    is = new ByteArrayInputStream(baos.toByteArray());
                } else {
                    //$NON-NLS-1$
                    String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
                    Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
                    is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
                    for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
                        String filename = wsdl.getKey();
                        IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
                        if (!importedWsdl.exists()) {
                            importedWsdl.create(wsdl.getValue(), true, monitor);
                        } else {
                            importedWsdl.setContents(wsdl.getValue(), 0, monitor);
                        }
                        createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
                    }
                }
                // store WSDL in service
                if (!fileWsdl.exists()) {
                    fileWsdl.create(is, true, monitor);
                } else {
                    fileWsdl.setContents(is, 0, monitor);
                }
                // create reference to wsdl
                //$NON-NLS-1$
                createReferenceResources("wsdl");
                // path
                definition = WSDLUtils.getDefinition(fileWsdl);
                populateModelFromWsdl(factory, definition, item, repositoryNode);
                factory.save(item);
                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
            } catch (Exception e) {
                //delete the node if any exception during the creation
                if (creation) {
                    try {
                        factory.save(item);
                        factory.deleteObjectPhysical(repositoryNode.getObject());
                    } catch (PersistenceException e1) {
                        throw getCoreException("WDSL creation failed", e1);
                    }
                }
                //throw the exception
                if (e instanceof CoreException) {
                    throw (CoreException) e;
                }
                if (e instanceof InvocationTargetException) {
                    throw getCoreException("WDSL creation failed", e.getCause());
                }
                throw getCoreException("WDSL creation failed", e);
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        // we use the workspace scheduling rule to lock all
        ISchedulingRule schedulingRule = workspace.getRoot();
        // workspace modifications during the run.
        // the update of the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    // open wsdl editor
    OpenWSDLEditorAction action = new OpenWSDLEditorAction();
    action.setServiceItem(item);
    action.run();
    // import schemas if required
    if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
        PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
        try {
            getContainer().run(true, true, publishMetadataRunnable);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
            setErrorMessage("Populate schema to repository: " + message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    return true;
}
Also used : ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) OpenWSDLEditorAction(org.talend.repository.services.action.OpenWSDLEditorAction) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) PublishMetadataRunnable(org.talend.repository.services.action.PublishMetadataRunnable) Map(java.util.Map)

Example 20 with IWorkspace

use of org.eclipse.core.resources.IWorkspace 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

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12