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 265550 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+6 lines)
Lines 15-20 Link Here
15
            library="lib/repository-tools-ant.jar"
15
            library="lib/repository-tools-ant.jar"
16
            name="p2.mirror">
16
            name="p2.mirror">
17
      </antTask>
17
      </antTask>
18
19
     <antTask
20
            class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask"
21
            library="lib/repository-tools-ant.jar"
22
            name="p2.composite.repository">
23
      </antTask>
18
      
24
      
19
      <antTask
25
      <antTask
20
			library="lib/repository-tools-ant.jar"
26
			library="lib/repository-tools-ant.jar"
(-)src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java (-37 / +74 lines)
Lines 13-19 Link Here
13
import java.net.URI;
13
import java.net.URI;
14
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
15
import java.util.*;
15
import java.util.*;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
18
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
18
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
19
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
19
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
20
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
Lines 22-32 Link Here
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
26
import org.eclipse.equinox.internal.provisional.p2.repository.*;
26
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
27
import org.eclipse.osgi.util.NLS;
27
28
28
public abstract class AbstractApplication {
29
public abstract class AbstractApplication {
30
	protected boolean removeUnknownRepositories = true;
29
31
32
	protected List sourceRepositories = new ArrayList();
30
	protected List sourceArtifactRepositories = new ArrayList();
33
	protected List sourceArtifactRepositories = new ArrayList();
31
	protected List sourceMetadataRepositories = new ArrayList();
34
	protected List sourceMetadataRepositories = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
35
	protected List artifactReposToRemove = new ArrayList();
Lines 40-45 Link Here
40
	private CompositeMetadataRepository compositeMetadataRepository = null;
43
	private CompositeMetadataRepository compositeMetadataRepository = null;
41
	private CompositeArtifactRepository compositeArtifactRepository = null;
44
	private CompositeArtifactRepository compositeArtifactRepository = null;
42
45
46
	/*
47
	 * Add a source metadata repository
48
	 */
43
	public void addSourceMetadataRepository(String location) {
49
	public void addSourceMetadataRepository(String location) {
44
		URI uri = Activator.getURI(location);
50
		URI uri = Activator.getURI(location);
45
		if (uri != null)
51
		if (uri != null)
Lines 71-85 Link Here
71
	}
77
	}
72
78
73
	protected void finalizeRepositories() throws ProvisionException {
79
	protected void finalizeRepositories() throws ProvisionException {
74
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
80
		if (removeUnknownRepositories) {
75
		for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
81
			IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
76
			artifactRepositoryManager.removeRepository((URI) iter.next());
82
			for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
77
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
83
				artifactRepositoryManager.removeRepository((URI) iter.next());
78
		for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
84
			IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
79
			metadataRepositoryManager.removeRepository((URI) iter.next());
85
			for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
86
				metadataRepositoryManager.removeRepository((URI) iter.next());
87
		}
80
	}
88
	}
81
89
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
90
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
91
		for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
92
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
93
			if (repo.isBoth()) {
94
				sourceArtifactRepositories.add(repo.getRepoLocation());
95
				sourceMetadataRepositories.add(repo.getRepoLocation());
96
			} else if (repo.isArtifact())
97
				sourceArtifactRepositories.add(repo.getRepoLocation());
98
			else if (repo.isMetadata())
99
				sourceMetadataRepositories.add(repo.getRepoLocation());
100
			else
101
				throw new ProvisionException(NLS.bind(Messages.unknown_repository_type, repo.getRepoLocation()));
102
		}
103
83
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
104
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
105
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
106
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
Lines 101-131 Link Here
101
		}
122
		}
102
123
103
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
124
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
104
105
	}
125
	}
106
126
107
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
127
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
108
		if (destinationRepos.size() != 2) {
128
		RepositoryDescriptor artifactRepoDescriptor = null;
109
			throw new ProvisionException("Too many or too few destination repositories.");
129
		RepositoryDescriptor metadataRepoDescriptor = null;
130
131
		Iterator iter = destinationRepos.iterator();
132
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
133
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
134
			if (repo.isArtifact() && artifactRepoDescriptor == null)
135
				artifactRepoDescriptor = repo;
136
			if (repo.isMetadata() && metadataRepoDescriptor == null)
137
				metadataRepoDescriptor = repo;
110
		}
138
		}
111
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
139
112
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
140
		if (artifactRepoDescriptor != null)
113
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
141
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
114
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
142
		if (metadataRepoDescriptor != null)
143
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
144
145
		if (destinationMetadataRepository == null && destinationArtifactRepository == null)
146
			throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations);
115
	}
147
	}
116
148
117
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
149
	protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
118
		try {
150
		try {
119
			if (!mgr.contains(toInit.getRepoLocation()))
151
			if (!mgr.contains(toInit.getRepoLocation()))
120
				metadataReposToRemove.add(toInit.getRepoLocation());
152
				metadataReposToRemove.add(toInit.getRepoLocation());
121
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
153
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
122
			if (repository != null && repository.isModifiable()) {
154
			if (initDestinationRepository(repository, toInit))
123
				if (toInit.getName() != null)
124
					repository.setName(toInit.getName());
125
				if (!toInit.isAppend())
126
					repository.removeAll();
127
				return repository;
155
				return repository;
128
			}
129
		} catch (ProvisionException e) {
156
		} catch (ProvisionException e) {
130
			//fall through and create a new repository below
157
			//fall through and create a new repository below
131
		}
158
		}
Lines 133-143 Link Here
133
		IMetadataRepository source = null;
160
		IMetadataRepository source = null;
134
		try {
161
		try {
135
			if (toInit.getFormat() != null)
162
			if (toInit.getFormat() != null)
136
				source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null);
163
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
137
		} catch (ProvisionException e) {
164
		} catch (ProvisionException e) {
138
			//Ignore.
165
			//Ignore.
139
		} catch (URISyntaxException e) {
140
			//Ignore
141
		}
166
		}
142
		//This code assumes source has been successfully loaded before this point
167
		//This code assumes source has been successfully loaded before this point
143
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
168
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
Lines 147-175 Link Here
147
		return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result);
172
		return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result);
148
	}
173
	}
149
174
150
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
175
	protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
151
		try {
176
		try {
152
			if (!mgr.contains(toInit.getRepoLocation()))
177
			if (!mgr.contains(toInit.getRepoLocation()))
153
				artifactReposToRemove.add(toInit.getRepoLocation());
178
				artifactReposToRemove.add(toInit.getRepoLocation());
154
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
179
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
155
			if (repository != null && repository.isModifiable()) {
180
			if (initDestinationRepository(repository, toInit))
156
				if (toInit.getName() != null)
157
					repository.setName(toInit.getName());
158
				if (!toInit.isAppend())
159
					repository.removeAll();
160
				return repository;
181
				return repository;
161
			}
162
		} catch (ProvisionException e) {
182
		} catch (ProvisionException e) {
163
			//fall through and create a new repository below
183
			//fall through and create a new repository below
164
		}
184
		}
165
		IArtifactRepository source = null;
185
		IArtifactRepository source = null;
166
		try {
186
		try {
167
			if (toInit.getFormat() != null)
187
			if (toInit.getFormat() != null)
168
				source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null);
188
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
169
		} catch (ProvisionException e) {
189
		} catch (ProvisionException e) {
170
			//Ignore.
190
			//Ignore.
171
		} catch (URISyntaxException e) {
172
			//Ignore
173
		}
