Search in sources :

Example 61 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.

the class TalendProcessJavaProject method buildWholeCodeProject.

/**
     * DOC ggu Comment method "buildWholeCodeProject".
     */
private void buildWholeCodeProject() {
    // build whole project
    try {
        NullProgressMonitor monitor = new NullProgressMonitor();
        IProject project = getProject();
        if (!project.isSynchronized(IResource.DEPTH_INFINITE)) {
            project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        }
        project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
        project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject)

Example 62 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.

the class JavaProcessor method initCodePath.

public void initCodePath(IContext c) throws ProcessorException {
    if (buildChildrenJobs != null) {
        buildChildrenJobs.clear();
    }
    ITalendProcessJavaProject tProcessJavaProject = getTalendJavaProject();
    IProgressMonitor monitor = new NullProgressMonitor();
    IFolder srcFolder = null;
    IFolder resourcesFolder = null;
    IFolder outputFolder = null;
    if (isTestJob) {
        srcFolder = tProcessJavaProject.getTestSrcFolder();
        resourcesFolder = tProcessJavaProject.getTestResourcesFolder();
        outputFolder = tProcessJavaProject.getTestOutputFolder();
    } else {
        srcFolder = tProcessJavaProject.getSrcFolder();
        resourcesFolder = tProcessJavaProject.getResourcesFolder();
        outputFolder = tProcessJavaProject.getOutputFolder();
    }
    /*
         * assume the job is "TestJob 0.1", project is "Test" .
         */
    String jobClassPackageFolder = null;
    String jobClassFilePath = null;
    // only for "standard" job
    if (isStandardJob()) {
        Item item = property.getItem();
        // test/testjob_0_1
        jobClassPackageFolder = JavaResourcesHelper.getJobClassPackageFolder(item, isTestJob);
        // test/testjob_0_1/TestJob.java
        jobClassFilePath = JavaResourcesHelper.getJobClassFilePath(item, filenameFromLabel, isTestJob);
        // test.testjob_0_1.TestJob
        this.mainClass = JavaResourcesHelper.getJobPackagedClass(item, filenameFromLabel, isTestJob);
    } else {
        // for shadow process, or preview process
        // test/shadowfileinputtodelimitedoutput_0_1, test/preview_data
        jobClassPackageFolder = JavaResourcesHelper.getProjectFolderName(property) + JavaUtils.PATH_SEPARATOR + JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion());
        // test/shadowfileinputtodelimitedoutput_0_1/ShadowFileInputToDelimitedOutput.java,
        // test/preview_data/Preview_Data.java
        jobClassFilePath = jobClassPackageFolder + JavaUtils.PATH_SEPARATOR + (filenameFromLabel ? JavaResourcesHelper.escapeFileName(process.getName()) : process.getId()) + JavaUtils.JAVA_EXTENSION;
        // test.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput,
        // test.preview_data.Preview_Data
        this.mainClass = new Path(jobClassFilePath).removeFileExtension().toString().replace('/', '.');
    }
    // create job packages, src/main/java/test/testjob_0_1
    // or test job packages, src/main/java/test/testjob_0_1/testjunitjob_0_1
    tProcessJavaProject.createSubFolder(monitor, srcFolder, jobClassPackageFolder);
    // src/main/java/test/testjob_0_1/TestJob.java
    // or src/main/java/test/testjob_0_1/testjunitjob_0_1/TestjunitJob.java
    this.codePath = srcFolder.getProjectRelativePath().append(jobClassFilePath);
    // target/classes/test/testjob_0_1
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1
    IFolder jobClassFolder = outputFolder.getFolder(jobClassPackageFolder);
    // TestJob
    String jobName = new Path(jobClassFilePath).removeFileExtension().lastSegment();
    // target/classes/test/testjob_0_1/TestJob
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/TestjunitJob
    this.compiledCodePath = jobClassFolder.getProjectRelativePath().append(jobName);
    if (isTestJob) {
        // test/testjob_0_1/datas
        IPath dataPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_DATAS_DIRECTORY);
        this.dataFilePath = resourcesFolder.getFolder(dataPath).getProjectRelativePath();
    }
    /*
         * for context.
         */
    // test/testjob_0_1/contexts
    // or test/testjob_0_1/testjunitjob_0_1/contexts
    IPath jobContextFolderPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY);
    // src/main/resources/test/testjob_0_1/contexts
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts
    tProcessJavaProject.createSubFolder(monitor, resourcesFolder, jobContextFolderPath.toString());
    // for example, Default
    String contextFileName = JavaResourcesHelper.getJobContextFileName(c);
    // test/testjob_0_1/contexts/Default.properties
    // or test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    IPath jobContextPath = jobContextFolderPath.append(contextFileName);
    // src/main/resources/test/testjob_0_1/contexts/Default.properties
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.contextPath = resourcesFolder.getFile(jobContextPath).getProjectRelativePath();
    // target/classes/test/testjob_0_1/contexts/Default.properties
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.compiledContextPath = outputFolder.getFile(jobContextPath).getProjectRelativePath();
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Example 63 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.

the class MavenJavaProcessor method updateProjectPom.

/**
     * update the project pom, and make sure the standard or fake(Preview/Data view) job can be compiled still.
     */
