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

Return to bug 265550