191
		}
174
		//This code assumes source has been successfully loaded before this point
192
		//This code assumes source has been successfully loaded before this point
175
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
193
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
Lines 180-185 Link Here
180
		return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result);
198
		return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result);
181
	}
199
	}
182
200
201
	protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) {
202
		if (repository != null && repository.isModifiable()) {
203
			if (descriptor.getName() != null)
204
				repository.setName(descriptor.getName());
205
			if (repository instanceof ICompositeRepository && !descriptor.isAppend())
206
				((ICompositeRepository) repository).removeAllChildren();
207
			else if (repository instanceof IMetadataRepository && !descriptor.isAppend())
208
				((IMetadataRepository) repository).removeAll();
209
			else if (repository instanceof IArtifactRepository && !descriptor.isAppend())
210
				((IArtifactRepository) repository).removeAll();
211
			return true;
212
		}
213
		return false;
214
	}
215
183
	public IMetadataRepository getCompositeMetadataRepository() {
216
	public IMetadataRepository getCompositeMetadataRepository() {
184
		if (compositeMetadataRepository == null) {
217
		if (compositeMetadataRepository == null) {
185
			try {
218
			try {
Lines 197-203 Link Here
197
	public IArtifactRepository getCompositeArtifactRepository() {
230
	public IArtifactRepository getCompositeArtifactRepository() {
198
		if (compositeArtifactRepository == null) {
231
		if (compositeArtifactRepository == null) {
199
			try {
232
			try {
200
				compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$
233
				compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$
201
			} catch (URISyntaxException e) {
234
			} catch (URISyntaxException e) {
202
				//Can't happen
235
				//Can't happen
203
			}
236
			}
Lines 213-216 Link Here
213
	public void addDestination(RepositoryDescriptor descriptor) {
246
	public void addDestination(RepositoryDescriptor descriptor) {
214
		destinationRepos.add(descriptor);
247
		destinationRepos.add(descriptor);
215
	}
248
	}
249
250
	public void addSource(RepositoryDescriptor repo) {
251
		sourceRepositories.add(repo);
252
	}
216
}
253
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Activator.java (-6 / +7 lines)
Lines 19-24 Link Here
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
20
import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
20
import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
22
import org.eclipse.osgi.util.NLS;
22
import org.osgi.framework.*;
23
import org.osgi.framework.*;
23
import org.osgi.service.packageadmin.PackageAdmin;
24
import org.osgi.service.packageadmin.PackageAdmin;
24
25
Lines 43-49 Link Here
43
		// TODO needed to do this to ensure the profile registry was registered
44
		// TODO needed to do this to ensure the profile registry was registered
44
		Bundle bundle = getBundle("org.eclipse.equinox.p2.exemplarysetup"); //$NON-NLS-1$
45
		Bundle bundle = getBundle("org.eclipse.equinox.p2.exemplarysetup"); //$NON-NLS-1$
45
		if (bundle == null)
46
		if (bundle == null)
46
			throw new ProvisionException("Unable to start exemplarysetup bundle.");
47
			throw new ProvisionException(Messages.unable_to_start_exemplarysetup);
47
		bundle.start(Bundle.START_TRANSIENT);
48
		bundle.start(Bundle.START_TRANSIENT);
48
	}
49
	}
49
50
Lines 64-70 Link Here
64
		try {
65
		try {
65
			return URIUtil.fromString(spec);
66
			return URIUtil.fromString(spec);
66
		} catch (URISyntaxException e) {
67
		} catch (URISyntaxException e) {
67
			LogHelper.log(new Status(IStatus.WARNING, ID, "Unable to process as URI: " + spec, e));
68
			LogHelper.log(new Status(IStatus.WARNING, ID, NLS.bind(Messages.unable_to_process_uri, spec), e));
68
		}
69
		}
69
		return null;
70
		return null;
70
	}
71
	}
Lines 75-81 Link Here
75
	public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException {
76
	public static IArtifactRepositoryManager getArtifactRepositoryManager() throws ProvisionException {
76
		IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(getBundleContext(), IArtifactRepositoryManager.class.getName());
77
		IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(getBundleContext(), IArtifactRepositoryManager.class.getName());
77
		if (manager == null)
78
		if (manager == null)
78
			throw new ProvisionException("Unable to acquire artifact repository manager service.");
79
			throw new ProvisionException(Messages.no_artifactRepo_manager);
79
		return manager;
80
		return manager;
80
	}
81
	}
81
82
Lines 85-91 Link Here
85
	static IProfileRegistry getProfileRegistry() throws ProvisionException {
86
	static IProfileRegistry getProfileRegistry() throws ProvisionException {
86
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(getBundleContext(), IProfileRegistry.class.getName());
87
		IProfileRegistry registry = (IProfileRegistry) ServiceHelper.getService(getBundleContext(), IProfileRegistry.class.getName());
87
		if (registry == null)
88
		if (registry == null)
88
			throw new ProvisionException("Unable to acquire profile registry service.");
89
			throw new ProvisionException(Messages.no_profile_registry);
89
		return registry;
90
		return registry;
90
	}
91
	}
91
92
Lines 95-101 Link Here
95
	public static synchronized Bundle getBundle(String symbolicName) throws ProvisionException {
96
	public static synchronized Bundle getBundle(String symbolicName) throws ProvisionException {
96
		PackageAdmin packageAdmin = (PackageAdmin) ServiceHelper.getService(getBundleContext(), PackageAdmin.class.getName());
97
		PackageAdmin packageAdmin = (PackageAdmin) ServiceHelper.getService(getBundleContext(), PackageAdmin.class.getName());
97
		if (packageAdmin == null)
98
		if (packageAdmin == null)
98
			throw new ProvisionException("Unable to acquire package admin service.");
99
			throw new ProvisionException(Messages.no_package_admin);
99
		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
100
		Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
100
		if (bundles == null)
101
		if (bundles == null)
101
			return null;
102
			return null;
Lines 113-119 Link Here
113
	public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException {
114
	public static IMetadataRepositoryManager getMetadataRepositoryManager() throws ProvisionException {
114
		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(getBundleContext(), IMetadataRepositoryManager.class.getName());
115
		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(getBundleContext(), IMetadataRepositoryManager.class.getName());
115
		if (manager == null)
116
		if (manager == null)
116
			throw new ProvisionException("Unable to acquire metadata repository manager service.");
117
			throw new ProvisionException(Messages.no_metadataRepo_manager);
117
		return manager;
118
		return manager;
118
	}
119
	}
119
}
120
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java (-15 / +194 lines)
Lines 10-54 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
12
13
import java.io.File;
14
import java.net.URI;
13
import java.util.ArrayList;
15
import java.util.ArrayList;
14
import java.util.Iterator;
16
import java.util.Iterator;
15
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.app.IApplication;
18
import org.eclipse.equinox.app.IApplication;
17
import org.eclipse.equinox.app.IApplicationContext;
19
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring;
20
import org.eclipse.equinox.internal.p2.artifact.mirror.*;
21
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
19
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
22
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
23
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
24
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
28
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
29
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
30
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
25
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
31
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
32
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
26
33
27
public class MirrorApplication extends AbstractApplication {
34
public class MirrorApplication extends AbstractApplication {
35
	private static final String LOG_ROOT = "p2.mirror"; //$NON-NLS-1$
36
28
	protected SlicingOptions slicingOptions = new SlicingOptions();
37
	protected SlicingOptions slicingOptions = new SlicingOptions();
29
38
39
	private URI baseline;
40
	private String comparatorID;
41
	private boolean compare = false;
42
	private boolean failOnError = true;
43
	private boolean raw = true;
44
	private boolean verbose = false;
45
	private boolean validate = false;
46
47
	private File mirrorLogFile; // file to log mirror output to (optional)
48
	private File comparatorLogFile; // file to comparator output to (optional)
49
	private IArtifactMirrorLog mirrorLog;
50
	private IArtifactMirrorLog comparatorLog;
51
30
	public Object start(IApplicationContext context) throws Exception {
52
	public Object start(IApplicationContext context) throws Exception {
31
		run(null);
53
		run(null);
32
		return IApplication.EXIT_OK;
54
		return IApplication.EXIT_OK;
33
	}
55
	}
34
56
35
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
57
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
58
		IStatus mirrorStatus = Status.OK_STATUS;
36
		try {
59
		try {
37
			validate();
60
			validate();
38
			initializeRepos(new NullProgressMonitor());
61
			initializeRepos(new NullProgressMonitor());
62
			initializeIUs();
39
			IQueryable slice = slice(new NullProgressMonitor());
63
			IQueryable slice = slice(new NullProgressMonitor());
40
			IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
64
			if (destinationArtifactRepository != null) {
41
			if (mirrorStatus.getSeverity() == IStatus.ERROR) {
65
				initializeLogs();
42
				return mirrorStatus;
66
				mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
67
				if (mirrorStatus.getSeverity() == IStatus.ERROR)
68
					return mirrorStatus;
43
			}
69
			}
44
			mirrorMetadata(slice, new NullProgressMonitor());
70
			if (destinationMetadataRepository != null)
71
				mirrorMetadata(slice, new NullProgressMonitor());
45
		} finally {
72
		} finally {
46
			finalizeRepositories();
73
			finalizeRepositories();
74
			finalizeLogs();
47
		}
75
		}
48
		return Status.OK_STATUS;
76
		if (mirrorStatus.isOK())
77
			return Status.OK_STATUS;
78
		return mirrorStatus;
49
	}
79
	}
50
80
51
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) {
81
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException {
52
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
82
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
53
		ArrayList keys = new ArrayList(ius.size());
83
		ArrayList keys = new ArrayList(ius.size());
54
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
84
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
Lines 58-66 Link Here
58
				keys.add(iuKeys[i]);
88
				keys.add(iuKeys[i]);
59
			}
89
			}
60
		}
90
		}
61
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true);
91
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw);
62
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
92
63
		return mirror.run(true, false);
93
		mirror.setCompare(compare);
94
		mirror.setComparatorId(comparatorID);
95
		mirror.setBaseline(initializeBaseline());
96
		mirror.setValidate(validate);
97
98
		// If IUs have been specified then only they should be mirrored, otherwise mirror everything.
99
		if (keys.size() > 0)
100
			mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
101
102
		if (comparatorLog != null)
103
			mirror.setComparatorLog(comparatorLog);
104
105
		IStatus result = mirror.run(failOnError, verbose);
106
107
		if (mirrorLog != null)
108
			mirrorLog.log(result);
109
		else
110
			LogHelper.log(result);
111
		return result;
112
	}
