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_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/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/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/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 (-61 / +80 lines)
Lines 16-27 Link Here
16
import java.util.*;
16
import java.util.*;
17
import org.apache.tools.ant.*;
17
import org.apache.tools.ant.*;
18
import org.apache.tools.ant.types.FileSet;
18
import org.apache.tools.ant.types.FileSet;
19
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.URIUtil;
20
import org.eclipse.core.runtime.URIUtil;
21
import org.eclipse.equinox.internal.p2.artifact.repository.ant.AntMirrorLog;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
23
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
23
import org.eclipse.equinox.internal.provisional.p2.query.Query;
24
import org.eclipse.equinox.internal.provisional.p2.query.Query;
24
import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication;
25
import org.eclipse.equinox.p2.internal.repository.tools.*;
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-50 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
		RepositoryDescriptor source = new RepositoryDescriptor();
37
		source.setLocation(repoLocation);
38
		source.setKind(RepositoryDescriptor.KIND_METADATA);
39
		application.addSource(source);
44
	}
40
	}
45
41
46
	protected void addArtifactSourceRepository(URI repoLocation) {
42
	protected void addArtifactSourceRepository(URI repoLocation) {
47
		application.addSourceArtifactRepository(repoLocation);
43
		RepositoryDescriptor source = new RepositoryDescriptor();
44
		source.setLocation(repoLocation);
45
		source.setKind(RepositoryDescriptor.KIND_ARTIFACT);
46
		application.addSource(source);
48
	}
47
	}
49
48
50
	/*
49
	/*
Lines 61-68 Link Here
61
	 * argument to specify both the artifact and metadata repositories.
60
	 * argument to specify both the artifact and metadata repositories.
62
	 */
61
	 */
63
	public void setSource(String location) {
62
	public void setSource(String location) {
64
		application.addSourceArtifactRepository(location);
63
		RepositoryDescriptor source = new RepositoryDescriptor();
65
		application.addSourceMetadataRepository(location);
64
		try {
65
			source.setLocation(URIUtil.fromString(location));
66
			application.addSource(source);
67
		} catch (URISyntaxException e) {
68
			throw new BuildException(e);
69
		}
66
	}
70
	}
67
71
68
	/*
72
	/*
Lines 70-89 Link Here
70
	 * argument to specify both the artifact and metadata repositories.
74
	 * argument to specify both the artifact and metadata repositories.
71
	 */
75
	 */
72
	public void setDestination(String location) {
76
	public void setDestination(String location) {
73
		DestinationRepository metadata = new DestinationRepository();
77
		// TODO depreciate 
74
		metadata.setLocation(URIUtil.toUnencodedString(new Path(location).toFile().toURI()));
78
		DestinationRepository dest = new DestinationRepository();
75
		metadata.setKind("metadata"); //$NON-NLS-1$
79
		dest.setLocation(location);
76
		application.addDestination(metadata.getDescriptor());
80
		destinations.add(dest);
77
		destinations.add(metadata);
81
		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
	}
82
	}
85
83
86
	public DestinationRepository createDestination() {
84
	public DestinationRepository createDestination() {
85
		// TODO depreciate 
87
		DestinationRepository destination = new DestinationRepository();
86
		DestinationRepository destination = new DestinationRepository();
88
		destinations.add(destination);
87
		destinations.add(destination);
89
		application.addDestination(destination.getDescriptor());
88
		application.addDestination(destination.getDescriptor());
Lines 91-107 Link Here
91
	}
90
	}
92
91
93
	/*
92
	/*
94
	 * New FileSet subclass which adds an optional "location" attribute.
93
	 * Add a repository to mirror into
95
	 */
94
	 */
96
	public class MyFileSet extends FileSet {
95
	public DestinationRepository createRepository() {
97
		String location;
96
		DestinationRepository destination = new DestinationRepository();
97
		destinations.add(destination);
98
		application.addDestination(destination.getDescriptor());
99
		return destination;
100
	}
98
101
99
		public MyFileSet() {
102
	/*
100
			super();
103
	 * Add source repositories to mirror from
104
	 */
105
	public void addConfiguredSource(RepositoryList sourceList) {
106
		for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) {
107
			DestinationRepository repo = (DestinationRepository) iter.next();
108
			application.addSource(repo.getDescriptor());
101
		}
109
		}
102
110
103
		public void setLocation(String value) {
111
		for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) {
104
			this.location = value;
112
			FileSet fileSet = (FileSet) iter.next();
113
			sourceRepos.add(fileSet);
114
			// Added to the application later through prepareSourceRepos
105
		}
115
		}
106
	}
116
	}
107
117
Lines 113-150 Link Here
113
		if (sourceRepos == null || sourceRepos.isEmpty())
123
		if (sourceRepos == null || sourceRepos.isEmpty())
114
			return;
124
			return;
115
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
125
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
116
			Object next = iter.next();
126
			RepositoryFileSet fileset = (RepositoryFileSet) iter.next();
