Search in sources :

Example 31 with ITalendProcessJavaProject

use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method getTalendJavaProject.

/**
     * A java project under folder .Java will be created if there is no existed.
     * 
     * DOC ggu Comment method "getTalendJavaProject".
     * 
     * @return
     * @throws CoreException
     */
public static ITalendProcessJavaProject getTalendJavaProject() {
    if (talendJavaProject == null) {
        synchronized (JavaProcessorUtilities.class) {
            if (talendJavaProject == null) {
                try {
                    IProject project = TalendCodeProjectUtil.initCodeProject(new NullProgressMonitor());
                    if (project != null) {
                        IJavaProject javaProject = JavaCore.create(project);
                        talendJavaProject = new TalendProcessJavaProject(javaProject);
                        // synchronize templates
                        if (talendJavaProject != null) {
                            MavenPomSynchronizer pomSynchronizer = new MavenPomSynchronizer(talendJavaProject);
                            pomSynchronizer.syncTemplates(false);
                        }
                    }
                } catch (Exception e) {
                    // create failure, only log it?
                    ExceptionHandler.process(e);
                }
            }
        }
    }
    return talendJavaProject;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) MavenPomSynchronizer(org.talend.designer.maven.tools.MavenPomSynchronizer) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ProcessorException(org.talend.designer.runprocess.ProcessorException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 32 with ITalendProcessJavaProject

use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.

the class JavaProcessor method createInternalPackage.

private void createInternalPackage() {
    ITalendProcessJavaProject tProcessJvaProject = getTalendJavaProject();
    if (tProcessJvaProject == null) {
        return;
    }
    tProcessJvaProject.createSubFolder(null, tProcessJvaProject.getSrcFolder(), JavaUtils.JAVA_INTERNAL_DIRECTORY);
}
Also used : ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject)

Example 33 with ITalendProcessJavaProject

use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.

the class JavaProcessor method generateEsbFiles.

/*
     * (non-Javadoc) generate ESB files on classpath for jobs with ESB components
     */
