Search in sources :

Example 1 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.

the class JavaProcessorUtilities method checkJavaProjectLib.

/**
     * DOC ycbai Comment method "checkJavaProjectLib".
     * 
     * @param jarsNeeded
     */
public static void checkJavaProjectLib(Collection<ModuleNeeded> jarsNeeded) {
    File libDir = getJavaProjectLibFolder();
    if ((libDir != null) && (libDir.isDirectory())) {
        Set<String> jarsNeedRetrieve = new HashSet<String>();
        for (ModuleNeeded moduleNeeded : jarsNeeded) {
            jarsNeedRetrieve.add(moduleNeeded.getModuleName());
        }
        for (File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
            jarsNeedRetrieve.remove(externalLib.getName());
        }
        if (!jarsNeedRetrieve.isEmpty()) {
            ILibraryManagerService repositoryBundleService = CorePlugin.getDefault().getRepositoryBundleService();
            repositoryBundleService.retrieve(jarsNeedRetrieve, libDir.getAbsolutePath(), false);
        }
    }
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) File(java.io.File) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) HashSet(java.util.HashSet)

Example 2 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService 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)

Example 3 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdi-studio-se by Talend.

the class CodeGeneratorService method refreshTemplates.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.codegen.ICodeGeneratorService#refreshTemplates()
     */
@Override
public Job refreshTemplates() {
    Element oldComponent = null;
    IComponentSettingsView viewer = null;
    if (!CommonUIPlugin.isFullyHeadless()) {
        // TDI-25866:In case select a component and sctrl+shift+f3,need clean its componentSetting view
        IWorkbenchWindow wwindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (wwindow != null && wwindow.getActivePage() != null) {
            viewer = (IComponentSettingsView) wwindow.getActivePage().findView(IComponentSettingsView.ID);
            if (viewer != null) {
                oldComponent = viewer.getElement();
                viewer.cleanDisplay();
            }
        }
    }
    ComponentCompilations.deleteMarkers();
    ComponentsFactoryProvider.getInstance().resetCache();
    ILibraryManagerService librairesManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
    librairesManagerService.clearCache();
    CorePlugin.getDefault().getLibrariesService().syncLibraries();
    Job job = CodeGeneratorEmittersPoolFactory.initialize();
    // achen modify to record ctrl+shift+f3 is pressed to fix bug 0006107
    IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
    designerCoreService.getLastGeneratedJobsDateMap().clear();
    if (oldComponent != null && viewer != null) {
        viewer.setElement(oldComponent);
    }
    if (!CommonUIPlugin.isFullyHeadless()) {
        CorePlugin.getDefault().getDesignerCoreService().synchronizeDesignerUI(new PropertyChangeEvent(this, IComponentConstants.NORMAL, null, null));
    }
    return job;
}
Also used : IComponentSettingsView(org.talend.core.views.IComponentSettingsView) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PropertyChangeEvent(java.beans.PropertyChangeEvent) ILibraryManagerService(org.talend.core.ILibraryManagerService) Element(org.talend.core.model.process.Element) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) Job(org.eclipse.core.runtime.jobs.Job)

Example 4 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdq-studio-se by Talend.

the class ConnectionUtils method getDriverJarRealPaths.

/**
 * find driver jar path from 'temp\dbWizard',if nof found,find it from 'lib\java' and "librariesIndex.xml".
 *
 * @return
 * @throws MalformedURLException
 */
public static LinkedList<String> getDriverJarRealPaths(List<String> driverJarNameList) throws MalformedURLException {
    LinkedList<String> linkedList = new LinkedList<String>();
    // no check the real jar path for None-Platform-Running
    if (!Platform.isRunning()) {
        return linkedList;
    }
    boolean jarNotFound = false;
    for (String jarName : driverJarNameList) {
        String tempLibPath = ExtractMetaDataUtils.getInstance().getJavaLibPath();
        File tempFolder = new File(tempLibPath);
        if (tempFolder.exists()) {
            List<File> jarFiles = FilesUtils.getJarFilesFromFolder(tempFolder, jarName);
            if (!jarFiles.isEmpty()) {
                linkedList.add(jarFiles.get(0).getPath());
                continue;
            }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService libManagerServic = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            String libPath = libManagerServic.getJarPath(jarName);
            if (libPath == null) {
                jarNotFound = true;
                break;
            }
            linkedList.add(libPath);
        } else {
            jarNotFound = true;
        }
    }
    // if has one jar file not be found,return a empty list
    if (jarNotFound) {
        linkedList.clear();
    }
    return linkedList;
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) File(java.io.File) LinkedList(java.util.LinkedList)

Example 5 with ILibraryManagerService

use of org.talend.core.ILibraryManagerService in project tdq-studio-se by Talend.

the class AbstractDQMissingJarsExtraUpdatesFactory method retrieveUninstalledExtraFeatures.