117
			if (next instanceof MyFileSet) {
127
118
				MyFileSet fileset = (MyFileSet) next;
128
			if (fileset.getRepoLocation() != null) {
119
				// determine if the user set a "location" attribute or used a fileset
129
				//TODO depreciate
120
				if (fileset.location == null) {
130
				if (!fileset.getRepoLocation().startsWith(ANT_PREFIX)) {
121
					DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
131
					addArtifactSourceRepository(fileset.getRepoLocationURI());
122
					String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
132
					addMetadataSourceRepository(fileset.getRepoLocationURI());
123
					for (int i = 0; i < 2; i++) {
133
				}
124
						for (int j = 0; j < elements[i].length; j++) {
134
			} else if (fileset.getDir() != null) {
125
							File file = new File(fileset.getDir(), elements[i][j]);
135
				DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
126
							URI uri = file.toURI();
136
				String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
127
137
				for (int i = 0; i < 2; i++) {
128
							if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
138
					for (int j = 0; j < elements[i].length; j++) {
129
								try {
139
						File file = new File(fileset.getDir(), elements[i][j]);
130
									uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
140
						URI uri = file.toURI();
131
								} catch (URISyntaxException e) {
141
132
									//?
142
						if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
133
									continue;
143
							uri = URIUtil.toJarURI(uri, null);
134
								}
135
							}
136
							application.addSourceArtifactRepository(uri);
137
							application.addSourceMetadataRepository(uri);
138
						}
144
						}
139
					}
145
						if (fileset.isBoth()) {
140
				} else {
146
							addArtifactSourceRepository(uri);
141
					if (!fileset.location.startsWith(ANT_PREFIX)) {
147
							addMetadataSourceRepository(uri);
142
						application.addSourceArtifactRepository(fileset.location);
148
						} else if (fileset.isArtifact())
143
						application.addSourceMetadataRepository(fileset.location);
149
							addArtifactSourceRepository(uri);
150
						else if (fileset.isMetadata())
151
							addMetadataSourceRepository(uri);
152
						else
153
							throw new BuildException(NLS.bind(Messages.unknown_repository_type, uri));
144
					}
154
					}
145
				}
155
				}
146
			}
156
			}
147
		}
157
		}
158
		sourceRepos.clear();
148
	}
159
	}
149
160
150
	protected List prepareIUs() {
161
	protected List prepareIUs() {
Lines 161-169 Link Here
161
			repository.query(iuQuery, collector, null);
172
			repository.query(iuQuery, collector, null);
162
173
163
			if (iu.isRequired() && collector.isEmpty())
174
			if (iu.isRequired() && collector.isEmpty())
164
				throw new BuildException("Unable to find: " + iu.toString()); //$NON-NLS-1$ 
175
				throw new BuildException(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString()));
165
			result.addAll(collector.toCollection());
176
			result.addAll(collector.toCollection());
166
		}
177
		}
167
		return result;
178
		return result;
168
	}
179
	}
180
181
	protected void log(IStatus status) {
182
		try {
183
			new AntMirrorLog(this).log(status);
184
		} catch (NoSuchMethodException e) {
185
			// Shouldn't occur
186
		}
187
	}
169
}
188
}
(-)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 (-106 / +131 lines)
Lines 10-19 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.net.*;
14
import java.net.URISyntaxException;
15
import java.util.*;
14
import java.util.*;
16
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
17
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
18
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
18
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
19
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
19
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
Lines 22-34 Link Here
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
25
import org.eclipse.equinox.internal.provisional.p2.repository.*;
26
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
26
import org.eclipse.osgi.util.NLS;
27
27
28
public abstract class AbstractApplication {
28
public abstract class AbstractApplication {
29
	protected boolean removeAddedRepositories = true;
29
30
30
	protected List sourceArtifactRepositories = new ArrayList();
31
	protected List sourceRepositories = new ArrayList(); //List of repository descriptors
31
	protected List sourceMetadataRepositories = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
33
	protected List metadataReposToRemove = new ArrayList();
33
	protected List metadataReposToRemove = new ArrayList();
34
	protected List sourceIUs = new ArrayList();
34
	protected List sourceIUs = new ArrayList();
Lines 40-131 Link Here
40
	private CompositeMetadataRepository compositeMetadataRepository = null;
40
	private CompositeMetadataRepository compositeMetadataRepository = null;
41
	private CompositeArtifactRepository compositeArtifactRepository = null;
41
	private CompositeArtifactRepository compositeArtifactRepository = null;
42
42
43
	public void addSourceMetadataRepository(String location) {
44
		URI uri = Activator.getURI(location);
45
		if (uri != null)
46
			sourceMetadataRepositories.add(RepositoryHelper.localRepoURIHelper(uri));
47
	}
48
49
	public void addSourceMetadataRepository(URI location) {
50
		if (location != null)
51
			sourceMetadataRepositories.add(RepositoryHelper.localRepoURIHelper(location));
52
	}
53
54
	public List getSourceMetadataRepositories() {
55
		return sourceMetadataRepositories;
56
	}
57
58
	public void addSourceArtifactRepository(String location) {
59
		URI uri = Activator.getURI(location);
60
		if (uri != null)
61
			sourceArtifactRepositories.add(RepositoryHelper.localRepoURIHelper(uri));
62
	}
63
64
	public void addSourceArtifactRepository(URI location) {
65
		if (location != null)
66
			sourceArtifactRepositories.add(RepositoryHelper.localRepoURIHelper(location));
67
	}
68
69
	public void setSourceIUs(List ius) {
43
	public void setSourceIUs(List ius) {
70
		sourceIUs = ius;
44
		sourceIUs = ius;
71
	}
45
	}
72
46
73
	protected void finalizeRepositories() throws ProvisionException {
47
	protected void finalizeRepositories() throws ProvisionException {
74
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
48
		if (removeAddedRepositories) {
75
		for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
49
			IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
76
			artifactRepositoryManager.removeRepository((URI) iter.next());
50
			for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
77
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
51
				artifactRepositoryManager.removeRepository((URI) iter.next());
78
		for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
52
			IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
79
			metadataRepositoryManager.removeRepository((URI) iter.next());
53
			for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
54
				metadataRepositoryManager.removeRepository((URI) iter.next());
55
		}
80
	}
56
	}
81
57
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
58
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
83
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
59
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
86
				URI repoLocation = (URI) iter.next();
87
				if (!artifactRepositoryManager.contains(repoLocation))
88
					artifactReposToRemove.add(repoLocation);
89
				artifactRepositoryManager.loadRepository(repoLocation, 0, progress);
90
			}
91
		}
