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

(-)src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java (-10 / +105 lines)
Lines 10-15 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.net.URI;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
Lines 17-32 Link Here
17
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring;
19
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring;
19
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
20
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
21
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
22
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
24
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
28
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
29
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
25
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
30
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
26
31
27
public class MirrorApplication extends AbstractApplication {
32
public class MirrorApplication extends AbstractApplication {
28
	protected SlicingOptions slicingOptions = new SlicingOptions();
33
	protected SlicingOptions slicingOptions = new SlicingOptions();
29
34
35
	private URI baseline;
36
	//private URI baseline;
37
	private String comparatorID;
38
	private boolean compare = false;
39
	private boolean failOnError = true;
40
	private boolean raw = true;
41
	private boolean verbose = false;
42
30
	public Object start(IApplicationContext context) throws Exception {
43
	public Object start(IApplicationContext context) throws Exception {
31
		run(null);
44
		run(null);
32
		return IApplication.EXIT_OK;
45
		return IApplication.EXIT_OK;
Lines 36-54 Link Here
36
		try {
49
		try {
37
			validate();
50
			validate();
38
			initializeRepos(new NullProgressMonitor());
51
			initializeRepos(new NullProgressMonitor());
52
			intializeIUs();
39
			IQueryable slice = slice(new NullProgressMonitor());
53
			IQueryable slice = slice(new NullProgressMonitor());
40
			IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
54
			if (destinationArtifactRepository != null) {
41
			if (mirrorStatus.getSeverity() == IStatus.ERROR) {
55
				IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
42
				return mirrorStatus;
56
				if (mirrorStatus.getSeverity() == IStatus.ERROR) {
57
					return mirrorStatus;
58
				}
43
			}
59
			}
44
			mirrorMetadata(slice, new NullProgressMonitor());
60
			if (destinationMetadataRepository != null)
61
				mirrorMetadata(slice, new NullProgressMonitor());
45
		} finally {
62
		} finally {
46
			finalizeRepositories();
63
			finalizeRepositories();
47
		}
64
		}
48
		return Status.OK_STATUS;
65
		return Status.OK_STATUS;
49
	}
66
	}
50
67
51
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) {
68
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException {
52
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
69
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
53
		ArrayList keys = new ArrayList(ius.size());
70
		ArrayList keys = new ArrayList(ius.size());
54
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
71
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
Lines 58-66 Link Here
58
				keys.add(iuKeys[i]);
75
				keys.add(iuKeys[i]);
59
			}
76
			}
60
		}
77
		}
61
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true);
78
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw);
79
80
		mirror.setCompare(compare);
81
		mirror.setComparatorId(comparatorID);
82
		mirror.setBaseline(initializeBaseline());
62
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
83
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
63
		return mirror.run(true, false);
84
85
		return mirror.run(failOnError, verbose);
86
	}
87
88
	private IArtifactRepository initializeBaseline() throws ProvisionException {
89
		if (baseline == null)
90
			return null;
91
		IArtifactRepositoryManager mgr = Activator.getArtifactRepositoryManager();
92
93
		if (!mgr.contains(baseline))
94
			artifactReposToRemove.add(baseline);
95
		return mgr.loadRepository(baseline, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
64
	}
96
	}
65
97
66
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
98
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
Lines 77-85 Link Here
77
	private void validate() throws ProvisionException {
109
	private void validate() throws ProvisionException {
78
		if (sourceMetadataRepositories == null)
110
		if (sourceMetadataRepositories == null)
79
			throw new ProvisionException("Need to set the source metadata repository location.");
111
			throw new ProvisionException("Need to set the source metadata repository location.");
80
		if (sourceIUs == null)
112
	}
81
			throw new ProvisionException("Mirroring root needs to be specified.");
113
82
		//TODO Check that the IU is in repo
114
	/*
115
	 * If no IUs have been specified we want to mirror them all
116
	 */
117
	private void intializeIUs() throws ProvisionException {
118
		if (sourceIUs == null || sourceIUs.isEmpty()) {
119
			sourceIUs = new ArrayList();
120
			IMetadataRepository metadataRepo = getCompositeMetadataRepository();
121
			Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
122
123
			for (Iterator iter = collector.iterator(); iter.hasNext();) {
124
				IInstallableUnit iu = (IInstallableUnit) iter.next();
125
				sourceIUs.add(iu);
126
			}
127
128
			if (collector.size() == 0) {
129
				throw new ProvisionException("No IUs specified and no IUs obtained from metadata repositories.");
130
			}
131
		} else {
132
			//TODO Check that the IU is in repo
133
		}
83
	}
134
	}
