Search in sources :

Example 1 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tdi-studio-se by Talend.

the class ImportItemUtil method deployJarToDesForArchive.

private void deployJarToDesForArchive(final ResourcesManager manager, Set<String> extRoutines) {
    if (extRoutines.isEmpty()) {
        return;
    }
    //$NON-NLS-1$  
    IPath tmpDir = new Path(System.getProperty("user.dir") + File.separatorChar + "tmpJar");
    Set<URL> jarsToDeploy = new HashSet<URL>();
    File dirFile = tmpDir.toFile();
    for (IPath path : manager.getPaths()) {
        String fileName = path.lastSegment();
        if (extRoutines.contains(fileName)) {
            try {
                InputStream is = manager.getStream(path);
                if (!dirFile.exists()) {
                    dirFile.mkdirs();
                }
                File temFile = tmpDir.append(fileName).toFile();
                if (temFile.exists()) {
                    temFile.delete();
                }
                byte[] b = new byte[1024];
                int length = 0;
                BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(temFile, true));
                while ((length = is.read(b)) != -1) {
                    fos.write(b, 0, length);
                }
                fos.close();
                jarsToDeploy.add(temFile.toURI().toURL());
            } catch (MalformedURLException e) {
                ExceptionHandler.process(e);
            } catch (IOException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    if (jarsToDeploy.size() > 0) {
        ILibrariesService libService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
        try {
            libService.deployLibrarys(jarsToDeploy.toArray(new URL[0]));
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
    }
    dirFile.delete();
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) MalformedURLException(java.net.MalformedURLException) ILibrariesService(org.talend.core.model.general.ILibrariesService) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashSet(java.util.HashSet)

Example 2 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tesb-studio-se by Talend.

the class SyncNexusButtonController method createCommand.

public Command createCommand(Button button) {
    IElementParameter parameter = (IElementParameter) button.getData();
    if (parameter != null) {
        callBeforeActive(parameter);
        // so as to invoke listeners to perform some actions.
        IElementParameter elementParameterFromField = elem.getElementParameter("DRIVER_JAR");
        IElementParameter needUpdateList = elem.getElementParameter("NEED_UPDATE_LIST");
        List needUpdateJars = (List) needUpdateList.getValue();
        if (needUpdateJars != null && needUpdateJars.size() == 0) {
            MessageDialog.openInformation(composite.getShell(), "Synchronizing libraries", "Everything is up-to-date");
        } else {
            for (int i = 0; i < needUpdateJars.size(); i++) {
                Map<String, Object> jar = (Map) needUpdateJars.get(i);
                String jn = TalendQuoteUtils.removeQuotes(jar.get("JAR_NAME").toString());
                String jnv = TalendQuoteUtils.removeQuotes(jar.get("JAR_NEXUS_VERSION").toString());
                String a = jn.replaceFirst("[.][^.]+$", "");
                if (Boolean.valueOf(jar.get("JAR_SYNC").toString())) {
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                        ILibrariesService librariesService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                        InputStream is = service.getContentInputStream(nexusServerBean, "", getGroupId(), a, jnv, null);
                        File file = generateTempFile(is, jn);
                        try {
                            librariesService.deployLibrary(file.toURI().toURL(), "mvn:org.talend.libraries/" + a + "/" + jnv + "/jar");
                            jar.put("JAR_STATUS", "✔");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        refresh(needUpdateList, true);
        return null;
    }
    return null;
}
Also used : ILibrariesService(org.talend.core.model.general.ILibrariesService) InputStream(java.io.InputStream) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) Map(java.util.Map) File(java.io.File) IOException(java.io.IOException)

Example 3 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tdi-studio-se by Talend.

the class JSONFileStep1Form method setVisible.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.widgets.Control#setVisible(boolean)
     */
@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (isReadOnly() != readOnly) {
        adaptFormToReadOnly();
    }
    if (super.isVisible()) {
        String JSONFilePath = getConnection().getJSONFilePath();
        // Fields to the Group Delimited File Settings
        if (getConnection().getEncoding() != null && !getConnection().getEncoding().equals("")) {
            //$NON-NLS-1$
            encodingCombo.setText(getConnection().getEncoding());
            isModifing = false;
            fileFieldJSON.setText(JSONFilePath);
        } else {
            encodingCombo.select(0);
        }
        if (isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
            JSONFilePath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, JSONFilePath));
        }
        if (!creation) {
            updateTreeNodes(JSONFilePath);
            JSONWizard wizard = ((JSONWizard) getPage().getWizard());
            if (wizard.getTreeRootNode() == null) {
                wizard.setTreeRootNode(treeNode);
            }
        }
        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL && GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
            ILibrariesService moduleService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
            try {
                ELibraryInstallStatus status = moduleService.getLibraryStatus("JSON::LibJSON");
                if (status != ELibraryInstallStatus.INSTALLED) {
                    new ErrorDialogWidthDetailArea(getShell(), PID, "The Perl Module" + " JSON::LibJSON " + "is not installed", "For more information, check out Talend's Wiki website at http\\://talendforge.org/wiki/doku.php.");
                    log.error("The Perl Module" + " JSON::LibJSONL " + "is not installed");
                }
            } catch (BusinessException e) {
                new ErrorDialogWidthDetailArea(getShell(), PID, "The Perl Module" + " JSON::LibJSON " + "is not installed", "For more information, check out Talend's Wiki website at http\\://talendforge.org/wiki/doku.php.");
                log.error("The Perl Module" + " JSON::LibJSONL " + "is not installed");
            }
        }
        adaptFormToEditable();
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) BusinessException(org.talend.commons.exception.BusinessException) ILibrariesService(org.talend.core.model.general.ILibrariesService) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) ELibraryInstallStatus(org.talend.core.model.general.ModuleNeeded.ELibraryInstallStatus)

Example 4 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionTemplate method registPluginExtensions.

@Override
public boolean registPluginExtensions() {
    if (registedPluginAdapter == null) {
        synchronized (registedPluginAdapterLock) {
            if (registedPluginAdapter == null) {
                DynamicPluginAdapter plugAdapter = getPluginAdapter();
                IDynamicPlugin plugin = plugAdapter.getPlugin();
                IDynamicPluginConfiguration pConfiguration = plugin.getPluginConfiguration();
                try {
                    plugin.setPluginConfiguration(null);
                    DynamicServiceUtil.addContribution(plugAdapter.getBundle(), plugin);
                    registedPluginAdapter = plugAdapter;
                    ILibrariesService libService = ILibrariesService.get();
                    if (libService != null) {
                        libService.resetModulesNeeded();
                    }
                    HadoopDistributionsHelper.updatePluginExtensionCacheVersion();
                    return true;
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                } finally {
                    plugin.setPluginConfiguration(pConfiguration);
                }
            }
        }
    }
    return false;
}
Also used : DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) ILibrariesService(org.talend.core.model.general.ILibrariesService) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 5 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tdi-studio-se by Talend.

the class AbstractTalendEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    //$NON-NLS-1$
    monitor.beginTask("begin save job...", 100);
    monitor.worked(10);
    savePreviewPictures();
    // generate the MR infor parameter.
    try {
        boolean isStormServiceRegistered = GlobalServiceRegister.getDefault().isServiceRegistered(IStormProcessService.class);
        boolean isMRServiceRegistered = GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class);
        if (isStormServiceRegistered || isMRServiceRegistered) {
            IProcess2 process = getProcess();
            if (process != null) {
                IRepositoryViewObject repoObjectView = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getLastVersion(process.getId());
                if (repoObjectView != null && repoObjectView.getProperty() != null) {
                    Item currentItem = repoObjectView.getProperty().getItem();
                    if (isMRServiceRegistered) {
                        IMRProcessService mrService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
                        if (mrService.isMapReduceItem(currentItem)) {
                            // We make sure that the current item is a Batch item before generating the M/R
                            // information parameters.
                            mrService.generateMRInfosParameter(process);
                        }
                    }
                    if (isStormServiceRegistered) {
                        IStormProcessService stormService = (IStormProcessService) GlobalServiceRegister.getDefault().getService(IStormProcessService.class);
                        if (stormService.isStormItem(currentItem)) {
                            // We make sure that the current item is a Streaming item before generating the Spark
                            // Streaming information parameters.
                            stormService.generateSparkStreamingInfosParameter(process);
                        }
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        e.printStackTrace();
    }
    try {
        if (getEditorInput() instanceof JobEditorInput) {
            boolean saved = ((JobEditorInput) getEditorInput()).saveProcess(new SubProgressMonitor(monitor, 80), null);
            if (!saved) {
                monitor.setCanceled(true);
                throw new InterruptedException();
            }
        }
        getCommandStack().markSaveLocation();
        setDirty(false);
        boolean isneedReload = false;
        for (int i = 0; i < getProcess().getGraphicalNodes().size(); i++) {
            Node node = (Node) getProcess().getGraphicalNodes().get(i);
            if (node.isNeedloadLib()) {
                isneedReload = true;
                node.setNeedLoadLib(false);
            }
        }
        if (isneedReload) {
            // / See bug 4821
            ((ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class)).updateModulesNeededForCurrentJob(getProcess());
        }
        monitor.worked(10);
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
        monitor.setCanceled(true);
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ILibrariesService(org.talend.core.model.general.ILibrariesService) IMRProcessService(org.talend.core.service.IMRProcessService) IStormProcessService(org.talend.core.service.IStormProcessService) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Point(org.eclipse.draw2d.geometry.Point) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IContributionItem(org.eclipse.jface.action.IContributionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

ILibrariesService (org.talend.core.model.general.ILibrariesService)15 File (java.io.File)7 IOException (java.io.IOException)7 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Point (org.eclipse.draw2d.geometry.Point)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 INode (org.talend.core.model.process.INode)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1