92
93
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
60
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
94
		if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) {
61
		URI curLocation = null;
95
			for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) {
62
		try {
96
				URI repoLocation = (URI) iter.next();
63
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
97
				if (!metadataRepositoryManager.contains(repoLocation))
64
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
98
					metadataReposToRemove.add(repoLocation);
65
				curLocation = repo.getRepoLocation();
99
				metadataRepositoryManager.loadRepository(repoLocation, 0, progress);
66
				if (repo.isBoth()) {
67
					addRepository(artifactRepositoryManager, curLocation, 0, progress);
68
					addRepository(metadataRepositoryManager, curLocation, 0, progress);
69
				} else if (repo.isArtifact())
70
					addRepository(artifactRepositoryManager, curLocation, 0, progress);
71
				else if (repo.isMetadata())
72
					addRepository(metadataRepositoryManager, curLocation, 0, progress);
73
				else
74
					throw new ProvisionException(NLS.bind(Messages.unknown_repository_type, repo.getRepoLocation()));
75
			}
76
		} catch (ProvisionException e) {
77
			if (e.getCause() instanceof MalformedURLException) {
78
				throw new ProvisionException(NLS.bind(Messages.exception_invalidSource, curLocation), e);
100
			}
79
			}
80
			throw e;
101
		}
81
		}
102
103
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
82
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
83
	}
104
84
85
	//Helper to add a repository. It takes care of adding the repos to the deletion list and loading it 
86
	protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
87
		if (!manager.contains(location))
88
			metadataReposToRemove.add(location);
89
		return manager.loadRepository(location, flags, monitor);
90
	}
91
92
	//Helper to add a repository. It takes care of adding the repos to the deletion list and loading it
93
	protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
94
		if (!manager.contains(location))
95
			artifactReposToRemove.add(location);
96
		return manager.loadRepository(location, flags, monitor);
105
	}
97
	}
106
98
107
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
99
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
108
		if (destinationRepos.size() != 2) {
100
		RepositoryDescriptor artifactRepoDescriptor = null;
109
			throw new ProvisionException("Too many or too few destination repositories.");
101
		RepositoryDescriptor metadataRepoDescriptor = null;
102
103
		Iterator iter = destinationRepos.iterator();
104
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
105
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
106
			if (repo.isArtifact() && artifactRepoDescriptor == null)
107
				artifactRepoDescriptor = repo;
108
			if (repo.isMetadata() && metadataRepoDescriptor == null)
109
				metadataRepoDescriptor = repo;
110
		}
110
		}
111
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
111
112
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
112
		if (artifactRepoDescriptor != null)
113
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
113
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
114
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
114
		if (metadataRepoDescriptor != null)
115
	}
115
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
116
116
117
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
117
		if (destinationMetadataRepository == null && destinationArtifactRepository == null)
118
		try {
118
			throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations);
119
			if (!mgr.contains(toInit.getRepoLocation()))
119
	}
120
				metadataReposToRemove.add(toInit.getRepoLocation());
120
121
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
121
	protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
122
			if (repository != null && repository.isModifiable()) {
122
		try {
123
				if (toInit.getName() != null)
123
			IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
124
					repository.setName(toInit.getName());
124
			if (initDestinationRepository(repository, toInit))
125
				if (!toInit.isAppend())
126
					repository.removeAll();
127
				return repository;
125
				return repository;
128
			}
129
		} catch (ProvisionException e) {
126
		} catch (ProvisionException e) {
130
			//fall through and create a new repository below
127
			//fall through and create a new repository below
131
		}
128
		}
Lines 133-183 Link Here
133
		IMetadataRepository source = null;
130
		IMetadataRepository source = null;
134
		try {
131
		try {
135
			if (toInit.getFormat() != null)
132
			if (toInit.getFormat() != null)
136
				source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null);
133
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
137
		} catch (ProvisionException e) {
134
		} catch (ProvisionException e) {
138
			//Ignore.
135
			//Ignore.
139
		} catch (URISyntaxException e) {
140
			//Ignore
141
		}