113
114
	private IArtifactRepository initializeBaseline() throws ProvisionException {
115
		if (baseline == null)
116
			return null;
117
		IArtifactRepositoryManager mgr = Activator.getArtifactRepositoryManager();
118
119
		if (!mgr.contains(baseline))
120
			artifactReposToRemove.add(baseline);
121
		return mgr.loadRepository(baseline, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
64
	}
122
	}
65
123
66
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
124
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
Lines 75-85 Link Here
75
	 * to add more if they wish)
133
	 * to add more if they wish)
76
	 */
134
	 */
77
	private void validate() throws ProvisionException {
135
	private void validate() throws ProvisionException {
78
		if (sourceMetadataRepositories == null)
136
		if (sourceMetadataRepositories.isEmpty() && sourceArtifactRepositories.isEmpty() && sourceRepositories.isEmpty())
79
			throw new ProvisionException("Need to set the source metadata repository location.");
137
			throw new ProvisionException(Messages.MirrorApplication_set_source_repositories);
80
		if (sourceIUs == null)
138
	}
81
			throw new ProvisionException("Mirroring root needs to be specified.");
139
82
		//TODO Check that the IU is in repo
140
	/*
141
	 * If no IUs have been specified we want to mirror them all
142
	 */
143
	private void initializeIUs() throws ProvisionException {
144
		if (sourceIUs == null || sourceIUs.isEmpty()) {
145
			sourceIUs = new ArrayList();
146
			IMetadataRepository metadataRepo = getCompositeMetadataRepository();
147
			Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
148
149
			for (Iterator iter = collector.iterator(); iter.hasNext();) {
150
				IInstallableUnit iu = (IInstallableUnit) iter.next();
151
				sourceIUs.add(iu);
152
			}
153
154
			if (collector.size() == 0 && destinationMetadataRepository != null) {
155
				throw new ProvisionException(Messages.MirrorApplication_no_IUs);
156
			}
157
		} else {
158
			//TODO Check that the IU is in repo
159
		}
160
	}
161
162
	/*
163
	 * Initialize logs, if applicable
164
	 */
165
	private void initializeLogs() {
166
		if (compare && comparatorLogFile != null)
167
			comparatorLog = getLog(comparatorLogFile, comparatorID);
168
		if (mirrorLog == null && mirrorLogFile != null)
169
			mirrorLog = getLog(mirrorLogFile, LOG_ROOT);
170
	}
171
172
	/*
173
	 * Finalize logs, if applicable
174
	 */
175
	private void finalizeLogs() {
176
		if (comparatorLog != null)
177
			comparatorLog.close();
178
		if (mirrorLog != null)
179
			mirrorLog.close();
180
	}
181
182
	/*
183
	 * Get the log for a location
184
	 */
185
	private IArtifactMirrorLog getLog(File location, String root) {
186
		String absolutePath = location.getAbsolutePath();
187
		if (absolutePath.toLowerCase().endsWith(".xml")) //$NON-NLS-1$
188
			return new XMLMirrorLog(absolutePath, 0, root);
189
		return new FileMirrorLog(absolutePath, 0, root);
83
	}
190
	}
