diff --git a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleNeeded.java b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleNeeded.java index 0f12951ff0..55d9441d76 100644 --- a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleNeeded.java +++ b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleNeeded.java @@ -25,38 +25,39 @@ import org.talend.core.runtime.CoreRuntimePlugin; */ public class ModuleNeeded { - private String id; + private String id; - private String context; + private String context; - private String moduleName; + private String moduleName; - private String informationMsg; + private String informationMsg; - private boolean required; + private boolean required; - private boolean mrRequired = false;// That indicates if the module is required by M/R job. + private boolean mrRequired = false; // That indicates if the module is + // required by M/R job. - private String requiredIf; + private String requiredIf; // bundleName and bundleVersion for osgi system,feature 0023460 - private String bundleName; + private String bundleName; - private String bundleVersion; + private String bundleVersion; - private ELibraryInstallStatus status = ELibraryInstallStatus.UNKNOWN; + private ELibraryInstallStatus status = ELibraryInstallStatus.UNKNOWN; - private boolean isShow = true; + private boolean isShow = true; - List installURL; + List installURL; - private String moduleLocaion; + private String moduleLocaion; - private String mavenUri; + private String mavenUri; - public static final String SINGLE_QUOTE = "'"; //$NON-NLS-1$ + public static final String SINGLE_QUOTE = "'"; //$NON-NLS-1$ - public static final String QUOTATION_MARK = "\""; //$NON-NLS-1$ + public static final String QUOTATION_MARK = "\""; //$NON-NLS-1$ /** * DOC smallet ModuleNeeded class global comment. Detailled comment
@@ -83,7 +84,7 @@ public class ModuleNeeded { public ModuleNeeded(String context, String moduleName, String informationMsg, boolean required) { super(); this.context = context; - setModuleName(moduleName); + setModuleName( moduleName ); this.informationMsg = informationMsg; this.required = required; } @@ -92,12 +93,12 @@ public class ModuleNeeded { String requiredIf, String mavenUrl) { super(); this.context = context; - setModuleName(moduleName); + setModuleName( moduleName ); this.informationMsg = informationMsg; this.required = required; this.installURL = installURL; this.requiredIf = requiredIf; - this.mavenUri = mavenUrl; + setMavenUri( mavenUrl ); } public String getRequiredIf() { @@ -125,7 +126,7 @@ public class ModuleNeeded { boolean isRequired = false; if (requiredIf != null && !requiredIf.isEmpty() && listParam != null) { - isRequired = CoreRuntimePlugin.getInstance().getDesignerCoreService().evaluate(requiredIf, listParam); + isRequired = CoreRuntimePlugin.getInstance().getDesignerCoreService().evaluate( requiredIf, listParam ); } return isRequired; } @@ -180,8 +181,8 @@ public class ModuleNeeded { public void setModuleName(String moduleName) { if (moduleName != null) { - this.moduleName = moduleName.replace(QUOTATION_MARK, "").replace(SINGLE_QUOTE, //$NON-NLS-1$ - ""); //$NON-NLS-1$ + this.moduleName = moduleName.replace( QUOTATION_MARK, "" ).replace( SINGLE_QUOTE, //$NON-NLS-1$ + "" ); //$NON-NLS-1$ } else { this.moduleName = moduleName; } @@ -300,7 +301,7 @@ public class ModuleNeeded { hashCode *= this.getBundleVersion().hashCode(); } - hashCode *= new Boolean(this.isRequired()).hashCode(); + hashCode *= new Boolean( this.isRequired() ).hashCode(); return hashCode; } @@ -327,7 +328,7 @@ public class ModuleNeeded { } else { if (this.getModuleName() == null) { return false; - } else if (!other.getModuleName().equals(this.getModuleName())) { + } else if (!other.getModuleName().equals( this.getModuleName() )) { return false; } } @@ -339,7 +340,7 @@ public class ModuleNeeded { } else { if (this.getBundleName() == null) { return false; - } else if (!other.getBundleName().equals(this.getBundleName())) { + } else if (!other.getBundleName().equals( this.getBundleName() )) { return false; } } @@ -351,7 +352,7 @@ public class ModuleNeeded { } else { if (this.getBundleVersion() == null) { return false; - } else if (!other.getBundleVersion().equals(this.getBundleVersion())) { + } else if (!other.getBundleVersion().equals( this.getBundleVersion() )) { return false; } } @@ -364,7 +365,7 @@ public class ModuleNeeded { } else { if (this.getModuleLocaion() == null) { return false; - } else if (!other.getModuleLocaion().equals(this.getModuleLocaion())) { + } else if (!other.getModuleLocaion().equals( this.getModuleLocaion() )) { return false; } } @@ -375,8 +376,21 @@ public class ModuleNeeded { return true; } + /** + * return the maven URI if any wa set or return the default maven uri else. The default is computed like this : + * mvn:org.talend.libraries/\/6.0.0 + * + * @return, return the maven uri, never null + */ public String getMavenUri() { - return this.mavenUri; + // set an defaut maven uri if uri is null or empty, this could be done in the set + // but this would mean to sure the set is called after the name is set. + if (mavenUri == null || "".equals( mavenUri )) { //$NON-NLS-1$ + String mavenArtifact = moduleName.endsWith( ".jar" ) ? moduleName + .substring( 0, moduleName.length() - ".jar".length() ) : moduleName; + mavenUri = "mvn:org.talend.libraries/" + mavenArtifact + "/6.0.0";// default value for unknown libs //$NON-NLS-1$ //$NON-NLS-2$ + } + return mavenUri; } /** diff --git a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleToInstall.java b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleToInstall.java index c5922b1d5c..7aaa3fc772 100644 --- a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleToInstall.java +++ b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/model/general/ModuleToInstall.java @@ -12,33 +12,31 @@ // ============================================================================ package org.talend.core.model.general; -import org.talend.core.runtime.maven.MavenConstants; - /** * created by WCHEN on 2012-9-17 Detailled comment * */ public class ModuleToInstall { - private String name; + private String name; - private String context; + private String context; - private String description; + private String description; - private String url_description; + private String url_description; - private String url_download; + private String url_download; private boolean required; - private String licenseType; + private String licenseType; - private String licenseUrl; + private String licenseUrl; - private String mavenUri; + private String mavenUri; - private String distribution = MavenConstants.DOWNLOAD_MANUAL; + private String distribution = ""; public String getName() { return this.name; diff --git a/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/DownloadModuleRunnable.java b/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/DownloadModuleRunnable.java index 5b85f2948c..735d3d1f16 100644 --- a/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/DownloadModuleRunnable.java +++ b/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/DownloadModuleRunnable.java @@ -12,10 +12,7 @@ // ============================================================================ package org.talend.librariesmanager.utils; -import java.io.File; -import java.io.IOException; import java.net.URL; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -31,13 +28,9 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.PlatformUI; import org.ops4j.pax.url.mvn.Handler; import org.talend.commons.exception.ExceptionHandler; -import org.talend.commons.utils.io.FilesUtils; import org.talend.core.GlobalServiceRegister; import org.talend.core.ILibraryManagerService; -import org.talend.core.download.DownloadHelperWithProgress; -import org.talend.core.language.ECodeLanguage; import org.talend.core.model.general.ModuleToInstall; -import org.talend.librariesmanager.prefs.LibrariesManagerUtils; import org.talend.librariesmanager.ui.LibManagerUiPlugin; import org.talend.librariesmanager.ui.i18n.Messages; import org.talend.librariesmanager.ui.wizards.AcceptModuleLicensesWizard; @@ -48,9 +41,9 @@ abstract public class DownloadModuleRunnable implements IRunnableWithProgress { protected List toDownload; - protected Set downloadFailed; + protected Set downloadFailed; - protected Set installedModules; + protected Set installedModules; /** * DOC sgandon DownloadModuleRunnable constructor comment. @@ -66,118 +59,65 @@ abstract public class DownloadModuleRunnable implements IRunnableWithProgress { @Override public void run(final IProgressMonitor monitor) { - SubMonitor subMonitor = SubMonitor.convert(monitor, - Messages.getString("ExternalModulesInstallDialog.downloading2"), toDownload.size() * 10 + 5); //$NON-NLS-1$ - if (checkAndAcceptLicenses(subMonitor)) { - downLoad(subMonitor); + SubMonitor subMonitor = SubMonitor + .convert( + monitor, + Messages.getString( "ExternalModulesInstallDialog.downloading2" ) + " (" + toDownload.size() + ")", toDownload.size() * 10 + 5 ); //$NON-NLS-1$ + if (checkAndAcceptLicenses( subMonitor )) { + downLoad( subMonitor ); } if (monitor != null) { - monitor.setCanceled(subMonitor.isCanceled()); + monitor.setCanceled( subMonitor.isCanceled() ); monitor.done(); } } private void downLoad(final IProgressMonitor monitor) { - SubMonitor subMonitor = SubMonitor.convert(monitor, - Messages.getString("ExternalModulesInstallDialog.downloading2"), toDownload.size() + 1); //$NON-NLS-1$ + SubMonitor subMonitor = SubMonitor + .convert( + monitor, + Messages.getString( "ExternalModulesInstallDialog.downloading2" ) + " (" + toDownload.size() + ")", toDownload.size() + 1 ); //$NON-NLS-1$ - if (RemoteModulesHelper.nexus_available) { - Map customUriToAdd = new HashMap(); - for (final ModuleToInstall module : toDownload) { - if (!monitor.isCanceled()) { - monitor.subTask(module.getName()); - boolean accepted; - try { - // check license - boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore() - .getBoolean(module.getLicenseType()); - accepted = isLicenseAccepted; - if (!accepted) { - subMonitor.worked(1); - continue; - } - if (monitor.isCanceled()) { - return; - } - NexusDownloadHelperWithProgress downloader = new NexusDownloadHelperWithProgress(); - downloader.download(new URL(null, module.getMavenUri(), new Handler()), null, subMonitor.newChild(1)); - customUriToAdd.put(module.getName(), module.getMavenUri()); - installedModules.add(module.getName()); - } catch (Exception e) { - downloadFailed.add(module.getName()); - ExceptionHandler.process(e); + Map customUriToAdd = new HashMap(); + for (final ModuleToInstall module : toDownload) { + if (!monitor.isCanceled()) { + monitor.subTask( module.getName() ); + boolean accepted; + try { + // check license + boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore() + .getBoolean( module.getLicenseType() ); + accepted = isLicenseAccepted; + if (!accepted) { + subMonitor.worked( 1 ); continue; } - accepted = false; - } else { - downloadFailed.add(module.getName()); - } - } - // reset the module install status - if (!customUriToAdd.isEmpty()) { - ILibraryManagerService libraryManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault() - .getService(ILibraryManagerService.class); - libraryManagerService.deployMavenIndex(customUriToAdd, monitor); - libraryManagerService.forceListUpdate(); - LibManagerUiPlugin.getDefault().getLibrariesService().resetModulesNeeded(); - } - subMonitor.worked(1); - } else { - // TODO to be removed after nexus server available - final List downloadOk = new ArrayList(); - for (final ModuleToInstall module : toDownload) { - if (!monitor.isCanceled()) { - monitor.subTask(module.getName()); - String librariesPath = LibrariesManagerUtils.getLibrariesPath(ECodeLanguage.JAVA); - File target = new File(librariesPath); - boolean accepted; - if (module.getUrl_download() != null && !"".equals(module.getUrl_download())) { //$NON-NLS-1$ - try { - // check license - boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore() - .getBoolean(module.getLicenseType()); - accepted = isLicenseAccepted; - if (!accepted) { - subMonitor.worked(1); - continue; - } - if (monitor.isCanceled()) { - return; - } - File destination = new File(target.toString() + File.separator + module.getName()); - File destinationTemp = target.createTempFile(destination.getName(), ".jar"); - DownloadHelperWithProgress downloader = new DownloadHelperWithProgress(); - downloader.download(new URL(module.getUrl_download()), destinationTemp, subMonitor.newChild(1)); - // if the jar had download complete , will copy it from system temp path to "lib/java" - if (!monitor.isCanceled()) { - FilesUtils.copyFile(destinationTemp, destination); - downloadOk.add(destination.toURI().toURL()); - installedModules.add(module.getName()); - } - if (destinationTemp.exists()) { - destinationTemp.delete(); - } - } catch (Exception e) { - downloadFailed.add(module.getName()); - ExceptionHandler.process(e); - continue; - } + if (monitor.isCanceled()) { + return; } - accepted = false; - } else { - downloadFailed.add(module.getName()); + NexusDownloadHelperWithProgress downloader = new NexusDownloadHelperWithProgress(); + downloader.download( new URL( null, module.getMavenUri(), new Handler() ), null, subMonitor.newChild( 1 ) ); + customUriToAdd.put( module.getName(), module.getMavenUri() ); + installedModules.add( module.getName() ); + } catch (Exception e) { + downloadFailed.add( module.getName() ); + ExceptionHandler.process( e ); + continue; } + accepted = false; + } else { + downloadFailed.add( module.getName() ); } - if (!downloadOk.isEmpty()) { - try { - LibManagerUiPlugin.getDefault().getLibrariesService() - .deployLibrarys(downloadOk.toArray(new URL[downloadOk.size()])); - } catch (IOException e) { - ExceptionHandler.process(e); - } - } - subMonitor.worked(1); } + // reset the module install status + if (!customUriToAdd.isEmpty()) { + ILibraryManagerService libraryManagerService = (ILibraryManagerService) GlobalServiceRegister.getDefault() + .getService( ILibraryManagerService.class ); + libraryManagerService.deployMavenIndex( customUriToAdd, monitor ); + libraryManagerService.forceListUpdate(); + LibManagerUiPlugin.getDefault().getLibrariesService().resetModulesNeeded(); + } + subMonitor.worked( 1 ); } protected boolean hasLicensesToAccept() { @@ -186,7 +126,7 @@ abstract public class DownloadModuleRunnable implements IRunnableWithProgress { String licenseType = module.getLicenseType(); if (licenseType != null) { boolean isLicenseAccepted = LibManagerUiPlugin.getDefault().getPreferenceStore() - .getBoolean(module.getLicenseType()); + .getBoolean( module.getLicenseType() ); if (!isLicenseAccepted) { return true; } @@ -198,22 +138,22 @@ abstract public class DownloadModuleRunnable implements IRunnableWithProgress { } protected boolean checkAndAcceptLicenses(final IProgressMonitor monitor) { - final AtomicBoolean accepted = new AtomicBoolean(true); + final AtomicBoolean accepted = new AtomicBoolean( true ); if (hasLicensesToAccept()) { - Display.getDefault().syncExec(new Runnable() { + Display.getDefault().syncExec( new Runnable() { @Override public void run() { - AcceptModuleLicensesWizard licensesWizard = new AcceptModuleLicensesWizard(toDownload); - AcceptModuleLicensesWizardDialog wizardDialog = new AcceptModuleLicensesWizardDialog(PlatformUI - .getWorkbench().getActiveWorkbenchWindow().getShell(), licensesWizard, toDownload, monitor); - wizardDialog.setPageSize(700, 380); + AcceptModuleLicensesWizard licensesWizard = new AcceptModuleLicensesWizard( toDownload ); + AcceptModuleLicensesWizardDialog wizardDialog = new AcceptModuleLicensesWizardDialog( PlatformUI + .getWorkbench().getActiveWorkbenchWindow().getShell(), licensesWizard, toDownload, monitor ); + wizardDialog.setPageSize( 700, 380 ); wizardDialog.create(); if (wizardDialog.open() != Window.OK) { - accepted.set(false); + accepted.set( false ); } } - }); + } ); } diff --git a/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/RemoteModulesHelper.java b/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/RemoteModulesHelper.java index 8063707ccd..7873e6bbaa 100644 --- a/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/RemoteModulesHelper.java +++ b/main/plugins/org.talend.librariesmanager.ui/src/main/java/org/talend/librariesmanager/utils/RemoteModulesHelper.java @@ -44,7 +44,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.operation.IRunnableWithProgress; import org.ops4j.pax.url.mvn.MavenResolver; -import org.talend.commons.CommonsPlugin; import org.talend.commons.exception.ExceptionHandler; import org.talend.commons.utils.network.NetworkUtil; import org.talend.core.model.general.ModuleNeeded; @@ -68,13 +67,13 @@ import us.monoid.json.JSONObject; */ public class RemoteModulesHelper { - private static final String SLASH = "/";//$NON-NLS-1$ + private static final String SLASH = "/"; //$NON-NLS-1$ // TODO to be removed after nexus server available - public static final boolean nexus_available = true; + public static final boolean nexus_available = true; // true if user was warned the network connection is not possible - static private boolean alreadyWarnedAboutConnectionIssue = false; + static private boolean alreadyWarnedAboutConnectionIssue = false; /** * created by sgandon on 24 sept. 2013 Detailled comment @@ -83,24 +82,24 @@ public class RemoteModulesHelper { private final class RemoteModulesFetchRunnable implements IRunnableWithProgress { // TODO to be removed after nexus server available - private Set globalUnavailableModulesToBeRemoved = new HashSet(); + private Set globalUnavailableModulesToBeRemoved = new HashSet(); /** * */ - private final String jarNames; + private final String jarNames; /** * */ - private final List toInstall; + private final List toInstall; /** * */ private final Map> contextMap; - private String messages; + private String messages; /** * DOC sgandon IRunnableWithProgressImplementation constructor comment. @@ -122,205 +121,105 @@ public class RemoteModulesHelper { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - if (nexus_available) { - String[] jars = jarNames.split(SEPARATOR_SLIP); - int size = jars.length; - Set unavailableModules = new HashSet(); - monitor.beginTask(Messages.getString("RemoteModulesHelper.fetch.module.info"), size * 10 + 10);//$NON-NLS-1$ - // if the network is not valid, all jars are not available. - boolean networkValid = false; - if (cache == null || recheckCache) { - networkValid = NetworkUtil.isNetworkValid(); - if (!networkValid) { - unavailableModules.addAll(Arrays.asList(jars)); - messages = Messages.getString("RemoteModulesHelper.offlineMessages"); //$NON-NLS-1$ - if (!alreadyWarnedAboutConnectionIssue) { - log.warn("failed to connect to internet"); - alreadyWarnedAboutConnectionIssue = true; - }// else already warned so do nothing - } - } - if (networkValid) { - try { - cache = new HashMap(); - // TODO , not sure about the version , don't add version in search condition for now - List searchResults = NexusServerManager.search(nexusServer.getServer(), - nexusServer.getUserName(), nexusServer.getPassword(), nexusServer.getRepositoryId(), - MavenConstants.DEFAULT_LIB_GROUP_ID, null); - monitor.worked(10); - for (MavenArtifact artifact : searchResults) { - String artifactId = artifact.getArtifactId(); - String packageName = artifact.getType(); - if (packageName == null) { - packageName = MavenConstants.TYPE_JAR; - } - String version = artifact.getVersion(); - String description = artifact.getDescription(); - String license = artifact.getLicense(); - String license_url = artifact.getLicenseUrl(); - String distribution = artifact.getDistribution(); - String url = null; - if (artifact.getUrl() != null && !"".equals(artifact.getUrl())) { - url = artifact.getUrl(); - } - ModuleToInstall m = new ModuleToInstall(); - m.setName(artifactId + "." + packageName); - // a maven uri like mvn:org.talend.libraries/mysql-connector-java-5.1.30-bin/6.0.0 ,no need - // type and classifier - String mvnUri = MavenUrlHelper.generateMvnUrl(artifact.getGroupId(), artifactId, version, null, null); - m.setMavenUri(mvnUri); - m.setLicenseType(license); - m.setLicenseUrl(license_url); - m.setDescription(description); - m.setUrl_description(url); - m.setUrl_download(url); - m.setDistribution(distribution); - setContext(m, contextMap); - - cache.put(m.getName(), m); - - monitor.worked(10); - } - - } catch (Exception e1) { - ExceptionHandler.process(e1); - recheckCache = true; - } - } - - for (String name : jars) { - String artifact2Check = name; - String key = getJarName(artifact2Check); - ModuleToInstall moduleToInstall = cache.get(key); - if (moduleToInstall != null) { - toInstall.add(moduleToInstall); - } else { - unavailableModules.add(name); - ExceptionHandler.log("The download URL for " + name + " is not available");//$NON-NLS-1$//$NON-NLS-2$ - } - monitor.worked(10); - } - - addUnavailableModulesToToBeInstalledModules(unavailableModules, toInstall, contextMap); - monitor.done(); - } else { - // TODO need to remove after nexus server available - if (cache == null) { - cache = new HashMap(); - } - String[] jars = jarNames.split(SEPARATOR_SLIP); - int size = jars.length; - Set unavailableModules = new HashSet(); - monitor.beginTask(Messages.getString("RemoteModulesHelper.fetch.module.info"), size * 10);//$NON-NLS-1$ - // if the network is not valid, all jars are not available. - boolean networkValid = NetworkUtil.isNetworkValid(); + String[] jars = jarNames.split( SEPARATOR_SLIP ); + int size = jars.length; + Set unavailableModules = new HashSet(); + monitor.beginTask( Messages.getString( "RemoteModulesHelper.fetch.module.info" ), size * 10 + 10 );//$NON-NLS-1$ + // if the network is not valid, all jars are not available. + boolean networkValid = false; + if (cache == null || recheckCache) { + networkValid = NetworkUtil.isNetworkValid(); if (!networkValid) { - globalUnavailableModulesToBeRemoved.addAll(Arrays.asList(jars)); - unavailableModules.addAll(Arrays.asList(jars)); - messages = Messages.getString("RemoteModulesHelper.offlineMessages"); //$NON-NLS-1$ + unavailableModules.addAll( Arrays.asList( jars ) ); + messages = Messages.getString( "RemoteModulesHelper.offlineMessages" ); //$NON-NLS-1$ if (!alreadyWarnedAboutConnectionIssue) { - log.warn("failed to connect to internet"); + log.warn( "failed to connect to internet" ); alreadyWarnedAboutConnectionIssue = true; }// else already warned so do nothing - } else { - try { - int index = 0; - int limit = 100; - while (index < jars.length) { - // get block of 100 jars - String jarsToCheck = ""; - while (index < limit && index < jars.length) { - jarsToCheck += jars[index]; - index++; - if (index < limit && index < jars.length) { - jarsToCheck += "|"; - } - } - limit += 100; - JSONObject message = new JSONObject(); - JSONObject child = new JSONObject(); - child.put("vaction", "getModules");//$NON-NLS-1$ - child.put("name", jarsToCheck);//$NON-NLS-1$ - message.put("module", child);//$NON-NLS-1$ - String url = serviceUrl + "?data=" + message; - monitor.worked(10); - if (monitor.isCanceled()) { - return; - } - JSONObject resultStr = readJsonFromUrl(url); - if (resultStr != null) { - JSONArray jsonArray = resultStr.getJSONArray("result");//$NON-NLS-1$ - if (jsonArray != null) { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject obj = jsonArray.getJSONObject(i); - if (obj != null) { - String url_description = obj.getString("url_description");//$NON-NLS-1$ - String url_download = obj.getString("url_download");//$NON-NLS-1$ - String name = obj.getString("filename");//$NON-NLS-1$ - if ((url_description == null && url_download == null) - || (("".equals(url_description) || "null".equals(url_description)) && (""//$NON-NLS-1$ - .equals(url_download) || "null".equals(url_download)))) {//$NON-NLS-1$ - ExceptionHandler.log("The download URL for " + name + " is not available");//$NON-NLS-1$ - if (CommonsPlugin.isDebugMode()) { - appendToLogFile(name + "\n"); - } - // keep null in cache no need to check from server again - cache.put(name, null); - globalUnavailableModulesToBeRemoved.add(name); - unavailableModules.add(name); - continue; - } - - ModuleToInstall m = new ModuleToInstall(); - - m.setName(name); - setContext(m, contextMap); - String license = obj.getString("licence");//$NON-NLS-1$ - m.setLicenseType(license); - if ("".equals(license) || "null".equals(license)) {//$NON-NLS-1$ - m.setLicenseType(null); - } - String description = obj.getString("description");//$NON-NLS-1$ - if (description == null || "".equals(description) || "null".equals(description)) {//$NON-NLS-1$ - description = m.getName(); - } - m.setDescription(description); - m.setUrl_description(url_description); - if (url_download == null || "".equals(url_download) || "null".equals(url_download)) {//$NON-NLS-1$ - m.setUrl_download(null); - } else { - m.setUrl_download(url_download); - } - this.toInstall.add(m); - cache.put(m.getName(), m); - } - if (monitor.isCanceled()) { - return; - } - monitor.worked(10); - } - } - } - } - } catch (JSONException e) { - ExceptionHandler.process(e); - } catch (IOException e) { - ExceptionHandler.process(e); - } } - addUnavailableModulesToToBeInstalledModules(unavailableModules, toInstall, contextMap); - monitor.done(); - } + if (networkValid) { + try { + cache = new HashMap(); + // TODO , not sure about the version , don't add version in search condition for now + List searchResults = NexusServerManager.search( nexusServer.getServer(), + nexusServer.getUserName(), nexusServer.getPassword(), nexusServer.getRepositoryId(), + MavenConstants.DEFAULT_LIB_GROUP_ID, null ); + monitor.worked( 10 ); + for (MavenArtifact artifact : searchResults) { + String artifactId = artifact.getArtifactId(); + String packageName = artifact.getType(); + if (packageName == null) { + packageName = MavenConstants.TYPE_JAR; + } + String version = artifact.getVersion(); + String description = artifact.getDescription(); + String license = artifact.getLicense(); + String license_url = artifact.getLicenseUrl(); + String distribution = artifact.getDistribution(); + String url = null; + if (artifact.getUrl() != null && !"".equals( artifact.getUrl() )) { + url = artifact.getUrl(); + } + ModuleToInstall m = new ModuleToInstall(); + m.setName( artifactId + "." + packageName ); + // a maven uri like mvn:org.talend.libraries/mysql-connector-java-5.1.30-bin/6.0.0 ,no need + // type and classifier + String mvnUri = MavenUrlHelper.generateMvnUrl( artifact.getGroupId(), artifactId, version, null, null ); + m.setMavenUri( mvnUri ); + m.setLicenseType( license ); + m.setLicenseUrl( license_url ); + m.setDescription( description ); + m.setUrl_description( url ); + m.setUrl_download( url ); + // the artiface distribution attribute may be emty because the remote server engine does not + // return it. + // so we use the classifier to check for availability + if (distribution == null || distribution.equals( "" )) { //$NON-NLS-1$ + String artifactType = artifact.getType(); + if (artifactType != null && artifactType.equals( "pom" )) { //$NON-NLS-1$ + m.setDistribution( MavenConstants.DOWNLOAD_MANUAL ); + }// else we do not set anything to the distribution value + } else {// distribution is already set so use it + m.setDistribution( distribution ); + } + setContext( m, contextMap ); + + cache.put( m.getName(), m ); + + monitor.worked( 10 ); + } + + } catch (Exception e1) { + ExceptionHandler.process( e1 ); + recheckCache = true; + } + } + + for (String name : jars) { + String artifact2Check = name; + String key = getJarName( artifact2Check ); + ModuleToInstall moduleToInstall = cache.get( key ); + if (moduleToInstall != null) { + toInstall.add( moduleToInstall ); + } else { + unavailableModules.add( name ); + ExceptionHandler.log( "The download URL for " + name + " is not available" );//$NON-NLS-1$//$NON-NLS-2$ + } + monitor.worked( 10 ); + } + + // addUnavailableModulesToToBeInstalledModules( unavailableModules, toInstall, contextMap ); + monitor.done(); } } private String getJarName(String jarNameOrUrl) { if (jarNameOrUrl != null) { - if (MavenUrlHelper.isMvnUrl(jarNameOrUrl)) { - MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl(jarNameOrUrl); + if (MavenUrlHelper.isMvnUrl( jarNameOrUrl )) { + MavenArtifact parseMvnUrl = MavenUrlHelper.parseMvnUrl( jarNameOrUrl ); String type = parseMvnUrl.getType(); - if (type == null || "".equals(type)) { + if (type == null || "".equals( type )) { type = MavenConstants.TYPE_JAR; } return parseMvnUrl.getArtifactId() + "." + type; @@ -344,8 +243,8 @@ public class RemoteModulesHelper { // add all unavailable modules, cause they need to be installed even if the are not available from remote // site. for (String unavailableModuleName : unavailableModules) { - ModuleToInstall m = createUnavailableModuleToInstall(unavailableModuleName, contextMap); - toInstall2.add(m); + ModuleToInstall m = createUnavailableModuleToInstall( unavailableModuleName, contextMap ); + toInstall2.add( m ); } } @@ -359,10 +258,10 @@ public class RemoteModulesHelper { private ModuleToInstall createUnavailableModuleToInstall(String unavailableModuleName, Map> contextMap) { ModuleToInstall m = new ModuleToInstall(); - m.setName(unavailableModuleName); - setContext(m, contextMap); + m.setName( unavailableModuleName ); + setContext( m, contextMap ); if (contextMap != null) { - m.setDescription(getFirstDescription(contextMap.get(unavailableModuleName))); + m.setDescription( getFirstDescription( contextMap.get( unavailableModuleName ) ) ); }// there will be no description return m; @@ -376,12 +275,12 @@ public class RemoteModulesHelper { */ protected void setContext(ModuleToInstall m, Map> contextMap) { if (contextMap != null) { - List nm = contextMap.get(m.getName()); - m.setContext(getContext(nm)); - m.setRequired(isRequired(nm)); + List nm = contextMap.get( m.getName() ); + m.setContext( getContext( nm ) ); + m.setRequired( isRequired( nm ) ); } else { - m.setContext("Current Operation");//$NON-NLS-1$ - m.setRequired(true); + m.setContext( "Current Operation" );//$NON-NLS-1$ + m.setRequired( true ); } } @@ -396,7 +295,7 @@ public class RemoteModulesHelper { return ""; //$NON-NLS-1$ } for (ModuleNeeded module : neededModules) { - if (module.getInformationMsg() != null && !"".equals(module.getInformationMsg())) { //$NON-NLS-1$ + if (module.getInformationMsg() != null && !"".equals( module.getInformationMsg() )) { //$NON-NLS-1$ return module.getInformationMsg(); } } @@ -405,13 +304,13 @@ public class RemoteModulesHelper { } private void appendToLogFile(String logTxt) { - Path absolutePath = new Path(Platform.getInstallLocation().getURL().getPath()); - File fullLogFile = new File(absolutePath.append("NotAvailableJarsFromWebservice.txt").toPortableString()); + Path absolutePath = new Path( Platform.getInstallLocation().getURL().getPath() ); + File fullLogFile = new File( absolutePath.append( "NotAvailableJarsFromWebservice.txt" ).toPortableString() ); FileWriter writer = null; try { - writer = new FileWriter(fullLogFile, true); - writer.append(logTxt); + writer = new FileWriter( fullLogFile, true ); + writer.append( logTxt ); } catch (IOException e) { // nothing } finally { @@ -426,31 +325,31 @@ public class RemoteModulesHelper { } - private static Logger log = Logger.getLogger(RemoteModulesHelper.class); + private static Logger log = Logger.getLogger( RemoteModulesHelper.class ); - private static RemoteModulesHelper helper; + private static RemoteModulesHelper helper; // private static final String serviceUrl = "http://www.talend.com/TalendRegisterWS/modules.php"; - private static final String serviceUrl = "http://www.talendforge.org/modules/webservices/modules.php";//$NON-NLS-1$ + private static final String serviceUrl = "http://www.talendforge.org/modules/webservices/modules.php"; //$NON-NLS-1$ - private static final String SEPARATOR_DISPLAY = " | ";//$NON-NLS-1$ + private static final String SEPARATOR_DISPLAY = " | "; //$NON-NLS-1$ - private static final String SEPARATOR = "|";//$NON-NLS-1$ + private static final String SEPARATOR = "|"; //$NON-NLS-1$ - private static final String SEPARATOR_SLIP = "\\|";//$NON-NLS-1$ + private static final String SEPARATOR_SLIP = "\\|"; //$NON-NLS-1$ - private MavenResolver mvnResolver; + private MavenResolver mvnResolver; - NexusServerBean nexusServer; + NexusServerBean nexusServer; - private boolean recheckCache = false; + private boolean recheckCache = false; private Map cache; private RemoteModulesHelper() { nexusServer = NexusServerManager.getLibrariesNexusServer(); - mvnResolver = MavenResolverCreator.getInstance().getMavenResolver(nexusServer); + mvnResolver = MavenResolverCreator.getInstance().getMavenResolver( nexusServer ); } public synchronized static RemoteModulesHelper getInstance() { @@ -462,18 +361,18 @@ public class RemoteModulesHelper { public void getNotInstalledModules(List neededModules, List toInstall, IModulesListener listener) { - getNotInstalledModules(neededModules, toInstall, listener, false); + getNotInstalledModules( neededModules, toInstall, listener, false ); } public void getNotInstalledModules(List neededModules, List toInstall, IModulesListener listener, boolean isUser) { - RemoteModulesFetchRunnable fecthUninstalledModulesRunnable = getNotInstalledModulesRunnable(neededModules, toInstall); + RemoteModulesFetchRunnable fecthUninstalledModulesRunnable = getNotInstalledModulesRunnable( neededModules, toInstall ); if (fecthUninstalledModulesRunnable == null) { listener.listModulesDone(); return; } - scheduleJob(fecthUninstalledModulesRunnable, listener, isUser); + scheduleJob( fecthUninstalledModulesRunnable, listener, isUser ); } @@ -489,19 +388,19 @@ public class RemoteModulesHelper { for (ModuleNeeded module : neededModules) { String moduleName = module.getModuleName().trim(); - if (!contextMap.keySet().contains(moduleName)) { + if (!contextMap.keySet().contains( moduleName )) { List modules = new ArrayList(); - modules.add(module); - contextMap.put(moduleName, modules); + modules.add( module ); + contextMap.put( moduleName, modules ); // only check that, but, it don't check available on site - if (cache == null || !cache.keySet().contains(moduleName)) { + if (cache == null || !cache.keySet().contains( moduleName )) { if (jars.length() != 0) { - jars.append(SEPARATOR); + jars.append( SEPARATOR ); } - jars.append(module.getModuleName()); + jars.append( module.getModuleName() ); }// have checked } else { - contextMap.get(moduleName).add(module); + contextMap.get( moduleName ).add( module ); } } String jarNames = jars.toString(); @@ -510,30 +409,30 @@ public class RemoteModulesHelper { for (String moduleName : contextMap.keySet()) { ModuleToInstall moduleToInstall = null; if (cache != null && !cache.isEmpty()) { - moduleToInstall = cache.get(moduleName); + moduleToInstall = cache.get( moduleName ); } if (moduleToInstall != null) { - List moduleContext = contextMap.get(moduleName); - moduleToInstall.setContext(getContext(moduleContext)); + List moduleContext = contextMap.get( moduleName ); + moduleToInstall.setContext( getContext( moduleContext ) ); if (moduleContext != null && moduleContext.size() > 0) { for (ModuleNeeded needed : moduleContext) { - if (moduleToInstall.getName().equals(needed.getModuleName())) { - moduleToInstall.setRequired(needed.isRequired()); + if (moduleToInstall.getName().equals( needed.getModuleName() )) { + moduleToInstall.setRequired( needed.isRequired() ); } } } - toInstall.add(moduleToInstall); + toInstall.add( moduleToInstall ); } else {// else not found in cache - notCachedModulesName.add(moduleName); + notCachedModulesName.add( moduleName ); } } if (jarNames.isEmpty()) { - addUnavailableModulesToToBeInstalledModules(notCachedModulesName, toInstall, contextMap); + addUnavailableModulesToToBeInstalledModules( notCachedModulesName, toInstall, contextMap ); return null; // if all have been in cache, no need fetching runnable again. } // fetch the jars which are not in cache. - return createRemoteModuleFetchRunnable(jarNames, toInstall, contextMap); + return createRemoteModuleFetchRunnable( jarNames, toInstall, contextMap ); } @@ -542,19 +441,19 @@ public class RemoteModulesHelper { // check that modules are already in cache or not if (names != null && names.length > 0) { for (String module : names) { - String moduleName = getJarName(module.trim()); + String moduleName = getJarName( module.trim() ); ModuleToInstall moduleToInstall = null; if (cache != null) { - moduleToInstall = cache.get(moduleName); + moduleToInstall = cache.get( moduleName ); } if (moduleToInstall != null) { // if not existed, or not available on site. - moduleToInstall.setContext("Current Operation");//$NON-NLS-1$ - toInstall.add(moduleToInstall); + moduleToInstall.setContext( "Current Operation" );//$NON-NLS-1$ + toInstall.add( moduleToInstall ); } else { // not existed if (toInstalljars.length() != 0) { - toInstalljars.append(SEPARATOR); + toInstalljars.append( SEPARATOR ); } - toInstalljars.append(moduleName); + toInstalljars.append( moduleName ); } } } @@ -564,39 +463,39 @@ public class RemoteModulesHelper { listener.listModulesDone(); return; } - scheduleJob(createRemoteModuleFetchRunnable(toInstallJarNames, toInstall, null), listener, false); + scheduleJob( createRemoteModuleFetchRunnable( toInstallJarNames, toInstall, null ), listener, false ); } private synchronized void scheduleJob(final RemoteModulesFetchRunnable runnableWithProgress, final IModulesListener listener, boolean isUser) { - Job job = new Job(Messages.getString("RemoteModulesHelper.job.title")) {//$NON-NLS-1$ + Job job = new Job( Messages.getString( "RemoteModulesHelper.job.title" ) ) {//$NON-NLS-1$ @Override protected IStatus run(IProgressMonitor progressMonitor) { try { - runnableWithProgress.run(progressMonitor); + runnableWithProgress.run( progressMonitor ); } catch (InvocationTargetException e) { - log.warn("fetching remote Modules data failed", e); //$NON-NLS-1$ + log.warn( "fetching remote Modules data failed", e ); //$NON-NLS-1$ return Status.CANCEL_STATUS; } catch (InterruptedException e) { - log.warn("fetching remote Modules data failed", e); //$NON-NLS-1$ + log.warn( "fetching remote Modules data failed", e ); //$NON-NLS-1$ return Status.CANCEL_STATUS; } return Status.OK_STATUS; } }; - job.addJobChangeListener(new JobChangeAdapter() { + job.addJobChangeListener( new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { listener.listModulesDone(); } - }); + } ); - job.setUser(isUser); - job.setPriority(Job.INTERACTIVE); + job.setUser( isUser ); + job.setPriority( Job.INTERACTIVE ); job.schedule(); } @@ -610,19 +509,19 @@ public class RemoteModulesHelper { */ public RemoteModulesFetchRunnable createRemoteModuleFetchRunnable(final String jarNames, final List toInstall, final Map> contextMap) { - return new RemoteModulesFetchRunnable(jarNames, toInstall, contextMap); + return new RemoteModulesFetchRunnable( jarNames, toInstall, contextMap ); } private JSONObject readJsonFromUrl(String url) throws IOException { - InputStream is = new URL(url).openStream(); + InputStream is = new URL( url ).openStream(); String jsonText = ""; JSONObject json = null; try { - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));//$NON-NLS-1$ - jsonText = readAll(rd); - json = new JSONObject(jsonText); + BufferedReader rd = new BufferedReader( new InputStreamReader( is, Charset.forName( "UTF-8" ) ) );//$NON-NLS-1$ + jsonText = readAll( rd ); + json = new JSONObject( jsonText ); } catch (Exception e) { - ExceptionHandler.process(new Exception(Messages.getString("RemoteModulesHelper.readJsonFromUrl.error"))); + ExceptionHandler.process( new Exception( Messages.getString( "RemoteModulesHelper.readJsonFromUrl.error" ) ) ); } finally { is.close(); } @@ -633,7 +532,7 @@ public class RemoteModulesHelper { StringBuilder sb = new StringBuilder(); int cp; while ((cp = rd.read()) != -1) { - sb.append((char) cp); + sb.append( (char) cp ); } return sb.toString(); } @@ -645,9 +544,9 @@ public class RemoteModulesHelper { StringBuffer context = new StringBuffer(); for (ModuleNeeded module : neededModules) { if (context.length() != 0) { - context.append(SEPARATOR_DISPLAY); + context.append( SEPARATOR_DISPLAY ); } - context.append(module.getContext()); + context.append( module.getContext() ); } return context.toString(); @@ -671,16 +570,16 @@ public class RemoteModulesHelper { JSONObject message = new JSONObject(); try { JSONObject child = new JSONObject(); - child.put("vaction", "getLicense");//$NON-NLS-1$ - child.put("label", licenseType);//$NON-NLS-1$ - message.put("module", child);//$NON-NLS-1$ + child.put( "vaction", "getLicense" );//$NON-NLS-1$ + child.put( "label", licenseType );//$NON-NLS-1$ + message.put( "module", child );//$NON-NLS-1$ String url = serviceUrl + "?data=" + message; - JSONObject resultStr = readJsonFromUrl(url); - JSONArray jsonArray = resultStr.getJSONArray("result");//$NON-NLS-1$ + JSONObject resultStr = readJsonFromUrl( url ); + JSONArray jsonArray = resultStr.getJSONArray( "result" );//$NON-NLS-1$ if (jsonArray != null) { - JSONObject object = jsonArray.getJSONObject(0); + JSONObject object = jsonArray.getJSONObject( 0 ); if (object != null) { - return object.getString("licenseText");//$NON-NLS-1$ + return object.getString( "licenseText" );//$NON-NLS-1$ } } } catch (JSONException e) { @@ -695,22 +594,22 @@ public class RemoteModulesHelper { List toInstall = new ArrayList(); ModuleToInstall m1 = new ModuleToInstall(); m1 = new ModuleToInstall(); - m1.setName("jtds-1.2.5.jar"); - m1.setContext("tMysqlInput | tMysqlOutput"); - m1.setDescription("Mysql Driver"); - m1.setUrl_description("http://jtds.sourceforge.net/"); - m1.setUrl_download(null); - m1.setLicenseType("LGPL_v3"); - toInstall.add(m1); + m1.setName( "jtds-1.2.5.jar" ); + m1.setContext( "tMysqlInput | tMysqlOutput" ); + m1.setDescription( "Mysql Driver" ); + m1.setUrl_description( "http://jtds.sourceforge.net/" ); + m1.setUrl_download( null ); + m1.setLicenseType( "LGPL_v3" ); + toInstall.add( m1 ); m1 = new ModuleToInstall(); m1 = new ModuleToInstall(); - m1.setName("test.jar"); - m1.setContext("tMysqalInput | tMysfqlOutput"); - m1.setDescription("testaaaaa"); - m1.setUrl_description("http://jtds.sourceforge.net/"); - m1.setUrl_download(null); - m1.setLicenseType("LGPL_v3"); - toInstall.add(m1); + m1.setName( "test.jar" ); + m1.setContext( "tMysqalInput | tMysfqlOutput" ); + m1.setDescription( "testaaaaa" ); + m1.setUrl_description( "http://jtds.sourceforge.net/" ); + m1.setUrl_download( null ); + m1.setLicenseType( "LGPL_v3" ); + toInstall.add( m1 ); return toInstall; } @@ -727,19 +626,19 @@ public class RemoteModulesHelper { // check that modules are already in cache or not if (requiredJars != null && requiredJars.length > 0) { for (String module : requiredJars) { - String moduleName = getJarName(module.trim()); + String moduleName = getJarName( module.trim() ); ModuleToInstall moduleToInstall = null; if (cache != null) { - moduleToInstall = cache.get(moduleName); + moduleToInstall = cache.get( moduleName ); } if (moduleToInstall != null) { - moduleToInstall.setContext("Current Operation");//$NON-NLS-1$ - toInstall.add(moduleToInstall); + moduleToInstall.setContext( "Current Operation" );//$NON-NLS-1$ + toInstall.add( moduleToInstall ); } else { // not existed, or not available on site. if (toInstallJars.length() != 0) { - toInstallJars.append(SEPARATOR); + toInstallJars.append( SEPARATOR ); } - toInstallJars.append(moduleName); + toInstallJars.append( moduleName ); } } } @@ -748,27 +647,27 @@ public class RemoteModulesHelper { if (toInstallJarNames.isEmpty()) { return null; } else { - return createRemoteModuleFetchRunnable(toInstallJarNames, toInstall, null); + return createRemoteModuleFetchRunnable( toInstallJarNames, toInstall, null ); } } public String getLicenseContentByUrl(String licenseUrl) { if (licenseUrl != null && licenseUrl.length() > 0) { try { - URL url = new URL(licenseUrl); + URL url = new URL( licenseUrl ); URLConnection urlConnection = url.openConnection(); Map> headerFields = urlConnection.getHeaderFields(); if (headerFields != null) { - List contentType = headerFields.get("Content-Type"); //$NON-NLS-1$ + List contentType = headerFields.get( "Content-Type" ); //$NON-NLS-1$ if (contentType != null) { - if (contentType.contains("text/plain")) { //$NON-NLS-1$ + if (contentType.contains( "text/plain" )) { //$NON-NLS-1$ // Get the plain text from connection. InputStream inputStream = urlConnection.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(500); + ByteArrayOutputStream baos = new ByteArrayOutputStream( 500 ); byte[] b = new byte[1024]; int len; - while ((len = inputStream.read(b)) != -1) { - baos.write(b, 0, len); + while ((len = inputStream.read( b )) != -1) { + baos.write( b, 0, len ); } inputStream.close(); return baos.toString(); diff --git a/main/plugins/org.talend.librariesmanager/src/main/java/org/talend/librariesmanager/model/ModulesNeededProvider.java b/main/plugins/org.talend.librariesmanager/src/main/java/org/talend/librariesmanager/model/ModulesNeededProvider.java index d3e70dc2e9..0e91b6aba3 100644 --- a/main/plugins/org.talend.librariesmanager/src/main/java/org/talend/librariesmanager/model/ModulesNeededProvider.java +++ b/main/plugins/org.talend.librariesmanager/src/main/java/org/talend/librariesmanager/model/ModulesNeededProvider.java @@ -35,6 +35,10 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl; +import org.ops4j.pax.url.mvn.MavenResolver; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; import org.talend.commons.exception.CommonExceptionHandler; import org.talend.commons.exception.PersistenceException; import org.talend.commons.runtime.model.repository.ERepositoryStatus; @@ -44,10 +48,7 @@ import org.talend.commons.utils.workbench.extensions.IExtensionPointLimiter; import org.talend.core.GlobalServiceRegister; import org.talend.core.ILibraryManagerUIService; import org.talend.core.PluginChecker; -import org.talend.core.context.Context; -import org.talend.core.context.RepositoryContext; import org.talend.core.database.conn.version.EDatabaseVersion4Drivers; -import org.talend.core.language.ECodeLanguage; import org.talend.core.language.LanguageManager; import org.talend.core.model.component_cache.ComponentCachePackage; import org.talend.core.model.component_cache.ComponentInfo; @@ -68,7 +69,6 @@ import org.talend.core.model.properties.Property; import org.talend.core.model.properties.RoutineItem; import org.talend.core.model.repository.ERepositoryObjectType; import org.talend.core.model.repository.IRepositoryViewObject; -import org.talend.core.runtime.CoreRuntimePlugin; import org.talend.core.utils.TalendCacheUtils; import org.talend.designer.core.model.utils.emf.component.IMPORTType; import org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType; @@ -88,29 +88,29 @@ public class ModulesNeededProvider { /** * TalendHookAdaptor.ORG_TALEND_EXTERNAL_LIB_FOLDER_SYS_PROP */ - public static final String ORG_TALEND_EXTERNAL_LIB_FOLDER_SYS_PROP = "talend.library.path"; //$NON-NLS-1$ + public static final String ORG_TALEND_EXTERNAL_LIB_FOLDER_SYS_PROP = "talend.library.path"; //$NON-NLS-1$ /** * */ - private static final String PLUGINS_CONTEXT_KEYWORD = "plugin:"; + private static final String PLUGINS_CONTEXT_KEYWORD = "plugin:"; - private static List componentImportNeedsList = new ArrayList();; + private static List componentImportNeedsList = new ArrayList(); ; - private static List unUsedModules = new ArrayList(); + private static List unUsedModules = new ArrayList(); - private static boolean isCreated = false; + private static boolean isCreated = false; - private static boolean cleanDone = false; + private static boolean cleanDone = false; - private static final String TALEND_COMPONENT_CACHE = "ComponentsCache."; + private static final String TALEND_COMPONENT_CACHE = "ComponentsCache."; - private static final String TALEND_FILE_NAME = "cache"; + private static final String TALEND_FILE_NAME = "cache"; - private static IRepositoryService service = null; + private static IRepositoryService service = null; static { - if (GlobalServiceRegister.getDefault().isServiceRegistered(IRepositoryService.class)) { - service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class); + if (GlobalServiceRegister.getDefault().isServiceRegistered( IRepositoryService.class )) { + service = (IRepositoryService) GlobalServiceRegister.getDefault().getService( IRepositoryService.class ); } } @@ -134,13 +134,13 @@ public class ModulesNeededProvider { */ if (componentImportNeedsList.isEmpty()) { // TimeMeasure.step("ModulesNeededProvider.getModulesNeededForRoutines"); - componentImportNeedsList.addAll(getRunningModules()); + componentImportNeedsList.addAll( getRunningModules() ); // TimeMeasure.step(Messages.getString("ModulesNeededProvider.1"), "ModulesNeededProvider.getModulesNeededForRoutines"); //$NON-NLS-1$ //$NON-NLS-2$ // TimeMeasure.begin("ModulesNeededProvider.getModulesNeededForApplication"); - componentImportNeedsList.addAll(getModulesNeededForApplication()); + componentImportNeedsList.addAll( getModulesNeededForApplication() ); if (PluginChecker.isMetadataPluginLoaded()) { - componentImportNeedsList.addAll(getModulesNeededForDBConnWizard()); + componentImportNeedsList.addAll( getModulesNeededForDBConnWizard() ); } // TimeMeasure.step("ModulesNeededProvider.getAllMoudlesNeeded", "ModulesNeededProvider.getModulesNeededForApplication"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -153,7 +153,7 @@ public class ModulesNeededProvider { // TimeMeasure.resume("ModulesNeededProvider.getModulesNeededForComponents"); // MOD qiongli TOP NO nedd to add the related components ModuleNeeded if (!org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) { - componentImportNeedsList.addAll(getModulesNeededForComponents()); + componentImportNeedsList.addAll( getModulesNeededForComponents() ); } // TimeMeasure.step("ModulesNeededProvider.getAllMoudlesNeeded", "ModulesNeededProvider.getModulesNeededForComponents"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -181,8 +181,8 @@ public class ModulesNeededProvider { public static List getModulesNeededForName(String moduleName) { ArrayList modulesMatching = new ArrayList(); for (ModuleNeeded modNeed : componentImportNeedsList) { - if (moduleName.equals(modNeed.getModuleName())) { - modulesMatching.add(modNeed); + if (moduleName.equals( modNeed.getModuleName() )) { + modulesMatching.add( modNeed ); } } return modulesMatching; @@ -191,7 +191,7 @@ public class ModulesNeededProvider { public static List getModulesNeededNames() { List componentImportNeedsListNames = new ArrayList(); for (ModuleNeeded m : componentImportNeedsList) { - componentImportNeedsListNames.add(m.getModuleName()); + componentImportNeedsListNames.add( m.getModuleName() ); } return componentImportNeedsListNames; } @@ -207,20 +207,20 @@ public class ModulesNeededProvider { */ public static void resetCurrentJobNeededModuleList(IProcess process) { // Step 1: remove all modules for current job; - List moduleForCurrentJobList = new ArrayList(5); + List moduleForCurrentJobList = new ArrayList( 5 ); for (ModuleNeeded module : componentImportNeedsList) { - if (module.getContext().equals("Job " + process.getName())) { //$NON-NLS-1$ - moduleForCurrentJobList.add(module); + if (module.getContext().equals( "Job " + process.getName() )) { //$NON-NLS-1$ + moduleForCurrentJobList.add( module ); } } - componentImportNeedsList.removeAll(moduleForCurrentJobList); + componentImportNeedsList.removeAll( moduleForCurrentJobList ); - Set neededLibraries = process.getNeededLibraries(false); + Set neededLibraries = process.getNeededLibraries( false ); if (neededLibraries != null) { for (String neededLibrary : neededLibraries) { boolean alreadyInImports = false; for (ModuleNeeded module : componentImportNeedsList) { - if (module.getModuleName().equals(neededLibrary)) { + if (module.getModuleName().equals( neededLibrary )) { alreadyInImports = true; } } @@ -229,20 +229,20 @@ public class ModulesNeededProvider { } // Step 2: re-add specific modules - ModuleNeeded toAdd = new ModuleNeeded("Job " + process.getName(), neededLibrary, //$NON-NLS-1$ - "Required for the job " + process.getName() + ".", true); //$NON-NLS-1$ //$NON-NLS-2$ + ModuleNeeded toAdd = new ModuleNeeded( "Job " + process.getName(), neededLibrary, //$NON-NLS-1$ + "Required for the job " + process.getName() + ".", true ); //$NON-NLS-1$ //$NON-NLS-2$ - componentImportNeedsList.add(toAdd); + componentImportNeedsList.add( toAdd ); // Step 3: remove added modules from unusedModule list ModuleNeeded unusedModule = null; for (ModuleNeeded module : unUsedModules) { - if (module.getModuleName().equals(neededLibrary)) { + if (module.getModuleName().equals( neededLibrary )) { unusedModule = module; } } if (unusedModule != null) { - unUsedModules.remove(unusedModule); + unUsedModules.remove( unusedModule ); } } } @@ -259,12 +259,12 @@ public class ModulesNeededProvider { Map bundlesAvailable = new HashMap(); while (it.hasNext()) { String key = (String) it.next(); - EList value = map.get(key); + EList value = map.get( key ); for (ComponentInfo info : value) { - Boolean available = bundlesAvailable.get(info.getSourceBundleName()); + Boolean available = bundlesAvailable.get( info.getSourceBundleName() ); if (available == null) { - available = Platform.getBundle(info.getSourceBundleName()) != null; - bundlesAvailable.put(info.getSourceBundleName(), available); + available = Platform.getBundle( info.getSourceBundleName() ) != null; + bundlesAvailable.put( info.getSourceBundleName(), available ); } if (!available) { continue; @@ -272,21 +272,21 @@ public class ModulesNeededProvider { EList emfImportList = info.getImportType(); for (int i = 0; i < emfImportList.size(); i++) { - IMPORTType importType = (IMPORTType) emfImportList.get(i); - collectModuleNeeded(key, importType, importNeedsList); + IMPORTType importType = (IMPORTType) emfImportList.get( i ); + collectModuleNeeded( key, importType, importNeedsList ); } } } return importNeedsList; } else { List importNeedsList = new ArrayList(); - if (GlobalServiceRegister.getDefault().isServiceRegistered(IComponentsService.class)) { + if (GlobalServiceRegister.getDefault().isServiceRegistered( IComponentsService.class )) { IComponentsService service = (IComponentsService) GlobalServiceRegister.getDefault().getService( - IComponentsService.class); + IComponentsService.class ); IComponentsFactory compFac = service.getComponentsFactory(); Set componentList = compFac.getComponents(); - for (IComponent comp : componentList.toArray(new IComponent[0])) { - importNeedsList.addAll(comp.getModulesNeeded()); + for (IComponent comp : componentList.toArray( new IComponent[0] )) { + importNeedsList.addAll( comp.getModulesNeeded() ); } } return importNeedsList; @@ -294,17 +294,17 @@ public class ModulesNeededProvider { } public static void collectModuleNeeded(String context, IMPORTType importType, List importNeedsList) { - boolean foundModule = createModuleNeededForComponentFromExtension(context, importType, importNeedsList); + boolean foundModule = createModuleNeededForComponentFromExtension( context, importType, importNeedsList ); if (!foundModule) { // If cannot find the jar from extension point then do it like before. - createModuleNeededForComponent(context, importType, importNeedsList); + createModuleNeededForComponent( context, importType, importNeedsList ); } } private static boolean createModuleNeededForComponentFromExtension(String context, IMPORTType importType, List importNeedsList) { - List importModuleNeeded = ExtensionModuleManager.getInstance().getModuleNeededForComponent(context, - importType); - importNeedsList.addAll(importModuleNeeded); + List importModuleNeeded = ExtensionModuleManager.getInstance().getModuleNeededForComponent( context, + importType ); + importNeedsList.addAll( importModuleNeeded ); return importModuleNeeded.size() > 0; } @@ -312,30 +312,30 @@ public class ModulesNeededProvider { public static void createModuleNeededForComponent(String context, IMPORTType importType, List importNeedsList) { if (importType.getMODULE() == null) { if (importType.getMODULEGROUP() != null) { - CommonExceptionHandler.warn("Missing module group definition: " + importType.getMODULEGROUP()); + CommonExceptionHandler.warn( "Missing module group definition: " + importType.getMODULEGROUP() ); } return; } String msg = importType.getMESSAGE(); if (msg == null) { - msg = Messages.getString("modules.required"); //$NON-NLS-1$ + msg = Messages.getString( "modules.required" ); //$NON-NLS-1$ } - List list = getInstallURL(importType); - ModuleNeeded moduleNeeded = new ModuleNeeded(context, importType.getMODULE(), msg, importType.isREQUIRED(), list, - importType.getREQUIREDIF(), importType.getMVN()); - initBundleID(importType, moduleNeeded); - moduleNeeded.setMrRequired(importType.isMRREQUIRED()); - moduleNeeded.setShow(importType.isSHOW()); - moduleNeeded.setModuleLocaion(importType.getUrlPath()); - importNeedsList.add(moduleNeeded); + List list = getInstallURL( importType ); + ModuleNeeded moduleNeeded = new ModuleNeeded( context, importType.getMODULE(), msg, importType.isREQUIRED(), list, + importType.getREQUIREDIF(), importType.getMVN() ); + initBundleID( importType, moduleNeeded ); + moduleNeeded.setMrRequired( importType.isMRREQUIRED() ); + moduleNeeded.setShow( importType.isSHOW() ); + moduleNeeded.setModuleLocaion( importType.getUrlPath() ); + importNeedsList.add( moduleNeeded ); } public static List getInstallURL(IMPORTType importType) { List list = new ArrayList(); EList emfInstall = importType.getURL(); for (int j = 0; j < emfInstall.size(); j++) { - String installtype = (String) emfInstall.get(j); - list.add(installtype); + String installtype = (String) emfInstall.get( j ); + list.add( installtype ); } return list; } @@ -345,29 +345,29 @@ public class ModulesNeededProvider { if (bundleID != null) { String bundleName = null; String bundleVersion = null; - if (bundleID.contains(":")) { - String[] nameAndVersion = bundleID.split(":"); + if (bundleID.contains( ":" )) { + String[] nameAndVersion = bundleID.split( ":" ); bundleName = nameAndVersion[0]; bundleVersion = nameAndVersion[1]; } else { bundleName = bundleID; } - componentImportNeeds.setBundleName(bundleName); - componentImportNeeds.setBundleVersion(bundleVersion); + componentImportNeeds.setBundleName( bundleName ); + componentImportNeeds.setBundleVersion( bundleVersion ); } } private static void initCache() { - String installLocation = new Path(Platform.getConfigurationLocation().getURL().getPath()).toFile().getAbsolutePath(); + String installLocation = new Path( Platform.getConfigurationLocation().getURL().getPath() ).toFile().getAbsolutePath(); boolean isNeedClean = !cleanDone && TalendCacheUtils.isSetCleanComponentCache(); cleanDone = true; - isCreated = hasComponentFile(installLocation) && !isNeedClean; + isCreated = hasComponentFile( installLocation ) && !isNeedClean; ComponentsCache cache = ComponentManager.getComponentCache(); try { if (isCreated) { if (cache.getComponentEntryMap().isEmpty()) { - ComponentsCache loadCache = loadComponentResource(installLocation); - cache.getComponentEntryMap().putAll(loadCache.getComponentEntryMap()); + ComponentsCache loadCache = loadComponentResource( installLocation ); + cache.getComponentEntryMap().putAll( loadCache.getComponentEntryMap() ); } } else { cache.getComponentEntryMap().clear(); @@ -382,25 +382,25 @@ public class ModulesNeededProvider { private static boolean hasComponentFile(String installLocation) { String filePath = ModulesNeededProvider.TALEND_COMPONENT_CACHE + LanguageManager.getCurrentLanguage().toString().toLowerCase() + ModulesNeededProvider.TALEND_FILE_NAME; - File file = new File(new Path(installLocation).append(filePath).toString()); + File file = new File( new Path( installLocation ).append( filePath ).toString() ); return file.exists(); } private static ComponentsCache loadComponentResource(String installLocation) throws IOException { String filePath = ModulesNeededProvider.TALEND_COMPONENT_CACHE + LanguageManager.getCurrentLanguage().toString().toLowerCase() + ModulesNeededProvider.TALEND_FILE_NAME; - URI uri = URI.createFileURI(installLocation).appendSegment(filePath); + URI uri = URI.createFileURI( installLocation ).appendSegment( filePath ); ComponentCacheResourceFactoryImpl compFact = new ComponentCacheResourceFactoryImpl(); - Resource resource = compFact.createResource(uri); + Resource resource = compFact.createResource( uri ); Map optionMap = new HashMap(); - optionMap.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE); - optionMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE); - optionMap.put(XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl()); - optionMap.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap()); - optionMap.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); - resource.load(optionMap); - ComponentsCache cache = (ComponentsCache) EcoreUtil.getObjectByType(resource.getContents(), - ComponentCachePackage.eINSTANCE.getComponentsCache()); + optionMap.put( XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE ); + optionMap.put( XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE ); + optionMap.put( XMLResource.OPTION_USE_PARSER_POOL, new XMLParserPoolImpl() ); + optionMap.put( XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP, new HashMap() ); + optionMap.put( XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE ); + resource.load( optionMap ); + ComponentsCache cache = (ComponentsCache) EcoreUtil.getObjectByType( resource.getContents(), + ComponentCachePackage.eINSTANCE.getComponentsCache() ); return cache; } @@ -412,14 +412,14 @@ public class ModulesNeededProvider { try { importNeedsList = repositoryFactory.getModulesNeededForJobs(); } catch (PersistenceException e) { - CommonExceptionHandler.process(e); + CommonExceptionHandler.process( e ); } return importNeedsList; } public static List getModulesNeededForRoutines(ProcessItem processItem, ERepositoryObjectType type) { - return getModulesNeededForRoutines(new ProcessItem[] { processItem }, type); + return getModulesNeededForRoutines( new ProcessItem[] { processItem }, type ); } /** @@ -438,7 +438,7 @@ public class ModulesNeededProvider { IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory(); try { - List routines = repositoryFactory.getAll(type, true); + List routines = repositoryFactory.getAll( type, true ); for (ProcessItem p : processItems) { if (p == null || p.getProcess() == null || p.getProcess().getParameters() == null @@ -448,35 +448,35 @@ public class ModulesNeededProvider { for (RoutinesParameterType infor : (List) p.getProcess().getParameters() .getRoutinesParameter()) { - Property property = findRoutinesPropery(infor.getId(), infor.getName(), routines, type); + Property property = findRoutinesPropery( infor.getId(), infor.getName(), routines, type ); if (property != null) { if (((RoutineItem) property.getItem()).isBuiltIn()) { - systemRoutines.add(infor.getId()); + systemRoutines.add( infor.getId() ); } else { - userRoutines.add(infor.getId()); + userRoutines.add( infor.getId() ); } } } } } catch (PersistenceException e) { - CommonExceptionHandler.process(e); + CommonExceptionHandler.process( e ); } } ILibraryManagerUIService libUiService = null; - if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerUIService.class)) { + if (GlobalServiceRegister.getDefault().isServiceRegistered( ILibraryManagerUIService.class )) { libUiService = (ILibraryManagerUIService) GlobalServiceRegister.getDefault().getService( - ILibraryManagerUIService.class); + ILibraryManagerUIService.class ); } // if (!systemRoutines.isEmpty() && libUiService != null) { - List systemRoutineItems = libUiService.collectRelatedRoutines(systemRoutines, true, type); - importNeedsList.addAll(collectModuleNeeded(systemRoutineItems, systemRoutines, true)); + List systemRoutineItems = libUiService.collectRelatedRoutines( systemRoutines, true, type ); + importNeedsList.addAll( collectModuleNeeded( systemRoutineItems, systemRoutines, true ) ); } // if (!userRoutines.isEmpty() && libUiService != null) { - List collectUserRoutines = libUiService.collectRelatedRoutines(userRoutines, false, type); - importNeedsList.addAll(collectModuleNeeded(collectUserRoutines, userRoutines, false)); + List collectUserRoutines = libUiService.collectRelatedRoutines( userRoutines, false, type ); + importNeedsList.addAll( collectModuleNeeded( collectUserRoutines, userRoutines, false ) ); } } @@ -487,13 +487,13 @@ public class ModulesNeededProvider { ERepositoryObjectType type) { if (service != null) { IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory(); - getRefRoutines(routines, ProjectManager.getInstance().getCurrentProject().getEmfProject(), type); + getRefRoutines( routines, ProjectManager.getInstance().getCurrentProject().getEmfProject(), type ); for (IRepositoryViewObject current : routines) { - if (repositoryFactory.getStatus(current) != ERepositoryStatus.DELETED) { + if (repositoryFactory.getStatus( current ) != ERepositoryStatus.DELETED) { Item item = current.getProperty().getItem(); RoutineItem routine = (RoutineItem) item; Property property = routine.getProperty(); - if (property.getId().equals(id) || property.getLabel().equals(name)) { + if (property.getId().equals( id ) || property.getLabel().equals( name )) { return property; } } @@ -507,12 +507,12 @@ public class ModulesNeededProvider { List importNeedsList = new ArrayList(); if (!routineItems.isEmpty()) { for (IRepositoryViewObject object : routineItems) { - if (routineIdOrNames.contains(object.getLabel()) && system || routineIdOrNames.contains(object.getId()) + if (routineIdOrNames.contains( object.getLabel() ) && system || routineIdOrNames.contains( object.getId() ) && !system) { Item item = object.getProperty().getItem(); if (item instanceof RoutineItem) { RoutineItem routine = (RoutineItem) item; - importNeedsList.addAll(createModuleNeededFromRoutine(routine)); + importNeedsList.addAll( createModuleNeededFromRoutine( routine ) ); } } } @@ -520,9 +520,9 @@ public class ModulesNeededProvider { // add modules which internal system routine(which under system folder and don't have item) need. if (system) { - if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerUIService.class)) { + if (GlobalServiceRegister.getDefault().isServiceRegistered( ILibraryManagerUIService.class )) { ILibraryManagerUIService libUiService = (ILibraryManagerUIService) GlobalServiceRegister.getDefault().getService( - ILibraryManagerUIService.class); + ILibraryManagerUIService.class ); Map> routineAndJars = libUiService.getRoutineAndJars(); Iterator>> iter = routineAndJars.entrySet().iterator(); while (iter.hasNext()) { @@ -530,23 +530,23 @@ public class ModulesNeededProvider { String routineName = entry.getKey(); List needJars = entry.getValue(); for (LibraryInfo jar : needJars) { - ModuleNeeded toAdd = new ModuleNeeded("Routine " + routineName, jar.getLibName(), //$NON-NLS-1$ - "", true); + ModuleNeeded toAdd = new ModuleNeeded( "Routine " + routineName, jar.getLibName(), //$NON-NLS-1$ + "", true ); String bundleId = jar.getBundleId(); if (bundleId != null) { String bundleName = null; String bundleVersion = null; - if (bundleId.contains(":")) { //$NON-NLS-1$ - String[] nameAndVersion = bundleId.split(":"); //$NON-NLS-1$ + if (bundleId.contains( ":" )) { //$NON-NLS-1$ + String[] nameAndVersion = bundleId.split( ":" ); //$NON-NLS-1$ bundleName = nameAndVersion[0]; bundleVersion = nameAndVersion[1]; } else { bundleName = bundleId; } - toAdd.setBundleName(bundleName); - toAdd.setBundleVersion(bundleVersion); + toAdd.setBundleName( bundleName ); + toAdd.setBundleVersion( bundleVersion ); } - importNeedsList.add(toAdd); + importNeedsList.add( toAdd ); } } } @@ -562,10 +562,10 @@ public class ModulesNeededProvider { for (Object o : imports) { IMPORTType currentImport = (IMPORTType) o; // FIXME SML i18n - ModuleNeeded toAdd = new ModuleNeeded("Routine " + currentImport.getNAME(), currentImport.getMODULE(), //$NON-NLS-1$ - currentImport.getMESSAGE(), currentImport.isREQUIRED()); + ModuleNeeded toAdd = new ModuleNeeded( "Routine " + currentImport.getNAME(), currentImport.getMODULE(), //$NON-NLS-1$ + currentImport.getMESSAGE(), currentImport.isREQUIRED() ); // toAdd.setStatus(ELibraryInstallStatus.INSTALLED); - importNeedsList.add(toAdd); + importNeedsList.add( toAdd ); } } return importNeedsList; @@ -576,17 +576,17 @@ public class ModulesNeededProvider { if (service != null && type != null) { IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory(); try { - List routines = repositoryFactory.getAll(type, true); - getRefRoutines(routines, ProjectManager.getInstance().getCurrentProject().getEmfProject(), type); + List routines = repositoryFactory.getAll( type, true ); + getRefRoutines( routines, ProjectManager.getInstance().getCurrentProject().getEmfProject(), type ); for (IRepositoryViewObject current : routines) { if (!current.isDeleted()) { Item item = current.getProperty().getItem(); RoutineItem routine = (RoutineItem) item; - importNeedsList.addAll(createModuleNeededFromRoutine(routine)); + importNeedsList.addAll( createModuleNeededFromRoutine( routine ) ); } } } catch (PersistenceException e) { - CommonExceptionHandler.process(e); + CommonExceptionHandler.process( e ); } } return importNeedsList; @@ -599,11 +599,11 @@ public class ModulesNeededProvider { try { if (mainProject.getReferencedProjects() != null) { for (Project referencedProject : ProjectManager.getInstance().getAllReferencedProjects()) { - routines.addAll(repositoryFactory.getAll(referencedProject, type, true)); + routines.addAll( repositoryFactory.getAll( referencedProject, type, true ) ); } } } catch (PersistenceException e) { - CommonExceptionHandler.process(e); + CommonExceptionHandler.process( e ); } } } @@ -614,8 +614,8 @@ public class ModulesNeededProvider { List extension = getAllModulesNeededExtensions(); for (IConfigurationElement current : extension) { - ModuleNeeded module = createModuleNeededInstance(current); - importNeedsList.add(module); + ModuleNeeded module = createModuleNeededInstance( current ); + importNeedsList.add( module ); } return importNeedsList; @@ -628,19 +628,19 @@ public class ModulesNeededProvider { * @return */ public static ModuleNeeded createModuleNeededInstance(IConfigurationElement current) { - String id = current.getAttribute(ExtensionModuleManager.ID_ATTR); - String context = current.getAttribute(ExtensionModuleManager.CONTEXT_ATTR); - String name = current.getAttribute(ExtensionModuleManager.NAME_ATTR); - String message = current.getAttribute(ExtensionModuleManager.MESSAGE_ATTR); - boolean required = new Boolean(current.getAttribute(ExtensionModuleManager.REQUIRED_ATTR)); - String uripath = current.getAttribute(ExtensionModuleManager.URIPATH_ATTR); - uripath = ExtensionModuleManager.getInstance().getFormalModulePath(uripath, current); - String mvn_rui = current.getAttribute(ExtensionModuleManager.MVN_URI_ATTR); - ModuleNeeded module = new ModuleNeeded(context, name, message, required); - module.setModuleLocaion(uripath); - module.setId(id); - module.setBundleName(current.getAttribute(ExtensionModuleManager.BUNDLEID_ATTR)); - module.setMavenUri(mvn_rui); + String id = current.getAttribute( ExtensionModuleManager.ID_ATTR ); + String context = current.getAttribute( ExtensionModuleManager.CONTEXT_ATTR ); + String name = current.getAttribute( ExtensionModuleManager.NAME_ATTR ); + String message = current.getAttribute( ExtensionModuleManager.MESSAGE_ATTR ); + boolean required = new Boolean( current.getAttribute( ExtensionModuleManager.REQUIRED_ATTR ) ); + String uripath = current.getAttribute( ExtensionModuleManager.URIPATH_ATTR ); + uripath = ExtensionModuleManager.getInstance().getFormalModulePath( uripath, current ); + String mvn_rui = current.getAttribute( ExtensionModuleManager.MVN_URI_ATTR ); + ModuleNeeded module = new ModuleNeeded( context, name, message, required ); + module.setModuleLocaion( uripath ); + module.setId( id ); + module.setBundleName( current.getAttribute( ExtensionModuleManager.BUNDLEID_ATTR ) ); + module.setMavenUri( mvn_rui ); return module; } @@ -650,8 +650,8 @@ public class ModulesNeededProvider { */ public static List getAllModulesNeededExtensions() { IExtensionPointLimiter actionExtensionPoint = new ExtensionPointLimiterImpl( - "org.talend.core.runtime.librariesNeeded", "libraryNeeded"); //$NON-NLS-1$ //$NON-NLS-2$ - List extension = ExtensionImplementationProvider.getInstanceV2(actionExtensionPoint); + "org.talend.core.runtime.librariesNeeded", "libraryNeeded" ); //$NON-NLS-1$ //$NON-NLS-2$ + List extension = ExtensionImplementationProvider.getInstanceV2( actionExtensionPoint ); return extension; } @@ -666,10 +666,10 @@ public class ModulesNeededProvider { List extension = getAllModulesNeededExtensions(); for (IConfigurationElement current : extension) { - String context = current.getAttribute("context"); //$NON-NLS-1$ - if (context != null && context.startsWith(PLUGINS_CONTEXT_KEYWORD)) { - ModuleNeeded module = createModuleNeededInstance(current); - allPluginsRequiredModules.add(module); + String context = current.getAttribute( "context" ); //$NON-NLS-1$ + if (context != null && context.startsWith( PLUGINS_CONTEXT_KEYWORD )) { + ModuleNeeded module = createModuleNeededInstance( current ); + allPluginsRequiredModules.add( module ); } } return allPluginsRequiredModules; @@ -685,25 +685,44 @@ public class ModulesNeededProvider { * */ public static List getAllNoInstalledModulesNeededExtensionsForPlugin(IProgressMonitor monitor) { List allPluginsRequiredModules = getAllModulesNeededExtensionsForPlugin(); - List allUninstalledModules = new ArrayList(allPluginsRequiredModules.size()); - SubMonitor subMonitor = SubMonitor.convert(monitor, allPluginsRequiredModules.size()); - String property = System.getProperty(ORG_TALEND_EXTERNAL_LIB_FOLDER_SYS_PROP); - if (property != null) { - File javaLibFolder = new File(property); - for (ModuleNeeded module : allPluginsRequiredModules) { - if (!new File(javaLibFolder, module.getModuleName()).exists()) { - allUninstalledModules.add(module); - }// else module is existing to ignor it - if (subMonitor.isCanceled()) { - return Collections.EMPTY_LIST; - }// else keep going - subMonitor.worked(1); + List allUninstalledModules = new ArrayList( allPluginsRequiredModules.size() ); + SubMonitor subMonitor = SubMonitor.convert( monitor, allPluginsRequiredModules.size() ); + Bundle bundle = FrameworkUtil.getBundle( ModulesNeededProvider.class ); + if (bundle != null && bundle.getBundleContext() != null) { + ServiceReference mavenResolverService = bundle.getBundleContext() + .getServiceReference( org.ops4j.pax.url.mvn.MavenResolver.class ); + if (mavenResolverService != null) { + MavenResolver mavenResolver = bundle.getBundleContext().getService( mavenResolverService ); + + if (mavenResolver != null) { + + for (ModuleNeeded module : allPluginsRequiredModules) { + // maven uri must not have any url attached to them + // we inject a special url to only look for local libs + String mvnUri = module.getMavenUri().replace( "mvn:", "mvn:localrepositories://!" ); + try { + // if the resolve succeed it means the artifact is installed. + mavenResolver.resolve( mvnUri ); + } catch (IOException ioe) { + // if the resolve fails, it means the module is not installed + allUninstalledModules.add( module ); + } + if (subMonitor.isCanceled()) { + return Collections.EMPTY_LIST; + }// else keep going + subMonitor.worked( 1 ); + } + } else {// throw an exception to tell that install folder was not properly initialised + throw new IllegalStateException( + "Could not get the maven resolver service, the bundle org.ops4j.pax.url.mvn man not be loaded" ); + } + } else {// throw an exception to tell that install folder was not properly initialised + throw new IllegalStateException( + "Could not get the maven resolver service referecne, the bundle org.ops4j.pax.url.mvn man not be loaded" ); } } else {// throw an exception to tell that install folder was not properly initialised - throw new IllegalStateException("Could not find the Talend library folder because the property [" - + ORG_TALEND_EXTERNAL_LIB_FOLDER_SYS_PROP + "] was not initlized"); + throw new IllegalStateException( "Could not find the current bundle context" ); } - return allUninstalledModules; } @@ -719,8 +738,8 @@ public class ModulesNeededProvider { List pluginRequiredModules = new ArrayList(); for (ModuleNeeded module : moduleList) { String context = module.getContext(); - if (context != null && context.startsWith(PLUGINS_CONTEXT_KEYWORD) && context.endsWith(":" + bundleSymbolicName)) { - pluginRequiredModules.add(module); + if (context != null && context.startsWith( PLUGINS_CONTEXT_KEYWORD ) && context.endsWith( ":" + bundleSymbolicName )) { + pluginRequiredModules.add( module ); } } return pluginRequiredModules; @@ -730,8 +749,8 @@ public class ModulesNeededProvider { List pluginRequiredModules = new ArrayList(); for (ModuleNeeded module : moduleList) { String context = module.getContext(); - if (context == null || !context.startsWith(PLUGINS_CONTEXT_KEYWORD)) { - pluginRequiredModules.add(module); + if (context == null || !context.startsWith( PLUGINS_CONTEXT_KEYWORD )) { + pluginRequiredModules.add( module ); }// else ignor } return pluginRequiredModules; @@ -740,11 +759,11 @@ public class ModulesNeededProvider { private static List getModulesNeededForDBConnWizard() { List importNeedsList = new ArrayList(); EDatabaseVersion4Drivers[] dbVersions = EDatabaseVersion4Drivers.values(); - String message = Messages.getString("ModulesNeededProvider.ModulesForDBConnWizard"); //$NON-NLS-1$; + String message = Messages.getString( "ModulesNeededProvider.ModulesForDBConnWizard" ); //$NON-NLS-1$; for (EDatabaseVersion4Drivers temp : dbVersions) { Set drivers = temp.getProviderDrivers(); for (String driver : drivers) { - importNeedsList.add(new ModuleNeeded(temp.name(), driver, message, true)); + importNeedsList.add( new ModuleNeeded( temp.name(), driver, message, true ) ); } } return importNeedsList; @@ -754,8 +773,8 @@ public class ModulesNeededProvider { public static List getModulesNeeded(String componentName) { List toReturn = new ArrayList(); for (ModuleNeeded current : getModulesNeeded()) { - if (current.getContext().equals(componentName)) { - toReturn.add(current); + if (current.getContext().equals( componentName )) { + toReturn.add( current ); } } @@ -769,10 +788,10 @@ public class ModulesNeededProvider { */ public static List getUnistalledModulesNeeded() { List modulesNeeded = getModulesNeeded(); - List uninstalledModules = new ArrayList(modulesNeeded.size()); + List uninstalledModules = new ArrayList( modulesNeeded.size() ); for (ModuleNeeded module : modulesNeeded) { if (module.getStatus() == ELibraryInstallStatus.NOT_INSTALLED) { - uninstalledModules.add(module); + uninstalledModules.add( module ); }// else installed or unknow state so ignor. } return uninstalledModules; @@ -786,30 +805,30 @@ public class ModulesNeededProvider { */ public static void userAddImportModules(String context, String name, ELibraryInstallStatus status) { boolean required = true; - String message = Messages.getString("ModulesNeededProvider.importModule"); //$NON-NLS-1$ - ModuleNeeded needed = new ModuleNeeded(context, name, message, required); - needed.setStatus(status); - componentImportNeedsList.add(needed); + String message = Messages.getString( "ModulesNeededProvider.importModule" ); //$NON-NLS-1$ + ModuleNeeded needed = new ModuleNeeded( context, name, message, required ); + needed.setStatus( status ); + componentImportNeedsList.add( needed ); } public static void userAddUnusedModules(String context, String name) { boolean required = false; - String message = Messages.getString("ModulesNeededProvider.unusedModule"); //$NON-NLS-1$ - ModuleNeeded needed = new ModuleNeeded(context, name, message, required); - needed.setStatus(ELibraryInstallStatus.UNUSED); - unUsedModules.add(needed); + String message = Messages.getString( "ModulesNeededProvider.unusedModule" ); //$NON-NLS-1$ + ModuleNeeded needed = new ModuleNeeded( context, name, message, required ); + needed.setStatus( ELibraryInstallStatus.UNUSED ); + unUsedModules.add( needed ); } public static void userRemoveUnusedModules(String urlOrName) { ModuleNeeded needed = null; for (ModuleNeeded module : unUsedModules) { - if (module.getModuleName().equals(urlOrName) || module.getContext().equals(urlOrName)) { + if (module.getModuleName().equals( urlOrName ) || module.getContext().equals( urlOrName )) { needed = module; break; } } if (needed != null) { - unUsedModules.remove(needed); + unUsedModules.remove( needed ); } } @@ -825,12 +844,12 @@ public class ModulesNeededProvider { public static Set getRunningModules() { Set runningModules = new HashSet(); - runningModules.addAll(getModulesNeededForRoutines(ERepositoryObjectType.ROUTINES)); + runningModules.addAll( getModulesNeededForRoutines( ERepositoryObjectType.ROUTINES ) ); // add the system routines modules - runningModules.addAll(collectModuleNeeded(new ArrayList(), new HashSet(), true)); + runningModules.addAll( collectModuleNeeded( new ArrayList(), new HashSet(), true ) ); - runningModules.addAll(getModulesNeededForRoutines(ERepositoryObjectType.getType("BEANS"))); - runningModules.addAll(getModulesNeededForRoutines(ERepositoryObjectType.PIG_UDF)); + runningModules.addAll( getModulesNeededForRoutines( ERepositoryObjectType.getType( "BEANS" ) ) ); + runningModules.addAll( getModulesNeededForRoutines( ERepositoryObjectType.PIG_UDF ) ); return runningModules; } diff --git a/main/plugins/org.talend.osgi.lib.loader/src/org/talend/osgi/hook/MissingJarBundleFileWrapper.java b/main/plugins/org.talend.osgi.lib.loader/src/org/talend/osgi/hook/MissingJarBundleFileWrapper.java index a762e019fa..26af83a444 100644 --- a/main/plugins/org.talend.osgi.lib.loader/src/org/talend/osgi/hook/MissingJarBundleFileWrapper.java +++ b/main/plugins/org.talend.osgi.lib.loader/src/org/talend/osgi/hook/MissingJarBundleFileWrapper.java @@ -160,11 +160,11 @@ public class MissingJarBundleFileWrapper extends BundleFileWrapper { createResolvedBundleFile( jarFile ); } else {// log an error if observer where notified and nothing was resolved if (MissingJarServices.getJarMissingObservable().countObservers() != 0) { - String message = "one third party library file [" + jarFile //$NON-NLS-1$ + String message = "one third party library file [" + jarPath.substring( 0, jarPath.length() - 1 ) //$NON-NLS-1$ + "] was not found, it is required for bundle [" + getBundleFile().getBaseFile().getName() //$NON-NLS-1$ + "]."; //$NON-NLS-1$ if (MissingJarServices.getLogService() != null) { - MissingJarServices.getLogService().log( LogService.LOG_ERROR, message ); + MissingJarServices.getLogService().log( LogService.LOG_DEBUG, message ); } else {// no log service available so throw a runtime exception to try // notifying the user of the problem. throw new RuntimeException( message ); diff --git a/main/plugins/org.talend.updates.runtime/src/main/java/org/talend/updates/runtime/model/TalendWebServiceUpdateExtraFeature.java b/main/plugins/org.talend.updates.runtime/src/main/java/org/talend/updates/runtime/model/TalendWebServiceUpdateExtraFeature.java index 5a963878ee..1a51e32031 100644 --- a/main/plugins/org.talend.updates.runtime/src/main/java/org/talend/updates/runtime/model/TalendWebServiceUpdateExtraFeature.java +++ b/main/plugins/org.talend.updates.runtime/src/main/java/org/talend/updates/runtime/model/TalendWebServiceUpdateExtraFeature.java @@ -28,6 +28,7 @@ import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Display; import org.talend.commons.utils.VersionUtils; import org.talend.core.model.general.ModuleToInstall; +import org.talend.core.runtime.maven.MavenConstants; import org.talend.librariesmanager.ui.dialogs.ModuleLicenseDialog; import org.talend.librariesmanager.utils.DownloadModuleRunnable; import org.talend.librariesmanager.utils.RemoteModulesHelper; @@ -41,11 +42,11 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { private final List modulesToBeInstalled; - private String name; + private String name; - private String description; + private String description; - private boolean mustBeInstalled; + private boolean mustBeInstalled; /** * DOC sgandon TalendWebServiceUpdate constructor comment. @@ -65,10 +66,10 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { * @return */ public static ArrayList filterAllAutomaticInstallableModules(ArrayList modules) { - ArrayList modulesForAutomaticInstall = new ArrayList(modules.size()); + ArrayList modulesForAutomaticInstall = new ArrayList( modules.size() ); for (ModuleToInstall module : modules) { - if (module.getUrl_download() != null) { - modulesForAutomaticInstall.add(module); + if (!MavenConstants.DOWNLOAD_MANUAL.equals( module.getDistribution() )) { + modulesForAutomaticInstall.add( module ); }// else not automatic so ignor } return modulesForAutomaticInstall; @@ -85,28 +86,28 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { // license // and I do not have the time to use a delegate pattern. - DownloadModuleRunnable downloadModule = new DownloadModuleRunnable(modulesToBeInstalled) { + DownloadModuleRunnable downloadModule = new DownloadModuleRunnable( modulesToBeInstalled ) { @Override protected boolean acceptLicence(ModuleToInstall module) { - return TalendWebServiceUpdateExtraFeature.acceptLicence(module); + return TalendWebServiceUpdateExtraFeature.acceptLicence( module ); } }; - downloadModule.run(progress); + downloadModule.run( progress ); // compute the dowload status Set jarsFailedToDownload = downloadModule.getDownloadFailed(); if (jarsFailedToDownload.isEmpty()) { - return Messages.createOkStatus("UpdateStudioWizard.missing.jar.download.ok"); //$NON-NLS-1$ + return Messages.createOkStatus( "UpdateStudioWizard.missing.jar.download.ok" ); //$NON-NLS-1$ } else { - Status errorStatus = Messages.createErrorStatus(null, "UpdateStudioWizard.missing.jar.download.failed", //$NON-NLS-1$ - Arrays.toString(jarsFailedToDownload.toArray(new String[jarsFailedToDownload.size()]))); - MultiStatus multiStatus = new MultiStatus(errorStatus.getPlugin(), errorStatus.getSeverity(), - errorStatus.getMessage(), null); - multiStatus.add(errorStatus); + Status errorStatus = Messages.createErrorStatus( null, "UpdateStudioWizard.missing.jar.download.failed", //$NON-NLS-1$ + Arrays.toString( jarsFailedToDownload.toArray( new String[jarsFailedToDownload.size()] ) ) ); + MultiStatus multiStatus = new MultiStatus( errorStatus.getPlugin(), errorStatus.getSeverity(), + errorStatus.getMessage(), null ); + multiStatus.add( errorStatus ); Set installedModules = downloadModule.getInstalledModules(); if (!installedModules.isEmpty()) { - multiStatus.add(Messages.createOkStatus("UpdateStudioWizard.some.jars.sucessfully.installed", //$NON-NLS-1$ - Arrays.toString(jarsFailedToDownload.toArray(new String[jarsFailedToDownload.size()])))); + multiStatus.add( Messages.createOkStatus( "UpdateStudioWizard.some.jars.sucessfully.installed", //$NON-NLS-1$ + Arrays.toString( jarsFailedToDownload.toArray( new String[jarsFailedToDownload.size()] ) ) ) ); } return multiStatus; } @@ -121,24 +122,24 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { protected static boolean acceptLicence(final ModuleToInstall module) { Display defaultDisplay = Display.getDefault(); if (defaultDisplay != null) { - final AtomicBoolean accepted = new AtomicBoolean(false);// just use atomic to have a final object. - Display.getDefault().syncExec(new Runnable() { + final AtomicBoolean accepted = new AtomicBoolean( false );// just use atomic to have a final object. + Display.getDefault().syncExec( new Runnable() { @Override public void run() { - String license = RemoteModulesHelper.getInstance().getLicenseUrl(module.getLicenseType()); - ModuleLicenseDialog licenseDialog = new ModuleLicenseDialog(Display.getDefault().getActiveShell(), module - .getLicenseType(), license, module.getName()); + String license = RemoteModulesHelper.getInstance().getLicenseUrl( module.getLicenseType() ); + ModuleLicenseDialog licenseDialog = new ModuleLicenseDialog( Display.getDefault().getActiveShell(), module + .getLicenseType(), license, module.getName() ); if (licenseDialog.open() != Window.OK) { - accepted.set(false); + accepted.set( false ); } else { - accepted.set(true); + accepted.set( true ); } } - }); + } ); return accepted.get(); } else {// should ask the user to agree on license. - throw new RuntimeException("Unable to get the default Display to show the license agreement, should never appear."); //$NON-NLS-1$ + throw new RuntimeException( "Unable to get the default Display to show the license agreement, should never appear." ); //$NON-NLS-1$ } } @@ -159,7 +160,7 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { */ @Override public String getName() { - return name; + return name + " (" + modulesToBeInstalled.size() + ")"; } /* @@ -216,7 +217,7 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { if (other.name != null) { return false; } - } else if (!this.name.equals(other.name)) { + } else if (!this.name.equals( other.name )) { return false; } return true; @@ -229,7 +230,7 @@ public class TalendWebServiceUpdateExtraFeature implements ExtraFeature { */ @Override public EnumSet getUpdateSiteCompatibleTypes() { - return EnumSet.of(UpdateSiteLocationType.DEFAULT_REPO); + return EnumSet.of( UpdateSiteLocationType.DEFAULT_REPO ); } /* diff --git a/test/plugins/org.talend.librariesmanager.ui.test/OsgiLoaderTest.launch b/test/plugins/org.talend.librariesmanager.ui.test/OsgiLoaderTest.launch index 2386c69c55..7f9ae21722 100644 --- a/test/plugins/org.talend.librariesmanager.ui.test/OsgiLoaderTest.launch +++ b/test/plugins/org.talend.librariesmanager.ui.test/OsgiLoaderTest.launch @@ -35,7 +35,7 @@ - +