Search in sources :

Example 71 with IFolder

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

the class TalendProcessJavaProjectTest method testGetTestSrcFolder.

/**
     * Test method for {@link org.talend.designer.runprocess.java.TalendProcessJavaProject#getTestSrcFolder()}.
     */
@Test
public void testGetTestSrcFolder() {
    IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
    Assert.assertNotNull(testSrcFolder);
    Assert.assertTrue(testSrcFolder.exists());
    IPath projectRelativePath = testSrcFolder.getProjectRelativePath();
    Assert.assertEquals(MavenSystemFolders.JAVA_TEST.getPath(), projectRelativePath.toString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 72 with IFolder

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

the class TalendProcessJavaProjectTest method testGetSrcFolder.

/**
     * Test method for {@link org.talend.designer.runprocess.java.TalendProcessJavaProject#getSrcFolder()}.
     */
@Test
public void testGetSrcFolder() {
    IFolder srcFolder = talendJavaProject.getSrcFolder();
    Assert.assertNotNull(srcFolder);
    Assert.assertTrue(srcFolder.exists());
    IPath projectRelativePath = srcFolder.getProjectRelativePath();
    Assert.assertEquals(MavenSystemFolders.JAVA.getPath(), projectRelativePath.toString());
}
Also used : IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 73 with IFolder

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

the class JavaTestShadow method process.

public void process(Text testResultText, TableViewer tableViewer) {
    Map<String, String> map = RoutineFunctionParser.getTypePackgeMethods();
    Function function = CategoryComposite.getSelectedFunction();
    String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
    if (function != null && expression != null && !"".equals(expression)) {
        if (serverThread == null || !serverThread.isAlive()) {
            server = ExpressionTestServer.getInstance(Display.getCurrent(), testResultText);
            serverThread = new Thread(server);
            serverThread.start();
        }
        //$NON-NLS-1$
        String methodFullName = map.get(function.getTalendType().getName() + "." + function.getName());
        //$NON-NLS-1$
        String[] fullClassAndMethod = methodFullName.split("\\.");
        String methodName = fullClassAndMethod[fullClassAndMethod.length - 1];
        expression = expression.replaceAll(methodName, methodFullName);
        ExpressionArguments arguments = new ExpressionArguments();
        arguments.setExpression(expression);
        arguments.setVariables((List<Variable>) tableViewer.getInput());
        ExpressionGenerator codeGenerator = new ExpressionGenerator();
        String fileContent = codeGenerator.generate(arguments);
        ITalendProcessJavaProject talendProcessJavaProject = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
            IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            talendProcessJavaProject = processService.getTalendProcessJavaProject();
        }
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFolder outputFolder = talendProcessJavaProject.getOutputFolder();
        //$NON-NLS-1$
        IFile file = srcFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.java"));
        //$NON-NLS-1$
        IFile classFile = outputFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.class"));
        InputStream in = new ByteArrayInputStream(fileContent.getBytes());
        try {
            if (!file.exists()) {
                file.create(in, true, null);
            } else {
                file.delete(true, null);
                classFile.delete(true, null);
                file.create(in, true, null);
            }
            while (!classFile.exists()) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        } catch (CoreException e1) {
            RuntimeExceptionHandler.process(e1);
        }
        try {
            in.close();
            in = null;
        } catch (IOException e2) {
            RuntimeExceptionHandler.process(e2);
        }
        String javaInterpreter = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.JAVA_INTERPRETER);
        IPath path = outputFolder.getLocation();
        //$NON-NLS-1$ //$NON-NLS-2$
        String[] str = new String[] { javaInterpreter, "-cp", path.toOSString(), "routines.ExpressionVariableTest" };
        InputStreamReader reader = null;
        try {
            Process exec = Runtime.getRuntime().exec(str);
            reader = new InputStreamReader(exec.getErrorStream());
            char[] buffer = new char[1024];
            int i = 0;
            StringBuffer bufferString = new StringBuffer();
            while ((i = reader.read(buffer)) != -1) {
                bufferString.append(buffer, 0, i);
            }
            reader.close();
            if (bufferString.length() > 0) {
                testResultText.setText(bufferString.toString());
            }
        } catch (IOException e1) {
            RuntimeExceptionHandler.process(e1);
        } finally {
            reader = null;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IOException(java.io.IOException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) Function(org.talend.designer.rowgenerator.data.Function) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 74 with IFolder

use of org.eclipse.core.resources.IFolder 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 75 with IFolder

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

the class JavaProcessor method cleanBeforeGenerate.

@Override
public void cleanBeforeGenerate(int options) throws ProcessorException {
    setDoClean(false);
    if (this.getProcess().isNeedRegenerateCode() || this.getProcess() instanceof IProcess2 && ((IProcess2) this.getProcess()).isProcessModified()) {
        // will do clean
        setDoClean(true);
    } else {
        return;
    }
    // clean the generated java source codes.
    if (BitwiseOptionUtils.containOption(options, CLEAN_JAVA_CODES)) {
        IFolder javaCodeFolder = getCodeProject().getFolder(this.getSrcCodePath().removeLastSegments(1));
        // cleanFolder(javaCodeFolder);
        try {
            if (javaCodeFolder != null) {
                String processSourceFileName = null;
                if (process != null) {
                    //$NON-NLS-1$
                    processSourceFileName = process.getName() + ".java";
                }
                for (IResource resource : javaCodeFolder.members()) {
                    if ("java".equals(resource.getFileExtension())) {
                        //$NON-NLS-1$
                        if (processSourceFileName != null && processSourceFileName.equals(resource.getName())) {
                            ((IFile) resource).setContents(new ByteArrayInputStream(new byte[0]), true, false, null);
                        } else {
                            resource.delete(true, null);
                        }
                    } else {
                        resource.delete(true, null);
                    }
                }
            }
        } catch (CoreException e) {
        // do nothing
        }
        IFolder classCodeFolder = getCodeProject().getFolder(this.getCompiledCodePath().removeLastSegments(1));
        cleanFolder(classCodeFolder);
    }
    // clean the context groups. Sometimes, if remove the context group, the context file be kept still.
    if (BitwiseOptionUtils.containOption(options, CLEAN_CONTEXTS)) {
        IFolder srcContextFolder = getCodeProject().getFolder(this.getSrcContextPath().removeLastSegments(1));
        cleanFolder(srcContextFolder);
        IFolder classContextFolder = getCodeProject().getFolder(this.getCompiledContextPath().removeLastSegments(1));
        cleanFolder(classContextFolder);
    }
    // if test case, clean the data
    if (BitwiseOptionUtils.containOption(options, CLEAN_DATA_SETS) && isTestJob) {
        IFolder srcDatasetFolder = getCodeProject().getFolder(this.getSrcDataSetPath());
        cleanFolder(srcDatasetFolder);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IProcess2(org.talend.core.model.process.IProcess2) IResource(org.eclipse.core.resources.IResource) 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