84
191
85
	private IQueryable slice(IProgressMonitor monitor) {
192
	private IQueryable slice(IProgressMonitor monitor) {
Lines 92-95 Link Here
92
	public void setSlicingOptions(SlicingOptions options) {
199
	public void setSlicingOptions(SlicingOptions options) {
93
		slicingOptions = options;
200
		slicingOptions = options;
94
	}
201
	}
202
203
	/*
204
	 * Set the location of the baseline repository. (used in comparison)
205
	 */
206
	public void setBaseline(URI baseline) {
207
		this.baseline = baseline;
208
		compare = true;
209
	}
210
211
	/*
212
	 * Set the identifier of the comparator to use.
213
	 */
214
	public void setComparatorID(String value) {
215
		comparatorID = value;
216
		compare = true;
217
	}
218
219
	/*
220
	 * Set whether or not the application should be calling a comparator when mirroring.
221
	 */
222
	public void setCompare(boolean value) {
223
		compare = value;
224
	}
225
226
	/*
227
	 * Set whether or not we should ignore errors when running the mirror application.
228
	 */
229
	public void setIgnoreErrors(boolean value) {
230
		failOnError = !value;
231
	}
232
233
	/*
234
	 * Set whether or not the the artifacts are raw.
235
	 */
236
	public void setRaw(boolean value) {
237
		raw = value;
238
	}
239
240
	/*
241
	 * Set whether or not the mirror application should be run in verbose mode.
242
	 */
243
	public void setVerbose(boolean value) {
244
		verbose = value;
245
	}
246
247
	/*
248
	 * Set the location of the log for comparator output
249
	 */
250
	public void setComparatorLog(File comparatorLog) {
251
		this.comparatorLogFile = comparatorLog;
252
	}
253
254
	/*
255
	 * Set the location of the log for mirroring. 
256
	 */
257
	public void setLog(File mirrorLog) {
258
		this.mirrorLogFile = mirrorLog;
259
	}
260
261
	/*
262
	 * Set the ArtifactMirror log
263
	 */
264
	public void setLog(IArtifactMirrorLog log) {
265
		mirrorLog = log;
266
	}
267
268
	/*
269
	 * Set if the artifact mirror should be validated
270
	 */
271
	public void setValidate(boolean value) {
272
		validate = value;
273
	}
95
}
274
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java (-8 / +3 lines)
Lines 247-260 Link Here
247
			}
247
			}
248
248
249
			if (option.equalsIgnoreCase("-destination")) { //$NON-NLS-1$
249
			if (option.equalsIgnoreCase("-destination")) { //$NON-NLS-1$
250
				RepositoryDescriptor artifact = new RepositoryDescriptor();
250
				RepositoryDescriptor destination = new RepositoryDescriptor();
251
				artifact.setLocation(URIUtil.fromString(arg));
251
				destination.setLocation(URIUtil.fromString(arg));
252
				artifact.setKind("A"); //$NON-NLS-1$
252
				addDestination(destination);
253
				addDestination(artifact);
254
				RepositoryDescriptor metadata = new RepositoryDescriptor();
255
				metadata.setLocation(URIUtil.fromString(arg));
256
				metadata.setKind("M"); //$NON-NLS-1$
257
				addDestination(metadata);
258
			}
253
			}
259
		}
254
		}
260
	}
255
	}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java (-12 / +44 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
14
15
import java.net.URI;
13
import java.net.URI;
14
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
15
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
16
import org.eclipse.osgi.util.NLS;
16
17
17
public class RepositoryDescriptor {
18
public class RepositoryDescriptor {
18
19
20
	public static final int TYPE_BOTH = -1;
21
	public static final String KIND_ARTIFACT = "A"; //$NON-NLS-1$
22
	public static final String KIND_METADATA = "M"; //$NON-NLS-1$
23
19
	private boolean compressed = true;
24
	private boolean compressed = true;
20
	private boolean append = true;
25
	private boolean append = true;
21
	private String name = null;
26
	private String name = null;
22
	private URI location = null;
27
	private URI location = null;
23
	private String format = null;
28
	private URI format = null;
24
	private int kind;
29
	private int kind = TYPE_BOTH;
25
30
26
	public void setCompressed(boolean compress) {
31
	public void setCompressed(boolean compress) {
27
		compressed = compress;
32
		compressed = compress;
Lines 32-42 Link Here
32
	}
37
	}
33
38
34
	public void setLocation(URI repoLocation) {
39
	public void setLocation(URI repoLocation) {
35
		location = repoLocation;
40
		location = RepositoryHelper.localRepoURIHelper(repoLocation);
36
	}
41
	}
37
42
38
	public void setFormat(String format) {
43
	public void setFormat(URI format) {
39
		this.format = format;
44
		this.format = RepositoryHelper.localRepoURIHelper(format);
40
	}
45
	}
41
46
42
	public void setAppend(boolean appendMode) {
47
	public void setAppend(boolean appendMode) {
Lines 59-65 Link Here
59
		return location;
64
		return location;
60
	}
65
	}
61
66
62
	public String getFormat() {
67
	public URI getFormat() {
63
		return format;
68
		return format;
64
	}
69
	}
65
70
Lines 67-77 Link Here
67
		return kind;
72
		return kind;
68
	}
73
	}
69
74
75
	public boolean isBoth() {
76
		return kind == TYPE_BOTH;
77
	}
78
79
	public boolean isArtifact() {
80
		return kind == TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
81
	}
82
83
	public boolean isMetadata() {
84
		return kind == TYPE_BOTH || kind == IRepository.TYPE_METADATA;
85
	}
86
70
	public void setKind(String repoKind) {
87
	public void setKind(String repoKind) {
71
		if (repoKind.startsWith("m") || repoKind.startsWith("M")) //$NON-NLS-1$//$NON-NLS-2$
88
		kind = determineKind(repoKind);
72
			kind = IRepository.TYPE_METADATA;
89
	}
73
90
74
		if (repoKind.startsWith("a") || repoKind.startsWith("A")) //$NON-NLS-1$//$NON-NLS-2$
91
	/*
75
			kind = IRepository.TYPE_ARTIFACT;
92
	 * Determine the repository type
93
	 */
94
	public static int determineKind(String repoKind) {
95
		if (kindMatches(repoKind, KIND_METADATA))
96
			return IRepository.TYPE_METADATA;
97
		else if (kindMatches(repoKind, KIND_ARTIFACT))
98
			return IRepository.TYPE_ARTIFACT;
99
100
		throw new IllegalArgumentException(NLS.bind(Messages.unknown_repository_type, repoKind));
101
	}
102
103
	/*
104
	 * Determine if the repository kind matches the identifier kind
105
	 */
106
	public static boolean kindMatches(String repoKind, String kindIdentifier) {
107
		return repoKind.startsWith(kindIdentifier) || repoKind.startsWith(kindIdentifier.toLowerCase());
76
	}
108
	}
77
}
109
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java (+33 lines)
Lines 20-25 Link Here
20
	public static String exception_noEngineService;
20
	public static String exception_noEngineService;
21
	public static String exception_needIUsOrNonEmptyRepo;
21
	public static String exception_needIUsOrNonEmptyRepo;
22
	public static String exception_needDestinationRepo;
22
	public static String exception_needDestinationRepo;
23
	public static String exception_onlyOneComparator;
24
25
	public static String AbstractApplication_no_valid_destinations;
26
27
	public static String AbstractRepositoryTask_unableToFind;
28
29
	public static String CompositeRepository_composite_repository_exists;
30
	public static String CompositeRepository_create_colocated_composite_repos;
31
	public static String CompositeRepository_creating_composite_repositories;
32
	public static String CompositeRepository_default_artifactRepo_name;
33
	public static String CompositeRepository_default_metadataRepo_name;
34
35
	public static String no_valid_IUs;
36
	public static String no_artifactRepo_manager;
37
	public static String no_metadataRepo_manager;
38
	public static String no_package_admin;
39
	public static String no_profile_registry;
40
	public static String unable_to_process_uri;
41
	public static String unable_to_start_exemplarysetup;
42
	public static String unknown_repository_type;
43
44
	public static String MirrorApplication_no_IUs;
45
	public static String MirrorApplication_set_source_repositories;
46
47
	public static String ProcessRepo_location_not_url;
48
	public static String ProcessRepo_must_be_local;
49
50
	public static String Repo2Runnable_no_destination_repository;
51
	public static String Repo2Runnable_no_engine;
52
53
	public static String Repo2RunnableTask_error_transforming_repository;