136
		}
142
		//This code assumes source has been successfully loaded before this point
137
		//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.
138
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
144
		IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null);
139
		try {
145
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
140
			IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null);
146
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
141
			if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
147
		return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result);
142
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
148
	}
143
			return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result);
149
144
		} catch (UnsupportedOperationException e) {
150
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
145
			throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
151
		try {
146
		}
152
			if (!mgr.contains(toInit.getRepoLocation()))
147
	}
153
				artifactReposToRemove.add(toInit.getRepoLocation());
148
154
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
149
	protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
155
			if (repository != null && repository.isModifiable()) {
150
		try {
156
				if (toInit.getName() != null)
151
			IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
157
					repository.setName(toInit.getName());
152
			if (initDestinationRepository(repository, toInit))
158
				if (!toInit.isAppend())
159
					repository.removeAll();
160
				return repository;
153
				return repository;
161
			}
162
		} catch (ProvisionException e) {
154
		} catch (ProvisionException e) {
163
			//fall through and create a new repository below
155
			//fall through and create a new repository below
164
		}
156
		}
165
		IArtifactRepository source = null;
157
		IArtifactRepository source = null;
166
		try {
158
		try {
167
			if (toInit.getFormat() != null)
159
			if (toInit.getFormat() != null)
168
				source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null);
160
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
169
		} catch (ProvisionException e) {
161
		} catch (ProvisionException e) {
170
			//Ignore.
162
			//Ignore.
171
		} catch (URISyntaxException e) {
172
			//Ignore
173
		}
163
		}
174
		//This code assumes source has been successfully loaded before this point
164
		//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.
165
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
176
		// TODO for now create a Simple repo by default.
166
		// TODO for now create a Simple repo by default.
177
		IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null);
167
		try {
178
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
168
			IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null);
179
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
169
			if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
180
		return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result);
170
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
171
			return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result);
172
		} catch (UnsupportedOperationException e) {
173
			throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
174
		}
175
	}
176
177
	protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) {
178
		if (repository != null && repository.isModifiable()) {
179
			if (descriptor.getName() != null)
180
				repository.setName(descriptor.getName());
181
			if (repository instanceof ICompositeRepository && !descriptor.isAppend())
182
				((ICompositeRepository) repository).removeAllChildren();
183
			else if (repository instanceof IMetadataRepository && !descriptor.isAppend())
184
				((IMetadataRepository) repository).removeAll();
185
			else if (repository instanceof IArtifactRepository && !descriptor.isAppend())
186
				((IArtifactRepository) repository).removeAll();
187
			return true;
188
		}
189
		return false;
181
	}
190
	}
182
191
183
	public IMetadataRepository getCompositeMetadataRepository() {
192
	public IMetadataRepository getCompositeMetadataRepository() {
Lines 187-194 Link Here
187
			} catch (URISyntaxException e) {
196
			} catch (URISyntaxException e) {
188
				//Can't happen
197
				//Can't happen
189
			}
198
			}
190
			for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) {
199
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
191
				compositeMetadataRepository.addChild((URI) iter.next());
200
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
201
				if (repo.isMetadata())
202
					compositeMetadataRepository.addChild(repo.getRepoLocation());
192
			}
203
			}
193
		}
204
		}
194
		return compositeMetadataRepository;
205
		return compositeMetadataRepository;
Lines 197-216 Link Here
197
	public IArtifactRepository getCompositeArtifactRepository() {
208
	public IArtifactRepository getCompositeArtifactRepository() {
198
		if (compositeArtifactRepository == null) {
209
		if (compositeArtifactRepository == null) {
199
			try {
210
			try {
200
				compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$
211
				compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$
201
			} catch (URISyntaxException e) {
212
			} catch (URISyntaxException e) {
202
				//Can't happen
213
				//Can't happen
203
			}
214
			}
204
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
215
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
205
				compositeArtifactRepository.addChild((URI) iter.next());
216
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
217
				if (repo.isArtifact())
218
					compositeArtifactRepository.addChild(repo.getRepoLocation());
206
			}
219
			}
207
		}
220
		}
208
		return compositeArtifactRepository;
221
		return compositeArtifactRepository;
209
	}
222
	}
210
223
224
	protected boolean hasArtifactSources() {
225
		return !((ICompositeRepository) getCompositeArtifactRepository()).getChildren().isEmpty();
226
	}
227
228
	protected boolean hasMetadataSources() {
229
		return !((ICompositeRepository) getCompositeMetadataRepository()).getChildren().isEmpty();
230
	}
231
211
	public abstract IStatus run(IProgressMonitor monitor) throws ProvisionException;
232
	public abstract IStatus run(IProgressMonitor monitor) throws ProvisionException;
212
233
213
	public void addDestination(RepositoryDescriptor descriptor) {
234
	public void addDestination(RepositoryDescriptor descriptor) {
214
		destinationRepos.add(descriptor);
235
		destinationRepos.add(descriptor);
215
	}
236
	}
