Search in sources :

Example 1 with MavenArtifact

use of org.talend.core.runtime.maven.MavenArtifact in project tdi-studio-se by Talend.

the class Component method getModulesNeeded.

@Override
public List<ModuleNeeded> getModulesNeeded(INode node) {
    List<ModuleNeeded> componentImportNeedsList = new ArrayList<>();
    ConnectorTopology topology = null;
    if (node != null) {
        boolean hasInput = !NodeUtil.getIncomingConnections(node, IConnectionCategory.DATA).isEmpty();
        boolean hasOutput = !NodeUtil.getOutgoingConnections(node, IConnectionCategory.DATA).isEmpty();
        if (hasInput && hasOutput) {
            topology = ConnectorTopology.INCOMING_AND_OUTGOING;
        } else if (hasInput) {
            topology = ConnectorTopology.INCOMING;
        } else if (hasOutput) {
            topology = ConnectorTopology.OUTGOING;
        } else {
            topology = ConnectorTopology.NONE;
        }
    } else {
        Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
        if (!topologies.isEmpty()) {
            topology = topologies.iterator().next();
        }
    }
    RuntimeInfo runtimeInfo = null;
    try {
        runtimeInfo = componentDefinition.getRuntimeInfo(ExecutionEngine.DI, node == null ? null : node.getComponentProperties(), topology);
    } catch (Exception e) {
        if (node == null) {
        // not handled, must because the runtime info must have a node configuration (properties are null)
        } else {
            ExceptionHandler.process(e);
        }
    }
    if (runtimeInfo != null) {
        if (runtimeInfo instanceof JarRuntimeInfo) {
            JarRuntimeInfo currentRuntimeInfo = (JarRuntimeInfo) runtimeInfo;
            JarRuntimeInfo localRuntimeInfo = new JarRuntimeInfo(//$NON-NLS-1$
            currentRuntimeInfo.getJarUrl().toString().replace(//$NON-NLS-1$
            "mvn:", //$NON-NLS-1$ //$NON-NLS-2$
            "mvn:" + MavenConstants.LOCAL_RESOLUTION_URL + "!"), currentRuntimeInfo.getDepTxtPath(), currentRuntimeInfo.getRuntimeClassName());
            runtimeInfo = localRuntimeInfo;
        }
        final Bundle bundle = FrameworkUtil.getBundle(componentDefinition.getClass());
        for (URL mvnUri : runtimeInfo.getMavenUrlDependencies()) {
            //$NON-NLS-1$
            ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, mvnUri.toString());
            componentImportNeedsList.add(moduleNeeded);
            if (bundle != null) {
                // update module location
                try {
                    final MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(moduleNeeded.getMavenUri());
                    final String moduleFileName = artifact.getFileName();
                    final File bundleFile = BundleFileUtil.getBundleFile(bundle, moduleFileName);
                    if (bundleFile != null && bundleFile.exists()) {
                        // FIXME, better install the embed jars from bundle directly in this way.
                        moduleNeeded.setModuleLocaion(ExtensionModuleManager.URIPATH_PREFIX + bundle.getSymbolicName() + '/' + moduleFileName);
                    }
                } catch (IOException e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
    ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/slf4j-log4j12-1.7.2/6.0.0");
    componentImportNeedsList.add(moduleNeeded);
    moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/talend-codegen-utils/0.17.0-SNAPSHOT");
    componentImportNeedsList.add(moduleNeeded);
    return componentImportNeedsList;
}
Also used : JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo) IOException(java.io.IOException) BusinessException(org.talend.commons.exception.BusinessException) IOException(java.io.IOException) URL(java.net.URL) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact) File(java.io.File) ConnectorTopology(org.talend.components.api.component.ConnectorTopology)

Example 2 with MavenArtifact

use of org.talend.core.runtime.maven.MavenArtifact in project tesb-studio-se by Talend.

the class CheckNexusButtonController method createCommand.

public Command createCommand(Button button) {
    if (!isAvailable()) {
        return null;
    }
    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");
        List needUpdateJars = null;
        List jars = (List) elementParameterFromField.getValue();
        if (jars.size() > 0) {
            IElementParameter needUpdateList = elem.getElementParameter("NEED_UPDATE_LIST");
            needUpdateJars = (List) needUpdateList.getValue();
            needUpdateJars.clear();
            List<ModuleNeeded> updatedModules = null;
            if (elem instanceof Node) {
                updatedModules = LibrariesManagerUtils.getNotInstalledModules(((Node) elem));
            }
            if (nexusServerBean == null) {
                return null;
            }
            for (int i = 0; i < jars.size(); i++) {
                Map<String, String> jar = (Map) jars.get(i);
                String currentNexusVersion = TalendQuoteUtils.removeQuotes(jar.get(JAR_NEXUS_VERSION));
                String currentNexusPreVersion = jar.get(JAR_NEXUS_PRE_VERSION);
                String jn = TalendQuoteUtils.removeQuotes(jar.get(JAR_NAME));
                String a = jn.replaceFirst("[.][^.]+$", "");
                try {
                    Map metadata = service.getMavenMetadata(nexusServerBean, getGroupId(), a, currentNexusVersion);
                    if (metadata.get("Versioning.Latest").equals(currentNexusVersion)) {
                        MavenArtifact ma = new MavenArtifact();
                        ma.setArtifactId(a);
                        ma.setGroupId("org.talend.libraries");
                        ma.setVersion(currentNexusVersion);
                        ma.setType("jar");
                        String p = PomUtil.getAbsArtifactPath(ma);
                        InputStream is = service.getContentInputStream(nexusServerBean, "", getGroupId(), a, metadata.get("Versioning.Latest").toString(), "jar.md5");
                        if (p != null) {
                            if (is != null) {
                                String remoteM2FileMD5 = "";
                                try (BufferedReader buffer = new BufferedReader(new InputStreamReader(is))) {
                                    remoteM2FileMD5 = buffer.lines().collect(Collectors.joining("\n"));
                                }
                                //local file
                                File f = new File(p);
                                if (f.exists()) {
                                    String localM2FileMD5 = MD5.getMD5(FilesUtils.getBytes(f));
                                    if (!StringUtils.equalsIgnoreCase(localM2FileMD5, remoteM2FileMD5)) {
                                        needUpdateJars.add(getNeedUpdateJar("✘", jn, currentNexusVersion, currentNexusPreVersion));
                                    }
                                } else {
                                    needUpdateJars.add(getNeedUpdateJar("✘", jn, currentNexusVersion, currentNexusPreVersion));
                                }
                            }
                        } else {
                            if (is != null) {
                                needUpdateJars.add(getNeedUpdateJar("✘", jn, currentNexusVersion, currentNexusPreVersion));
                            }
                        }
                    } else {
                        needUpdateJars.add(getNeedUpdateJar("✘", jn, currentNexusVersion, metadata.get("Versioning.Latest").toString()));
                    }
                } catch (Exception ee) {
                    ee.printStackTrace();
                }
            }
            refresh(needUpdateList, true);
        }
        if (needUpdateJars != null && needUpdateJars.size() == 0) {
            MessageDialog.openInformation(composite.getShell(), "Checking libraries", "Everything is up-to-date");
        }
        return null;
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.talend.designer.core.ui.editor.nodes.Node) BufferedReader(java.io.BufferedReader) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Map(java.util.Map) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact) File(java.io.File)