54
55
	public static String SlicingOption_invalid_platform;
23
56
24
	static {
57
	static {
25
		// initialize resource bundles
58
		// initialize resource bundles
(-)src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties (-1 / +28 lines)
Lines 8-17 Link Here
8
# Contributors:
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
10
###############################################################################
11
AbstractApplication_no_valid_destinations=Unable to locate a valid destination repository.
12
AbstractRepositoryTask_unableToFind=Unable to find: {0} 
13
14
CompositeRepository_default_metadataRepo_name=Composite Metadata Repository
15
CompositeRepository_default_artifactRepo_name=Composite Artifact Repository
16
CompositeRepository_create_colocated_composite_repos=Creating co-located composite repositories.
17
CompositeRepository_composite_repository_exists=Composite repository already exists at location: {0}
18
CompositeRepository_creating_composite_repositories=Creating Composite Repositories
19
CompositeRepository_default_artifactRepo_name=Composite Artifact Repository
20
CompositeRepository_default_metadataRepo_name=Composite Artifact Repository
21
22
no_valid_IUs=Need to specify either a non-empty source metadata repository or a valid list of IUs.
23
no_artifactRepo_manager=Unable to acquire artifact repository manager service.
24
no_metadataRepo_manager=Unable to acquire metadata repository manager service.
25
no_package_admin=Unable to acquire package admin service.
26
no_profile_registry=Unable to acquire profile registry service.
27
unable_to_process_uri=Unable to process as URI: {0}
28
unable_to_start_exemplarysetup=Unable to start exemplarysetup bundle.
29
unknown_repository_type=Repository is of an unknown type: {0}
30
31
MirrorApplication_no_IUs=No IUs specified and no IUs obtained from metadata repositories.
32
MirrorApplication_set_source_repositories=Need to set the source repository location(s).
33
ProcessRepo_location_not_url=Repository location {0} must be a URL.
34
ProcessRepo_must_be_local=Repository must be local: {0}
35
36
SlicingOption_invalid_platform=Invalid platform filter format: {0}.
11
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
37
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
12
38
13
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
39
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
14
exception_notLocalFileRepo= {0} is not a local file based repository.
40
exception_notLocalFileRepo= {0} is not a local file based repository.
15
exception_noEngineService=Unable to acquire engine service.
41
exception_noEngineService=Unable to acquire engine service.
16
exception_needIUsOrNonEmptyRepo=Need to specify either a non-empty source metadata repository or a valid list of IUs.
42
exception_needIUsOrNonEmptyRepo=Need to specify either a non-empty source metadata repository or a valid list of IUs.
17
exception_needDestinationRepo=Need to set the destination artifact repository location.
43
exception_needDestinationRepo=Need to set the destination artifact repository location.
44
exception_onlyOneComparator=Only one comparator should be defined.
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java (-1 / +3 lines)
Lines 13-19 Link Here
13
import java.util.*;
13
import java.util.*;
14
import org.apache.tools.ant.BuildException;
14
import org.apache.tools.ant.BuildException;
15
import org.apache.tools.ant.Task;
15
import org.apache.tools.ant.Task;
16
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
16
import org.eclipse.equinox.p2.internal.repository.tools.SlicingOptions;
17
import org.eclipse.equinox.p2.internal.repository.tools.SlicingOptions;
18
import org.eclipse.osgi.util.NLS;
17
19
18
public class SlicingOption extends Task {
20
public class SlicingOption extends Task {
19
21
Lines 51-57 Link Here
51
		}
53
		}
52
		StringTokenizer tok = new StringTokenizer(platformFilter, ","); //$NON-NLS-1$
54
		StringTokenizer tok = new StringTokenizer(platformFilter, ","); //$NON-NLS-1$
53
		if (tok.countTokens() != 3)
55
		if (tok.countTokens() != 3)
54
			throw new BuildException("Invalid platform filter format: " + platformFilter + ".");
56
			throw new BuildException(NLS.bind(Messages.SlicingOption_invalid_platform, platformFilter));
55
		Dictionary filter = options.getFilter();
57
		Dictionary filter = options.getFilter();
56
		if (filter == null)
58
		if (filter == null)
57
			filter = new Properties();
59
			filter = new Properties();
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java (-4 / +71 lines)
Lines 10-41 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
12
12
13
import java.io.File;
13
import java.util.List;
14
import java.util.List;
14
import org.apache.tools.ant.BuildException;
15
import org.apache.tools.ant.BuildException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
19
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
17
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
20
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
18
21
19
public class MirrorTask extends AbstractRepositoryTask {
22
public class MirrorTask extends AbstractRepositoryTask {
20
23
24
	private File mirrorLog; // file to log mirror output to (optional)
25
	private ComparatorDescription comparator;
26
21
	public MirrorTask() {
27
	public MirrorTask() {
22
		application = new MirrorApplication();
28
		application = new MirrorApplication();
23
	}
29
	}
24
30
25
	public void execute() throws BuildException {
31
	public void execute() throws BuildException {
26
		try {
32
		try {
33
			if (mirrorLog != null)
34
				((MirrorApplication) application).setLog(mirrorLog);
35
			else
36
				((MirrorApplication) application).setLog(new AntMirrorLog(this));
37
38
			if (comparator != null) {
39
				// Enable comparison
40
				((MirrorApplication) application).setCompare(true);
41
				// Set baseline location
42
				if (comparator.getBaseline() != null)
43
					((MirrorApplication) application).setBaseline(comparator.getBaseline().getDescriptor().getRepoLocation());
44
				// Set comparator to use
45
				if (comparator.getComparator() != null)
46
					((MirrorApplication) application).setComparatorID(comparator.getComparator());
47
				// Set comparator log
48
				if (comparator.getComparatorLog() != null)
49
					((MirrorApplication) application).setComparatorLog(comparator.getComparatorLog());
50
			}
51
27
			prepareSourceRepos();
52
			prepareSourceRepos();
28
			application.initializeRepos(null);
53
			application.initializeRepos(null);
29
			List ius = prepareIUs();
54
			List ius = prepareIUs();
30
			if (ius == null || ius.size() == 0)
31
				throw new BuildException("Need to specify one or more IUs to mirror.");
32
			application.setSourceIUs(ius);
55
			application.setSourceIUs(ius);
33
			IStatus result = application.run(null);
56
			IStatus result = application.run(null);
34
			if (result.matches(IStatus.ERROR)) {
57
			if (result.matches(IStatus.ERROR))
35
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
58
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
36
			}
37
		} catch (ProvisionException e) {
59
		} catch (ProvisionException e) {
38
			throw new BuildException(e);
60
			throw new BuildException(e);
61
		} catch (NoSuchMethodException e) {
62
			// Should not occur
63
			throw new BuildException(e);
39
		}
64
		}
40
	}
65
	}
41
66
Lines 44-47 Link Here
44
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
69
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
45
		return options;
70
		return options;
46
	}
71
	}
72
73
	/*
74
	 * Set the comparison information
75
	 */
76
	public ComparatorDescription createComparator() {
77
		if (comparator != null)
78
			throw new BuildException(Messages.exception_onlyOneComparator);
79
		comparator = new ComparatorDescription();
80
		return comparator;
81
	}
82
83
	/*
84
	 * Set the location of the mirror log
85
	 */
86
	public void setLog(String value) {
87
		mirrorLog = new File(value);
88
	}
89
90
	/*
91
	 * Set whether or not we should ignore errors when running the mirror application.
92
	 */
93
	public void setIgnoreErrors(boolean value) {
94
		((MirrorApplication) application).setIgnoreErrors(value);
95
	}
96
97
	/*
98
	 * Set whether or not the the artifacts are raw.
99
	 */
100
	public void setRaw(boolean value) {
101
		((MirrorApplication) application).setRaw(value);
102
	}
103
104
	/*
105
	 * Set whether or not the mirror application should be run in verbose mode.
106
	 */
107
	public void setVerbose(boolean value) {
108
		((MirrorApplication) application).setVerbose(value);
109
	}
110
111
	public void setValidate(boolean value) {
112
		((MirrorApplication) application).setValidate(value);
113
	}
47
}
114
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/DestinationRepository.java (-2 / +6 lines)
Lines 36-43 Link Here
36
		}