@Override
public void retrieveUninstalledExtraFeatures(IProgressMonitor monitor, Set<ExtraFeature> uninstalledExtraFeatures) throws Exception {
    Bundle bundle = Platform.getBundle(getPluginName());
    if (bundle == null) {
        // if the bundle is not installed then propose to download it.
        // $NON-NLS-1$
        String pathToStore = Platform.getInstallLocation().getURL().getFile() + "plugins";
        File jarfile = new File(pathToStore, getJarFileWithVersionNames().get(0));
        if (jarfile.exists()) {
            return;
        } else {
            SubMonitor mainSubMonitor = SubMonitor.convert(monitor, 2);
            // add all needed models into the allUninstalledModules
            List<ModuleNeeded> allUninstalledModules = getAllUninstalledModules();
            if (monitor.isCanceled()) {
                return;
            }
            // else keep going fetch missing jar information from remote web site.
            ArrayList<ModuleToInstall> modulesRequiredToBeInstalled = new ArrayList<ModuleToInstall>();
            IRunnableWithProgress notInstalledModulesRunnable = RemoteModulesHelper.getInstance().getNotInstalledModulesRunnable(allUninstalledModules, modulesRequiredToBeInstalled);
            // jface because it adds graphical dependencies.
            // some data need to be fetched
            runNotInstallModule(mainSubMonitor, notInstalledModulesRunnable);
            // else all data already fetched or already try and failed so keep going
            if (mainSubMonitor.isCanceled()) {
                return;
            }
            // else keep going.
            final ArrayList<ModuleToInstall> modulesForAutomaticInstall = TalendWebServiceUpdateExtraFeature.filterAllAutomaticInstallableModules(modulesRequiredToBeInstalled);
            if (modulesForAutomaticInstall.isEmpty()) {
                // if could not find anything to download log and error and
                // return nothing
                // $NON-NLS-1$
                log.error("failed to fetch missing third parties jars information for " + getJarFileNames().get(0));
                return;
            }
            // else something to dowload to return the Extra feature to dowload.
            addToSet(uninstalledExtraFeatures, new TalendWebServiceUpdateExtraFeature(modulesForAutomaticInstall, DefaultMessagesImpl.getString(getDownloadName()), DefaultMessagesImpl.getString("DownloadSqlexplorerPluginJarFactory.description", // $NON-NLS-1$
            getContainPluginNames()), // $NON-NLS-1$
            true) {

                @Override
                public boolean needRestart() {
                    return true;
                }

                @Override
                public IStatus install(IProgressMonitor progress, List<URI> allRepoUris) throws Exception {
                    IStatus installStatus = super.install(progress, allRepoUris);
                    // move the jar to plugins folder
                    if (installStatus.isOK()) {
                        try {
                            copyJars2PluginsFolder(modulesForAutomaticInstall);
                        } catch (MalformedURLException e) {
                            MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
                            multiStatus.add(installStatus);
                            return multiStatus;
                        } catch (IOException e) {
                            MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
                            multiStatus.add(installStatus);
                            return multiStatus;
                        }
                    }
                    // else install not ok so return the error status.
                    return installStatus;
                }

                private void copyJars2PluginsFolder(ArrayList<ModuleToInstall> modules) throws MalformedURLException, IOException {
                    List<File> jarFiles = new ArrayList<File>();
                    ILibraryManagerService librariesService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                    if (librariesService != null) {
                        for (ModuleToInstall module : modules) {
                            String jarPathFromMaven = librariesService.getJarPathFromMaven(module.getMavenUri());
                            if (jarPathFromMaven == null) {
                                continue;
                            }
                            jarFiles.add(new File(jarPathFromMaven));
                        }
                    } else {
                        IMaven maven = MavenPlugin.getMaven();
                        String librariesPath = maven.getLocalRepositoryPath();
                        for (String jarFileName : getJarFileWithVersionNames()) {
                            jarFiles.addAll(FilesUtils.getJarFilesFromFolder(new File(librariesPath), jarFileName));
                        }
                    }
                    for (File jarFile : jarFiles) {
                        // $NON-NLS-1$
                        String pluginPath = Platform.getInstallLocation().getURL().getFile() + "plugins";
                        File movedfile = new File(pluginPath, jarFile.getName().replace(MavenConstants.SNAPSHOT, ""));
                        if (!movedfile.exists()) {
                            File target = new File(StringUtils.trimToEmpty(pluginPath));
                            if (!target.exists()) {
                                target.mkdirs();
                            }
                            FilesUtils.copyFile(jarFile, movedfile);
                        }
                    }
                }
            });
        }
    } else {
    // if it is not TOP loaded only, need not to do anyting
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MalformedURLException(java.net.MalformedURLException) Bundle(org.osgi.framework.Bundle) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IOException(java.io.IOException) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModuleToInstall(org.talend.core.model.general.ModuleToInstall) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILibraryManagerService(org.talend.core.ILibraryManagerService) TalendWebServiceUpdateExtraFeature(org.talend.updates.runtime.model.TalendWebServiceUpdateExtraFeature) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Aggregations

ILibraryManagerService (org.talend.core.ILibraryManagerService)15 File (java.io.File)13 ArrayList (java.util.ArrayList)5 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 List (java.util.List)3 IPath (org.eclipse.core.runtime.IPath)3 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 IProject (org.eclipse.core.resources.IProject)2 Point (org.eclipse.swt.graphics.Point)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1