Search in sources :

Example 1 with IProfile

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);
    }
}
Also used : Path(java.nio.file.Path) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) GzipCompressorInputStream(org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream) InputStream(java.io.InputStream) IProfile(org.eclipse.equinox.p2.engine.IProfile) File(java.io.File) XZCompressorInputStream(org.apache.commons.compress.compressors.xz.XZCompressorInputStream)

Example 2 with IProfile

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;
}
Also used : IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) BundleContext(org.osgi.framework.BundleContext)

Example 3 with IProfile

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;
}
Also used : IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Example 4 with IProfile

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IProfile(org.eclipse.equinox.p2.engine.IProfile) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob) RepositoryTracker(org.eclipse.equinox.p2.operations.RepositoryTracker)

Example 5 with IProfile

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;
}
Also used : IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Aggregations

IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)5 IProfile (org.eclipse.equinox.p2.engine.IProfile)5 IProfileRegistry (org.eclipse.equinox.p2.engine.IProfileRegistry)5 BundleContext (org.osgi.framework.BundleContext)3 IStatus (org.eclipse.core.runtime.IStatus)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)1 XZCompressorInputStream (org.apache.commons.compress.compressors.xz.XZCompressorInputStream)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1