Example 3 with MavenArtifact

use of org.talend.core.runtime.maven.MavenArtifact in project tesb-studio-se by Talend.

the class BeansImportHandlerUtil method arrangeBeansMoudulesImport.

/**
 * Extract method from org.talend.camel.designer.ui.view.handler.BeanImportHandler.beforeCreatingItem(ImportItem)
 * DOC jding Comment method "arrangeBeansMoudulesImport".
 *
 * @param imports
 */
public static void arrangeBeansMoudulesImport(EList<IMPORTType> imports) {
    if (imports == null || imports.isEmpty()) {
        return;
    }
    IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
    String camelVersionSubString = "";
    String camelVersion = "";
    String camelPrefix = "camel-core-";
    String camelCxfPrefix = "camel-cxf-";
    String VERSION_PATTERN = "-([0-9]+)(.([0-9]+)?)(.([0-9]+)?)";
    for (ModuleNeeded mn : component.getModulesNeeded()) {
        MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mn.getMavenUri());
        if (ma != null) {
            if (StringUtils.equals(camelPrefix, ma.getArtifactId() + "-")) {
                camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                camelVersion = ma.getVersion();
                break;
            }
        } else {
            if (mn.getModuleName().startsWith(camelPrefix)) {
                camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                camelVersion = camelVersionSubString.substring(0, camelVersionSubString.lastIndexOf(".jar"));
                break;
            }
        }
    }
    List<ModuleNeeded> modulesNeededForBeans = ModulesNeededProvider.getModulesNeededForBeans();
    Set<String> modulesNeededForBeansNames = new HashSet<String>();
    for (ModuleNeeded module : modulesNeededForBeans) {
        modulesNeededForBeansNames.add(module.getModuleName().replaceAll(VERSION_PATTERN, ""));
    }
    // remove default modules in the list of modules that are being imported from external project
    imports.removeIf(i -> modulesNeededForBeansNames.contains(i.getMODULE().replaceAll(VERSION_PATTERN, "")));
    // add new default modules
    for (ModuleNeeded model : modulesNeededForBeans) {
        IMPORTType importType = ComponentFactory.eINSTANCE.createIMPORTType();
        importType.setMODULE(model.getModuleName());
        importType.setMESSAGE(model.getInformationMsg());
        importType.setREQUIRED(model.isRequired());
        importType.setMVN(model.getMavenUri());
        imports.add(importType);
    }
    for (Object imp : imports) {
        if (imp instanceof IMPORTType) {
            IMPORTType importType = (IMPORTType) imp;
            String impName = importType.getMODULE().substring(importType.getMODULE().lastIndexOf('-') + 1);
            if (StringUtils.startsWith(importType.getMODULE(), camelCxfPrefix) && "TESB.jar".equals(impName)) {
                importType.setMODULE(camelCxfPrefix + camelVersionSubString);
                importType.setMVN("mvn:org.talend.libraries/" + camelCxfPrefix + camelVersion + "/6.0.0-SNAPSHOT/jar");
            }
        }
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact) HashSet(java.util.HashSet)

