Search in sources :

Example 11 with ITestContainerProviderService

use of org.talend.core.ui.ITestContainerProviderService in project tdi-studio-se by Talend.

the class ExportItemUtil method exportItems2.

private Map<File, IPath> exportItems2(Collection<Item> items, File destinationDirectory, boolean projectFolderStructure, IProgressMonitor progressMonitor) throws Exception {
    Map<File, IPath> toExport = new HashMap<File, IPath>();
    //$NON-NLS-1$
    progressMonitor.beginTask("Export Items", items.size() + 1);
    final boolean oldMeasureActived = TimeMeasure.measureActive;
    if (!oldMeasureActived) {
        // not active before.
        TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    }
    //$NON-NLS-1$
    final String idTimer = "exportItems";
    TimeMeasure.begin(idTimer);
    try {
        // store item and its corresponding project
        Map<Item, Project> itemProjectMap = new HashMap<Item, Project>();
        Collection<Item> allItems = new ArrayList<Item>(items);
        items.clear();
        // ycbai added for TDI-21387
        if (allItems.isEmpty()) {
            addTalendProjectFile(toExport, destinationDirectory);
            return toExport;
        }
        allItems = sortItemsByProject(allItems, itemProjectMap);
        ITransformService tdmService = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
            tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
        }
        itemProjectMap.clear();
        Set<String> jarNameList = new HashSet<String>();
        Iterator<Item> iterator = allItems.iterator();
        Set<String> projectHasTdm = new HashSet<String>();
        while (iterator.hasNext()) {
            Item item = iterator.next();
            project = pManager.getProject(item);
            String label = item.getProperty().getLabel();
            // project
            addTalendProjectFile(toExport, destinationDirectory);
            // tdm .settings/com.oaklandsw.base.projectProps
            String technicalLabel = project.getTechnicalLabel();
            if (tdmService != null && !projectHasTdm.contains(technicalLabel) && tdmService.isTransformItem(item)) {
                projectHasTdm.add(technicalLabel);
                IPath propsSourcePath = getProjectLocationPath(technicalLabel).append(FileConstants.TDM_PROPS_PATH);
                IPath tdmPropsPath = getProjectOutputPath().append(FileConstants.TDM_PROPS_PATH);
                IPath propsTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(tdmPropsPath);
                File source = new File(propsSourcePath.toPortableString());
                if (source.exists()) {
                    copyAndAddResource(toExport, propsSourcePath, propsTargetPath, tdmPropsPath);
                }
            }
            // tdm simple files
            if (item.getProperty() instanceof FakePropertyImpl) {
                FakePropertyImpl fakeProperty = (FakePropertyImpl) item.getProperty();
                IPath itemResPath = fakeProperty.getItemPath().makeRelative();
                IPath itemSourcePath = getProjectLocationPath(technicalLabel).removeLastSegments(1).append(itemResPath);
                // replace the project segment
                IPath outputRelativeItemPath = getProjectOutputPath().append(itemResPath.removeFirstSegments(1));
                IPath itemTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
                copyAndAddResource(toExport, itemSourcePath, itemTargetPath, outputRelativeItemPath);
                continue;
            }
            // property and related resources eg:item, reference files
            XmiResourceManager localRepositoryManager = ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager();
            IPath propertyPath = null;
            for (Resource curResource : localRepositoryManager.getAffectedResources(item.getProperty())) {
                URI uri = curResource.getURI();
                IPath relativeItemPath = URIHelper.convert(uri).makeRelative();
                Project project = ProjectManager.getInstance().getProject(item);
                IPath sourcePath = getProjectLocationPath(project.getTechnicalLabel()).removeLastSegments(1).append(relativeItemPath);
                // replace the project segment
                IPath outputRelativeItemPath = getProjectOutputPath().append(relativeItemPath.removeFirstSegments(1));
                IPath targetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
                copyAndAddResource(toExport, sourcePath, targetPath, outputRelativeItemPath);
                if (uri.lastSegment() != null && uri.lastSegment().endsWith(FileConstants.PROPERTIES_FILE_SUFFIX)) {
                    propertyPath = targetPath;
                }
            }
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null) {
                    List<IResource> dataFileList = testContainerService.getDataFiles(item);
                    for (IResource dataFile : dataFileList) {
                        IPath relativeItemPath = dataFile.getFullPath();
                        IPath sourcePath = getProjectLocationPath(project.getTechnicalLabel()).removeLastSegments(1).append(relativeItemPath);
                        // replace the project segment
                        IPath outputRelativeItemPath = getProjectOutputPath().append(relativeItemPath.removeFirstSegments(1));
                        IPath targetPath = new Path(destinationDirectory.getAbsolutePath()).append(outputRelativeItemPath);
                        copyAndAddResource(toExport, sourcePath, targetPath, outputRelativeItemPath);
                    }
                }
            }
            if (propertyPath == null) {
                return toExport;
            }
            if (item instanceof RoutineItem) {
                List list = ((RoutineItem) item).getImports();
                for (int i = 0; i < list.size(); i++) {
                    String jarName = ((IMPORTTypeImpl) list.get(i)).getMODULE();
                    jarNameList.add(jarName.toString());
                }
            }
            boolean needChangeItem = false;
            needChangeItem = needChangeItem || item.getState().isLocked();
            // keep the same as function fixItem()
            needChangeItem = needChangeItem || !item.getProperty().getLabel().replace(' ', '_').equals(item.getProperty().getLabel());
            if (needChangeItem) {
                // load in memory, fix the item and save it
                XmiResourceManager xmiMamanger = new XmiResourceManager();
                // loadProject
                IPath proRelativePath = getProjectOutputPath().append(FileConstants.LOCAL_PROJECT_FILENAME);
                IPath proTargetPath = new Path(destinationDirectory.getAbsolutePath()).append(proRelativePath);
                Resource loadProject = projectResourcMap.get(proTargetPath);
                if (loadProject == null) {
                    URI projectUri = URI.createFileURI(proTargetPath.toPortableString());
                    loadProject = xmiMamanger.resourceSet.getResource(projectUri, true);
                    projectResourcMap.put(proTargetPath, loadProject);
                }
                URI propertyUri = URI.createFileURI(propertyPath.toPortableString());
                Resource propertyResource = xmiMamanger.resourceSet.getResource(propertyUri, true);
                Property loadProperty = (Property) EcoreUtil.getObjectByType(propertyResource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
                Item newItem = loadProperty.getItem();
                fixItem(newItem);
                fixItemLockState(newItem);
                saveResources(xmiMamanger.resourceSet);
            }
            iterator.remove();
            TimeMeasure.step(idTimer, "export item: " + label);
            progressMonitor.worked(1);
        }
        ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
        // add the routines of the jars at the end, to add them only once in the export.
        IPath libPath = getProjectOutputPath().append(JavaUtils.JAVA_LIB_DIRECTORY);
        String libAbsPath = new Path(destinationDirectory.toString()).append(libPath.toString()).toPortableString();
        for (String jarName : jarNameList) {
            if (repositoryBundleService.contains(jarName)) {
                repositoryBundleService.retrieve(jarName, libAbsPath, new NullProgressMonitor());
                toExport.put(new File(libAbsPath, jarName), libPath.append(jarName));
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        TimeMeasure.end(idTimer);
        // if active before, not disable and active still.
        if (!oldMeasureActived) {
            TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
        }
    }
    return toExport;
}
Also used : IMPORTTypeImpl(org.talend.designer.core.model.utils.emf.component.impl.IMPORTTypeImpl) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(org.eclipse.emf.common.util.URI) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ILibraryManagerService(org.talend.core.ILibraryManagerService) List(java.util.List) ArrayList(java.util.ArrayList) Property(org.talend.core.model.properties.Property) HashSet(java.util.HashSet) TarFileExporterFullPath(org.talend.core.ui.export.TarFileExporterFullPath) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ZipFileExporterFullPath(org.talend.core.ui.export.ZipFileExporterFullPath) IFileExporterFullPath(org.talend.core.ui.export.IFileExporterFullPath) ITransformService(org.talend.core.service.ITransformService) IPath(org.eclipse.core.runtime.IPath) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) RoutineItem(org.talend.core.model.properties.RoutineItem) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 12 with ITestContainerProviderService

