Search in sources :

Example 1 with NexusServerBean

use of org.talend.core.nexus.NexusServerBean 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

File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ILibrariesService (org.talend.core.model.general.ILibrariesService)1 INode (org.talend.core.model.process.INode)1 NexusServerBean (org.talend.core.nexus.NexusServerBean)1 MavenArtifact (org.talend.core.runtime.maven.MavenArtifact)1