use of org.eclipse.core.runtime.MultiStatus 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
}
}
use of org.eclipse.core.runtime.MultiStatus in project tycho by eclipse.
the class DependencyCollectorTest method missingDependencies.
@Test
public void missingDependencies() {
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
String time = Long.toString(System.currentTimeMillis());
iud.setId(time);
iud.setVersion(Version.createOSGi(0, 0, 0, time));
ArrayList<IRequirement> requirements = new ArrayList<>();
VersionRange range = new VersionRange("[1.2.3,1.2.4)");
requirements.add(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, "this.is.a.missing.iu", range, null, 1, /* min */
1, /* max */
true));
iud.setRequirements(requirements.toArray(new IRequirement[requirements.size()]));
HashSet<IInstallableUnit> rootUIs = new HashSet<>();
rootUIs.add(MetadataFactory.createInstallableUnit(iud));
ResolutionDataImpl data = new ResolutionDataImpl(ExecutionEnvironmentTestUtils.NOOP_EE_RESOLUTION_HINTS);
data.setRootIUs(rootUIs);
data.setAdditionalRequirements(new ArrayList<IRequirement>());
data.setAvailableIUs(Collections.<IInstallableUnit>emptyList());
DependencyCollector dc = new DependencyCollector(logVerifier.getLogger());
dc.setData(data);
try {
dc.resolve(Collections.<String, String>emptyMap(), new NullProgressMonitor());
Assert.fail();
} catch (RuntimeException e) {
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof ProvisionException);
ProvisionException pe = (ProvisionException) cause;
Assert.assertTrue(pe.getStatus().isMultiStatus());
MultiStatus status = (MultiStatus) pe.getStatus();
Assert.assertEquals(1, status.getChildren().length);
Assert.assertTrue(e.toString().contains("this.is.a.missing.iu"));
}
}
use of org.eclipse.core.runtime.MultiStatus in project tycho by eclipse.
the class DependencyCollector method resolve.
@Override
public Collection<IInstallableUnit> resolve(Map<String, String> properties, IProgressMonitor monitor) {
Set<IInstallableUnit> result = new LinkedHashSet<>();
LinkedHashSet<IStatus> errors = new LinkedHashSet<>();
if (logger.isExtendedDebugEnabled()) {
logger.debug("Available IUs:\n" + ResolverDebugUtils.toDebugString(data.getAvailableIUs(), false));
logger.debug("Root IUs:\n" + ResolverDebugUtils.toDebugString(data.getRootIUs(), true));
}
result.addAll(data.getRootIUs());
QueryableCollection availableUIsQueryable = new QueryableCollection(data.getAvailableIUs());
for (IInstallableUnit iu : data.getRootIUs()) {
collectIncludedIUs(availableUIsQueryable, result, errors, iu, true, monitor);
}
if (logger.isExtendedDebugEnabled()) {
logger.debug("Collected IUs:\n" + ResolverDebugUtils.toDebugString(result, false));
}
if (!errors.isEmpty()) {
MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 0, errors.toArray(new IStatus[errors.size()]), "Missing dependencies", null);
throw new RuntimeException(status.toString(), new ProvisionException(status));
}
return result;
}
use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.
the class TomcatVersionHelper method cleanupCatalinaServer.
/**
* Cleanup server instance location in preparation for next server publish.
* This currently involves deleting work directories for currently
* existing Contexts which will not be included in the next publish.
* In addition, Context XML files which may have been created for these
* Contexts are also deleted. If requested, Context XML files for
* kept Contexts will be deleted since they will be kept in server.xml.
*
* @param baseDir path to server instance directory, i.e. catalina.base
* @param installDir path to server installation directory (not currently used)
* @param removeKeptContextFiles true if kept contexts should have a separate
* context XML file removed
* @param modules list of currently added modules
* @param monitor a progress monitor or null
* @return MultiStatus containing results of the cleanup operation
*/
public static IStatus cleanupCatalinaServer(IPath baseDir, IPath installDir, boolean removeKeptContextFiles, List modules, IProgressMonitor monitor) {
MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.cleanupServerTask, null);
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.cleanupServerTask, 200);
monitor.subTask(Messages.detectingRemovedProjects);
IPath serverXml = baseDir.append("conf").append("server.xml");
ServerInstance oldInstance = TomcatVersionHelper.getCatalinaServerInstance(serverXml, null, null);
if (oldInstance != null) {
Map<String, Context> removedContextsMap = new HashMap<String, Context>();
Map<String, Context> keptContextsMap = new HashMap<String, Context>();
TomcatVersionHelper.getRemovedKeptCatalinaContexts(oldInstance, modules, removedContextsMap, keptContextsMap);
monitor.worked(100);
if (removedContextsMap.size() > 0) {
// Delete context files and work directories for managed web modules that have gone away
IProgressMonitor subMonitor = ProgressUtil.getSubMonitorFor(monitor, 100);
subMonitor.beginTask(Messages.deletingContextFilesTask, removedContextsMap.size() * 200);
Iterator iter = removedContextsMap.keySet().iterator();
while (iter.hasNext()) {
String oldPath = (String) iter.next();
Context ctx = removedContextsMap.get(oldPath);
// Delete the corresponding context file, if it exists
IPath ctxFilePath = oldInstance.getContextFilePath(baseDir, ctx);
if (ctxFilePath != null) {
File ctxFile = ctxFilePath.toFile();
if (ctxFile.exists()) {
subMonitor.subTask(NLS.bind(Messages.deletingContextFile, ctxFile.getName()));
if (ctxFile.delete()) {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Leftover context file " + ctxFile.getName() + " deleted.");
ms.add(new Status(IStatus.OK, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.deletedContextFile, ctxFile.getName()), null));
} else {
Trace.trace(Trace.SEVERE, "Could not delete obsolete context file " + ctxFilePath.toOSString());
ms.add(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotDeleteContextFile, ctxFilePath.toOSString()), null));
}
}
}
subMonitor.worked(100);
// Delete work directory associated with the removed context if it is within confDir.
// If it is outside of confDir, assume user is going to manage it.
IPath ctxWorkPath = oldInstance.getContextWorkDirectory(baseDir, ctx);
if (baseDir.isPrefixOf(ctxWorkPath)) {
File ctxWorkDir = ctxWorkPath.toFile();
if (ctxWorkDir.exists() && ctxWorkDir.isDirectory()) {
IStatus[] results = PublishHelper.deleteDirectory(ctxWorkDir, ProgressUtil.getSubMonitorFor(monitor, 100));
if (results.length > 0) {
Trace.trace(Trace.SEVERE, "Could not delete work directory " + ctxWorkDir.getPath() + " for removed context " + oldPath);
for (int i = 0; i < results.length; i++) {
ms.add(results[i]);
}
}
} else
subMonitor.worked(100);
} else
subMonitor.worked(100);
}
subMonitor.done();
}
monitor.worked(100);
// If requested, remove any separate context XML files for contexts being kept
if (removeKeptContextFiles && keptContextsMap.size() > 0) {
// Delete context files and work directories for managed web modules that have gone away
IProgressMonitor subMonitor = ProgressUtil.getSubMonitorFor(monitor, 100);
// TODO Improve task name
subMonitor.beginTask(Messages.deletingContextFilesTask, keptContextsMap.size() * 100);
Iterator iter = keptContextsMap.keySet().iterator();
while (iter.hasNext()) {
String keptPath = (String) iter.next();
Context ctx = keptContextsMap.get(keptPath);
// Delete the corresponding context file, if it exists
IPath ctxFilePath = oldInstance.getContextFilePath(baseDir, ctx);
if (ctxFilePath != null) {
File ctxFile = ctxFilePath.toFile();
if (ctxFile.exists()) {
subMonitor.subTask(NLS.bind(Messages.deletingContextFile, ctxFile.getName()));
if (ctxFile.delete()) {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Leftover context file " + ctxFile.getName() + " deleted.");
ms.add(new Status(IStatus.OK, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.deletedContextFile, ctxFile.getName()), null));
} else {
Trace.trace(Trace.SEVERE, "Could not delete obsolete context file " + ctxFilePath.toOSString());
ms.add(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotDeleteContextFile, ctxFilePath.toOSString()), null));
}
}
}
subMonitor.worked(100);
}
subMonitor.done();
}
} else // Else no server.xml. Assume first publish to new temp directory
{
monitor.worked(200);
}
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Server cleaned");
} catch (Exception e) {
Trace.trace(Trace.SEVERE, "Could not cleanup server at " + baseDir.toOSString() + ": " + e.getMessage());
ms.add(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCleanupServer, new String[] { e.getLocalizedMessage() }), e));
} finally {
monitor.done();
}
return ms;
}
use of org.eclipse.core.runtime.MultiStatus in project webtools.servertools by eclipse.
the class TomcatVersionHelper method publishCatalinaContextConfig.
/**
* Add context configuration found in META-INF/context.xml files
* present in projects to published server.xml. Used by
* Tomcat 4.1, 5.0, and 5.5 which support use of META-INF/context.xml
* in some form.
*
* @param baseDir absolute path to catalina instance directory
* @param webappsDir absolute path to deployment directory
* @param monitor a progress monitor or null
* @return result of operation
*/
public static IStatus publishCatalinaContextConfig(IPath baseDir, IPath webappsDir, IProgressMonitor monitor) {
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Apply context configurations");
IPath confDir = baseDir.append("conf");
try {
monitor = ProgressUtil.getMonitorFor(monitor);
monitor.beginTask(Messages.publishConfigurationTask, 300);
monitor.subTask(Messages.publishContextConfigTask);
Factory factory = new Factory();
factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
Server publishedServer = (Server) factory.loadDocument(new FileInputStream(confDir.append("server.xml").toFile()));
ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
monitor.worked(100);
boolean modified = false;
MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.publishContextConfigTask, null);
Context[] contexts = publishedInstance.getContexts();
if (contexts != null) {
for (int i = 0; i < contexts.length; i++) {
Context context = contexts[i];
monitor.subTask(NLS.bind(Messages.checkingContextTask, new String[] { context.getPath() }));
if (addCatalinaContextConfig(webappsDir, context, ms)) {
modified = true;
}
}
}
monitor.worked(100);
if (modified) {
monitor.subTask(Messages.savingContextConfigTask);
factory.save(confDir.append("server.xml").toOSString());
}
// If problem(s) occurred adding context configurations, return error status
if (ms.getChildren().length > 0) {
return ms;
}
if (Trace.isTraceEnabled())
Trace.trace(Trace.FINER, "Server.xml updated with context.xml configurations");
return Status.OK_STATUS;
} catch (Exception e) {
Trace.trace(Trace.WARNING, "Could not apply context configurations to published Tomcat configuration from " + confDir.toOSString() + ": " + e.getMessage());
return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
} finally {
monitor.done();
}
}
Aggregations