use of org.eclipse.equinox.p2.engine.IProfile in project knime-core by knime.
the class ExtractTarGz method execute.
@Override
public IStatus execute(final Map<String, Object> parameters) {
try {
String source = readParameter(parameters, SOURCE_ARCHIVE);
String targetDir = readParameter(parameters, TARGET_DIR);
File destDir;
Path targetDirPath = Paths.get(targetDir);
if (targetDirPath.isAbsolute()) {
// targetDir is absolute path or contains @artifact
destDir = targetDirPath.toFile();
} else {
// targetDir is something like '.'
IProfile profile = (IProfile) parameters.get("profile");
File installFolder = new File(profile.getProperty(IProfile.PROP_INSTALL_FOLDER));
destDir = new File(installFolder, targetDir);
}
try (InputStream fileInputStream = FileUtil.openInputStream(source)) {
InputStream in;
if (StringUtils.endsWithIgnoreCase(source, ".tar.gz") || StringUtils.endsWithIgnoreCase(source, ".tgz")) {
in = new GzipCompressorInputStream(fileInputStream);
} else if (StringUtils.endsWithIgnoreCase(source, ".tar.bz2")) {
in = new BZip2CompressorInputStream(fileInputStream);
} else if (StringUtils.endsWithIgnoreCase(source, ".tar.xz")) {
in = new XZCompressorInputStream(fileInputStream);
} else {
in = fileInputStream;
}
untar(in, destDir);
}
return Status.OK_STATUS;
} catch (Throwable e) {
return new Status(IStatus.ERROR, bundle.getSymbolicName(), e.getMessage(), e);
}
}
use of org.eclipse.equinox.p2.engine.IProfile in project knime-core by knime.
the class OSGIHelper method getP2Profile.
private static synchronized IProfile getP2Profile() {
if (EclipseUtil.isRunFromSDK()) {
// when started from the SDK there is no installation profile
return null;
}
if (p2Profile == null) {
BundleContext ctx = FrameworkUtil.getBundle(OSGIHelper.class).getBundleContext();
IProvisioningAgent agent = ServiceHelper.getService(ctx, IProvisioningAgent.class);
if (agent == null) {
NodeLogger.getLogger(OSGIHelper.class).debug("Strange, I couldn't get a service reference for " + IProvisioningAgent.class);
return null;
}
IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null) {
NodeLogger.getLogger(OSGIHelper.class).debug("Couldn't get profile registry.");
return null;
}
p2Profile = profileRegistry.getProfile(IProfileRegistry.SELF);
if (p2Profile == null) {
NodeLogger.getLogger(OSGIHelper.class).debug("Couldn't get the p2 installation profile");
// happens when started from the SDK
return null;
}
}
return p2Profile;
}
use of org.eclipse.equinox.p2.engine.IProfile in project translationstudio8 by heartsome.
the class PreloadingRepositoryHandler method execute.
/**
* Execute the command.
*/
public Object execute(ExecutionEvent event) {
// Look for a profile. We may not immediately need it in the
// handler, but if we don't have one, whatever we are trying to do
// will ultimately fail in a more subtle/low-level way. So determine
// up front if the system is configured properly.
String profileId = getProvisioningUI().getProfileId();
IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
IProfile profile = null;
if (agent != null) {
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
if (registry != null) {
profile = registry.getProfile(profileId);
}
}
if (profile == null) {
// Inform the user nicely
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_CHECK);
return null;
} else {
BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {
public void run() {
doExecuteAndLoad();
}
});
}
return null;
}
use of org.eclipse.equinox.p2.engine.IProfile in project translationstudio8 by heartsome.
the class AutomaticUpdate method checkForUpdates.
public void checkForUpdates() throws OperationCanceledException {
// 检查 propfile
String profileId = getProvisioningUI().getProfileId();
IProvisioningAgent agent = getProvisioningUI().getSession().getProvisioningAgent();
IProfile profile = null;
if (agent != null) {
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
if (registry != null) {
profile = registry.getProfile(profileId);
}
}
if (profile == null) {
// Inform the user nicely
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
// 开始检查前先确定是否有repository
RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
final IStatus[] checkStatus = new IStatus[1];
Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {
public IStatus runModal(IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, P2UpdateUtil.CHECK_UPDATE_TASK_NAME, 1000);
// load repository
IStatus status = super.runModal(sub.newChild(500));
if (status.getSeverity() == IStatus.CANCEL) {
return status;
}
if (status.getSeverity() != Status.OK) {
// load repository error
checkStatus[0] = status;
}
operation = getProvisioningUI().getUpdateOperation(null, null);
// check for updates
IStatus resolveStatus = operation.resolveModal(sub.newChild(500));
if (resolveStatus.getSeverity() == IStatus.CANCEL) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
loadJob.setName(P2UpdateUtil.ATUO_CHECK_UPDATE_JOB_NAME);
loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
loadJob.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (PlatformUI.isWorkbenchRunning())
if (event.getResult().isOK()) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
if (checkStatus[0] != null) {
// 提示连接异常
P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_AUTO_CHECK);
return;
}
doUpdate();
}
});
}
}
});
loadJob.setUser(true);
loadJob.schedule();
}
use of org.eclipse.equinox.p2.engine.IProfile in project webtools.servertools by eclipse.
the class ExtensionUtility method getExistingFeatures.
private static List<Extension> getExistingFeatures(IProgressMonitor monitor) throws CoreException {
monitor.beginTask(Messages.discoverLocalConfiguration, 100);
IProfileRegistry profileRegistry = (IProfileRegistry) getService(Activator.getDefault().getBundle().getBundleContext(), IProfileRegistry.class.getName());
IProfile[] profiles = profileRegistry.getProfiles();
IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
if (profile == null) {
// it happens sometime , possibility of bug in profileRegistry
for (int i = 0; i < profiles.length; i++) {
if (profiles[i].getProfileId().equals(IProfileRegistry.SELF)) {
profile = profiles[i];
break;
}
}
}
List<Extension> list = new ArrayList<Extension>();
if (profile == null)
return list;
IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
// Query query = new InstallableUnitQuery("org.eclipse.wst.server.core.serverAdapter");
// List<String> list2 = new ArrayList();
// Query query = new ExtensionInstallableUnitQuery(list2);
IQueryResult<IInstallableUnit> collector = profile.query(query, monitor);
Iterator<IInstallableUnit> iter = collector.iterator();
while (iter.hasNext()) {
IInstallableUnit iu = iter.next();
if (!list.contains(iu))
list.add(new Extension(iu, null));
}
monitor.done();
return list;
}
Aggregations