237
238
	public void addSource(RepositoryDescriptor repo) {
239
		sourceRepositories.add(repo);
240
	}
216
}
241
}
(-)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 (-17 / +193 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;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
24
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
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 {
33
	private static final String LOG_ROOT = "p2.mirror"; //$NON-NLS-1$
34
28
	protected SlicingOptions slicingOptions = new SlicingOptions();
35
	protected SlicingOptions slicingOptions = new SlicingOptions();
29
36
37
	private URI baseline;
38
	private String comparatorID;
39
	private boolean compare = false;
40
	private boolean failOnError = true;
41
	private boolean raw = true;
42
	private boolean verbose = false;
43
	private boolean validate = false;
44
45
	private File mirrorLogFile; // file to log mirror output to (optional)
46
	private File comparatorLogFile; // file to comparator output to (optional)
47
	private IArtifactMirrorLog mirrorLog;
48
	private IArtifactMirrorLog comparatorLog;
49
30
	public Object start(IApplicationContext context) throws Exception {
50
	public Object start(IApplicationContext context) throws Exception {
31
		run(null);
51
		run(null);
32
		return IApplication.EXIT_OK;
52
		return IApplication.EXIT_OK;
33
	}
53
	}
34
54
35
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
55
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
56
		IStatus mirrorStatus = Status.OK_STATUS;
36
		try {
57
		try {
37
			validate();
58
			validate();
38
			initializeRepos(new NullProgressMonitor());
59
			initializeRepos(new NullProgressMonitor());
60
			initializeIUs();
39
			IQueryable slice = slice(new NullProgressMonitor());
61
			IQueryable slice = slice(new NullProgressMonitor());
40
			IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
62
			if (destinationArtifactRepository != null) {
41
			if (mirrorStatus.getSeverity() == IStatus.ERROR) {
63
				initializeLogs();
42
				return mirrorStatus;
64
				mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
65
				if (mirrorStatus.getSeverity() == IStatus.ERROR)
66
					return mirrorStatus;
43
			}
67
			}
44
			mirrorMetadata(slice, new NullProgressMonitor());
68
			if (destinationMetadataRepository != null)
69
				mirrorMetadata(slice, new NullProgressMonitor());
45
		} finally {
70
		} finally {
46
			finalizeRepositories();
71
			finalizeRepositories();
72
			finalizeLogs();
47
		}
73
		}
48
		return Status.OK_STATUS;
74
		if (mirrorStatus.isOK())
75
			return Status.OK_STATUS;
76
		return mirrorStatus;
49
	}
77
	}
50
78
51
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) {
79
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException {
52
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
80
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
53
		ArrayList keys = new ArrayList(ius.size());
81
		ArrayList keys = new ArrayList(ius.size());
54
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
82
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
Lines 58-66 Link Here
58
				keys.add(iuKeys[i]);
86
				keys.add(iuKeys[i]);
59
			}
87
			}
60
		}
88
		}
61
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true);
89
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw);
62
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
90
63
		return mirror.run(true, false);
91
		mirror.setCompare(compare);
92
		mirror.setComparatorId(comparatorID);
93
		mirror.setBaseline(initializeBaseline());
94
		mirror.setValidate(validate);
95
96
		// If IUs have been specified then only they should be mirrored, otherwise mirror everything.
97
		if (keys.size() > 0)
98
			mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
99
100
		if (comparatorLog != null)
101
			mirror.setComparatorLog(comparatorLog);
102
103
		IStatus result = mirror.run(failOnError, verbose);
104
105
		if (mirrorLog != null)
106
			mirrorLog.log(result);
107
		else
108
			LogHelper.log(result);
109
		return result;
110
	}
111
112
	private IArtifactRepository initializeBaseline() throws ProvisionException {
113
		if (baseline == null)
114
			return null;
115
		return addRepository(Activator.getArtifactRepositoryManager(), baseline, 0, null);
64
	}
116
	}
65
117
66
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
118
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
Lines 75-95 Link Here
75
	 * to add more if they wish)
127
	 * to add more if they wish)
76
	 */
128
	 */
77
	private void validate() throws ProvisionException {
129
	private void validate() throws ProvisionException {
78
		if (sourceMetadataRepositories == null)
130
		if (sourceRepositories.isEmpty())
79
			throw new ProvisionException("Need to set the source metadata repository location.");
131
			throw new ProvisionException(Messages.MirrorApplication_set_source_repositories);
80
		if (sourceIUs == null)
132
	}
81
			throw new ProvisionException("Mirroring root needs to be specified.");
133
82
		//TODO Check that the IU is in repo
134
	/*
135
	 * If no IUs have been specified we want to mirror them all
136
	 */
137
	private void initializeIUs() throws ProvisionException {
138
		if (sourceIUs == null || sourceIUs.isEmpty()) {
139
			sourceIUs = new ArrayList();
140
			IMetadataRepository metadataRepo = getCompositeMetadataRepository();
141
			Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
142
143
			for (Iterator iter = collector.iterator(); iter.hasNext();) {
144
				IInstallableUnit iu = (IInstallableUnit) iter.next();
145
				sourceIUs.add(iu);
146
			}
147
148
			if (collector.size() == 0 && destinationMetadataRepository != null) {
149
				throw new ProvisionException(Messages.MirrorApplication_no_IUs);
150
			}
151
		} else {
152
			//TODO Check that the IU is in repo
153
		}
154
	}
155
156
	/*
157
	 * Initialize logs, if applicable
158
	 */
159
	private void initializeLogs() {
160
		if (compare && comparatorLogFile != null)
161
			comparatorLog = getLog(comparatorLogFile, comparatorID);
162
		if (mirrorLog == null && mirrorLogFile != null)
163
			mirrorLog = getLog(mirrorLogFile, LOG_ROOT);
164
	}
165
166
	/*
167
	 * Finalize logs, if applicable
168
	 */
169
	private void finalizeLogs() {
170
		if (comparatorLog != null)
171
			comparatorLog.close();
172
		if (mirrorLog != null)
173
			mirrorLog.close();
83
	}
174
	}
