Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 238169
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 22-28 Link Here
22
   org.eclipse.equinox.p2.installer,
22
   org.eclipse.equinox.p2.installer,
23
   org.eclipse.equinox.p2.reconciler.dropins,
23
   org.eclipse.equinox.p2.reconciler.dropins,
24
   org.eclipse.pde.p2.ui",
24
   org.eclipse.pde.p2.ui",
25
 org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository;x-friends:="org.eclipse.equinox.p2.extensionlocation,org.eclipse.equinox.p2.updatesite"
25
 org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository;x-friends:="org.eclipse.equinox.p2.extensionlocation,org.eclipse.equinox.p2.updatesite,org.eclipse.equinox.p2.engine"
26
Import-Package: org.eclipse.core.runtime.preferences,
26
Import-Package: org.eclipse.core.runtime.preferences,
27
 org.eclipse.equinox.app;resolution:=optional,
27
 org.eclipse.equinox.app;resolution:=optional,
28
 org.eclipse.equinox.internal.p2.core.helpers,
28
 org.eclipse.equinox.internal.p2.core.helpers,
(-)plugin.xml (+10 lines)
Lines 10-13 Link Here
10
			class="org.eclipse.equinox.internal.p2.engine.NullTouchpoint"
10
			class="org.eclipse.equinox.internal.p2.engine.NullTouchpoint"
11
			version="1.0.0"/>
11
			version="1.0.0"/>
12
	</extension>
12
	</extension>
13
 <extension
14
       id="metadataRepository"
15
       point="org.eclipse.equinox.p2.metadata.repository.metadataRepositories">
16
    <factory
17
          class="org.eclipse.equinox.internal.p2.engine.repo.ProfileMetadataRepositoryFactory">
18
    </factory>
19
    <filter
20
          suffix="profile">
21
    </filter>
22
 </extension>
13
</plugin>
23
</plugin>
(-)src/org/eclipse/equinox/internal/p2/engine/repo/ProfileMetadataRepositoryFactory.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.engine.repo;
12
13
import java.net.URL;
14
import java.util.Map;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
17
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
18
import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory;
19
20
public class ProfileMetadataRepositoryFactory implements IMetadataRepositoryFactory {
21
22
	/* (non-Javadoc)
23
	 * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#create(java.net.URL, java.lang.String, java.lang.String, java.util.Map)
24
	 */
25
	public IMetadataRepository create(URL location, String name, String type, Map properties) {
26
		return null;
27
	}
28
29
	/*
30
	 * (non-Javadoc)
31
	 * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#validate(java.net.URL, org.eclipse.core.runtime.IProgressMonitor)
32
	 */
33
34
	public IStatus validate(URL location, IProgressMonitor monitor) {
35
		try {
36
			ProfileMetadataRepository.validate(location, monitor);
37
		} catch (ProvisionException e) {
38
			return e.getStatus();
39
		}
40
		return Status.OK_STATUS;
41
	}
42
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.IMetadataRepositoryFactory#load(java.net.URL, org.eclipse.core.runtime.IProgressMonitor)
45
	 */
46
	public IMetadataRepository load(URL location, IProgressMonitor monitor) throws ProvisionException {
47
		return new ProfileMetadataRepository(location, monitor);
48
	}
49
}
(-)src/org/eclipse/equinox/internal/p2/engine/repo/ProfileMetadataRepository.java (+121 lines)
Added Link Here
1
package org.eclipse.equinox.internal.p2.engine.repo;
2
3
import java.io.File;
4
import java.net.MalformedURLException;
5
import java.net.URL;
6
import java.util.*;
7
import org.eclipse.core.runtime.*;
8
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
9
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
10
import org.eclipse.equinox.internal.p2.engine.EngineActivator;
11
import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry;
12
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
13
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
14
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
15
import org.eclipse.equinox.internal.provisional.p2.core.repository.RepositoryEvent;
16
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
17
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
18
import org.eclipse.equinox.internal.provisional.p2.query.Query;
19
import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.AbstractMetadataRepository;
20
21
public class ProfileMetadataRepository extends AbstractMetadataRepository {
22
23
	public static final String TYPE = "org.eclipse.equinox.p2.engine.repo.metadataRepository"; //$NON-NLS-1$
24
	public static final Integer VERSION = new Integer(1);
25
	private IProfile profile;
26
27
	public ProfileMetadataRepository(URL location, IProgressMonitor monitor) throws ProvisionException {
28
		super(location.toExternalForm(), TYPE, VERSION.toString(), location, null, null, null);
29
30
		try {
31
			profile = getProfile(location);
32
		} catch (RuntimeException e) {
33
			throw new ProvisionException(new Status(IStatus.ERROR, EngineActivator.ID, ProvisionException.REPOSITORY_FAILED_READ, e.getMessage(), e));
34
		}
35
36
		publishArtifactRepos();
37
	}
38
39
	private void publishArtifactRepos() {
40
		List artifactRepos = new ArrayList();
41
		String bundlePool = profile.getProperty(IProfile.PROP_CACHE);
42
		if (bundlePool != null) {
43
			try {
44
				artifactRepos.add(new File(bundlePool).toURL().toExternalForm());
45
			} catch (MalformedURLException e) {
46
				LogHelper.log(new Status(IStatus.WARNING, EngineActivator.ID, "invalid repo reference with location: " + bundlePool, e)); //$NON-NLS-1$
47
			}
48
		}
49
50
		String sharedBundlePool = profile.getProperty(IProfile.PROP_SHARED_CACHE);
51
		if (sharedBundlePool != null) {
52
			try {
53
				artifactRepos.add(new File(sharedBundlePool).toURL().toExternalForm());
54
			} catch (MalformedURLException e) {
55
				LogHelper.log(new Status(IStatus.WARNING, EngineActivator.ID, "invalid repo reference with location: " + sharedBundlePool, e)); //$NON-NLS-1$
56
			}
57
		}
58
59
		String dropinRepositories = profile.getProperty("org.eclipse.equinox.p2.cache.extensions");
60
		if (dropinRepositories != null) {
61
			StringTokenizer tokenizer = new StringTokenizer(dropinRepositories, "|");
62
			while (tokenizer.hasMoreTokens()) {
63
				artifactRepos.add(tokenizer.nextToken());
64
			}
65
		}
66
67
		IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME);
68
		if (bus == null)
69
			return;
70
		for (Iterator it = artifactRepos.iterator(); it.hasNext();) {
71
			String repo = (String) it.next();
72
			try {
73
				URL artifactRepo = new URL(repo);
74
				bus.publishEvent(new RepositoryEvent(artifactRepo, IRepository.TYPE_ARTIFACT, RepositoryEvent.DISCOVERED, true));
75
			} catch (MalformedURLException e) {
76
				LogHelper.log(new Status(IStatus.WARNING, EngineActivator.ID, "invalid repo reference with location: " + repo, e)); //$NON-NLS-1$
77
			}
78
		}
79
	}
