Search in sources :

Example 1 with IRulesProviderService

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

the class JavaProcessor method generateCode.

/*
     * Append the generated java code form context into java file wihtin the project. If the file not existed new one
     * will be created.
     * 
     * @see org.talend.designer.runprocess.IProcessor#generateCode(org.talend.core .model.process.IContext, boolean,
     * boolean, boolean)
     */
@Override
public void generateCode(boolean statistics, boolean trace, boolean javaProperties, int option) throws ProcessorException {
    super.generateCode(statistics, trace, javaProperties, option);
    try {
        // hywang modified for 6484
        String currentJavaProject = ProjectManager.getInstance().getProject(property).getTechnicalLabel();
        ICodeGenerator codeGen;
        ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
        if (javaProperties) {
            //$NON-NLS-1$
            String javaInterpreter = "";
            //$NON-NLS-1$
            String javaLib = "";
            String javaContext = getContextPath().toPortableString();
            codeGen = service.createCodeGenerator(process, statistics, trace, javaInterpreter, javaLib, javaContext, currentJavaProject);
        } else {
            codeGen = service.createCodeGenerator(process, statistics, trace);
        }
        // set the selected context. if don't find, will keep default
        if (!process.getContextManager().getDefaultContext().getName().equals(context.getName())) {
            boolean found = false;
            for (IContext c : process.getContextManager().getListContext()) {
                if (c.getName().equals(context.getName())) {
                    found = true;
                }
            }
            if (found) {
                codeGen.setContextName(context.getName());
            }
        }
        //$NON-NLS-1$
        String processCode = "";
        try {
            // must before codegen for job to set the rule flag.
            if (PluginChecker.isRulesPluginLoaded()) {
                IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
                if (rulesService != null) {
                    boolean useGenerateRuleFiles = false;
                    List<? extends INode> allNodes = this.process.getGeneratingNodes();
                    for (int i = 0; i < allNodes.size(); i++) {
                        if (allNodes.get(i) instanceof INode) {
                            INode node = allNodes.get(i);
                            if (rulesService.isRuleComponent(node) && !node.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getValue().toString().equals("BUILT_IN")) {
                                //$NON-NLS-1$
                                useGenerateRuleFiles = true;
                                break;
                            }
                        }
                    }
                    if (useGenerateRuleFiles && rulesService != null && currentJavaProject != null) {
                        rulesService.generateFinalRuleFiles(currentJavaProject, this.process);
                        LastGenerationInfo.getInstance().setUseRules(this.process.getId(), this.process.getVersion(), true);
                    }
                }
            }
            processCode = codeGen.generateProcessCode();
        } catch (SystemException e) {
            //$NON-NLS-1$
            throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
        if (!BitwiseOptionUtils.containOption(option, TalendProcessOptionConstants.GENERATE_WITHOUT_FORMAT)) {
            processCode = doFormat(processCode);
        }
        // see feature 4610:option to see byte length of each code method
        processCode = computeMethodSizeIfNeeded(processCode);
        InputStream codeStream = new ByteArrayInputStream(processCode.getBytes());
        // Generating files
        IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath());
        if (!codeFile.exists()) {
            // in win.
            try {
                org.talend.commons.utils.io.FilesUtils.removeExistedResources(null, codeFile, true, true);
            } catch (Exception e) {
                throw new ProcessorException(e);
            }
            IFolder parentFolder = (IFolder) codeFile.getParent();
            if (!parentFolder.exists()) {
                parentFolder.create(true, true, null);
            }
            codeFile.create(codeStream, true, null);
        } else {
            codeFile.setContents(codeStream, true, false, null);
        }
        // codeFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        processCode = null;
        // updateContextCode(codeGen);
        //$NON-NLS-1$
        codeFile.getProject().deleteMarkers("org.eclipse.jdt.debug.javaLineBreakpointMarker", true, IResource.DEPTH_INFINITE);
        List<INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process);
        if (!breakpointNodes.isEmpty()) {
            String[] nodeNames = new String[breakpointNodes.size()];
            int pos = 0;
            String nodeName;
            for (INode node : breakpointNodes) {
                nodeName = node.getUniqueName();
                if (node.getComponent().getMultipleComponentManagers().size() > 0) {
                    //$NON-NLS-1$
                    nodeName += "_" + node.getComponent().getMultipleComponentManagers().get(0).getInput().getName();
                }
                //$NON-NLS-1$ //$NON-NLS-2$
                nodeNames[pos++] = "[" + nodeName + " main ] start";
            }
            int[] lineNumbers = getLineNumbers(codeFile, nodeNames);
            setBreakpoints(codeFile, getMainClass(), lineNumbers);
        }
    } catch (CoreException e1) {
        if (e1.getStatus() != null && e1.getStatus().getException() != null) {
            ExceptionHandler.process(e1.getStatus().getException());
        }
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
    }
}
Also used : INode(org.talend.core.model.process.INode) IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) IRulesProviderService(org.talend.core.ui.services.IRulesProviderService) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) ZipInputStream(java.util.zip.ZipInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IJavaBreakpoint(org.eclipse.jdt.debug.core.IJavaBreakpoint) IJavaLineBreakpoint(org.eclipse.jdt.debug.core.IJavaLineBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IOException(java.io.IOException) SystemException(org.talend.commons.exception.SystemException) ProcessorException(org.talend.designer.runprocess.ProcessorException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ICodeGenerator(org.talend.designer.codegen.ICodeGenerator) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IRulesProviderService

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

the class RepositoryService method getRulesProviderPath.

@Override
public String getRulesProviderPath(RulesItem currentRepositoryItem) {
    IRulesProviderService rulesService = null;
    if (PluginChecker.isRulesPluginLoaded()) {
        rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
        try {
            rulesService.syncRule(currentRepositoryItem);
            IFile ruleFile = rulesService.getRuleFile(currentRepositoryItem, FileConstants.XLS_FILE_SUFFIX);
            if (ruleFile == null) {
                return null;
            }
            String path = ruleFile.getLocation().toOSString();
            return path;
        } catch (SystemException e) {
            // added by SeB, log it at least butthe devlopper should have a look at this
            //$NON-NLS-1$
            log.error("failed to get the Rules provider path", e);
        }
    }
    //$NON-NLS-1$
    return "";
}
Also used : IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) IRulesProviderService(org.talend.core.ui.services.IRulesProviderService)

Example 3 with IRulesProviderService

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

the class JobJavaScriptsManager method initUrlForRulesFiles.

/**
     * DOC hywang Comment method "initUrlForDrlFiles".
     * 
     * @param process
     * @param talendDrlFiles
     * @throws PersistenceException
     * @throws CoreException
     * @throws MalformedURLException
     */
private Map<String, List<URL>> initUrlForRulesFiles(ExportFileResource[] process) throws PersistenceException, CoreException, MalformedURLException {
    Map<String, List<URL>> map = new HashMap<String, List<URL>>();
    List<URL> urlList = new ArrayList<URL>();
    String processLabelAndVersion = null;
    IFile file;
    Item item = null;
    ProcessItem pi = null;
    if (PluginChecker.isRulesPluginLoaded()) {
        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
        IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
        for (ExportFileResource proces : process) {
            // loop every exported job
            if (!urlList.isEmpty()) {
                urlList = new ArrayList<URL>();
            }
            item = (proces).getItem();
            if (item instanceof ProcessItem) {
                pi = (ProcessItem) item;
                processLabelAndVersion = JavaResourcesHelper.getJobFolderName(pi.getProperty().getLabel(), pi.getProperty().getVersion());
            }
            for (int j = 0; j < pi.getProcess().getNode().size(); j++) {
                // loop every node in every exported job
                if (pi.getProcess().getNode().get(j) instanceof NodeType) {
                    NodeType node = (NodeType) pi.getProcess().getNode().get(j);
                    if (rulesService.isRuleComponent(node)) {
                        for (Object obj : node.getElementParameter()) {
                            if (obj instanceof ElementParameterType) {
                                ElementParameterType elementParameter = (ElementParameterType) obj;
                                if (elementParameter.getName().equals("PROPERTY:REPOSITORY_PROPERTY_TYPE")) {
                                    //$NON-NLS-1$
                                    String id = elementParameter.getValue();
                                    if (factory.getLastVersion(id).getProperty().getItem() != null) {
                                        if (factory.getLastVersion(id).getProperty().getItem() instanceof RulesItem) {
                                            RulesItem rulesItem = (RulesItem) factory.getLastVersion(id).getProperty().getItem();
                                            file = rulesService.getFinalRuleFile(rulesItem, processLabelAndVersion);
                                            if (file != null) {
                                                URL url = file.getLocationURI().toURL();
                                                urlList.add(url);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            map.put(processLabelAndVersion, urlList);
        }
    }
    return map;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IRulesProviderService(org.talend.core.ui.services.IRulesProviderService) ArrayList(java.util.ArrayList) RulesItem(org.talend.core.model.properties.RulesItem) URL(java.net.URL) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) 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) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IFile (org.eclipse.core.resources.IFile)3 IRulesProviderService (org.talend.core.ui.services.IRulesProviderService)3 SystemException (org.talend.commons.exception.SystemException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 InflaterInputStream (java.util.zip.InflaterInputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 Base64InputStream (org.apache.commons.codec.binary.Base64InputStream)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 DebugException (org.eclipse.debug.core.DebugException)1 EList (org.eclipse.emf.common.util.EList)1