@Override
public void generateEsbFiles() throws ProcessorException {
    // process.getGeneratingNodes();
    List<? extends INode> graphicalNodes = process.getGraphicalNodes();
    try {
        IPath jobPackagePath = getSrcCodePath().removeLastSegments(1);
        IFolder jobPackageFolder = this.getCodeProject().getFolder(jobPackagePath);
        //$NON-NLS-1$
        IFolder wsdlsPackageFolder = jobPackageFolder.getFolder("wsdl");
        if (wsdlsPackageFolder.exists()) {
            wsdlsPackageFolder.delete(true, null);
        }
        for (INode node : graphicalNodes) {
            if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
                List<? extends INode> graphicalNodesOfJoblet = node.getProcess().getGeneratingNodes();
                for (INode nodeOfJoblet : graphicalNodesOfJoblet) {
                    if ("tESBConsumer".equals(nodeOfJoblet.getComponent().getName()) && nodeOfJoblet.isActivate()) {
                        //$NON-NLS-1$
                        generateWSDL(wsdlsPackageFolder, nodeOfJoblet);
                    }
                }
            } else {
                if ("tESBConsumer".equals(node.getComponent().getName()) && node.isActivate()) {
                    //$NON-NLS-1$
                    generateWSDL(wsdlsPackageFolder, node);
                }
            }
        }
    } catch (CoreException e) {
        if (e.getStatus() != null && e.getStatus().getException() != null) {
            ExceptionHandler.process(e.getStatus().getException());
        }
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("Processor.tempFailed"), e);
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("Processor.tempFailed"), e);
    }
    boolean samEnabled = false;
    boolean slEnabled = false;
    boolean oidcEnabled = false;
    for (INode node : graphicalNodes) {
        if (node.isActivate()) {
            final String nodeName = node.getComponent().getName();
            Object slValue = null, samValue = null;
            if (//$NON-NLS-1$
            "tESBConsumer".equals(nodeName) || //$NON-NLS-1$
            "tRESTClient".equals(nodeName) || //$NON-NLS-1$
            "tRESTRequest".equals(nodeName) || "cREST".equals(nodeName)) {
                //$NON-NLS-1$
                if (!slEnabled) {
                    //$NON-NLS-1$
                    slValue = node.getPropertyValue("SERVICE_LOCATOR");
                }
                if (!samEnabled) {
                    //$NON-NLS-1$
                    samValue = node.getPropertyValue("SERVICE_ACTIVITY_MONITOR");
                }
                oidcEnabled = true;
            } else if ("cSOAP".equals(nodeName)) {
                //$NON-NLS-1$
                if (!slEnabled) {
                    //$NON-NLS-1$
                    slValue = node.getPropertyValue("ENABLE_SL");
                }
                if (!samEnabled) {
                    //$NON-NLS-1$
                    samValue = node.getPropertyValue("ENABLE_SAM");
                }
            }
            if (null != slValue) {
                slEnabled = (Boolean) slValue;
            }
            if (null != samValue) {
                samEnabled = (Boolean) samValue;
            }
            if (samEnabled && slEnabled && oidcEnabled) {
                break;
            }
        }
    }
    if (samEnabled || slEnabled || oidcEnabled) {
        File esbConfigsSourceFolder = EsbConfigUtils.getEclipseEsbFolder();
        if (!esbConfigsSourceFolder.exists()) {
            RunProcessPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, RunProcessPlugin.getDefault().getBundle().getSymbolicName(), //$NON-NLS-1$
            "ESB configuration folder does not exists - " + esbConfigsSourceFolder.toURI()));
            return;
        }
        ITalendProcessJavaProject tProcessJvaProject = this.getTalendJavaProject();
        if (tProcessJvaProject == null) {
            return;
        }
        IFolder esbConfigsTargetFolder = tProcessJvaProject.getResourcesFolder();
        // add SAM config file to classpath
        if (samEnabled) {
            //$NON-NLS-1$
            copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "agent.properties");
        }
        // add SL config file to classpath
        if (slEnabled) {
            //$NON-NLS-1$
            copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "locator.properties");
        }
        // add OIDC config file to classpath
        if (oidcEnabled) {
            //$NON-NLS-1$
            copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "oidc.properties");
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) INode(org.talend.core.model.process.INode) ProcessorException(org.talend.designer.runprocess.ProcessorException) IPath(org.eclipse.core.runtime.IPath) IOException(java.io.IOException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 34 with ITalendProcessJavaProject

use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.

the class JavaCompilationParticipant method updateProblems.

/**
     * yzhang Comment method "updateProblems".
     */
private void updateProblems(List<IRepositoryViewObject> routineObjectList, String filePath) {
    IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
    try {
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        final ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        IProject javaProject = talendProcessJavaProject.getProject();
        IFile file = javaProject.getFile(filePath);
        String fileName = file.getName();
        for (IRepositoryViewObject repositoryObject : routineObjectList) {
            Property property = repositoryObject.getProperty();
            Item item = property.getItem();
            IFile currentFile = synchronizer.getFile(item);
            if (currentFile != null && fileName.equals(currentFile.getName()) && currentFile.exists()) {
                Problems.addRoutineFile(currentFile, property);
                break;
            }
        }
    } catch (SystemException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) Item(org.talend.core.model.properties.Item) IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProject(org.eclipse.core.resources.IProject)

Example 35 with ITalendProcessJavaProject

use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method sortClasspath.

// // see bug 3914, make the order of the jar files consistent with the
// command
// // line in run mode
private static void sortClasspath(Set<ModuleNeeded> jobModuleList, IProcess process, Set<ModuleNeeded> alreadyRetrievedModules) throws CoreException, ProcessorException {
    ITalendProcessJavaProject jProject = getTalendJavaProject();
    if (jProject == null) {
        return;
    }
    Set<ModuleNeeded> listModulesReallyNeeded = new HashSet<ModuleNeeded>();
    listModulesReallyNeeded.addAll(jobModuleList);
    Set<ModuleNeeded> optionalJarsOnlyForRoutines = new HashSet<ModuleNeeded>();
    // only for wizards or additional jars only to make the java project compile without any error.
    for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getSystemRunningModules()) {
        optionalJarsOnlyForRoutines.add(moduleNeeded);
    }
    // list contains all routines linked to job as well as routines not used in the job
    // rebuild the list to have only the libs linked to routines "not used".
    optionalJarsOnlyForRoutines.removeAll(listModulesReallyNeeded);
    // only to be able to compile java project without error.
    for (ModuleNeeded jar : optionalJarsOnlyForRoutines) {
        listModulesReallyNeeded.add(jar);
    }
    addLog4jToModuleList(listModulesReallyNeeded);
    listModulesReallyNeeded.removeAll(alreadyRetrievedModules);
    alreadyRetrievedModules.addAll(listModulesReallyNeeded);
    String missingJars = null;
    Set<String> missingJarsForRoutinesOnly = new HashSet<String>();
    Set<String> missingJarsForProcessOnly = new HashSet<String>();
    File libDir = getJavaProjectLibFolder();
    ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<ModuleNeeded> jarsNeedRetrieve = new HashSet<ModuleNeeded>();
        for (ModuleNeeded moduleNeeded : listModulesReallyNeeded) {
            jarsNeedRetrieve.add(moduleNeeded);
        }
        if (!jarsNeedRetrieve.isEmpty()) {
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath(), true);
            if (process instanceof IProcess2) {
                ((IProcess2) process).checkProcess();
            }
        }
        Set<ModuleNeeded> exist = new HashSet<ModuleNeeded>();
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            for (ModuleNeeded module : jarsNeedRetrieve) {
                if (externalLib.getName().equals(module.getModuleName())) {
                    exist.add(module);
                }
            }
        }
        jarsNeedRetrieve.removeAll(exist);
        Set<String> jarStringListNeededByProcess = new HashSet<String>();
        for (ModuleNeeded moduleNeeded : jobModuleList) {
            jarStringListNeededByProcess.add(moduleNeeded.getModuleName());
        }
        for (ModuleNeeded jar : jarsNeedRetrieve) {
            if (jobModuleList.contains(jar)) {
                missingJarsForProcessOnly.add(jar.getModuleName());
            } else {
                missingJarsForRoutinesOnly.add(jar.getModuleName());
            }
            if (missingJars == null) {
                //$NON-NLS-1$
                missingJars = Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess") + jar;
            } else {
                //$NON-NLS-1$
                missingJars = missingJars + ", " + jar;
            }
        }
    }
    repositoryBundleService.deployModules(listModulesReallyNeeded, null);
    if (missingJars != null) {
        handleMissingJarsForProcess(missingJarsForRoutinesOnly, missingJarsForProcessOnly, missingJars);
    }
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) IProcess2(org.talend.core.model.process.IProcess2) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) HashSet(java.util.HashSet)

Aggregations

ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)49 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)27 IFolder (org.eclipse.core.resources.IFolder)25 IFile (org.eclipse.core.resources.IFile)17 CoreException (org.eclipse.core.runtime.CoreException)16 IOException (java.io.IOException)12 File (java.io.File)11 ArrayList (java.util.ArrayList)11 IPath (org.eclipse.core.runtime.IPath)11 URL (java.net.URL)10 PersistenceException (org.talend.commons.exception.PersistenceException)9 MalformedURLException (java.net.MalformedURLException)8 HashMap (java.util.HashMap)8 ProcessorException (org.talend.designer.runprocess.ProcessorException)8 IProject (org.eclipse.core.resources.IProject)7 Test (org.junit.Test)7 RepositoryObjectTypeBuildProvider (org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider)7 DocumentException (org.dom4j.DocumentException)6 Path (org.eclipse.core.runtime.Path)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4