org.eclipse.equinox.p2.core.IProvisioningAgent Java Examples

The following examples show how to use org.eclipse.equinox.p2.core.IProvisioningAgent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add a repository to declared updates repositories.
 * 
 * @param repo
 * @return
 */
public static boolean addRepository(IProvisioningAgent agent, String repo){
	System.out.println(">> adding repository " + repo);
	IMetadataRepositoryManager metadataManager =
		(IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
	IArtifactRepositoryManager artifactManager =
		(IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
	if (metadataManager == null) {
		System.out.println("metadataManager is null!!!");
		return false;
	}
	if (artifactManager == null) {
		System.out.println("artifactManager is null!!!");
		return false;
	}
	try {
		URI uri = new URI(repo);
		metadataManager.addRepository(uri);
		artifactManager.addRepository(uri);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
Example #2
Source File: InstallWizardOpener.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public void open(Map<String, Set<String>> features, IProgressMonitor monitor) {
	try {
		IProvisioningAgent agent = agentProvider.get();
		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent
				.getService(IMetadataRepositoryManager.SERVICE_NAME);

		Set<IInstallableUnit> units = collectIUs(features, manager, monitor);
		if (monitor.isCanceled())
			return;

		List<URI> knownRepos = Arrays.asList(manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL));
		InstallOperation op = new OperationFactory().createInstallOperation(units, knownRepos, monitor);
		agent.stop();

		open(units, op);
	} catch (ProvisionException e) {
		e.printStackTrace();
	}
}
 
Example #3
Source File: InstallationChecker.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isFeatureInstalled(String featureId) {
	try {
		IProvisioningAgent agent = agentProvider.get();
		IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
		IProfile selfProfile = profileRegistry.getProfile(IProfileRegistry.SELF);
		if(selfProfile == null)
			return true;
		Set<IInstallableUnit> installed = selfProfile
				.available(QueryUtil.createIUQuery(featureId), new NullProgressMonitor()).toUnmodifiableSet();
		agent.stop();
		return !installed.isEmpty();
	} catch (ProvisionException e) {
		e.printStackTrace();
	}
	return false;
}
 
Example #4
Source File: PreloadingRepositoryHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Download and install application updates.
 * 
 * @param agent
 * @param monitor
 * @return
 * @throws OperationCanceledException
 */
public static IStatus installUpdates(IProvisioningAgent agent, IProgressMonitor monitor)
	throws OperationCanceledException{
	ProvisioningSession session = new ProvisioningSession(agent);
	UpdateOperation operation = new UpdateOperation(session);
	SubMonitor sub = SubMonitor.convert(monitor, "Installing updates ...", 200);
	operation.resolveModal(sub.newChild(100));
	ProvisioningJob job = operation.getProvisioningJob(monitor);
	return job.runModal(sub.newChild(100));
}
 
Example #6
Source File: P2Util.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check for application updates.
 * 
 * @param agent
 * @param monitor
 * @return
 * @throws OperationCanceledException
 */
public static IStatus checkForUpdates(IProvisioningAgent agent, IProgressMonitor monitor)
	throws OperationCanceledException{
	System.out.println(">> checkForUpdates");
	ProvisioningSession session = new ProvisioningSession(agent);
	UpdateOperation operation = new UpdateOperation(session);
	SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
	return operation.resolveModal(sub.newChild(100));
}
 
Example #7
Source File: PreloadingRepositoryHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the command.
 */
public Object execute(ExecutionEvent event) {
	// SystemResourceUtil.load();
	// String tshelp = System.getProperties().getProperty("TSHelp");
	// String tsstate = System.getProperties().getProperty("TSState");
	// if (tshelp == null || !"true".equals(tshelp) || tsstate == null || !"true".equals(tsstate)) {
	// LoggerFactory.getLogger(PreloadingRepositoryHandler.class).error("Exception:key hs008 is lost.(Can't find the key)");
	// System.exit(0);
	// }
	// 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;
}
 
Example #8
Source File: UpdateHandler.java    From offspring with MIT License 5 votes vote down vote up
@Execute
public void execute(Display display, Shell shell, UISynchronize sync,
    IProvisioningAgent agent, INxtService nxt, IDataProviderPool pool,
    IWorkbench workbench) {

  UpdateDialog dialog = new UpdateDialog(display, shell, sync, agent, pool,
      workbench);
  dialog.create();
  dialog.open();
}
 
Example #9
Source File: UpdateDialog.java    From offspring with MIT License 5 votes vote down vote up
public UpdateDialog(Display display, Shell shell, UISynchronize sync,
    IProvisioningAgent agent, IDataProviderPool pool, IWorkbench workbench) {
  super(shell);
  this.monitor = new UpdateProgressMonitor(this, sync);
  this.sync = sync;
  this.agent = agent;
  this.display = display;
  this.pool = pool;
  this.workbench = workbench;
}
 
Example #10
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static IProvisioningAgent getAgent ( final URI location ) throws ProvisionException
{
    final IProvisioningAgentProvider provider = INSTANCE.tracker.getService ();
    if ( provider == null )
    {
        throw new IllegalStateException ( "Provisioning agent provider not found. Is P2 started?" );
    }

    return provider.createAgent ( location );
}
 
Example #11
Source File: ProvisioningAgentProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public IProvisioningAgent get() throws ProvisionException {
	ServiceReference sr = getContext().getServiceReference(IProvisioningAgentProvider.SERVICE_NAME);
	if (sr == null) {
		throw new ProvisionException("No service reference found for " + IProvisioningAgentProvider.SERVICE_NAME);
	}
	IProvisioningAgentProvider agentProvider = (IProvisioningAgentProvider) getContext().getService(sr);
	return agentProvider.createAgent(null);
}
 
Example #12
Source File: Processor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public Processor ( final IProvisioningAgent agent, final File output, final URI repositoryLocation, final Properties properties ) throws Exception
{
    this.mapping = makeMappingInstance ( properties );

    this.agent = agent;
    this.output = output;
    this.properties = properties;
    this.repositoryLocation = repositoryLocation;

    this.metaManager = (IMetadataRepositoryManager)this.agent.getService ( IMetadataRepositoryManager.SERVICE_NAME );
    this.artManager = (IArtifactRepositoryManager)this.agent.getService ( IArtifactRepositoryManager.SERVICE_NAME );

    this.documentBuilderFactor = DocumentBuilderFactory.newInstance ();
    this.documentBuilder = this.documentBuilderFactor.newDocumentBuilder ();
    this.transformerFactory = TransformerFactory.newInstance ();

    this.organizationName = properties.getProperty ( "pom.origanization.name", "Eclipse Foundation" );
    this.organizationUrl = properties.getProperty ( "pom.origanization.url", "http://www.eclipse.org/" );

    this.licenseProvider = new LicenseProvider ( this.properties );

    this.scrubJars = Boolean.parseBoolean ( properties.getProperty ( "scrubJars" ) );

    this.checkQualifier = Boolean.parseBoolean ( properties.getProperty ( "checkQualifier", "true" ) );

    loadDevelopers ();
    setupBndTools ();
}
 
Example #13
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static IProvisioningAgent getAgent ( final URI location ) throws ProvisionException
{
    final IProvisioningAgentProvider provider = INSTANCE.tracker.getService ();
    if ( provider == null )
    {
        throw new IllegalStateException ( "Provisioning agent provider not found. Is P2 started?" );
    }

    return provider.createAgent ( location );
}
 
Example #14
Source File: Processor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public Processor ( final IProvisioningAgent agent, final File output, final URI repositoryLocation, final Properties properties ) throws Exception
{
    this.mapping = makeMappingInstance ( properties );

    this.agent = agent;
    this.output = output;
    this.properties = properties;
    this.repositoryLocation = repositoryLocation;

    this.metaManager = (IMetadataRepositoryManager)this.agent.getService ( IMetadataRepositoryManager.SERVICE_NAME );
    this.artManager = (IArtifactRepositoryManager)this.agent.getService ( IArtifactRepositoryManager.SERVICE_NAME );

    this.documentBuilderFactor = DocumentBuilderFactory.newInstance ();
    this.documentBuilder = this.documentBuilderFactor.newDocumentBuilder ();
    this.transformerFactory = TransformerFactory.newInstance ();

    this.organizationName = properties.getProperty ( "pom.organization.name", "Eclipse Foundation" );
    this.organizationUrl = properties.getProperty ( "pom.organization.url", "http://www.eclipse.org/" );

    this.licenseProvider = new LicenseProvider ( this.properties );

    this.scrubJars = Boolean.parseBoolean ( properties.getProperty ( "scrubJars" ) );

    this.checkQualifier = Boolean.parseBoolean ( properties.getProperty ( "checkQualifier", "true" ) );

    loadDevelopers ();
    setupBndTools ();
}
 
Example #15
Source File: AutomaticUpdate.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example #16
Source File: AutomaticUpdate.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example #17
Source File: Application.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object start ( final IApplicationContext context ) throws Exception
{
    // final IProgressMonitor pm = new ConsoleProgressMonitor ( new PrintWriter ( System.out ) );
    final IProgressMonitor pm = new NullProgressMonitor ();

    final Version version = context.getBrandingBundle ().getVersion ();

    System.out.format ( "P2 to Maven 2 converter - Version: %s%n", version );

    final String[] args = (String[])context.getArguments ().get ( IApplicationContext.APPLICATION_ARGS );

    if ( args.length < 2 )
    {
        System.err.println ( "p2tom2 <config.properties> <sourceRepositoryUri> [<validationRepoUri1>] ..." );
        return null;
    }

    final URL propertiesLocation = new URL ( args[0] );
    final Properties lp = new Properties ();
    try ( InputStream input = propertiesLocation.openStream () )
    {
        lp.load ( input );
    }

    final Properties p = new Properties ( lp );
    p.putAll ( System.getProperties () );

    final File output = new File ( p.getProperty ( "path.output" ) );
    output.mkdirs ();

    final File p2temp = new File ( p.getProperty ( "path.p2temp", p.getProperty ( "path.output" ) ) );
    p2temp.mkdirs ();

    System.out.format ( "Getting P2 agent: %s%n", p2temp );

    final IProvisioningAgent agent = Activator.getAgent ( p2temp.toURI () );

    try ( Processor processor = new Processor ( agent, output, new URI ( args[1] ), p ) )
    {
        for ( int i = 2; i < args.length; i++ )
        {
            processor.addValidationRepository ( new URI ( args[i] ) );
        }

        processor.process ( pm );

        System.out.println ( "=== START - MAVEN EXPORTS ===" );
        processor.getMavenExports ().stream ().forEach ( System.out::println );
        System.out.println ( "===  END  - MAVEN EXPORTS ===" );

        System.out.println ( "=== START - MAVEN EXTERNAL DEPENDENCIES ===" );
        final Set<MavenDependency> deps = new LinkedHashSet<> ( processor.getMavenDependencies () );
        processor.getMavenExports ().stream ().filter ( ref -> ref.getClassifier () == null ).map ( ref -> new MavenDependency ( ref.getGroupId (), ref.getArtifactId (), ref.getVersion (), false ) ).forEach ( deps::remove );
        deps.stream ().forEach ( System.out::println );
        System.out.println ( "===  END  - MAVEN EXTERNAL DEPENDENCIES ===" );

        final List<String> errors = processor.getErrors ();
        if ( !errors.isEmpty () )
        {
            System.out.println ( "=== START - ERRORS ===" );
            errors.stream ().forEach ( System.out::println );
            System.out.println ( "===  END  - ERRORS ===" );
        }

        if ( !errors.isEmpty () )
        {
            System.out.println ( "Exiting with validation errors!" );
            return 1;
        }
    }

    // default
    return null;
}