use of org.talend.core.model.general.ModuleToInstall in project tdq-studio-se by Talend.
the class AbstractDQMissingJarsExtraUpdatesFactory method retrieveUninstalledExtraFeatures.
@Override
public void retrieveUninstalledExtraFeatures(IProgressMonitor monitor, Set<ExtraFeature> uninstalledExtraFeatures) throws Exception {
Bundle bundle = Platform.getBundle(getPluginName());
if (bundle == null) {
// if the bundle is not installed then propose to download it.
// $NON-NLS-1$
String pathToStore = Platform.getInstallLocation().getURL().getFile() + "plugins";
File jarfile = new File(pathToStore, getJarFileWithVersionNames().get(0));
if (jarfile.exists()) {
return;
} else {
SubMonitor mainSubMonitor = SubMonitor.convert(monitor, 2);
// add all needed models into the allUninstalledModules
List<ModuleNeeded> allUninstalledModules = getAllUninstalledModules();
if (monitor.isCanceled()) {
return;
}
// else keep going fetch missing jar information from remote web site.
ArrayList<ModuleToInstall> modulesRequiredToBeInstalled = new ArrayList<ModuleToInstall>();
IRunnableWithProgress notInstalledModulesRunnable = RemoteModulesHelper.getInstance().getNotInstalledModulesRunnable(allUninstalledModules, modulesRequiredToBeInstalled);
// jface because it adds graphical dependencies.
// some data need to be fetched
runNotInstallModule(mainSubMonitor, notInstalledModulesRunnable);
// else all data already fetched or already try and failed so keep going
if (mainSubMonitor.isCanceled()) {
return;
}
// else keep going.
final ArrayList<ModuleToInstall> modulesForAutomaticInstall = TalendWebServiceUpdateExtraFeature.filterAllAutomaticInstallableModules(modulesRequiredToBeInstalled);
if (modulesForAutomaticInstall.isEmpty()) {
// if could not find anything to download log and error and
// return nothing
// $NON-NLS-1$
log.error("failed to fetch missing third parties jars information for " + getJarFileNames().get(0));
return;
}
// else something to dowload to return the Extra feature to dowload.
addToSet(uninstalledExtraFeatures, new TalendWebServiceUpdateExtraFeature(modulesForAutomaticInstall, DefaultMessagesImpl.getString(getDownloadName()), DefaultMessagesImpl.getString("DownloadSqlexplorerPluginJarFactory.description", // $NON-NLS-1$
getContainPluginNames()), // $NON-NLS-1$
true) {
@Override
public boolean needRestart() {
return true;
}
@Override
public IStatus install(IProgressMonitor progress, List<URI> allRepoUris) throws Exception {
IStatus installStatus = super.install(progress, allRepoUris);
// move the jar to plugins folder
if (installStatus.isOK()) {
try {
copyJars2PluginsFolder(modulesForAutomaticInstall);
} catch (MalformedURLException e) {
MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
multiStatus.add(installStatus);
return multiStatus;
} catch (IOException e) {
MultiStatus multiStatus = new MultiStatus(CorePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
multiStatus.add(installStatus);
return multiStatus;
}
}
// else install not ok so return the error status.
return installStatus;
}
private void copyJars2PluginsFolder(ArrayList<ModuleToInstall> modules) throws MalformedURLException, IOException {
List<File> jarFiles = new ArrayList<File>();
ILibraryManagerService librariesService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
if (librariesService != null) {
for (ModuleToInstall module : modules) {
String jarPathFromMaven = librariesService.getJarPathFromMaven(module.getMavenUri());
if (jarPathFromMaven == null) {
continue;
}
jarFiles.add(new File(jarPathFromMaven));
}
} else {
IMaven maven = MavenPlugin.getMaven();
String librariesPath = maven.getLocalRepositoryPath();
for (String jarFileName : getJarFileWithVersionNames()) {
jarFiles.addAll(FilesUtils.getJarFilesFromFolder(new File(librariesPath), jarFileName));
}
}
for (File jarFile : jarFiles) {
// $NON-NLS-1$
String pluginPath = Platform.getInstallLocation().getURL().getFile() + "plugins";
File movedfile = new File(pluginPath, jarFile.getName().replace(MavenConstants.SNAPSHOT, ""));
if (!movedfile.exists()) {
File target = new File(StringUtils.trimToEmpty(pluginPath));
if (!target.exists()) {
target.mkdirs();
}
FilesUtils.copyFile(jarFile, movedfile);
}
}
}
});
}
} else {
// if it is not TOP loaded only, need not to do anyting
}
}
Aggregations