36
		}
37
	}
37
	}
38
38
39
	public void setFormat(String format) {
39
	public void setFormat(String formatLocation) {
40
		descriptor.setFormat(format);
40
		try {
41
			descriptor.setFormat(URIUtil.fromString(formatLocation));
42
		} catch (URISyntaxException e) {
43
			throw new BuildException(e);
44
		}
41
	}
45
	}
42
46
43
	public void setAppend(boolean appendMode) {
47
	public void setAppend(boolean appendMode) {
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ProcessRepoTask.java (-4 / +4 lines)
Lines 21-28 Link Here
21
import org.eclipse.core.runtime.URIUtil;
21
import org.eclipse.core.runtime.URIUtil;
22
import org.eclipse.equinox.internal.p2.jarprocessor.ant.JarProcessorTask;
22
import org.eclipse.equinox.internal.p2.jarprocessor.ant.JarProcessorTask;
23
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
24
import org.eclipse.equinox.p2.internal.repository.tools.RecreateRepositoryApplication;
24
import org.eclipse.equinox.p2.internal.repository.tools.*;
25
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
25
import org.eclipse.osgi.util.NLS;
26
26
27
public class ProcessRepoTask extends Task {
27
public class ProcessRepoTask extends Task {
28
28
Lines 64-70 Link Here
64
	public void execute() throws BuildException {
64
	public void execute() throws BuildException {
65
		File file = URIUtil.toFile(repository);
65
		File file = URIUtil.toFile(repository);
66
		if (file == null || !file.exists()) {
66
		if (file == null || !file.exists()) {
67
			throw new BuildException("Repository must be local: " + repository.toString()); //$NON-NLS-1$
67
			throw new BuildException(NLS.bind(Messages.ProcessRepo_must_be_local, repository.toString()));
68
		}
68
		}
69
		if (pack | repack | signing != null) {
69
		if (pack | repack | signing != null) {
70
			if (jarProcessor == null)
70
			if (jarProcessor == null)
Lines 113-119 Link Here
113
		try {
113
		try {
114
			this.repository = URIUtil.fromString(repository);
114
			this.repository = URIUtil.fromString(repository);
115
		} catch (URISyntaxException e) {
115
		} catch (URISyntaxException e) {
116
			throw new IllegalArgumentException("Repository location (" + repository + ") must be a URL."); //$NON-NLS-1$ //$NON-NLS-2$
116
			throw new IllegalArgumentException(NLS.bind(Messages.ProcessRepo_location_not_url, repository));
117
		}
117
		}
118
	}
118
	}
119
119
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java (-56 / +63 lines)
Lines 12-27 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.net.URI;
14
import java.net.URI;
15
import java.net.URISyntaxException;
16
import java.util.*;
15
import java.util.*;
17
import org.apache.tools.ant.*;
16
import org.apache.tools.ant.*;
18
import org.apache.tools.ant.types.FileSet;
17
import org.apache.tools.ant.types.FileSet;
19
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.URIUtil;
19
import org.eclipse.core.runtime.URIUtil;
20
import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
22
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
23
import org.eclipse.equinox.internal.provisional.p2.query.Query;
23
import org.eclipse.equinox.internal.provisional.p2.query.Query;
24
import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication;
24
import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication;
25
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
26
import org.eclipse.osgi.util.NLS;
25
27
26
public abstract class AbstractRepositoryTask extends Task {
28
public abstract class AbstractRepositoryTask extends Task {
27
	protected static final String ANT_PREFIX = "${"; //$NON-NLS-1$
29
	protected static final String ANT_PREFIX = "${"; //$NON-NLS-1$
Lines 30-44 Link Here
30
	protected List sourceRepos = new ArrayList();
32
	protected List sourceRepos = new ArrayList();
31
	protected List destinations = new ArrayList();
33
	protected List destinations = new ArrayList();
32
34
33
	/*
34
	  * Create a special file set since the user specified a "source" sub-element.
35
	  */
36
	public FileSet createSource() {
37
		MyFileSet set = new MyFileSet();
38
		sourceRepos.add(set);
39
		return set;
40
	}
41
42
	protected void addMetadataSourceRepository(URI repoLocation) {
35
	protected void addMetadataSourceRepository(URI repoLocation) {
43
		application.addSourceMetadataRepository(repoLocation);
36
		application.addSourceMetadataRepository(repoLocation);
44
	}
37
	}
Lines 70-89 Link Here
70
	 * argument to specify both the artifact and metadata repositories.
63
	 * argument to specify both the artifact and metadata repositories.
71
	 */
64
	 */
72
	public void setDestination(String location) {
65
	public void setDestination(String location) {
73
		DestinationRepository metadata = new DestinationRepository();
66
		// TODO depreciate 
74
		metadata.setLocation(URIUtil.toUnencodedString(new Path(location).toFile().toURI()));
67
		DestinationRepository dest = new DestinationRepository();
75
		metadata.setKind("metadata"); //$NON-NLS-1$
68
		dest.setLocation(location);
76
		application.addDestination(metadata.getDescriptor());
69
		destinations.add(dest);
77
		destinations.add(metadata);
70
		application.addDestination(dest.getDescriptor());
78
79
		DestinationRepository artifact = new DestinationRepository();
80
		artifact.setLocation(URIUtil.toUnencodedString(new Path(location).toFile().toURI()));
81
		metadata.setKind("artifact"); //$NON-NLS-1$
82
		application.addDestination(artifact.getDescriptor());
83
		destinations.add(artifact);
84
	}
71
	}
85
72
86
	public DestinationRepository createDestination() {
73
	public DestinationRepository createDestination() {
74
		// TODO depreciate 
87
		DestinationRepository destination = new DestinationRepository();
75
		DestinationRepository destination = new DestinationRepository();
88
		destinations.add(destination);
76
		destinations.add(destination);
89
		application.addDestination(destination.getDescriptor());
77
		application.addDestination(destination.getDescriptor());
Lines 91-107 Link Here
91
	}
79
	}
92
80
93
	/*
81
	/*
94
	 * New FileSet subclass which adds an optional "location" attribute.
82
	 * Add a repository to mirror into
95
	 */
83
	 */
96
	public class MyFileSet extends FileSet {
84
	public DestinationRepository createRepository() {
97
		String location;
85
		DestinationRepository destination = new DestinationRepository();
86
		destinations.add(destination);
87
		application.addDestination(destination.getDescriptor());
88
		return destination;
89
	}
98
90
99
		public MyFileSet() {
91
	/*
100
			super();
92
	 * Add source repositories to mirror from
93
	 */
94
	public void addConfiguredSource(RepositoryList sourceList) {
95
		for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) {
96
			DestinationRepository repo = (DestinationRepository) iter.next();
97
			application.addSource(repo.getDescriptor());
101
		}
98
		}
102
99
103
		public void setLocation(String value) {
100
		for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) {
104
			this.location = value;
101
			FileSet fileSet = (FileSet) iter.next();
102
			sourceRepos.add(fileSet);
103
			// Added to the application later through prepareSourceRepos
105
		}
104
		}
106
	}
105
	}
107
106
Lines 113-146 Link Here
113
		if (sourceRepos == null || sourceRepos.isEmpty())
112
		if (sourceRepos == null || sourceRepos.isEmpty())
114
			return;
113
			return;
115
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
114
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
116
			Object next = iter.next();
115
			RepositoryFileSet fileset = (RepositoryFileSet) iter.next();
117
			if (next instanceof MyFileSet) {
116
118
				MyFileSet fileset = (MyFileSet) next;
117
			if (fileset.getRepoLocation() != null) {
119
				// determine if the user set a "location" attribute or used a fileset
118
				//TODO depreciate
120
				if (fileset.location == null) {
119
				if (!fileset.getRepoLocation().startsWith(ANT_PREFIX)) {
121
					DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
120
					application.addSourceArtifactRepository(fileset.getRepoLocation());
122
					String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
121
					application.addSourceMetadataRepository(fileset.getRepoLocation());
123
					for (int i = 0; i < 2; i++) {
122
				}
124
						for (int j = 0; j < elements[i].length; j++) {
123
			} else if (fileset.getDir() != null) {
125
							File file = new File(fileset.getDir(), elements[i][j]);
124
				DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
126
							URI uri = file.toURI();
125
				String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
127
126
				for (int i = 0; i < 2; i++) {
128
							if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
127
					for (int j = 0; j < elements[i].length; j++) {
129
								try {
128
						File file = new File(fileset.getDir(), elements[i][j]);
130
									uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
129
						URI uri = file.toURI();
131
								} catch (URISyntaxException e) {
130
132
									//?
131
						if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
133
									continue;
132
							uri = URIUtil.toJarURI(uri, null);
134
								}
133
						}
135
							}
134
						if (fileset.isBoth()) {
136
							application.addSourceArtifactRepository(uri);
135
							application.addSourceArtifactRepository(uri);
137
							application.addSourceMetadataRepository(uri);
136
							application.addSourceMetadataRepository(uri);
138
						}
137
						} else if (fileset.isArtifact())
139
					}
138
							application.addSourceArtifactRepository(uri);
140
				} else {
139
						else if (fileset.isMetadata())
141
					if (!fileset.location.startsWith(ANT_PREFIX)) {
140
							application.addSourceMetadataRepository(uri);
142
						application.addSourceArtifactRepository(fileset.location);
141
						else
143
						application.addSourceMetadataRepository(fileset.location);
142
							throw new BuildException(NLS.bind(Messages.unknown_repository_type, uri));
144
					}
143
					}
145
				}
144
				}
146
			}
145
			}
Lines 161-169 Link Here
161
			repository.query(iuQuery, collector, null);
160
			repository.query(iuQuery, collector, null);
162
161
163
			if (iu.isRequired() && collector.isEmpty())
162
			if (iu.isRequired() && collector.isEmpty())
164
				throw new BuildException("Unable to find: " + iu.toString()); //$NON-NLS-1$ 
163
				throw new BuildException(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString()));
165
			result.addAll(collector.toCollection());
164
			result.addAll(collector.toCollection());
166
		}
165
		}
167
		return result;
166
		return result;
168
	}