84
135
85
	private IQueryable slice(IProgressMonitor monitor) {
136
	private IQueryable slice(IProgressMonitor monitor) {
Lines 92-95 Link Here
92
	public void setSlicingOptions(SlicingOptions options) {
143
	public void setSlicingOptions(SlicingOptions options) {
93
		slicingOptions = options;
144
		slicingOptions = options;
94
	}
145
	}
146
147
	/*
148
	 * Set the location of the baseline repository. (used in comparison)
149
	 */
150
	public void setBaseline(URI baseline) {
151
		this.baseline = baseline;
152
		compare = true;
153
	}
154
155
	/*
156
	 * Set the identifier of the comparator to use.
157
	 */
158
	public void setComparatorID(String value) {
159
		comparatorID = value;
160
		compare = true;
161
	}
162
163
	/*
164
	 * Set whether or not the application should be calling a comparator when mirroring.
165
	 */
166
	public void setCompare(boolean value) {
167
		compare = value;
168
	}
169
170
	/*
171
	 * Set whether or not we should ignore errors when running the mirror application.
172
	 */
173
	public void setIgnoreErrors(boolean value) {
174
		failOnError = !value;
175
	}
176
177
	/*
178
	 * Set whether or not the the artifacts are raw.
179
	 */
180
	public void setRaw(boolean value) {
181
		raw = value;
182
	}
183
184
	/*
185
	 * Set whether or not the mirror application should be run in verbose mode.
186
	 */
187
	public void setVerbose(boolean value) {
188
		verbose = value;
189
	}
95
}
190
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java (-1 / +3 lines)
Lines 15-26 Link Here
15
15
16
public class RepositoryDescriptor {
16
public class RepositoryDescriptor {
17
17
18
	public static final int TYPE_BOTH = -1;
19
18
	private boolean compressed = true;
20
	private boolean compressed = true;
19
	private boolean append = true;
21
	private boolean append = true;
20
	private String name = null;
22
	private String name = null;
21
	private URI location = null;
23
	private URI location = null;
22
	private String format = null;
24
	private String format = null;
23
	private int kind;
25
	private int kind = TYPE_BOTH;
24
26
25
	public void setCompressed(boolean compress) {
27
	public void setCompressed(boolean compress) {
26
		compressed = compress;
28
		compressed = compress;
(-)src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java (-9 / +42 lines)
Lines 28-33 Link Here
28
28
29
	protected List sourceArtifactRepositories = new ArrayList();
29
	protected List sourceArtifactRepositories = new ArrayList();
30
	protected List sourceMetadataRepositories = new ArrayList();
30
	protected List sourceMetadataRepositories = new ArrayList();
31
	protected List sourceRepositories = new ArrayList();
31
	protected List artifactReposToRemove = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
32
	protected List metadataReposToRemove = new ArrayList();
33
	protected List metadataReposToRemove = new ArrayList();
33
	protected List sourceIUs = new ArrayList();
34
	protected List sourceIUs = new ArrayList();
Lines 79-84 Link Here
79
	}
80
	}
80
81
81
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
83
		for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
84
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
85
			if (repo.getKind() == IRepository.TYPE_ARTIFACT) {
86
				sourceArtifactRepositories.add(repo.getRepoLocation());
87
			} else if (repo.getKind() == IRepository.TYPE_METADATA) {
88
				sourceMetadataRepositories.add(repo.getRepoLocation());
89
			} else
90
				throw new ProvisionException("Repository of unknown type: " + repo.getRepoLocation());
91
92
		}
82
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
93
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
83
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
94
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
84
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
95
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
Lines 100-121 Link Here
100
		}
111
		}
101
112
102
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
113
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
103
104
	}
114
	}