84
175
85
	private IQueryable slice(IProgressMonitor monitor) {
176
	/*
177
	 * Get the log for a location
178
	 */
179
	private IArtifactMirrorLog getLog(File location, String root) {
180
		String absolutePath = location.getAbsolutePath();
181
		if (absolutePath.toLowerCase().endsWith(".xml")) //$NON-NLS-1$
182
			return new XMLMirrorLog(absolutePath, 0, root);
183
		return new FileMirrorLog(absolutePath, 0, root);
184
	}
185
186
	private IQueryable slice(IProgressMonitor monitor) throws ProvisionException {
86
		if (slicingOptions == null)
187
		if (slicingOptions == null)
87
			slicingOptions = new SlicingOptions();
188
			slicingOptions = new SlicingOptions();
88
		PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), slicingOptions.getFilter(), slicingOptions.includeOptionalDependencies(), slicingOptions.isEverythingGreedy(), slicingOptions.forceFilterTo(), slicingOptions.considerStrictDependencyOnly());
189
		PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), slicingOptions.getFilter(), slicingOptions.includeOptionalDependencies(), slicingOptions.isEverythingGreedy(), slicingOptions.forceFilterTo(), slicingOptions.considerStrictDependencyOnly());
89
		return slicer.slice((IInstallableUnit[]) sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor);
190
		IQueryable slice = slicer.slice((IInstallableUnit[]) sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), monitor);
191
		if (slice == null)
192
			throw new ProvisionException(slicer.getStatus());
193
		return slice;
90
	}
194
	}
91
195
92
	public void setSlicingOptions(SlicingOptions options) {
196
	public void setSlicingOptions(SlicingOptions options) {
93
		slicingOptions = options;
197
		slicingOptions = options;
94
	}
198
	}
199
200
	/*
201
	 * Set the location of the baseline repository. (used in comparison)
202
	 */
203
	public void setBaseline(URI baseline) {
204
		this.baseline = baseline;
205
		compare = true;
206
	}
207
208
	/*
209
	 * Set the identifier of the comparator to use.
210
	 */
211
	public void setComparatorID(String value) {
212
		comparatorID = value;
213
		compare = true;
214
	}
215
216
	/*
217
	 * Set whether or not the application should be calling a comparator when mirroring.
218
	 */
219
	public void setCompare(boolean value) {
220
		compare = value;
221
	}
222
223
	/*
224
	 * Set whether or not we should ignore errors when running the mirror application.
225
	 */
226
	public void setIgnoreErrors(boolean value) {
227
		failOnError = !value;
228
	}
229
230
	/*
231
	 * Set whether or not the the artifacts are raw.
232
	 */
233
	public void setRaw(boolean value) {
234
		raw = value;
235
	}
236
237
	/*
238
	 * Set whether or not the mirror application should be run in verbose mode.
239
	 */
240
	public void setVerbose(boolean value) {
241
		verbose = value;
242
	}
243
244
	/*
245
	 * Set the location of the log for comparator output
246
	 */
247
	public void setComparatorLog(File comparatorLog) {
248
		this.comparatorLogFile = comparatorLog;
249
	}
250
251
	/*
252
	 * Set the location of the log for mirroring. 
253
	 */
254
	public void setLog(File mirrorLog) {
255
		this.mirrorLogFile = mirrorLog;
256
	}
257
258
	/*
259
	 * Set the ArtifactMirror log
260
	 */
261
	public void setLog(IArtifactMirrorLog log) {
262
		mirrorLog = log;
263
	}
264
265
	/*
266
	 * Set if the artifact mirror should be validated
267
	 */
268
	public void setValidate(boolean value) {
269
		validate = value;
270
	}
