@Override public void mirrorStandalone( RepositoryReferences sources, DestinationRepositoryDescriptor destination, Collection<IUDescription> seedIUs, MirrorOptions mirrorOptions, BuildOutputDirectory tempDirectory) throws FacadeException { IProvisioningAgent agent = Activator.createProvisioningAgent(tempDirectory); try { final MirrorApplication mirrorApp = createMirrorApplication(sources, destination, agent, mirrorOptions.isIncludePacked()); mirrorApp.setSlicingOptions(createSlicingOptions(mirrorOptions)); try { // we want to see mirror progress as this is a possibly long-running operation mirrorApp.setVerbose(true); mirrorApp.setLog(new LogListener(mavenContext.getLogger())); mirrorApp.setSourceIUs( querySourceIus(seedIUs, mirrorApp.getCompositeMetadataRepository(), sources)); IStatus returnStatus = mirrorApp.run(null); checkStatus(returnStatus); } catch (ProvisionException e) { throw new FacadeException( MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e); } } finally { agent.stop(); } }
protected void startup() { String location = PropertyManager.getProperty(PROFILE_LOCATION); if (location != null) try { dataLocation = new URI(location); } catch (URISyntaxException e) { // do nothing. will deal with it below } if (dataLocation == null) { LogUtility.logError("Invalid profile location URI - " + location); return; } try { agent = agentProvider.createAgent(dataLocation); } catch (ProvisionException e) { LogUtility.logError("Unable to initialize p2 agent", e); return; } registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); planner = (IPlanner) agent.getService(IPlanner.SERVICE_NAME); engine = (IEngine) agent.getService(IEngine.SERVICE_NAME); String spec = PropertyManager.getProperty(REPO_LOCATIONS); if (spec != null) addRepositories(spec); }
public TargetDefinitionResolver( List<TargetEnvironment> environments, ExecutionEnvironmentResolutionHints executionEnvironment, IProvisioningAgent agent, MavenLogger logger) { this.environments = environments; this.executionEnvironment = executionEnvironment; this.logger = logger; this.metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); this.repositoryIdManager = (IRepositoryIdManager) agent.getService(IRepositoryIdManager.SERVICE_NAME); }
@Override public void mirrorReactor( RepositoryReferences sources, DestinationRepositoryDescriptor destination, Collection<DependencySeed> projectSeeds, BuildContext context, boolean includeAllDependencies, boolean includePacked, Map<String, String> filterProperties) throws FacadeException { IProvisioningAgent agent = Activator.createProvisioningAgent(context.getTargetDirectory()); try { final MirrorApplication mirrorApp = createMirrorApplication(sources, destination, agent, includePacked); // mirror scope: seed units... mirrorApp.setSourceIUs( toInstallableUnitList(projectSeeds, mirrorApp.getCompositeMetadataRepository(), sources)); // TODO the p2 mirror tool should support mirroring multiple environments at once for (TargetEnvironment environment : context.getEnvironments()) { SlicingOptions options = new SlicingOptions(); options.considerStrictDependencyOnly(!includeAllDependencies); Map<String, String> filter = options.getFilter(); addFilterForFeatureJARs(filter); if (filterProperties != null) { filter.putAll(filterProperties); } filter.putAll(environment.toFilterProperties()); mirrorApp.setSlicingOptions(options); try { LogListener logListener = new LogListener(mavenContext.getLogger()); mirrorApp.setLog(logListener); IStatus returnStatus = mirrorApp.run(null); checkStatus(returnStatus); logListener.showHelpForLoggedMessages(); } catch (ProvisionException e) { throw new FacadeException( MIRROR_FAILURE_MESSAGE + ": " + StatusTool.collectProblems(e.getStatus()), e); } } } finally { agent.stop(); } }
private Repositories loadRepositories(String id, URI specifiedUrl) throws Exception { IRepositoryIdManager idManager = (IRepositoryIdManager) subject.getService(IRepositoryIdManager.SERVICE_NAME); idManager.addMapping(id, specifiedUrl); IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) subject.getService(IMetadataRepositoryManager.SERVICE_NAME); IMetadataRepository metadataRepo = metadataManager.loadRepository(specifiedUrl, null); IArtifactRepositoryManager artifactsManager = (IArtifactRepositoryManager) subject.getService(IArtifactRepositoryManager.SERVICE_NAME); IArtifactRepository artifactsRepo = artifactsManager.loadRepository(specifiedUrl, null); return new Repositories(metadataRepo, artifactsRepo); }
/** The constructor. */ public AutomaticUpdateScheduler() { AutomaticUpdatePlugin.getDefault().setScheduler(this); IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService( AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME); checker = (IUpdateChecker) agent.getService(IUpdateChecker.SERVICE_NAME); if (checker == null) { // Something did not initialize properly IStatus status = new Status( IStatus.ERROR, AutomaticUpdatePlugin.PLUGIN_ID, AutomaticUpdateMessages.AutomaticUpdateScheduler_UpdateNotInitialized); StatusManager.getManager().handle(status, StatusManager.LOG); return; } profileId = IProfileRegistry.SELF; }
protected void initProvisioningAgent() throws RuntimeException { try { // Inject references BundleContext bundleContext = FrameworkUtil.getBundle(UpdateManager.class).getBundleContext(); IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext); ContextInjectionFactory.inject(this, serviceContext); // get p2 agent for current system(Eclipse instance in this // case) // the location for the currently running system is null (see // docs) p2Agent = agentProvider.createAgent(null); session = new ProvisioningSession(p2Agent); artifactRepoManager = (IArtifactRepositoryManager) p2Agent.getService(IArtifactRepositoryManager.class.getName()); metadataRepoManager = (IMetadataRepositoryManager) p2Agent.getService(IMetadataRepositoryManager.class.getName()); } catch (Exception e) { throw new RuntimeException(Messages.UpdateManager_14, e); } }
public static IArtifactRepositoryManager getArtifactRepositoryManager(IProvisioningAgent agent) { return (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); }
public static IAgentLocation getAgentLocation(IProvisioningAgent agent) { return (IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME); }
public List<IServerExtension> getExtensions(IProgressMonitor monitor) throws CoreException, ProvisionException { try { /* * To discovery the server adapter, there are three methods: * 1. Looking at the site.xml (if it exists). This is the legacy method * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2 * update site (that may not have a site.xml). The property is necessary to identify * the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show * up regardless of whether it is a server or not * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml * to use category.xml) */ BundleContext bd = org.eclipse.wst.server.discovery.internal.Activator.getDefault() .getBundle() .getBundleContext(); IProvisioningAgent agent = ExtensionUtility.getAgent(bd); URI url2 = new URI(url); // Method 1: Looking at the site.xml UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory(); mrf.setAgent(ExtensionUtility.getAgent(bd)); // If the site.xml does not exist, the load will throw a // org.eclipse.equinox.p2.core.ProvisionException List<IServerExtension> list = new ArrayList<IServerExtension>(); try { IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor); IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery( "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$ list = getInstallableUnits(repo, query, url2, monitor); } catch (ProvisionException pe) { Trace.trace(Trace.WARNING, "Error getting update site information", pe); // $NON-NLS-1$ } // Call Method 2 if there are no results from Method 1 (e.g. if the site.xml exists without // specifying any server adapters there or no site.xml exists) if (list.isEmpty()) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); manager.addRepository(url2); // Need to query for all IUs IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery(); IMetadataRepository repo = manager.loadRepository(url2, monitor); List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor); int size = list2.size(); for (int i = 0; i < size; i++) { Extension e = (Extension) list2.get(i); IInstallableUnit[] iuArr = e.getIUs(); if (iuArr != null && iuArr.length > 0) { if (iuArr[0] != null) { if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) { list.add(e); } } } } } // Call Method 3 if no results from Method 2. Creating the p2 update site using the // category.xml will generate // a provider property with org.eclipse.wst.server.core.serverAdapter if (list.isEmpty()) { IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); manager.addRepository(url2); IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery( "id ~=/*org.eclipse.wst.server.core.serverAdapter/"); //$NON-NLS-1$ IMetadataRepository repo = manager.loadRepository(url2, monitor); list = getInstallableUnits(repo, query, url2, monitor); } return list; } catch (ProvisionException e) { Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$ throw e; } catch (Exception e) { Trace.trace(Trace.WARNING, "Error getting update info", e); // $NON-NLS-1$ return new ArrayList<IServerExtension>(0); } }
public Object createService(IProvisioningAgent agent) { ProvisioningUI ui = (ProvisioningUI) agent.getService(ProvisioningUI.class.getName()); if (ui == null) return null; return new ColocatedRepositoryTracker(ui); }