105
115
106
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
116
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
107
		if (destinationRepos.size() != 2) {
117
		RepositoryDescriptor artifactRepoDescriptor = null;
108
			throw new ProvisionException("Too many or too few destination repositories.");
118
		RepositoryDescriptor metadataRepoDescriptor = null;
119
120
		Iterator iter = destinationRepos.iterator();
121
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
122
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
123
			int kind = repo.getKind();
124
			if (kind == IRepository.TYPE_ARTIFACT && artifactRepoDescriptor == null)
125
				artifactRepoDescriptor = repo;
126
			else if (kind == IRepository.TYPE_METADATA && metadataRepoDescriptor == null)
127
				metadataRepoDescriptor = repo;
128
			else if (kind == RepositoryDescriptor.TYPE_BOTH) {
129
				if (artifactRepoDescriptor == null)
130
					artifactRepoDescriptor = repo;
131
				if (metadataRepoDescriptor == null)
132
					metadataRepoDescriptor = repo;
133
			}
109
		}
134
		}
110
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
135
111
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
136
		if (artifactRepoDescriptor != null)
112
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
137
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
113
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
138
		if (metadataRepoDescriptor != null)
139
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
140
141
		if (destinationMetadataRepository == null && destinationArtifactRepository == null)
142
			throw new ProvisionException("Unable to locate a valid destiation repository.");
114
	}
143
	}