protected void updateProjectPom(IProgressMonitor monitor) {
    try {
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }
        JavaProcessorUtilities.checkJavaProjectLib(getNeededModules());
        ProjectPomManager pomManager = new ProjectPomManager(getTalendJavaProject().getProject()) {

            @Override
            protected boolean isStandardJob() {
                return MavenJavaProcessor.this.isStandardJob();
            }

            @Override
            protected IFile getBasePomFile() {
                return MavenJavaProcessor.this.getPomFile();
            }
        };
        // won't update module for fake job.
        pomManager.setUpdateModules(isStandardJob());
        if (getArguments() != null) {
            pomManager.setArgumentsMap(getArguments());
        }
        pomManager.update(monitor, this);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProjectPomManager(org.talend.designer.maven.tools.ProjectPomManager) ProcessorException(org.talend.designer.runprocess.ProcessorException)

Example 64 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.

the class DeleteAllJobWhenStartUp method earlyStartup.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IStartup#earlyStartup()
     */
@Override
public void earlyStartup() {
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return;
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
    if (!codeProject.exists() || !codeProject.isAccessible()) {
        return;
    }
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
            if (talendJavaProject != null) {
                IJavaProject jProject = talendJavaProject.getJavaProject();
                if (!jProject.isOpen()) {
                    jProject.open(monitor);
                }
                // empty the src/main/java...
                IFolder srcFolder = talendJavaProject.getSrcFolder();
                talendJavaProject.cleanFolder(monitor, srcFolder);
                // contexts
                IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
                emptyContexts(monitor, resourcesFolder, talendJavaProject);
                // empty the outputs, target
                IFolder targetFolder = talendJavaProject.getTargetFolder();
                talendJavaProject.cleanFolder(monitor, targetFolder);
                // empty the src/test/java
                IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
                talendJavaProject.cleanFolder(monitor, testSrcFolder);
                // empty the src/test/java (main for contexts)
                IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
                talendJavaProject.cleanFolder(monitor, testResourcesFolder);
                // empty temp
                IFolder tempFolder = talendJavaProject.getTempFolder();
                talendJavaProject.cleanFolder(monitor, tempFolder);
                // empty lib/...
                IFolder libFolder = talendJavaProject.getLibFolder();
                talendJavaProject.cleanFolder(monitor, libFolder);
                // rules
                IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, rulesResFolder);
                // sqltempalte
                IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
            }
        }

        ;
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        ISchedulingRule schedulingRule = workspace.getRoot();
        // the update the project files need to be done in the workspace runnable to avoid all
        // notification
        // of changes before the end of the modifications.
        workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() != null) {
            ExceptionHandler.process(e.getCause());
        } else {
            ExceptionHandler.process(e);
        }
    }
    executed = true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 65 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.

the class JavaCommandController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Button btnEdit;
    //$NON-NLS-1$
    btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    FormData data;
    btnEdit.setData(NAME, JAVA_COMMAND);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            // execute Java Command
            ElementParameter fullParam = (ElementParameter) param;
            File jar;
            URL url;
            try {
                List<URL> listURL = new ArrayList<URL>();
                ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                IFolder javaLibFolder = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                    IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                    ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
                    if (talendProcessJavaProject != null) {
                        javaLibFolder = talendProcessJavaProject.getLibFolder();
                    }
                }
                if (javaLibFolder == null) {
                    return;
                }
                for (String jarString : fullParam.getJar().split(";")) {
                    IPath libPath = javaLibFolder.getLocation();
                    libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
                    jar = libPath.append(jarString).toFile();
                    url = jar.toURL();
                    listURL.add(url);
                }
                URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
                Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
                Object object = classLoaded.newInstance();
                List<String> args = new ArrayList<String>();
                for (String arg : fullParam.getArgs()) {
                    args.add(ElementParameterParser.parse(elem, arg));
                }
                for (Method method : classLoaded.getDeclaredMethods()) {
                    if (method.getName().equals(fullParam.getJavaFunction())) {
                        Object[] arglist = new Object[1];
                        arglist[0] = args.toArray(new String[0]);
                        method.invoke(object, arglist);
                    }
                }
            } catch (Exception e1) {
                MessageBoxExceptionHandler.process(e1);
            }
        }
    });
    if (elem instanceof Node) {
        btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // **************************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
            data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
            data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
        data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    btnEdit.setLayoutData(data);
    // **************************
    hashCurControls.put(param.getName(), btnEdit);
    Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Node(org.talend.designer.core.ui.editor.nodes.Node) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ILibraryManagerService(org.talend.core.ILibraryManagerService) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) IPath(org.eclipse.core.runtime.IPath) Method(java.lang.reflect.Method) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1614 CoreException (org.eclipse.core.runtime.CoreException)416 Test (org.junit.Test)382 IFile (org.eclipse.core.resources.IFile)342 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)267 IProject (org.eclipse.core.resources.IProject)258 File (java.io.File)205 IPath (org.eclipse.core.runtime.IPath)182 IOException (java.io.IOException)153 Path (org.eclipse.core.runtime.Path)132 ArrayList (java.util.ArrayList)122 IStatus (org.eclipse.core.runtime.IStatus)113 IFolder (org.eclipse.core.resources.IFolder)87 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)69 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)60 List (java.util.List)59 IProjectDescription (org.eclipse.core.resources.IProjectDescription)57 IType (org.eclipse.jdt.core.IType)57 Status (org.eclipse.core.runtime.Status)55