167
	}
168
169
	protected void log(IStatus status) {
170
		try {
171
			new AntMirrorLog(this).log(status);
172
		} catch (NoSuchMethodException e) {
173
			// Shouldn't occur
174
		}
175
	}
169
}
176
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 12-17 Link Here
12
 org.eclipse.equinox.app;version="1.0.0",
12
 org.eclipse.equinox.app;version="1.0.0",
13
 org.eclipse.equinox.internal.p2.artifact.mirror,
13
 org.eclipse.equinox.internal.p2.artifact.mirror,
14
 org.eclipse.equinox.internal.p2.artifact.repository,
14
 org.eclipse.equinox.internal.p2.artifact.repository,
15
 org.eclipse.equinox.internal.p2.artifact.repository.ant,
15
 org.eclipse.equinox.internal.p2.artifact.repository.simple,
16
 org.eclipse.equinox.internal.p2.artifact.repository.simple,
16
 org.eclipse.equinox.internal.p2.core.helpers,
17
 org.eclipse.equinox.internal.p2.core.helpers,
17
 org.eclipse.equinox.internal.p2.director,
18
 org.eclipse.equinox.internal.p2.director,
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.p2.internal.repository.tools.tasks;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
public class RepositoryList extends RepositoryFileSet {
17
	// TODO this class should extend DataType, currently RepoFileSet to support <source location="xxx" /> 
18
	List repositories = new ArrayList();
19
	List sourceFileSets = new ArrayList();
20
21
	public DestinationRepository createRepository() {
22
		DestinationRepository repo = new DestinationRepository();
23
		repositories.add(repo);
24
		return repo;
25
	}
26
27
	public RepositoryFileSet createFileSet() {
28
		RepositoryFileSet fileSet = new RepositoryFileSet();
29
		sourceFileSets.add(fileSet);
30
		return fileSet;
31
	}
32
33
	public List getRepositoryList() {
34
		return repositories;
35
	}
36
37
	public List getFileSetList() {
38
		//TODO this should eventually be removed
39
		sourceFileSets.add(this);
40
		return sourceFileSets;
41
	}
42
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.p2.internal.repository.tools;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
16
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
17
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
18
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
19
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
20
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
21
import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository;
22
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
23
import org.eclipse.osgi.util.NLS;
24
25
public class CompositeRepositoryApplication extends AbstractApplication {
26
	private List childrenToAdd = new ArrayList();
27
	private List childrenToRemove = new ArrayList();
28
	private boolean failOnExists = false;
29
30
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
31
		try {
32
			initializeRepos(new NullProgressMonitor());
33
			// load repository
34
			ICompositeRepository metadataRepo = (ICompositeRepository) destinationMetadataRepository;
35
			ICompositeRepository artifactRepo = (ICompositeRepository) destinationArtifactRepository;
36
37
			// Remove children from the Composite Repositories
38
			for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) {
39
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
40
				if (child.isArtifact() && artifactRepo != null)
41
					artifactRepo.removeChild(child.getRepoLocation());
42
				if (child.isMetadata() && metadataRepo != null)
43
					metadataRepo.removeChild(child.getRepoLocation());
44
			}
45
46
			// Add children to the Composite Repositories
47
			for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) {
48
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
49
				if (child.isArtifact() && artifactRepo != null)
50
					artifactRepo.addChild(child.getRepoLocation());
51
				if (child.isMetadata() && metadataRepo != null)
52
					metadataRepo.addChild(child.getRepoLocation());
53
			}
54
			return Status.OK_STATUS;
55
		} finally {
56
			finalizeRepositories();
57
		}
58
	}
59
60
	public void setRemoveUnknownRepositories(boolean value) {
61
		removeUnknownRepositories = value;
62
	}
63
64
	public void addChild(RepositoryDescriptor child) {
65
		childrenToAdd.add(child);
66
	}
67
68
	public void removeChild(RepositoryDescriptor child) {
69
		childrenToRemove.add(child);
70
	}