115
144
116
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
145
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
117
		try {
146
		try {
118
			if (mgr.contains(toInit.getRepoLocation()))
147
			if (!mgr.contains(toInit.getRepoLocation()))
119
				metadataReposToRemove.add(toInit.getRepoLocation());
148
				metadataReposToRemove.add(toInit.getRepoLocation());
120
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
149
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
121
			if (repository != null && repository.isModifiable()) {
150
			if (repository != null && repository.isModifiable()) {
Lines 148-154 Link Here
148
177
149
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
178
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
150
		try {
179
		try {
151
			if (mgr.contains(toInit.getRepoLocation()))
180
			if (!mgr.contains(toInit.getRepoLocation()))
152
				artifactReposToRemove.add(toInit.getRepoLocation());
181
				artifactReposToRemove.add(toInit.getRepoLocation());
153
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
182
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
154
			if (repository != null && repository.isModifiable()) {
183
			if (repository != null && repository.isModifiable()) {
Lines 212-215 Link Here
212
	public void addDestination(RepositoryDescriptor descriptor) {
241
	public void addDestination(RepositoryDescriptor descriptor) {
213
		destinationRepos.add(descriptor);
242
		destinationRepos.add(descriptor);
214
	}
243
	}
244
245
	public void addSource(RepositoryDescriptor repo) {
246
		sourceRepositories.add(repo);
247
	}
215
}
248
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java (-55 / +54 lines)
Lines 30-44 Link Here
30
	protected List sourceRepos = new ArrayList();
30
	protected List sourceRepos = new ArrayList();
31
	protected List destinations = new ArrayList();
31
	protected List destinations = new ArrayList();
32
32
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) {
33
	protected void addMetadataSourceRepository(URI repoLocation) {
43
		application.addSourceMetadataRepository(repoLocation);
34
		application.addSourceMetadataRepository(repoLocation);
44
	}
35
	}
Lines 48-53 Link Here
48
	}
39
	}
49
40
50
	/*
41
	/*
42
	 * Add source repositories to mirror from
43
	 */
44
	public void addConfiguredSource(SourceList sourceList) {
45
		for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) {
46
			DestinationRepository repo = (DestinationRepository) iter.next();
47
			application.addSource(repo.getDescriptor());
48
		}
49
50
		for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) {
51
			FileSet fileSet = (FileSet) iter.next();
52
			sourceRepos.add(fileSet);
53
			// Added to the application later through prepareSourceRepos
54
		}
55
	}
56
57
	/*
58
	 * Add a repository to mirror into
59
	 */
60
	public DestinationRepository createRepository() {
61
		DestinationRepository destination = new DestinationRepository();
62
		destinations.add(destination);
63
		application.addDestination(destination.getDescriptor());
64
		return destination;
65
	}
66
67
	/*
51
	 * Create an object to hold IU information since the user specified an "iu" sub-element.
68
	 * Create an object to hold IU information since the user specified an "iu" sub-element.
52
	 */
69
	 */
53
	public Object createIu() {
70
	public Object createIu() {
Lines 83-110 Link Here
83
		destinations.add(artifact);
100
		destinations.add(artifact);
84
	}
101
	}
85
102
86
	public DestinationRepository createDestination() {
87
		DestinationRepository destination = new DestinationRepository();
88
		destinations.add(destination);
89
		application.addDestination(destination.getDescriptor());
90
		return destination;
91
	}
92
93
	/*
94
	 * New FileSet subclass which adds an optional "location" attribute.
95
	 */
96
	public class MyFileSet extends FileSet {
97
		String location;
98
99
		public MyFileSet() {
100
			super();
101
		}
102
103
		public void setLocation(String value) {
104
			this.location = value;
105
		}
106
	}
107
108
	/*
103
	/*
109
	 * If the user specified some source repositories via sub-elements
104
	 * If the user specified some source repositories via sub-elements
110
	 * then add them to the transformer for consideration.
105
	 * then add them to the transformer for consideration.
Lines 113-145 Link Here
113
		if (sourceRepos == null || sourceRepos.isEmpty())
108
		if (sourceRepos == null || sourceRepos.isEmpty())
114
			return;
109
			return;
115
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
110
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
116
			Object next = iter.next();
111
			RepositoryFileSet fileset = (RepositoryFileSet) iter.next();
117
			if (next instanceof MyFileSet) {
112
118
				MyFileSet fileset = (MyFileSet) next;
113
			DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
119
				// determine if the user set a "location" attribute or used a fileset
114
			String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
120
				if (fileset.location == null) {
115
			for (int i = 0; i < 2; i++) {
121
					DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
116
				for (int j = 0; j < elements[i].length; j++) {
122
					String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
117
					File file = new File(fileset.getDir(), elements[i][j]);
123
					for (int i = 0; i < 2; i++) {
118
					URI uri = file.toURI();
124
						for (int j = 0; j < elements[i].length; j++) {
119
125
							File file = new File(fileset.getDir(), elements[i][j]);
120
					if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
126
							URI uri = file.toURI();
121
						try {
127
122
							uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
128
							if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
123
						} catch (URISyntaxException e) {
129
								try {
124
							//?
130
									uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
125
							continue;
131
								} catch (URISyntaxException e) {
126
						}
132
									//?
127
					}
133
									continue;
128
					switch (fileset.getKind()) {
134
								}
129
						case RepositoryFileSet.TYPE_BOTH :
135
							}
136
							application.addSourceArtifactRepository(uri);
130
							application.addSourceArtifactRepository(uri);
137
							application.addSourceMetadataRepository(uri);
131
							application.addSourceMetadataRepository(uri);
138
						}
132
							break;
133
						case RepositoryFileSet.TYPE_ARTIFACT :
134
							application.addSourceArtifactRepository(uri);
135
							break;
136
						case RepositoryFileSet.TYPE_METADATA :
137
							application.addSourceMetadataRepository(uri);
138
							break;
139
						default :
140
							throw new BuildException("Unknown repository type for: " + uri);
139
					}
141
					}
140
				} else {
141
					application.addSourceArtifactRepository(fileset.location);
142
					application.addSourceMetadataRepository(fileset.location);
143
				}
142
				}
144
			}
143
			}
145
		}
144
		}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java (+48 lines)
Lines 10-18 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.net.URISyntaxException;
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.core.runtime.URIUtil;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
17
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
19
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
18
20
Lines 44-47 Link Here
44
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
46
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
45
		return options;
47
		return options;
46
	}
48
	}
49
50
	/*
51
	 * Set the location of the baseline repository. (used in comparison)
52
	 */
53
	public void setBaseline(String value) {
54
		try {
55
			((MirrorApplication) application).setBaseline(URIUtil.fromString(value));
56
		} catch (URISyntaxException e) {
57
			throw new BuildException(e);
58
		}
59
	}
60
61
	/*
62
	 * Set the identifier of the comparator to use.
63
	 */
64
	public void setComparatorID(String value) {
65
		((MirrorApplication) application).setComparatorID(value);
66
	}
67
68
	/*
69
	 * Set whether or not the application should be calling a comparator when mirroring.
70
	 */
71
	public void setCompare(boolean value) {
72
		((MirrorApplication) application).setCompare(value);
73
	}
74
75
	/*
76
	 * Set whether or not we should ignore errors when running the mirror application.
77
	 */
78
	public void setIgnoreErrors(boolean value) {
79
		((MirrorApplication) application).setIgnoreErrors(value);
80
	}
81
82
	/*
83
	 * Set whether or not the the artifacts are raw.
84
	 */
85
	public void setRaw(boolean value) {
86
		((MirrorApplication) application).setRaw(value);
87
	}
88
89
	/*
90
	 * Set whether or not the mirror application should be run in verbose mode.
91
	 */
92
	public void setVerbose(boolean value) {
93
		((MirrorApplication) application).setVerbose(value);
94
	}
47
}
95
}
(-)plugin.xml (+12 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.ModifyRepositoryChildrenTask"
21
            library="lib/repository-tools-ant.jar"
22
            name="p2.modify.composite.repository.children">
23
      </antTask>
24
25
     <antTask
26
            class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CreateCompositeRepositoryTask"
27
            library="lib/repository-tools-ant.jar"
28
            name="p2.create.composite.repository">
29
      </antTask>
18
      
30
      
19
      <antTask
31
      <antTask
20
			library="lib/repository-tools-ant.jar"
32
			library="lib/repository-tools-ant.jar"
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepoChildrenTask.java (+58 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.ModifyCompositeApplication;
18
19
public class ModifyRepoChildrenTask extends AbstractRepositoryTask {
20
21
	public ModifyRepoChildrenTask() {
22
		application = new ModifyCompositeApplication();
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
			((ModifyCompositeApplication) 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
			((ModifyCompositeApplication) application).removeChild(repo.getDescriptor());
56
		}
57
	}
58
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java (+64 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
2
3
import java.util.Iterator;
4
import org.apache.tools.ant.BuildException;
5
import org.apache.tools.ant.Task;
6
import org.eclipse.core.runtime.IStatus;
7
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
8
import org.eclipse.equinox.p2.internal.repository.tools.CreateCompositeRepositoryApplication;
9
import org.eclipse.equinox.p2.internal.repository.tools.ModifyCompositeApplication;
10
11
public class CreateCompositeRepositoryTask extends Task {
12
	CreateCompositeRepositoryApplication createApp;
13
	ModifyCompositeApplication modifyApp;
14
15
	public CreateCompositeRepositoryTask() {
16
		createApp = new CreateCompositeRepositoryApplication();
17
		modifyApp = new ModifyCompositeApplication();
18
	}
19
20
	/* (non-Javadoc)
21
	 * @see org.apache.tools.ant.Task#execute()
22
	 */
23
	public void execute() throws BuildException {
24
		try {
25
			IStatus result = createApp.run(null);
26
			if (result.matches(IStatus.ERROR)) {
27
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
28
			}
29
			result = modifyApp.run(null);
30
			if (result.matches(IStatus.ERROR)) {
31
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
32
			}
33
		} catch (ProvisionException e) {
34
			throw new BuildException(e);
35
		}
36
	}
37
38
	/*
39
	 * Add a repository to create
40
	 */
41
	public DestinationRepository createRepository() {
42
		DestinationRepository repo = new DestinationRepository();
43
		createApp.addRepository(repo.getDescriptor());
44
		modifyApp.addDestination(repo.getDescriptor());
45
		return repo;
46
	}
47
48
	/*
49
	 * Set whether the task should fail if the repository already exists
50
	 */
51
	public void setFailOnExsists(boolean value) {
52
		createApp.setFailOnExists(value);
53
	}
54
55
	/*
56
	 * Add a list of child repositories to add to the newly created repository
57
	 */
58
	public void addConfiguredAdd(RepositoryList addList) {
59
		for (Iterator iter = addList.getRepositoryList().iterator(); iter.hasNext();) {
60
			DestinationRepository repo = (DestinationRepository) iter.next();
61
			modifyApp.addChild(repo.getDescriptor());
62
		}
63
	}
64
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java (+161 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools;
2
3
import java.net.URISyntaxException;
4
import java.util.*;
5
import org.apache.tools.ant.BuildException;
6
import org.eclipse.core.runtime.*;
7
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
8
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
9
import org.eclipse.equinox.internal.p2.metadata.repository.Activator;
10
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
11
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
12
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
13
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
14
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
17
18
public class CreateCompositeRepositoryApplication {
19
20
	private String artifactName = "Composite Artifact Repository";
21
	private String metadataName = "Composite Artifact Repository";
22
	private List repositories = new ArrayList();
23
	private boolean failOnExists = false;
24
	private IArtifactRepositoryManager artifactManager;
25
	private IMetadataRepositoryManager metadataManager;
26
27
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
28
29
		MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$
30
		status.add(Status.OK_STATUS);
31
		for (Iterator iterator = repositories.iterator(); iterator.hasNext();)
32
			status.add(createRepository((RepositoryDescriptor) iterator.next()));
33
34
		return status;
35
	}
36
37
	public void addRepository(RepositoryDescriptor repo) {
38
		repositories.add(repo);
39
	}
40
41
	public void setFailOnExists(boolean value) {
42
		failOnExists = value;
43
	}
44
45
	private IStatus createRepository(RepositoryDescriptor repo) throws ProvisionException {
46
		if (repo.getKind() == IRepository.TYPE_ARTIFACT)
47
			return createArtifactRepository(repo);
48
		else if (repo.getKind() == IRepository.TYPE_METADATA)
49
			return createMetadataRepository(repo);
50
		else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) {
51
			MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$
52
			status.add(createArtifactRepository(repo));
53
			status.add(createMetadataRepository(repo));
54
			return status;
55
		} else
56
			throw new ProvisionException("Repository is of an unknown kind: " + repo.getRepoLocation());
57
	}
58
59
	private IStatus createArtifactRepository(RepositoryDescriptor repo) throws ProvisionException {
60
		if (artifactManager == null) {
61
			artifactManager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
62
			if (artifactManager == null)
63
				throw new ProvisionException("Unable to obtain metadata repository manager.");
64
		}
65
66
		boolean repoKnown = artifactManager.contains(repo.getRepoLocation());
67
68
		// remove the repo first.
69
		artifactManager.removeRepository(repo.getRepoLocation());
70
71
		// first try and load to see if one already exists at that location.
72
		// if we have an already existing repository at that location, then throw an error
73
		// if the user told us to
74
		try {
75
			IArtifactRepository repository = artifactManager.loadRepository(repo.getRepoLocation(), null);
76
			if (repository instanceof CompositeArtifactRepository) {
77
				// Remove the repository if it wasn't previously known
78
				if (!repoKnown)
79
					artifactManager.removeRepository(repo.getRepoLocation());
80
				if (failOnExists)
81
					throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation());
82
				return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation());
83
			} else {
84
				// we have a non-composite repo at this location. that is ok because we can co-exist.
85
			}
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 (repo.getFormat() != null)
95
				source = artifactManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null);
96
		} catch (ProvisionException e) {
97
			//Ignore.
98
		} catch (URISyntaxException e) {
99
			//Ignore
100
		}
101
		//This code assumes source has been successfully loaded before this point
102
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
103
		// TODO for now create a Simple repo by default.
104
105
		IArtifactRepository result = null;
106
		result = artifactManager.createRepository(repo.getRepoLocation(), repo.getName() != null ? repo.getName() : (source != null ? source.getName() : artifactName), IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null);
107
		if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
108
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
109
110
		return Status.OK_STATUS;
111
	}
112
113
	private IStatus createMetadataRepository(RepositoryDescriptor repo) throws ProvisionException {
114
		if (metadataManager == null) {
115
			metadataManager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
116
			if (metadataManager == null)
117
				throw new ProvisionException("Unable to obtain metadata repository manager.");
118
		}
119
120
		boolean repoKnown = metadataManager.contains(repo.getRepoLocation());
121
		// remove the repo first.
122
		metadataManager.removeRepository(repo.getRepoLocation());
123
124
		// first try and load to see if one already exists at that location.
125
		// if we have an already existing repository at that location, then throw an error
126
		// if the user told us to
127
		try {
128
			IMetadataRepository repository = metadataManager.loadRepository(repo.getRepoLocation(), null);
129
			if (repository instanceof CompositeMetadataRepository) {
130
				if (!repoKnown)
131
					metadataManager.removeRepository(repo.getRepoLocation());
132
				if (failOnExists)
133
					throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation());
134
				return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation());
135
			} else {
136
				// we have a non-composite repo at this location. that is ok because we can co-exist.
137
			}
138
		} catch (ProvisionException e) {
139
			// re-throw the exception if we got anything other than "repo not found"
140
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND)
141
				throw e;
142
		}