use of org.talend.core.ui.ITestContainerProviderService in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method doSave.

/**
     * Saves the multi-page editor's document.
     */
@Override
public void doSave(final IProgressMonitor monitor) {
    Item curItem = getProcess().getProperty().getItem();
    IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        // For TDI-23825, if not lock by user try to lock again.
        if (!getProcess().isReadOnly()) {
            repFactory.lock(curItem);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    if (getProcess().isReadOnly() || repFactory.isUserReadOnlyOnCurrentProject()) {
        MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.readonly"), Messages.getString("AbstractMultiPageTalendEditor.readonlyMessage"));
        return;
    }
    ERepositoryStatus status = repFactory.getStatus(curItem);
    if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
        MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage"));
        return;
    }
    if (!isDirty()) {
        return;
    }
    Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
    changeCollapsedState(true, jobletMap);
    updateRunJobContext();
    designerEditor.getProcess().getProperty().eAdapters().remove(dirtyListener);
    repFactory.addRepositoryWorkUnitListener(repositoryWorkListener);
    if (jobletEditor == getActiveEditor()) {
        boolean isDirty = jobletEditor.isDirty();
        refreshPropertyDirtyStatus();
        jobletEditor.doSave(monitor);
        try {
            IProcess2 oldProcess = getProcess();
            ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
            ProcessType processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
            IProcess2 newProcess = null;
            Item item = getProcess().getProperty().getItem();
            if (item instanceof ProcessItem) {
                ((Process) designerEditor.getProcess()).updateProcess(processType);
                if (isDirty) {
                    getProcess().setProcessModified(true);
                    getProcess().setNeedRegenerateCode(true);
                }
            } else if (item instanceof JobletProcessItem) {
                AbstractProcessProvider processProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
                if (processProvider != null) {
                    newProcess = processProvider.buildNewGraphicProcess(item);
                }
                designerEditor.setProcess(newProcess);
                Boolean lastVersion = null;
                if (oldProcess instanceof ILastVersionChecker) {
                    lastVersion = ((ILastVersionChecker) oldProcess).isLastVersion(item);
                }
                if (designerEditor.getEditorInput() instanceof JobEditorInput) {
                    ((JobEditorInput) designerEditor.getEditorInput()).checkInit(lastVersion, null, true);
                }
            }
            getEditor(0).doSave(monitor);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    } else {
        refreshPropertyDirtyStatus();
        getEditor(0).doSave(monitor);
    }
    /*
         * refresh should be executed before add the listener,or it will has eProxy on the property,it will cause a
         * editor dirty problem. hywang commet bug 17357
         */
    if (processEditorInput != null) {
        propertyInformation = new ArrayList(processEditorInput.getItem().getProperty().getInformations());
        propertyIsDirty = false;
    }
    if (designerEditor != null && dirtyListener != null) {
        designerEditor.getProcess().getProperty().eAdapters().add(dirtyListener);
    }
    refreshJobSettingsView();
    changeCollapsedState(false, jobletMap);
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
        ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
        if (testContainerService != null) {
            testContainerService.updateDetect(getProcess(), false);
        }
    }
    if (isCheckout) {
        CommandStack stack = (CommandStack) getAdapter(CommandStack.class);
        stack.flush();
        isCheckout = false;
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) Process(org.talend.designer.core.ui.editor.process.Process) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) IRepositoryService(org.talend.repository.model.IRepositoryService) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ILastVersionChecker(org.talend.core.ui.ILastVersionChecker) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CommandStack(org.eclipse.gef.commands.CommandStack) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ProcessorException(org.talend.designer.runprocess.ProcessorException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource)

Aggregations

ITestContainerProviderService (org.talend.core.ui.ITestContainerProviderService)12 ArrayList (java.util.ArrayList)7 Item (org.talend.core.model.properties.Item)6 PersistenceException (org.talend.commons.exception.PersistenceException)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 CoreException (org.eclipse.core.runtime.CoreException)3 IProcess2 (org.talend.core.model.process.IProcess2)3 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 Point (org.eclipse.draw2d.geometry.Point)2 CommandStack (org.eclipse.gef.commands.CommandStack)2 PartInitException (org.eclipse.ui.PartInitException)2