80
81
	public void initialize(RepositoryState state) {
82
		// nothing to do
83
	}
84
85
	public Collector query(Query query, Collector collector, IProgressMonitor monitor) {
86
		return profile.query(query, collector, monitor);
87
	}
88
89
	public static void validate(URL location, IProgressMonitor monitor) throws ProvisionException {
90
		try {
91
			getProfile(location);
92
		} catch (RuntimeException e) {
93
			throw new ProvisionException(new Status(IStatus.ERROR, "org.eclipse.equinox.p2.engine", ProvisionException.REPOSITORY_FAILED_READ, e.getMessage(), e));
94
		}
95
	}
96
97
	private static IProfile getProfile(URL location) {
98
		if (!"file".equalsIgnoreCase(location.getProtocol()))
99
			throw new IllegalArgumentException("Profile Registry must use 'file' protocol.");
100
101
		File registryDirectory = new File(location.getPath());
102
		if (!registryDirectory.isDirectory())
103
			throw new IllegalArgumentException("Profile Registry not found. " + registryDirectory + " is not a directory.");
104
105
		String query = location.getQuery();
106
		//expect profileid=xyz
107
		if (query == null || query.indexOf("profileid=") == -1)
108
			throw new IllegalArgumentException("'profileid' query parameter not specified.");
109
110
		String profileid = query.substring(query.indexOf("profileid=") + "profileid=".length());
111
		if (profileid == null || profileid.length() == 0 || profileid.indexOf('&') != -1)
112
			throw new IllegalArgumentException("bad 'profileid' query parameter: " + profileid);
113
114
		SimpleProfileRegistry profileRegistry = new SimpleProfileRegistry(registryDirectory, null, false);
115
		IProfile profile = profileRegistry.getProfile(profileid);
116
		if (profile == null)
117
			throw new IllegalArgumentException("No profile found for : " + profileid);
118
119
		return profile;
120
	}
121
}

Return to bug 238169