Example 4 with MavenArtifact

use of org.talend.core.runtime.maven.MavenArtifact in project tesb-studio-se by Talend.

the class UpdateBeansDefaultLibrariesMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof BeanItem) {
        if (camelVersion == null) {
            IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
            for (ModuleNeeded mn : component.getModulesNeeded()) {
                MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mn.getMavenUri());
                if (ma != null) {
                    if (StringUtils.equals(camelPrefix, ma.getArtifactId() + "-")) {
                        camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                        camelVersion = ma.getVersion();
                        break;
                    }
                } else {
                    if (mn.getModuleName().startsWith(camelPrefix)) {
                        camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                        camelVersion = camelVersionSubString.substring(0, camelVersionSubString.lastIndexOf(".jar"));
                        break;
                    }
                }
            }
        }
        BeanItem beanItem = (BeanItem) item;
        addModulesNeededForBeans(beanItem);
        try {
            ProxyRepositoryFactory.getInstance().save(beanItem);
            generateReportRecord(new MigrationReportRecorder(this, item, "Set of default Bean dependencies is updated"));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) PersistenceException(org.talend.commons.exception.PersistenceException) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact)

Example 5 with MavenArtifact

use of org.talend.core.runtime.maven.MavenArtifact in project tesb-studio-se by Talend.

the class CamelTalendEditor method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    super.doSave(monitor);
    if (!PluginChecker.isTIS()) {
        return;
    }
    NexusServerBean nexusServerBean = TalendLibsServerManager.getInstance().getCustomNexusServer();
    if (nexusServerBean == null) {
        return;
    }
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
        ILibrariesService service = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
        List<? extends INode> graphicalNodes = this.getProcess().getGraphicalNodes();
        for (INode node : graphicalNodes) {
            if (node.getComponent().getName().equals("cConfig")) {
                List<Map<String, String>> jars = (List) node.getElementParameter("DRIVER_JAR").getValue();
                for (Map<String, String> o : jars) {
                    String jn = TalendQuoteUtils.removeQuotes(o.get("JAR_NAME"));
                    String jnv = TalendQuoteUtils.removeQuotes(o.get("JAR_NEXUS_VERSION"));
                    String jv = String.valueOf(o.get("JAR_PATH"));
                    String a = jn.replaceFirst("[.][^.]+$", "");
                    if (StringUtils.isNotBlank(jv)) {
                        File jarFile = new File(jv);
                        if (jarFile.exists()) {
                            try {
                                service.deployLibrary(jarFile.toURI().toURL(), "mvn:org.talend.libraries/" + a + "/" + jnv + "/jar");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            cConfigStoredInfo.put(jn, jnv);
                            o.put("JAR_PATH", "");
                        }
                    }
                    if (cConfigStoredInfo.get(jn) == null) {
                        cConfigStoredInfo.put(jn, jnv);
                        continue;
                    }
                    if (cConfigStoredInfo.get(jn).equals(jnv)) {
                        continue;
                    } else {
                        MavenArtifact ma = new MavenArtifact();
                        ma.setArtifactId(a);
                        ma.setGroupId("org.talend.libraries");
                        ma.setVersion(cConfigStoredInfo.get(jn));
                        ma.setType("jar");
                        String p = PomUtil.getAbsArtifactPath(ma);
                        if (p != null) {
                            File file = new File(p);
                            try {
                                if (file.exists()) {
                                    File tmp = new File(ExportJobUtil.getTmpFolder() + File.separator + jn);
                                    FilesUtils.copyFile(file, tmp);
                                    service.deployLibrary(tmp.toURI().toURL(), "mvn:org.talend.libraries/" + a + "/" + jnv + "/jar");
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) ILibrariesService(org.talend.core.model.general.ILibrariesService) NexusServerBean(org.talend.core.nexus.NexusServerBean) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact)

Aggregations

MavenArtifact (org.talend.core.runtime.maven.MavenArtifact)5 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)4 File (java.io.File)3 List (java.util.List)2 Map (java.util.Map)2 IComponent (org.talend.core.model.components.IComponent)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Bundle (org.osgi.framework.Bundle)1 BeanItem (org.talend.camel.core.model.camelProperties.BeanItem)1 BusinessException (org.talend.commons.exception.BusinessException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 ConnectorTopology (org.talend.components.api.component.ConnectorTopology)1 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)1