95
}
271
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Repo2Runnable.java (-25 / +17 lines)
Lines 10-16 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;
14
import java.net.URISyntaxException;
13
import java.net.URISyntaxException;
15
import java.util.*;
14
import java.util.*;
16
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.*;
Lines 27-33 Link Here
27
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
28
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
29
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
28
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
30
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
31
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
29
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
32
30
33
/**
31
/**
Lines 165-175 Link Here
165
			return;
163
			return;
166
		}
164
		}
167
		// get all IUs from the repos
165
		// get all IUs from the repos
168
		if (sourceMetadataRepositories == null || sourceMetadataRepositories.isEmpty())
166
		if (!hasMetadataSources())
169
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
167
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
170
		for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) {
168
171
			processedIUs.addAll(getAllIUs((URI) iter.next(), monitor).toCollection());
169
		processedIUs.addAll(getAllIUs(getCompositeMetadataRepository(), monitor).toCollection());
172
		}
170
173
		if (processedIUs.isEmpty())
171
		if (processedIUs.isEmpty())
174
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
172
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
175
	}
173
	}
Lines 188-202 Link Here
188
	/*
186
	/*
189
	 * Return a collector over all the IUs contained in the given repository.
187
	 * Return a collector over all the IUs contained in the given repository.
190
	 */
188
	 */
191
	private Collector getAllIUs(URI location, IProgressMonitor monitor) throws ProvisionException {
189
	private Collector getAllIUs(IMetadataRepository repository, IProgressMonitor monitor) {
192
		SubMonitor progress = SubMonitor.convert(monitor, 2);
190
		SubMonitor progress = SubMonitor.convert(monitor, 2);
193
		IMetadataRepositoryManager manager = Activator.getMetadataRepositoryManager();
191
		try {
194
		if (!manager.contains(location))
192
			return repository.query(InstallableUnitQuery.ANY, new Collector(), progress.newChild(1));
195
			metadataReposToRemove.add(location);
193
		} finally {
196
		IMetadataRepository repository = manager.loadRepository(location, progress.newChild(1));
194
			progress.done();
197
		Collector result = new Collector();
195
		}
198
		repository.query(InstallableUnitQuery.ANY, result, progress.newChild(1)).iterator();
199
		return result;
200
	}
196
	}
201
197
202
	/*
198
	/*
Lines 242-260 Link Here
242
			String arg = args[++i];
238
			String arg = args[++i];
243
239
244
			if (option.equalsIgnoreCase("-source")) { //$NON-NLS-1$
240
			if (option.equalsIgnoreCase("-source")) { //$NON-NLS-1$
245
				addSourceArtifactRepository(arg);
241
				RepositoryDescriptor source = new RepositoryDescriptor();
246
				addSourceMetadataRepository(arg);
242
				source.setLocation(URIUtil.fromString(arg));
243
				addSource(source);
247
			}
244
			}
248
245
249
			if (option.equalsIgnoreCase("-destination")) { //$NON-NLS-1$
246
			if (option.equalsIgnoreCase("-destination")) { //$NON-NLS-1$
250
				RepositoryDescriptor artifact = new RepositoryDescriptor();
247
				RepositoryDescriptor destination = new RepositoryDescriptor();
251
				artifact.setLocation(URIUtil.fromString(arg));
248
				destination.setLocation(URIUtil.fromString(arg));
252
				artifact.setKind("A"); //$NON-NLS-1$
249
				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
			}
250
			}
259
		}
251
		}
260
	}
252
	}
Lines 266-272 Link Here
266
	 * to add more if they wish)
258
	 * to add more if they wish)
267
	 */
259
	 */
