Search in sources :

Example 16 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateSourceCodeInfo.

/**
     * DOC qwei Comment method "generateSourceCodeInfo".
     */
private void generateSourceCodeInfo(ProcessItem item, Element element) {
    if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(item);
        IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
        // hidePasswordInSourceCode4Doc(process);
        try {
            processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
            processor.generateCode(false, true, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
        //$NON-NLS-1$
        Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        // StringBuffer componentsCode = new StringBuffer();
        try {
            IFile codeFile = synchronizer.getFile(item);
            if (codeFile == null) {
                return;
            }
            //$NON-NLS-1$
            String tempStr = "";
            InputStream in = codeFile.getContents();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            while ((tempStr = buffer.readLine()) != null) {
                //$NON-NLS-1$
                Element codeElement = DocumentHelper.createElement("code");
                // componentsCode.append(tempStr).append("\n");
                //$NON-NLS-1$
                codeElement.addAttribute("content", tempStr);
                sourceCodeInfoElement.add(codeElement);
            }
            buffer.close();
            in.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        element.add(sourceCodeInfoElement);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 17 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class BDJobReArchieveCreator method getLibPath.

/**
     * 
     * maybe, should be same result with JobJavaScriptsManager.getLibPath
     */
public List<File> getLibPath(File zipTmpFolder, boolean isSpecialMR) {
    List<File> neededLibFiles = new ArrayList<File>();
    File libFolder = new File(zipTmpFolder, JavaUtils.JAVA_LIB_DIRECTORY);
    Set<String> compiledModulesSet = new HashSet<String>(100);
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(processItem.getProperty().getId(), processItem.getProperty().getVersion());
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
        IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
        IProcess process = designerCoreService.getProcessFromProcessItem(processItem);
        compiledModulesSet.addAll(PomUtil.getCodesExportJars(process));
        if (neededModules.isEmpty()) {
            neededModules = process.getNeededModules(true);
        }
    }
    for (ModuleNeeded module : neededModules) {
        if (((isSpecialMR || isSparkWithHDInsight) && module.isMrRequired()) || (!isSpecialMR && !isSparkWithHDInsight)) {
            compiledModulesSet.add(module.getModuleName());
        }
    }
    Set<String> jarNames = new HashSet<String>();
    try {
        // from org.talend.libraries.apache.storm/lib
        Bundle bundle = Platform.getBundle(PLUGIN_ID);
        if (bundle != null) {
            //$NON-NLS-1$
            URL stormLibUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path("lib"), null));
            if (stormLibUrl != null) {
                File file = new File(stormLibUrl.getFile());
                File[] jars = file.listFiles();
                for (File f : jars) {
                    jarNames.add(f.getName());
                }
            }
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    for (String jarName : compiledModulesSet) {
        File jarFile = new File(libFolder, jarName);
        if (jarFile.exists()) {
            if (!isSpecialMR && !jarNames.isEmpty()) {
                // for storm not include the jar from libraries.apache.strom
                if (!jarNames.contains(jarName)) {
                    neededLibFiles.add(jarFile);
                }
            } else {
                neededLibFiles.add(jarFile);
            }
        }
    }
    return neededLibFiles;
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IProcess(org.talend.core.model.process.IProcess) HashSet(java.util.HashSet)

Example 18 with IProcess

use of org.talend.core.model.process.IProcess in project tesb-studio-se by Talend.

the class CheckRouteBuilderNodeService method checkNode.

@Override
public void checkNode(Node node) {
    //TESB-7698
    IProcess process = node.getProcess();
    if (process == null || !(process instanceof RouteProcess)) {
        return;
    }
    //End TESB-7698
    checkIncomingConnections(node);
    checkSpecialComponent(node);
}
Also used : RouteProcess(org.talend.camel.designer.ui.editor.RouteProcess) IProcess(org.talend.core.model.process.IProcess)

Example 19 with IProcess

use of org.talend.core.model.process.IProcess in project tesb-studio-se by Talend.

the class CheckMultiRestRequestNodes method checkNode.

@Override
public void checkNode(Node node) {
    String name = node.getComponent().getName();
    if (!RESTREQUEST_COMPONENT.equals(name)) {
        return;
    }
    IProcess process = node.getProcess();
    if (process.getNodesOfType(RESTREQUEST_COMPONENT).size() > 1) {
        Problems.add(ProblemStatus.ERROR, (Element) node, "Only one " + RESTREQUEST_COMPONENT + " component is allowed in a Job!");
    } else if (process.getNodesOfType(ESBPROVIDER_COMPONENT).size() > 0) {
        Problems.add(ProblemStatus.ERROR, (Element) node, RESTREQUEST_COMPONENT + " and " + ESBPROVIDER_COMPONENT + " can't present in a same Job!");
    }
}
Also used : Element(org.talend.core.model.process.Element) IProcess(org.talend.core.model.process.IProcess)

Example 20 with IProcess

use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.

the class StandardJobStandaloneBuildProviderTest 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);
    final Method getAssemblyFileMethod = processorClazz.getDeclaredMethod("getAssemblyFile");
    getAssemblyFileMethod.setAccessible(true);
    final Object getAssemblyFile = getAssemblyFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile assemblyFile = (IFile) getAssemblyFile;
    parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, assemblyFile);
    // before set classpath, must do initJobClasspath
    final Method initJobClasspathMethod = processorClazz.getDeclaredMethod("initJobClasspath");
    initJobClasspathMethod.setAccessible(true);
    initJobClasspathMethod.invoke(processor);
    final Field windowsClasspathField = processorClazz.getDeclaredField("windowsClasspath");
    windowsClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_WIN, windowsClasspathField.get(processor));
    final Field unixClasspathField = processorClazz.getDeclaredField("unixClasspath");
    unixClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_LINUX, unixClasspathField.get(processor));
    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(CreateMavenJobPom.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());
    assemblyFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the assembly file " + assemblyFile.getName() + " is not created ", assemblyFile.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) Field(java.lang.reflect.Field) 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)

Aggregations

IProcess (org.talend.core.model.process.IProcess)102 INode (org.talend.core.model.process.INode)33 ArrayList (java.util.ArrayList)28 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)24 IProcess2 (org.talend.core.model.process.IProcess2)22 ProcessItem (org.talend.core.model.properties.ProcessItem)21 Node (org.talend.designer.core.ui.editor.nodes.Node)20 List (java.util.List)17 Item (org.talend.core.model.properties.Item)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 IOException (java.io.IOException)15 PersistenceException (org.talend.commons.exception.PersistenceException)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 IEditorPart (org.eclipse.ui.IEditorPart)11 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 File (java.io.File)9 Element (org.talend.core.model.process.Element)9 IConnection (org.talend.core.model.process.IConnection)9 IContext (org.talend.core.model.process.IContext)9