143
144
		IMetadataRepository source = null;
145
		try {
146
			if (repo.getFormat() != null)
147
				source = metadataManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null);
148
		} catch (ProvisionException e) {
149
			//Ignore.
150
		} catch (URISyntaxException e) {
151
			//Ignore
152
		}
153
		//This code assumes source has been successfully loaded before this point
154
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
155
		IMetadataRepository result = metadataManager.createRepository(repo.getRepoLocation(), repo.getName() != null ? repo.getName() : (source != null ? source.getName() : metadataName), IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null);
156
		if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
157
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
158
159
		return Status.OK_STATUS;
160
	}
161
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java (+22 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
2
3
import org.apache.tools.ant.types.FileSet;
4
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
5
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
6
7
public class RepositoryFileSet extends FileSet {
8
	public final static int TYPE_BOTH = RepositoryDescriptor.TYPE_BOTH;
9
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
10
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
11
12
	int kind = TYPE_BOTH;
13
14
	public void setKind(String kind) {
15
		// parse it
16
	}
17
18
	public int getKind() {
19
		return kind;
20
	}
21
22
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java (+29 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
import org.apache.tools.ant.types.DataType;
16
17
public class RepositoryList extends DataType {
18
	List repositories = new ArrayList();
19
20
	public DestinationRepository createRepository() {
21
		DestinationRepository repo = new DestinationRepository();
22
		repositories.add(repo);
23
		return repo;
24
	}
25
26
	public List getRepositoryList() {
27
		return repositories;
28
	}
29
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SourceList.java (+39 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
import org.apache.tools.ant.types.DataType;
16
import org.apache.tools.ant.types.FileSet;
17
18
public class SourceList extends DataType {
19
	List repositories = new ArrayList();
20
	List sourceFileSets = new ArrayList();
21
22
	public DestinationRepository addRepository() {
23
		DestinationRepository repo = new DestinationRepository();
24
		repositories.add(repo);
25
		return repo;
26
	}
27
28
	public void addFileSet(FileSet files) {
29
		sourceFileSets.add(files);
30
	}
31
32
	public List getRepositoryList() {
33
		return repositories;
34
	}
35
36
	public List getFileSetList() {
37
		return sourceFileSets;
38
	}
39
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeApplication.java (+69 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.artifact.repository.CompositeArtifactRepository;
16
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
17
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
19
20
public class ModifyCompositeApplication extends AbstractApplication {
21
	private List childrenToAdd = new ArrayList();
22
	private List childrenToRemove = new ArrayList();
23
24
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
25
		try {
26
			initializeRepos(new NullProgressMonitor());
27
			// load repository
28
			CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) destinationMetadataRepository;
29
			CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) destinationArtifactRepository;
30
31
			// Remove children from the Composite Repositories
32
			for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) {
33
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
34
				if (child.getKind() == IRepository.TYPE_ARTIFACT)
35
					artifactRepo.removeChild(child.getRepoLocation());
36
				else if (child.getKind() == IRepository.TYPE_METADATA)
37
					metadataRepo.removeChild(child.getRepoLocation());
38
				else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) {
39
					artifactRepo.removeChild(child.getRepoLocation());
40
					metadataRepo.removeChild(child.getRepoLocation());
41
				}
42
			}
43
44
			// Add children to the Composite Repositories
45
			for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) {
46
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
47
				if (child.getKind() == IRepository.TYPE_ARTIFACT)
48
					artifactRepo.addChild(child.getRepoLocation());
49
				else if (child.getKind() == IRepository.TYPE_METADATA)
50
					metadataRepo.addChild(child.getRepoLocation());
51
				else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) {
52
					artifactRepo.addChild(child.getRepoLocation());
53
					metadataRepo.addChild(child.getRepoLocation());
54
				}
55
			}
56
			return null;
57
		} finally {
58
			finalizeRepositories();
59
		}
60
	}
61
62
	public void addChild(RepositoryDescriptor child) {
63
		childrenToAdd.add(child);
64
	}
65
66
	public void removeChild(RepositoryDescriptor child) {
67
		childrenToRemove.add(child);
68
	}
69
}

Return to bug 265550