Search in sources :

Example 31 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class TestComponentsAction method generateCode.

public void generateCode(File[] tempFile, String componentPath) {
    for (File file : tempFile) {
        if (file.length() > 0) {
            URI uri = URI.createFileURI(file.toString());
            TalendFilePackage.eINSTANCE.getNsURI();
            Resource resource = new ResourceSetImpl().getResource(uri, true);
            ProcessType processType = (ProcessType) EcoreUtil.getObjectByType(resource.getContents(), TalendFilePackage.eINSTANCE.getProcessType());
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            ProcessItem item = PropertiesFactory.eINSTANCE.createProcessItem();
            item.setProcess(processType);
            item.setProperty(PropertiesFactory.eINSTANCE.createProperty());
            item.getProperty().setLabel(TestParameter.TEST_DIR);
            item.getProperty().setAuthor(PropertiesFactory.eINSTANCE.createUser());
            item.getProperty().setId(file.getName());
            item.getProperty().setStatusCode(file.getName());
            item.getProperty().setVersion(TestParameter.VERSION);
            IProcess process = service.getProcessFromProcessItem(item);
            setDefaultProperties(process, componentPath);
            IProcessor processor = ProcessorUtilities.getProcessor(process, item.getProperty(), process.getContextManager().getDefaultContext());
            try {
                // generate
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_START + " : " + file.getName());
                // processor.generateCode(process.getContextManager().getDefaultContext(), false, false, true);
                processor.generateCode(false, false, true);
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_END + " : " + file.getName());
                // run
                //$NON-NLS-1$
                log.info(TestParameter.RUN_START + " : " + file.getName());
                java.lang.Process runningProcess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
                StringBuffer errBuff = new StringBuffer();
                if (isRunOK(runningProcess, errBuff)) {
                    //$NON-NLS-1$
                    log.info(TestParameter.RUN_SUCCESS + " : " + file.getName());
                } else {
                    // 2 possibilities : OK not found / error stream
                    //$NON-NLS-1$
                    log.error(TestParameter.RUN_FAIL + " : " + file.getName(), new Exception(errBuff.toString()));
                }
            } catch (ProcessorException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ProcessorException(org.talend.designer.runprocess.ProcessorException) Resource(org.eclipse.emf.ecore.resource.Resource) IProcessor(org.talend.designer.runprocess.IProcessor) URI(org.eclipse.emf.common.util.URI) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 32 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class StandardJobOSGiBundleBuildProviderTest method test_createPomCreator.

@Test
public void test_createPomCreator() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Item jobItem = createJobItem();
    final IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    Assert.assertNotNull(designerCoreService);
    final IProcess processFromItem = designerCoreService.getProcessFromItem(jobItem);
    IProcessor processor = ProcessorUtilities.getProcessor(processFromItem, jobItem.getProperty());
    final Class<? extends IProcessor> processorClazz = processor.getClass();
    Assert.assertEquals("org.talend.designer.runprocess.maven.MavenJavaProcessor", processorClazz.getName());
    processor.setContext(processor.getProcess().getContextManager().getDefaultContext());
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, processor);
    final Method getPomFileMethod = processorClazz.getDeclaredMethod("getPomFile");
    getPomFileMethod.setAccessible(true);
    final Object getPomFile = getPomFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile pomFile = (IFile) getPomFile;
    parameters.put(IBuildPomCreatorParameters.FILE_POM, pomFile);
    parameters.put(IBuildParametes.ITEM, processor.getProperty().getItem());
    final Map<String, Object> arguments = processor.getArguments();
    parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, arguments);
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, true);
    // create pom and assembly
    RepositoryObjectTypeBuildProvider provider = createTestBuildProvider();
    final IMavenPomCreator pomCreator = provider.createPomCreator(parameters);
    Assert.assertNotNull("Create the pom creator failure", pomCreator);
    Assert.assertEquals(CreateMavenStandardJobOSGiPom.class, pomCreator.getClass());
    pomCreator.create(null);
    pomFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the pom file " + pomFile.getName() + " is not created ", pomFile.exists());
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) Method(java.lang.reflect.Method) Item(org.talend.core.model.properties.Item) RepositoryObjectTypeBuildProvider(org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 33 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class SpagicJavaDeployManager method getProperties.

public List<URL> getProperties(ProcessItem processItem, String contextName) {
    List<URL> list = new ArrayList<URL>();
    Properties p = new Properties();
    FileOutputStream out = null;
    String projectName = getCorrespondingProjectName(processItem);
    String jobName = processItem.getProperty().getLabel();
    String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), processItem.getProperty().getVersion());
    try {
        // List<SpagoBiServer> listServerSapgo = null;
        // listServerSapgo = SpagicServerHelper.parse(new SpagicPreferencePage().getPreferenceStore().getString(
        // SpagoBiServer.SPAGOBI_SERVER));
        // if (listServerSapgo != null && !listServerSapgo.isEmpty()) {
        // Iterator<SpagoBiServer> iterator = listServerSapgo.iterator();
        // while (iterator.hasNext()) {
        // SpagoBiServer spagoBiServer = iterator.next();
        // }
        // }
        IPath path = getSrcRootLocation();
        //$NON-NLS-1$
        File file = new File(getTmpFolder() + PATH_SEPARATOR + "spagic.properties");
        //$NON-NLS-1$
        path = path.append(projectName).append(jobFolderName).append(jobName + ".java");
        BufferedReader buff = new BufferedReader(new FileReader(path.toPortableString()));
        int nbLine = 0;
        while (buff.readLine() != null) {
            nbLine++;
        }
        out = new FileOutputStream(file);
        PrintStream ps = new PrintStream(out);
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(processItem);
        List<IContextParameter> ctxParams = process.getContextManager().getContext(contextName).getContextParameterList();
        for (IContextParameter ctxParam : ctxParams) {
            p.put(ctxParam.getName(), ctxParam.getValue());
        }
        p.put("JobClassName", //$NON-NLS-1$
        getCorrespondingProjectName(null) + //$NON-NLS-1$
        "." + JavaResourcesHelper.getJobFolderName(processItem.getProperty().getLabel(), processItem.getProperty().getVersion()) + "." + //$NON-NLS-1$
        processItem.getProperty().getLabel());
        //$NON-NLS-1$
        p.put("talendJobClassDescription", HTMLDocUtils.checkString(processItem.getProperty().getDescription()));
        //$NON-NLS-1$
        p.put("rowNumber", Integer.toString(nbLine));
        //$NON-NLS-1$ //$NON-NLS-2$
        p.put("host", "localhost");
        p.list(ps);
        ps.flush();
        list.add(file.toURI().toURL());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (Exception e) {
            }
        }
    }
    return list;
}
Also used : PrintStream(java.io.PrintStream) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) Properties(java.util.Properties) IContextParameter(org.talend.core.model.process.IContextParameter) URL(java.net.URL) ProcessorException(org.talend.designer.runprocess.ProcessorException) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 34 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class VisibleComponentSettingsMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    List<ComponentSetting> componentsSettings = (List<ComponentSetting>) currentProject.getEmfProject().getComponentsSettings();
    boolean modified = false;
    if (processType != null) {
        EList nodes = processType.getNode();
        for (Object node : nodes) {
            NodeType nodeType = (NodeType) node;
            for (ComponentSetting setting : componentsSettings) {
                if (setting.getName().equals(nodeType.getComponentName())) {
                    if (setting.isHidden()) {
                        setting.setHidden(false);
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
        try {
            prf.saveProject(currentProject);
        } catch (Exception ex) {
            ExceptionHandler.process(ex);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ComponentSetting(org.talend.core.model.properties.ComponentSetting) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 35 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method getExternalLibraries.

/**
     * Gets required java jars.
     * 
     * @param process
     * 
     * @param boolean1
     * @return
     */
protected List<URL> getExternalLibraries(boolean needLibraries, ExportFileResource[] process, final Set<String> neededLibraries) {
    List<URL> list = new ArrayList<URL>();
    if (!needLibraries) {
        return list;
    }
    IFolder libFolder = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
        if (talendProcessJavaProject != null) {
            libFolder = talendProcessJavaProject.getLibFolder();
        }
    }
    if (libFolder == null) {
        return list;
    }
    File file = libFolder.getLocation().toFile();
    File[] files = file.listFiles(FilesUtils.getAcceptModuleFilesFilter());
    // Lists all the needed jar files
    Set<String> listModulesReallyNeeded = new HashSet<String>();
    if (neededLibraries == null) {
        // in case export as been done with option "not recompile", then libraires can't be retrieved when build.
        IDesignerCoreService designerService = RepositoryPlugin.getDefault().getDesignerCoreService();
        for (ExportFileResource resource : process) {
            ProcessItem item = (ProcessItem) resource.getItem();
            String version = item.getProperty().getVersion();
            if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
                version = this.getSelectedJobVersion();
            }
            ProcessItem selectedProcessItem;
            if (resource.getNode() != null) {
                selectedProcessItem = ItemCacheManager.getProcessItem(resource.getNode().getRoot().getProject(), item.getProperty().getId(), version);
            } else {
                // if no node given, take in the current project only
                selectedProcessItem = ItemCacheManager.getProcessItem(item.getProperty().getId(), version);
            }
            IProcess iProcess = designerService.getProcessFromProcessItem(selectedProcessItem);
            Set<String> processNeededLibraries = iProcess.getNeededLibraries(true);
            if (processNeededLibraries != null) {
                listModulesReallyNeeded.addAll(processNeededLibraries);
            }
        }
    } else {
        listModulesReallyNeeded.addAll(neededLibraries);
    }
    // jar from routines
    List<IRepositoryViewObject> collectRoutines = new ArrayList<IRepositoryViewObject>();
    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;
        }
    }
    String include = null;
    if (useBeans) {
        include = USER_BEANS_PATH;
    } else {
        include = USER_ROUTINES_PATH;
    }
    collectRoutines.addAll(collectRoutines(process, include));
    collectRoutines.addAll(collectRoutines(process, USER_PIGUDF_PATH));
    for (IRepositoryViewObject object : collectRoutines) {
        Item item = object.getProperty().getItem();
        if (item instanceof RoutineItem) {
            RoutineItem routine = (RoutineItem) item;
            EList imports = routine.getImports();
            for (Object o : imports) {
                IMPORTType type = (IMPORTType) o;
                listModulesReallyNeeded.add(type.getMODULE());
            }
        }
    }
    if (Log4jPrefsSettingManager.getInstance().isLog4jEnable()) {
        addLog4jToJarList(listModulesReallyNeeded);
    }
    for (File tempFile : files) {
        try {
            if (listModulesReallyNeeded.contains(tempFile.getName())) {
                list.add(tempFile.toURL());
            }
        } catch (MalformedURLException e) {
            ExceptionHandler.process(e);
        }
    }
    return list;
// List<URL> libraries = new ArrayList<URL>();
// if (needLibraries) {
// try {
// ILibrariesService service = CorePlugin.getDefault().getLibrariesService();
// libraries = service.getTalendRoutines();
// } catch (Exception e) {
// ExceptionHandler.process(e);
// }
// }
// return libraries;
}
Also used : MalformedURLException(java.net.MalformedURLException) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) RulesItem(org.talend.core.model.properties.RulesItem) RoutineItem(org.talend.core.model.properties.RoutineItem) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) EList(org.eclipse.emf.common.util.EList) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)40 IProcess (org.talend.core.model.process.IProcess)25 ProcessItem (org.talend.core.model.properties.ProcessItem)21 Item (org.talend.core.model.properties.Item)13 ArrayList (java.util.ArrayList)12 INode (org.talend.core.model.process.INode)12 PersistenceException (org.talend.commons.exception.PersistenceException)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 IOException (java.io.IOException)8 List (java.util.List)8 IProcess2 (org.talend.core.model.process.IProcess2)7 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IFile (org.eclipse.core.resources.IFile)6 IElementParameter (org.talend.core.model.process.IElementParameter)6 Process (org.talend.designer.core.ui.editor.process.Process)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 IEditorReference (org.eclipse.ui.IEditorReference)5 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)5 File (java.io.File)4