Search in sources :

Example 61 with IFolder

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

the class RouteResourceUtil method synchronizeRouteResource.

public static Collection<IPath> synchronizeRouteResource(final ProcessItem item) {
    final boolean routelet;
    if (item.eClass() == CamelPropertiesPackage.Literals.CAMEL_PROCESS_ITEM) {
        routelet = false;
    } else if (item.eClass() == CamelPropertiesPackage.Literals.ROUTELET_PROCESS_ITEM) {
        routelet = true;
    } else {
        return null;
    }
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return null;
    }
    final IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
    final ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
    if (talendProcessJavaProject == null) {
        return null;
    }
    final IFolder routeResourceFolder = talendProcessJavaProject.getResourcesFolder();
    final Collection<IPath> result = new ArrayList<IPath>();
    // add spring file
    if (!routelet) {
        final IFolder metaInf = routeResourceFolder.getFolder("META-INF/spring/");
        try {
            prepareFolder(metaInf);
            final IFile spring = metaInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final InputStream inputStream = new ByteArrayInputStream(((CamelProcessItem) item).getSpringContent().getBytes());
            if (spring.exists()) {
                spring.setContents(inputStream, 0, null);
            } else {
                spring.create(inputStream, true, null);
            }
            result.add(spring.getLocation());
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
    for (ResourceDependencyModel model : getResourceDependencies(item)) {
        IFile file = copyResources(routeResourceFolder, model);
        if (file != null) {
            result.add(file.getLocation());
        }
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceDependencyModel(org.talend.designer.camel.resource.core.model.ResourceDependencyModel) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) IFolder(org.eclipse.core.resources.IFolder)

Example 62 with IFolder

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

the class JobJavaScriptsManager method getLog4jFiles.

/**
     * Gets required java jars.
     * 
     * @param process
     * 
     * @param boolean1
     * @return
     */
protected List<URL> getLog4jFiles() {
    List<URL> list = new ArrayList<URL>();
    if (Log4jUtil.isEnable() && Boolean.parseBoolean(Log4jPrefsSettingManager.getInstance().getValueOfPreNode(Log4jPrefsConstants.LOG4J_ENABLE_NODE)) && GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        try {
            ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
            if (talendProcessJavaProject != null) {
                IFolder resourcesFolder = talendProcessJavaProject.getResourcesFolder();
                IFile log4jFile = resourcesFolder.getFile(Log4jPrefsConstants.LOG4J_FILE_NAME);
                if (log4jFile.exists()) {
                    list.add(FileLocator.toFileURL(log4jFile.getLocationURI().toURL()));
                }
            }
        } catch (MalformedURLException e) {
            ExceptionHandler.process(e);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    return list;
}
Also used : MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 63 with IFolder

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

the class JobJavaScriptsManager method addXmlMapping.

protected void addXmlMapping(ExportFileResource resource, boolean needSource) {
    try {
        boolean hasDynamicMetadata = false;
        if (resource.getItem() instanceof ProcessItem) {
            List<JobInfo> list = new ArrayList<JobInfo>();
            hasDynamicMetadata = LastGenerationInfo.getInstance().isUseDynamic(resource.getItem().getProperty().getId(), resource.getItem().getProperty().getVersion());
        }
        if (hasDynamicMetadata) {
            needMappingInSystemRoutine = true;
            if (needSource) {
                IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
                ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
                if (talendProcessJavaProject == null) {
                    return;
                }
                // for db mapping xml
                IFolder xmlMappingFolder = talendProcessJavaProject.getResourcesFolder().getFolder(JavaUtils.JAVA_XML_MAPPING);
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreService.class)) {
                    ICoreService coreService = (ICoreService) GlobalServiceRegister.getDefault().getService(ICoreService.class);
                    coreService.synchronizeMapptingXML();
                    coreService.syncLog4jSettings();
                }
                List<URL> xmlMappingFileUrls = new ArrayList<URL>();
                if (xmlMappingFolder.exists()) {
                    for (IResource fileResource : xmlMappingFolder.members()) {
                        if (XmlUtil.isXMLFile(fileResource.getName())) {
                            xmlMappingFileUrls.add(fileResource.getLocationURI().toURL());
                        }
                    }
                    resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + JavaUtils.JAVA_XML_MAPPING, xmlMappingFileUrls);
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) ICoreService(org.talend.core.ICoreService) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 64 with IFolder

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

the class JobJavaScriptsManager method addDependenciesSourceCode.

protected void addDependenciesSourceCode(ExportFileResource[] process, ExportFileResource resource, boolean needSource) {
    if (!needSource) {
        return;
    }
    try {
        // get different routines.
        IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFolder systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH);
        List<URL> systemRoutinesFileUrls = new ArrayList<URL>();
        if (systemRoutineFolder.exists()) {
            for (IResource fileResource : systemRoutineFolder.members()) {
                if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
                    systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
                }
            }
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH, systemRoutinesFileUrls);
        }
        // bug TDI-8647
        // empty and re-use it
        systemRoutinesFileUrls.clear();
        systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY);
        if (systemRoutineFolder.exists()) {
            for (IResource fileResource : systemRoutineFolder.members()) {
                if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
                    systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
                }
            }
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY, systemRoutinesFileUrls);
        }
        // add for routines
        boolean useBeans = false;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (camelService.isInstanceofCamel(process[0].getItem())) {
                useBeans = true;
            }
        }
        addRoutinesSourceCodes(process, resource, talendProcessJavaProject, useBeans);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 65 with IFolder

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

the class JobJavaScriptsManager method addLog4jXmlToRes.

protected void addLog4jXmlToRes(ExportFileResource libResource) {
    List<URL> list = new ArrayList<URL>();
    if (Log4jPrefsSettingManager.getInstance().isLog4jEnable() && GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        try {
            ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
            if (talendProcessJavaProject != null) {
                IFolder resourcesFolder = talendProcessJavaProject.getResourcesFolder();
                IFile log4jFile = resourcesFolder.getFile(Log4jPrefsConstants.LOG4J_FILE_NAME);
                if (log4jFile.exists()) {
                    list.add(log4jFile.getLocationURI().toURL());
                }
            }
        } catch (MalformedURLException e) {
            ExceptionHandler.process(e);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    libResource.addResources(list);
}
Also used : MalformedURLException(java.net.MalformedURLException) IFile(org.eclipse.core.resources.IFile) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15