71
72
	public void setFailOnExists(boolean value) {
73
		failOnExists = value;
74
	}
75
76
	protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
77
		// remove the repo first.
78
		mgr.removeRepository(toInit.getRepoLocation());
79
80
		// first try and load to see if one already exists at that location.
81
		try {
82
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null);
83
			if (validRepositoryLocation(repository) && initDestinationRepository(repository, toInit))
84
				return repository;
85
			throw new ProvisionException(new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation())));
86
		} catch (ProvisionException e) {
87
			// re-throw the exception if we got anything other than "repo not found"
88
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND)
89
				throw e;
90
		}
91
92
		IArtifactRepository source = null;
93
		try {
94
			if (toInit.getFormat() != null)
95
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
96
		} catch (ProvisionException e) {
97
			//Ignore.
98
		}
99
		//This code assumes source has been successfully loaded before this point
100
		try {
101
			//No existing repository; create a new repository at destinationLocation but with source's attributes.
102
			IArtifactRepository repo = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : Messages.CompositeRepository_default_artifactRepo_name), IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null);
103
			initRepository(repo, toInit);
104
			return repo;
105
		} catch (IllegalStateException e) {
106
			mgr.removeRepository(toInit.getRepoLocation());
107
			throw e;
108
		}
109
	}
110
111
	protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
112
		// remove the repo first.
113
		mgr.removeRepository(toInit.getRepoLocation());
114
115
		// first try and load to see if one already exists at that location.
116
		try {
117
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null);
118
			if (!validRepositoryLocation(repository) && initDestinationRepository(repository, toInit))
119
				throw new ProvisionException(new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation())));
120
			return repository;
121
		} catch (ProvisionException e) {
122
			// re-throw the exception if we got anything other than "repo not found"
123
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND)
124
				throw e;
125
		}
126
127
		IMetadataRepository source = null;
128
		try {
129
			if (toInit.getFormat() != null)
130
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
131
		} catch (ProvisionException e) {
132
			//Ignore
133
		}
134
		//This code assumes source has been successfully loaded before this point
135
		try {
136
			//No existing repository; create a new repository at destinationLocation but with source's attributes.
137
			IMetadataRepository repo = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : Messages.CompositeRepository_default_metadataRepo_name), IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null);
138
			initRepository(repo, toInit);
139
			return repo;
140
		} catch (IllegalStateException e) {
141
			mgr.removeRepository(toInit.getRepoLocation());
142
			throw e;
143
		}
144
	}
145
146
	/*
147
	 * Determine if the repository is valid for this operation
148
	 */
149
	private boolean validRepositoryLocation(IRepository repository) throws ProvisionException {
150
		if (repository instanceof ICompositeRepository) {
151
			// if we have an already existing repository at that location, then throw an error
152
			// if the user told us to
153
			if (failOnExists)
154
				throw new ProvisionException(NLS.bind(Messages.CompositeRepository_composite_repository_exists, repository.getLocation()));
155
			RepositoryHelper.validDestinationRepository(repository);
156
			return true;
157
		}
158
		// we have a non-composite repo at this location. that is ok because we can co-exist.
159
		return true;
160
	}
161
162
	/*
163
	 * Initialize a new repository
164
	 */
165
	private void initRepository(IRepository repository, RepositoryDescriptor desc) {
166
		RepositoryHelper.validDestinationRepository(repository);
167
		if (desc.isCompressed() && !repository.getProperties().containsKey(IRepository.PROP_COMPRESSED))
168
			repository.setProperty(IRepository.PROP_COMPRESSED, String.valueOf(true));
169
	}
170
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.p2.internal.repository.tools.tasks;
12
13
import org.apache.tools.ant.types.FileSet;
14
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
15
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
16
17
public class RepositoryFileSet extends FileSet {
18
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
19
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
20
21
	private int kind = RepositoryDescriptor.TYPE_BOTH;
22
	protected String myLocation = null;
23
24
	public void setKind(String repoKind) {
25
		kind = RepositoryDescriptor.determineKind(repoKind);
26
	}
27
28
	public int getKind() {
29
		return kind;
30
	}
31
32
	public boolean isBoth() {
33
		return kind == RepositoryDescriptor.TYPE_BOTH;
34
	}
35
36
	public boolean isArtifact() {
37
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
38
	}
39
40
	public boolean isMetadata() {
41
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_METADATA;
42
	}
43
44
	public void setLocation(String value) {
45
		// TODO depreciate 
46
		myLocation = value;
47
	}
48
49
	public String getRepoLocation() {
50
		// TODO depreciate 
51
		return myLocation;
52
	}
53
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ComparatorDescription.java (+54 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2009 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.p2.internal.repository.tools.tasks;
12
13
import java.io.File;
14
import org.apache.tools.ant.types.DataType;
15
16
public class ComparatorDescription extends DataType {
17
18
	DestinationRepository baseline;
19
	String comparatorId;
20
	File comparatorLog;
21
22
	/*
23
	 * Set the baseline repository to compare to
24
	 */
25
	public void addRepository(DestinationRepository value) {
26
		this.baseline = value;
27
	}
28
29
	/*
30
	 * Set the comparator to use
31
	 */
32
	public void setComparator(String value) {
33
		comparatorId = value;
34
	}
35
36
	/*
37
	 * Set the log location for the comparator
38
	 */
39
	public void setComparatorLog(File value) {
40
		comparatorLog = value;
41
	}
42
43
	public DestinationRepository getBaseline() {
44
		return baseline;
45
	}
46
47
	public String getComparator() {
48
		return comparatorId;
49
	}
50
51
	public File getComparatorLog() {
52
		return comparatorLog;
53
	}
54
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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.p2.internal.repository.tools.tasks;
12
13
import java.util.Iterator;
14
import org.apache.tools.ant.BuildException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
17
import org.eclipse.equinox.p2.internal.repository.tools.CompositeRepositoryApplication;
18
19
public class CompositeRepositoryTask extends AbstractRepositoryTask {
20
21
	public CompositeRepositoryTask() {
22
		application = new CompositeRepositoryApplication();
23
	}
24
25
	/* (non-Javadoc)
26
	 * @see org.apache.tools.ant.Task#execute()
27
	 */
28
	public void execute() throws BuildException {
29
		try {
30
			IStatus result = application.run(null);
31
			if (result.matches(IStatus.ERROR)) {
32
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
33
			}
34
		} catch (ProvisionException e) {
35
			throw new BuildException(e);
36
		}
37
	}
38
39
	/*
40
	 * Add the listed repositories to the composite repository
41
	 */
42
	public void addConfiguredAdd(RepositoryList list) {
43
		for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) {
44
			DestinationRepository repo = (DestinationRepository) iter.next();
45
			((CompositeRepositoryApplication) application).addChild(repo.getDescriptor());
46
		}
47
	}
48
49
	/*	
50
	 * Remove the listed repositories from the composite repository
51
	 */
52
	public void addConfiguredRemove(RepositoryList list) {
53
		for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) {
54
			DestinationRepository repo = (DestinationRepository) iter.next();
55
			((CompositeRepositoryApplication) application).removeChild(repo.getDescriptor());
56
		}
57
	}
58
59
	/*
60
	 * Set whether the task should fail if the repository already exists
61
	 */
62
	public void setFailOnExists(boolean value) {
63
		((CompositeRepositoryApplication) application).setFailOnExists(value);
64
	}
65
}

Return to bug 265550