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;
}
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;
}
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");
}
}
}
}
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;
}
}
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();
}
}
}
}
}
}
}
}
Aggregations