268
	private void validate() throws ProvisionException {
260
	private void validate() throws ProvisionException {
269
		if (sourceMetadataRepositories == null && sourceIUs == null)
261
		if (!hasMetadataSources() && sourceIUs == null)
270
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
262
			throw new ProvisionException(Messages.exception_needIUsOrNonEmptyRepo);
271
		if (destinationArtifactRepository == null)
263
		if (destinationArtifactRepository == null)
272
			throw new ProvisionException(Messages.exception_needDestinationRepo);
264
			throw new ProvisionException(Messages.exception_needDestinationRepo);
(-)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 (+35 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;
56
	public static String exception_invalidDestination;
57
	public static String exception_invalidSource;
23
58
24
	static {
59
	static {
25
		// initialize resource bundles
60
		// initialize resource bundles
(-)src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties (-2 / +30 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
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
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}
12
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}.
37
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
38
exception_invalidDestination=Invalid destination repository location: {0}.
39
exception_invalidSource=Invalid source repository location: {0}.
13
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
40
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
14
exception_notLocalFileRepo= {0} is not a local file based repository.
41
exception_notLocalFileRepo= {0} is not a local file based repository.
15
exception_noEngineService=Unable to acquire engine service.
42
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.
43
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.
44
exception_needDestinationRepo=Need to set the destination artifact repository location.
45
exception_onlyOneComparator=Only one comparator should be defined.
(-)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 (+173 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.net.MalformedURLException;
14
import java.util.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
17
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
18
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
20
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
22
import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository;
23
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
24
import org.eclipse.osgi.util.NLS;
25
26
public class CompositeRepositoryApplication extends AbstractApplication {
27
	private List childrenToAdd = new ArrayList();
28
	private List childrenToRemove = new ArrayList();
29
	private boolean failOnExists = false;
30
31
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
32
		try {
33
			initializeRepos(new NullProgressMonitor());
34
			// load repository
35
			ICompositeRepository metadataRepo = (ICompositeRepository) destinationMetadataRepository;
36
			ICompositeRepository artifactRepo = (ICompositeRepository) destinationArtifactRepository;
37
38
			// Remove children from the Composite Repositories
39
			for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) {
40
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
41
				if (child.isArtifact() && artifactRepo != null)
42
					artifactRepo.removeChild(child.getRepoLocation());
43
				if (child.isMetadata() && metadataRepo != null)
44
					metadataRepo.removeChild(child.getRepoLocation());
45
			}
46
47
			// Add children to the Composite Repositories
48
			for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) {
49
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
50
				if (child.isArtifact() && artifactRepo != null)
51
					artifactRepo.addChild(child.getRepoLocation());
52
				if (child.isMetadata() && metadataRepo != null)
53
					metadataRepo.addChild(child.getRepoLocation());
54
			}
55
			return Status.OK_STATUS;
56
		} finally {
57
			finalizeRepositories();
58
		}
59
	}
60
61
	public void addChild(RepositoryDescriptor child) {
62
		childrenToAdd.add(child);
63
	}
64
65
	public void removeChild(RepositoryDescriptor child) {
66
		childrenToRemove.add(child);
67
	}
68
69
	public void setFailOnExists(boolean value) {
70
		failOnExists = value;
71
	}
72
73
	protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
74
		// remove the repo first.
75
		mgr.removeRepository(toInit.getRepoLocation());
76
77
		// first try and load to see if one already exists at that location.
78
		try {
79
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), null);
80
			if (validRepositoryLocation(repository) && initDestinationRepository(repository, toInit))
81
				return repository;
82
			throw new ProvisionException(new Status(IStatus.INFO, Activator.ID, NLS.bind(Messages.CompositeRepository_composite_repository_exists, toInit.getRepoLocation())));
83
		} catch (ProvisionException e) {
84
			// re-throw the exception if we got anything other than "repo not found"
85
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) {
86
				if (e.getCause() instanceof MalformedURLException)
87
					throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
88
				throw e;
89
			}
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
				if (e.getCause() instanceof MalformedURLException)
125
					throw new ProvisionException(NLS.bind(Messages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
126
				throw e;
127
			}
128
		}
129
130
		IMetadataRepository source = null;
131
		try {
132
			if (toInit.getFormat() != null)
133
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
134
		} catch (ProvisionException e) {
135
			//Ignore
136
		}
137
		//This code assumes source has been successfully loaded before this point
138
		try {
139
			//No existing repository; create a new repository at destinationLocation but with source's attributes.
140
			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);
141
			initRepository(repo, toInit);
142
			return repo;
143
		} catch (IllegalStateException e) {
144
			mgr.removeRepository(toInit.getRepoLocation());
145
			throw e;
146
		}
147
	}
148
149
	/*
150
	 * Determine if the repository is valid for this operation
151
	 */
152
	private boolean validRepositoryLocation(IRepository repository) throws ProvisionException {
153
		if (repository instanceof ICompositeRepository) {
154
			// if we have an already existing repository at that location, then throw an error
155
			// if the user told us to
156
			if (failOnExists)
157
				throw new ProvisionException(NLS.bind(Messages.CompositeRepository_composite_repository_exists, repository.getLocation()));
158
			RepositoryHelper.validDestinationRepository(repository);
159
			return true;
160
		}
161
		// we have a non-composite repo at this location. that is ok because we can co-exist.
162
		return true;
163
	}
164
165
	/*
166
	 * Initialize a new repository
167
	 */
168
	private void initRepository(IRepository repository, RepositoryDescriptor desc) {
169
		RepositoryHelper.validDestinationRepository(repository);
170
		if (desc.isCompressed() && !repository.getProperties().containsKey(IRepository.PROP_COMPRESSED))
171
			repository.setProperty(IRepository.PROP_COMPRESSED, String.valueOf(true));
172
	}
173
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java (+67 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.net.URI;
14
import java.net.URISyntaxException;
15
import org.apache.tools.ant.BuildException;
16
import org.apache.tools.ant.types.FileSet;
17
import org.eclipse.core.runtime.URIUtil;
18
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
19
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
20
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
21
22
public class RepositoryFileSet extends FileSet {
23
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
24
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
25
26
	private int kind = RepositoryDescriptor.TYPE_BOTH;
27
	protected String myLocation = null;
28
29
	public void setKind(String repoKind) {
30
		kind = RepositoryDescriptor.determineKind(repoKind);
31
	}
32
33
	public int getKind() {
34
		return kind;
35
	}
36
37
	public boolean isBoth() {
38
		return kind == RepositoryDescriptor.TYPE_BOTH;
39
	}
40
41
	public boolean isArtifact() {
42
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
43
	}
44
45
	public boolean isMetadata() {
46
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_METADATA;
47
	}
48
49
	public void setLocation(String value) {
50
		// TODO depreciate 
51
		myLocation = value;
52
	}
53
54
	public String getRepoLocation() {
55
		// TODO depreciate 
56
		return myLocation;
57
	}
58
59
	public URI getRepoLocationURI() {
60
		// TODO depreciate 
61
		try {
62
			return RepositoryHelper.localRepoURIHelper(URIUtil.fromString(getRepoLocation()));
63
		} catch (URISyntaxException e) {
64
			throw new BuildException(e);
65
		}
66
	}
67
}
(-)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