View | Details | Raw Unified | Return to bug 264110 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties (+1 lines)
Lines 53-58 Link Here
53
Mirroring_compareAndDownload=Compare and download of {0} from baseline.
53
Mirroring_compareAndDownload=Compare and download of {0} from baseline.
54
MirrorLog_Console_Log=Logging to the console instead.
54
MirrorLog_Console_Log=Logging to the console instead.
55
MirrorLog_Exception_Occurred=An exception occurred while writing to the log:
55
MirrorLog_Exception_Occurred=An exception occurred while writing to the log:
56
Mirroring_DestinationNotModifiable=Destination repository must be modifiable: {0}
56
57
57
exception_unsupportedAddToComposite = Cannot add descriptors to a composite repository.
58
exception_unsupportedAddToComposite = Cannot add descriptors to a composite repository.
58
exception_unsupportedGetOutputStream=Cannot write artifacts to a composite repository.
59
exception_unsupportedGetOutputStream=Cannot write artifacts to a composite repository.
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java (+1 lines)
Lines 56-61 Link Here
56
	public static String Mirroring_NO_MATCHING_DESCRIPTOR;
56
	public static String Mirroring_NO_MATCHING_DESCRIPTOR;
57
	public static String Mirroring_MISSING_DESCRIPTOR;
57
	public static String Mirroring_MISSING_DESCRIPTOR;
58
	public static String Mirroring_DIFFERENT_DESCRIPTOR_PROPERTY;
58
	public static String Mirroring_DIFFERENT_DESCRIPTOR_PROPERTY;
59
	public static String Mirroring_DestinationNotModifiable;
59
60
60
	public static String Mirroring_ValidationError;
61
	public static String Mirroring_ValidationError;
61
	public static String Mirroring_compareAndDownload;
62
	public static String Mirroring_compareAndDownload;
(-)src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java (-42 / +89 lines)
Lines 21-28 Link Here
21
import org.eclipse.equinox.internal.p2.artifact.repository.*;
21
import org.eclipse.equinox.internal.p2.artifact.repository.*;
22
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
22
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
23
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
23
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
24
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
24
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
25
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
26
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
26
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
27
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
27
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
28
import org.eclipse.osgi.framework.log.FrameworkLog;
28
import org.eclipse.osgi.framework.log.FrameworkLog;
Lines 58-88 Link Here
58
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
58
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
59
	 */
59
	 */
60
	public Object start(IApplicationContext context) throws Exception {
60
	public Object start(IApplicationContext context) throws Exception {
61
		Map args = context.getArguments();
61
		try {
62
		initializeFromArguments((String[]) args.get(IApplicationContext.APPLICATION_ARGS));
62
			Map args = context.getArguments();
63
		setupRepositories();
63
			initializeFromArguments((String[]) args.get(IApplicationContext.APPLICATION_ARGS));
64
64
			setupRepositories();
65
		Mirroring mirroring = new Mirroring(source, destination, raw);
65
66
		mirroring.setCompare(compare);
66
			Mirroring mirroring = new Mirroring(source, destination, raw);
67
		mirroring.setComparatorId(comparatorID);
67
			mirroring.setCompare(compare);
68
		mirroring.setBaseline(baseline);
68
			mirroring.setComparatorId(comparatorID);
69
		mirroring.setValidate(validate);
69
			mirroring.setBaseline(baseline);
70
		if (comparatorLog != null)
70
			mirroring.setValidate(validate);
71
			mirroring.setComparatorLog(comparatorLog);
71
			if (comparatorLog != null)
72
72
				mirroring.setComparatorLog(comparatorLog);
73
		IStatus result = mirroring.run(failOnError, verbose);
73
74
		if (!result.isOK()) {
74
			IStatus result = mirroring.run(failOnError, verbose);
75
			//only noteworthy statuses should be resulted from mirroring.run
75
			if (!result.isOK()) {
76
			if (result.matches(IStatus.INFO))
76
				//only noteworthy statuses should be resulted from mirroring.run
77
				System.err.println("Mirroring completed. Please check log file for more information."); //$NON-NLS-1$
77
				if (result.matches(IStatus.INFO))
78
			else
78
					System.err.println("Mirroring completed. Please check log file for more information."); //$NON-NLS-1$
79
				System.err.println("Mirroring completed with warnings and/or errors. Please check log file for more information."); //$NON-NLS-1$
79
				else
80
			log(result);
80
					System.err.println("Mirroring completed with warnings and/or errors. Please check log file for more information."); //$NON-NLS-1$
81
				log(result);
82
			}
83
			return IApplication.EXIT_OK;
84
		} catch (Exception e) {
85
			// Display the error the user
86
			System.err.println(e.getMessage());
87
			// Throw the exception so it can be logged
88
			throw e;
89
		} finally {
90
			cleanup();
81
		}
91
		}
82
83
		cleanup();
84
85
		return IApplication.EXIT_OK;
86
	}
92
	}
87
93
88
	/*
94
	/*
Lines 102-134 Link Here
102
		return result;
108
		return result;
103
	}
109
	}
104
110
105
	private void setupRepositories() throws ProvisionException {
111
	private void setupRepositories() throws Exception {
106
		if (destinationLocation == null || sourceLocation == null)
112
		if (destinationLocation == null || sourceLocation == null)
107
			throw new IllegalStateException(Messages.exception_needSourceDestination);
113
			throw new IllegalStateException(Messages.exception_needSourceDestination);
108
114
109
		//Check if repositories are already loaded
115
		// Attempt to load the source repository
110
		sourceLoaded = getManager().contains(sourceLocation);
111
		destinationLoaded = getManager().contains(destinationLocation);
112
113
		//must execute before initializeDestination is called
116
		//must execute before initializeDestination is called
114
		source = getManager().loadRepository(sourceLocation, 0, null);
117
		try {
115
		destination = initializeDestination();
118
			sourceLoaded = getManager().contains(sourceLocation);
119
			source = getManager().loadRepository(sourceLocation, 0, null);
120
		} catch (Exception e) {
121
			// Attempt to help the user with the repository location
122
			sourceLocation = RepositoryHelper.fileURIHelper(sourceLocation);
123
			sourceLoaded = getManager().contains(sourceLocation);
124
			try {
125
				source = getManager().loadRepository(sourceLocation, 0, null);
126
			} catch (Exception e2) {
127
				// throw original error to avoid confusion
128
				throw e;
129
			}
130
		}
131
132
		// Attempt to load the destination repository
133
		try {
134
			destinationLoaded = getManager().contains(destinationLocation);
135
			destination = initializeDestination();
136
		} catch (Exception e) {
137
			// Attempt to help the user with repository location
138
			destinationLocation = RepositoryHelper.fileURIHelper(destinationLocation);
139
			destinationLoaded = getManager().contains(destinationLocation);
140
			try {
141
				destination = initializeDestination();
142
			} catch (Exception e2) {
143
				// throw original error to avoid confusion
144
				throw e;
145
			}
146
		}
116
147
117
		if (baselineLocation != null) {
148
		if (baselineLocation != null) {
118
			baselineLoaded = getManager().contains(baselineLocation);
149
			baselineLoaded = getManager().contains(baselineLocation);
119
			try {
150
			try {
120
				baseline = getManager().loadRepository(baselineLocation, 0, null);
151
				baseline = getManager().loadRepository(baselineLocation, 0, null);
121
			} catch (ProvisionException e) {
152
			} catch (Exception e) {
122
				// catch the exception and log it. we will continue without doing a baseline comparison
153
				baselineLocation = RepositoryHelper.fileURIHelper(baselineLocation);
123
				System.err.println("Error occurred while trying to load baseline repository.");
154
				baselineLoaded = getManager().contains(baselineLocation);
124
				e.printStackTrace();
155
				try {
156
					baseline = getManager().loadRepository(baselineLocation, 0, null);
157
				} catch (Exception e2) {
158
					// catch the exception and log it. we will continue without doing a baseline comparison
159
					System.err.println("Error occurred while trying to load baseline repository.");
160
					e.printStackTrace();
161
				}
125
			}
162
			}
126
		}
163
		}
127
	}
164
	}
128
165
129
	private IArtifactRepository initializeDestination() throws ProvisionException {
166
	private IArtifactRepository initializeDestination() throws ProvisionException {
167
		IArtifactRepository repository;
130
		try {
168
		try {
131
			IArtifactRepository repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
169
			repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
132
			if (repository != null && repository.isModifiable()) {
170
			if (repository != null && repository.isModifiable()) {
133
				if (destinationName != null)
171
				if (destinationName != null)
134
					repository.setName(destinationName);
172
					repository.setName(destinationName);
Lines 142-148 Link Here
142
		//This code assumes source has been successfully loaded before this point
180
		//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.
181
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
144
		// TODO for now create a Simple repo by default.
182
		// TODO for now create a Simple repo by default.
145
		return getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties());
183
		repository = getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties());
184
		if (!repository.isModifiable())
185
			throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, destinationLocation));
186
		return repository;
146
	}
187
	}
147
188
148
	/* (non-Javadoc)
189
	/* (non-Javadoc)
Lines 180-186 Link Here
180
			String arg = args[++i];
221
			String arg = args[++i];
181
222
182
			if (args[i - 1].equalsIgnoreCase("-comparator")) //$NON-NLS-1$
223
			if (args[i - 1].equalsIgnoreCase("-comparator")) //$NON-NLS-1$
183
				comparatorID = arg;
224
				setComparator(arg);
184
			if (args[i - 1].equalsIgnoreCase("-comparatorLog")) //$NON-NLS-1$
225
			if (args[i - 1].equalsIgnoreCase("-comparatorLog")) //$NON-NLS-1$
185
				comparatorLogLocation = arg;
226
				comparatorLogLocation = arg;
186
			if (args[i - 1].equalsIgnoreCase("-destinationName")) //$NON-NLS-1$
227
			if (args[i - 1].equalsIgnoreCase("-destinationName")) //$NON-NLS-1$
Lines 211-216 Link Here
211
			comparatorLog = getLog(comparatorLogLocation, comparatorID);
252
			comparatorLog = getLog(comparatorLogLocation, comparatorID);
212
	}
253
	}
213
254
255
	public void setComparator(String comparator) {
256
		// If the factory fails to load the comparator an exception will be thrown
257
		ArtifactComparatorFactory.getArtifactComparator(comparator);
258
		comparatorID = comparator;
259
	}
260
214
	public void setLog(IArtifactMirrorLog log) {
261
	public void setLog(IArtifactMirrorLog log) {
215
		mirrorLog = log;
262
		mirrorLog = log;
216
	}
263
	}
Lines 242-250 Link Here
242
	 */
289
	 */
243
	private void cleanup() {
290
	private void cleanup() {
244
		//if the repository was not already loaded before the mirror application started, close it.
291
		//if the repository was not already loaded before the mirror application started, close it.
245
		if (!sourceLoaded)
292
		if (!sourceLoaded && sourceLocation != null)
246
			getManager().removeRepository(sourceLocation);
293
			getManager().removeRepository(sourceLocation);
247
		if (!destinationLoaded)
294
		if (!destinationLoaded && destinationLocation != null)
248
			getManager().removeRepository(destinationLocation);
295
			getManager().removeRepository(destinationLocation);
249
		if (baselineLocation != null && !baselineLoaded)
296
		if (baselineLocation != null && !baselineLoaded)
250
			getManager().removeRepository(baselineLocation);
297
			getManager().removeRepository(baselineLocation);
(-)src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java (+36 lines)
Added Link Here
1
package org.eclipse.equinox.internal.p2.repository.helpers;
2
3
import java.io.File;
4
import java.net.URI;
5
import org.eclipse.core.runtime.URIUtil;
6
7
public class RepositoryHelper {
8
9
	private static final String FILE_SCHEME = "file"; //$NON-NLS-1$
10
11
	/**
12
	 * Creates a new URI representing a local file from one with a null scheme, 
13
	 * or a one character scheme. (eg. C:\myfile, or /var/myfile)
14
	 * @param location the URI to convert
15
	 * @return the converted URI, or the original
16
	 */
17
	public static URI fileURIHelper(URI location) {
18
		if (location == null)
19
			return null;
20
		URI result = location;
21
		if (location.getScheme() == null)
22
			// Probably a local path:  /home/user/repo
23
			result = (new File(location.getPath())).getAbsoluteFile().toURI();
24
		else if (location.getScheme().length() == 1)
25
			// Likely a windows path:  C:\repo
26
			result = (new File(URIUtil.toUnencodedString(location))).toURI();
27
		else if (!FILE_SCHEME.equalsIgnoreCase(location.getScheme()))
28
			return result;
29
30
		// Zipped repository?
31
		String lowerCase = result.toString().toLowerCase();
32
		if (lowerCase.endsWith(".jar") || lowerCase.endsWith(".zip")) //$NON-NLS-1$//$NON-NLS-2$
33
			return URIUtil.toJarURI(result, null);
34
		return result;
35
	}
36
}
(-)src/org/eclipse/equinox/internal/p2/metadata/repository/messages.properties (-1 / +2 lines)
Lines 21-24 Link Here
21
repoMan_invalidLocation={0} is not a valid repository location
21
repoMan_invalidLocation={0} is not a valid repository location
22
CacheManager_Neither_0_nor_1_found=Neither {0} nor {1} found.
22
CacheManager_Neither_0_nor_1_found=Neither {0} nor {1} found.
23
CacheManager_AuthenticationFaileFor_0=Authentication failed for {0}
23
CacheManager_AuthenticationFaileFor_0=Authentication failed for {0}
24
CacheManager_FailedCommunicationWithRepo_0=Communication with repository at {0} failed.
24
CacheManager_FailedCommunicationWithRepo_0=Communication with repository at {0} failed.
25
Mirroring_DestinationNotModifiable=Destination repository must be modifiable: {0}
(-)src/org/eclipse/equinox/internal/p2/metadata/repository/Messages.java (+1 lines)
Lines 38-41 Link Here
38
	public static String repoMan_notExists;
38
	public static String repoMan_notExists;
39
	public static String repoMan_invalidLocation;
39
	public static String repoMan_invalidLocation;
40
40
41
	public static String Mirroring_DestinationNotModifiable;
41
}
42
}
(-)src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java (-24 / +59 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.metadata.mirror;
11
package org.eclipse.equinox.internal.p2.metadata.mirror;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
14
15
import java.net.URI;
13
import java.net.URI;
16
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
17
import java.util.*;
15
import java.util.*;
Lines 19-29 Link Here
19
import org.eclipse.equinox.app.IApplication;
17
import org.eclipse.equinox.app.IApplication;
20
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.app.IApplicationContext;
21
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
19
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
22
import org.eclipse.equinox.internal.p2.metadata.repository.Activator;
20
import org.eclipse.equinox.internal.p2.metadata.repository.*;
23
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
21
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
24
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
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.IRepositoryManager;
26
import org.eclipse.osgi.util.NLS;
27
27
28
/**
28
/**
29
 * An application that performs mirroring of artifacts between repositories.
29
 * An application that performs mirroring of artifacts between repositories.
Lines 66-95 Link Here
66
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
66
	 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
67
	 */
67
	 */
68
	public Object start(IApplicationContext context) throws Exception {
68
	public Object start(IApplicationContext context) throws Exception {
69
		initializeFromArguments((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
69
		try {
70
		setupRepositories();
70
			initializeFromArguments((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
71
		new Mirroring().mirror(source, destination, rootSpecs, transitive);
71
			setupRepositories();
72
		//if the repository was not already loaded before the mirror application started, close it.
72
			new Mirroring().mirror(source, destination, rootSpecs, transitive);
73
		if (!sourceLoaded)
73
74
			getManager().removeRepository(sourceLocation);
74
			return IApplication.EXIT_OK;
75
		if (!destinationLoaded)
75
		} catch (Exception e) {
76
			getManager().removeRepository(destinationLocation);
76
			// Display the error to the user
77
		return IApplication.EXIT_OK;
77
			System.err.println(e.getMessage());
78
			// Throw the exception so it can be logged
79
			throw e;
80
		} finally {
81
			//if the repository was not already loaded before the mirror application started, close it.
82
			if (!sourceLoaded && sourceLocation != null)
83
				getManager().removeRepository(sourceLocation);
84
			if (!destinationLoaded && destinationLocation != null)
85
				getManager().removeRepository(destinationLocation);
86
		}
78
	}
87
	}
79
88
80
	private void setupRepositories() throws ProvisionException {
89
	private void setupRepositories() throws Exception {
81
		if (destinationLocation == null || sourceLocation == null)
90
		if (destinationLocation == null || sourceLocation == null)
82
			throw new IllegalStateException("Must specify a source and destination"); //$NON-NLS-1$
91
			throw new IllegalStateException("Must specify a source and destination"); //$NON-NLS-1$
83
92
84
		//Check if repositories are already loaded
93
		// Load the source repository
85
		//TODO modify the contains statement once the API is available
86
		sourceLoaded = getManager().contains(sourceLocation);
87
		//TODO modify the contains statement once the API is available
88
		destinationLoaded = getManager().contains(destinationLocation);
89
90
		//must execute before initializeDestination is called
94
		//must execute before initializeDestination is called
91
		source = getManager().loadRepository(sourceLocation, 0, null);
95
		try {
92
		destination = initializeDestination();
96
			sourceLoaded = getManager().contains(sourceLocation);
97
			source = getManager().loadRepository(sourceLocation, 0, null);
98
		} catch (Exception e) {
99
			// Retry but this time help the user
100
			sourceLocation = RepositoryHelper.fileURIHelper(sourceLocation);
101
			sourceLoaded = getManager().contains(sourceLocation);
102
			try {
103
				source = getManager().loadRepository(sourceLocation, 0, null);
104
			} catch (Exception e2) {
105
				// throw original error to avoid confusion
106
				throw e;
107
			}
108
		}
109
110
		try {
111
			destinationLoaded = getManager().contains(destinationLocation);
112
			destination = initializeDestination();
113
		} catch (Exception e) {
114
			// Attempt to help the user & retry
115
			destinationLocation = RepositoryHelper.fileURIHelper(destinationLocation);
116
			destinationLoaded = getManager().contains(destinationLocation);
117
			try {
118
				destination = initializeDestination();
119
			} catch (Exception e2) {
120
				// throw original error to avoid confusion
121
				throw e;
122
			}
123
		}
93
	}
124
	}
94
125
95
	/*
126
	/*
Lines 110-117 Link Here
110
	}
141
	}
111
142
112
	private IMetadataRepository initializeDestination() throws ProvisionException {
143
	private IMetadataRepository initializeDestination() throws ProvisionException {
144
		IMetadataRepository repository;
113
		try {
145
		try {
114
			IMetadataRepository repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
146
			repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
115
			if (repository != null && repository.isModifiable()) {
147
			if (repository != null && repository.isModifiable()) {
116
				if (destinationName != null)
148
				if (destinationName != null)
117
					repository.setName(destinationName);
149
					repository.setName(destinationName);
Lines 125-131 Link Here
125
		//This code assumes source has been successfully loaded before this point
157
		//This code assumes source has been successfully loaded before this point
126
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
158
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
127
		// TODO for now create a Simple repo by default.
159
		// TODO for now create a Simple repo by default.
128
		return getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties());
160
		repository = getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties());
161
		if (!repository.isModifiable())
162
			throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, destinationLocation));
163
		return repository;
129
	}
164
	}
130
165
131
	/* (non-Javadoc)
166
	/* (non-Javadoc)
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 16-31 Link Here
16
 org.eclipse.equinox.internal.p2.core.helpers,
16
 org.eclipse.equinox.internal.p2.core.helpers,
17
 org.eclipse.equinox.internal.p2.director,
17
 org.eclipse.equinox.internal.p2.director,
18
 org.eclipse.equinox.internal.p2.metadata.repository,
18
 org.eclipse.equinox.internal.p2.metadata.repository,
19
 org.eclipse.equinox.internal.p2.repository.helpers,
19
 org.eclipse.equinox.internal.provisional.p2.artifact.repository,
20
 org.eclipse.equinox.internal.provisional.p2.artifact.repository,
20
 org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing,
21
 org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing,
21
 org.eclipse.equinox.internal.provisional.p2.core,
22
 org.eclipse.equinox.internal.provisional.p2.core,
22
 org.eclipse.equinox.internal.provisional.p2.repository,
23
 org.eclipse.equinox.internal.provisional.p2.engine,
23
 org.eclipse.equinox.internal.provisional.p2.engine,
24
 org.eclipse.equinox.internal.provisional.p2.engine.phases,
24
 org.eclipse.equinox.internal.provisional.p2.engine.phases,
25
 org.eclipse.equinox.internal.provisional.p2.metadata,
25
 org.eclipse.equinox.internal.provisional.p2.metadata,
26
 org.eclipse.equinox.internal.provisional.p2.metadata.query,
26
 org.eclipse.equinox.internal.provisional.p2.metadata.query,
27
 org.eclipse.equinox.internal.provisional.p2.metadata.repository,
27
 org.eclipse.equinox.internal.provisional.p2.metadata.repository,
28
 org.eclipse.equinox.internal.provisional.p2.query,
28
 org.eclipse.equinox.internal.provisional.p2.query,
29
 org.eclipse.equinox.internal.provisional.p2.repository,
29
 org.eclipse.internal.provisional.equinox.p2.jarprocessor,
30
 org.eclipse.internal.provisional.equinox.p2.jarprocessor,
30
 org.eclipse.osgi.util;version="1.1.0",
31
 org.eclipse.osgi.util;version="1.1.0",
31
 org.osgi.framework;version="1.5.0",
32
 org.osgi.framework;version="1.5.0",
(-)src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties (-1 / +2 lines)
Lines 11-14 Link Here
11
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
11
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
12
12
13
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
13
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
14
exception_notLocalFileRepo= {0} is not a local file based repository.
14
exception_notLocalFileRepo= {0} is not a local file based repository.
15
Mirroring_DestinationNotModifiable=Destination repository must be modifiable: {0}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java (-14 / +94 lines)
Lines 10-29 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
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
15
16
import java.net.URI;
13
import java.net.URI;
17
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
18
import java.util.*;
15
import java.util.*;
19
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
20
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
17
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
21
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;
22
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
20
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
23
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
21
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
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;
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 {
29
30
Lines 82-107 Link Here
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
83
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
83
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
86
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();)
86
				URI repoLocation = (URI) iter.next();
87
				loadArtifactRepo((URI) iter.next(), artifactRepositoryManager, progress);
88
		}
89
90
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
91
		if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) {
92
			for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();)
93
				loadMetadataRepo((URI) iter.next(), metadataRepositoryManager, progress);
94
		}
95
96
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
97
	}
98
99
	private void loadArtifactRepo(URI repoLocation, IArtifactRepositoryManager artifactRepositoryManager, IProgressMonitor progress) throws ProvisionException {
100
		try {
101
			if (!artifactRepositoryManager.contains(repoLocation))
102
				artifactReposToRemove.add(repoLocation);
103
			artifactRepositoryManager.loadRepository(repoLocation, 0, progress);
104
		} catch (ProvisionException e) {
105
			// Wasn't added, remove from the list
106
			artifactReposToRemove.remove(repoLocation);
107
			try {
108
				// Attempt to help the user
109
				repoLocation = RepositoryHelper.fileURIHelper(repoLocation);
87
				if (!artifactRepositoryManager.contains(repoLocation))
110
				if (!artifactRepositoryManager.contains(repoLocation))
88
					artifactReposToRemove.add(repoLocation);
111
					artifactReposToRemove.add(repoLocation);
89
				artifactRepositoryManager.loadRepository(repoLocation, 0, progress);
112
				artifactRepositoryManager.loadRepository(repoLocation, 0, progress);
113
			} catch (ProvisionException e2) {
114
				throw e;
90
			}
115
			}
91
		}
116
		}
117
	}
92
118
93
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
119
	private void loadMetadataRepo(URI repoLocation, IMetadataRepositoryManager metadataRepositoryManager, IProgressMonitor progress) throws ProvisionException {
94
		if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) {
120
		// If the repository is unknown it should be removed before exiting
95
			for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) {
121
		try {
96
				URI repoLocation = (URI) iter.next();
122
			if (!metadataRepositoryManager.contains(repoLocation))
123
				metadataReposToRemove.add(repoLocation);
124
			metadataRepositoryManager.loadRepository(repoLocation, 0, progress);
125
		} catch (ProvisionException e) {
126
			// Wasn't added, remove from the list
127
			metadataReposToRemove.remove(repoLocation);
128
			try {
129
				// Attempt to help the user by modifying the URI
130
				repoLocation = RepositoryHelper.fileURIHelper(repoLocation);
97
				if (!metadataRepositoryManager.contains(repoLocation))
131
				if (!metadataRepositoryManager.contains(repoLocation))
98
					metadataReposToRemove.add(repoLocation);
132
					metadataReposToRemove.add(repoLocation);
99
				metadataRepositoryManager.loadRepository(repoLocation, 0, progress);
133
				metadataRepositoryManager.loadRepository(repoLocation, 0, progress);
134
			} catch (ProvisionException e2) {
135
				// Throw original exception to avoid confusion
136
				throw e;
100
			}
137
			}
101
		}
138
		}
102
103
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
104
105
	}
139
	}
106
140
107
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
141
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
Lines 110-117 Link Here
110
		}
144
		}
111
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
145
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
112
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
146
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
113
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
147
114
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
148
		try {
149
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
150
		} catch (ProvisionException e) {
151
			try {
152
				// Assist the user with the URI
153
				artifactRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(artifactRepoDescriptor.getRepoLocation()));
154
				destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
155
			} catch (Exception e2) {
156
				throw e;
157
			}
158
		} catch (UnsupportedOperationException e) {
159
			try {
160
				// Assist the user with the URI
161
				artifactRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(artifactRepoDescriptor.getRepoLocation()));
162
				destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
163
			} catch (Exception e2) {
164
				throw e;
165
			}
166
		}
167
168
		try {
169
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
170
		} catch (ProvisionException e) {
171
			try {
172
				// Assist the user with the URI
173
				metadataRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(metadataRepoDescriptor.getRepoLocation()));
174
				destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
175
			} catch (Exception e2) {
176
				throw e;
177
			}
178
		} catch (UnsupportedOperationException e) {
179
			try {
180
				// Assist the user with the URI
181
				metadataRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(metadataRepoDescriptor.getRepoLocation()));
182
				destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
183
			} catch (Exception e2) {
184
				throw e;
185
			}
186
		}
115
	}
187
	}
116
188
117
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
189
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
Lines 142-147 Link Here
142
		//This code assumes source has been successfully loaded before this point
214
		//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.
215
		//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);
216
		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);
217
		// Ensure destination is modifiable
218
		if (!result.isModifiable())
219
			throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, toInit.getRepoLocation()));
145
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
220
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
146
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
221
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
147
		return result;
222
		return result;
Lines 175-180 Link Here
175
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
250
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
176
		// TODO for now create a Simple repo by default.
251
		// 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);
252
		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);
253
254
		// Ensure destination is modifiable
255
		if (!result.isModifiable())
256
			throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, toInit.getRepoLocation()));
257
178
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
258
		if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
179
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
259
			result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
180
		return result;
260
		return result;
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java (+2 lines)
Lines 17-22 Link Here
17
	public static String exception_destinationNotModifiable;
17
	public static String exception_destinationNotModifiable;
18
	public static String exception_unableToRemoveRepo;
18
	public static String exception_unableToRemoveRepo;
19
	public static String exception_notLocalFileRepo;
19
	public static String exception_notLocalFileRepo;
20
	public static String Mirroring_DestinationNotModifiable;
21
20
	static {
22
	static {
21
		// initialize resource bundles
23
		// initialize resource bundles
22
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
24
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
(-)src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java (-2 / +15 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.tests.mirror;
11
package org.eclipse.equinox.p2.tests.mirror;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
14
15
import java.io.*;
13
import java.io.*;
16
import java.net.*;
14
import java.net.*;
17
import java.util.*;
15
import java.util.*;
Lines 27-32 Link Here
27
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
28
import org.eclipse.equinox.internal.provisional.p2.core.Version;
26
import org.eclipse.equinox.internal.provisional.p2.core.Version;
29
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
28
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
30
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
29
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
31
import org.eclipse.equinox.p2.tests.TestActivator;
30
import org.eclipse.equinox.p2.tests.TestActivator;
32
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
31
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
Lines 1464-1467 Link Here
1464
			fail("Error verifying log", e);
1463
			fail("Error verifying log", e);
1465
		}
1464
		}
1466
	}
1465
	}
1466
1467
	/**
1468
	 * Test how the mirror application handles a repository specified without a scheme (eg: /usr/ or C:/usr)
1469
	 */
1470
	public void testArtifactMirrorNonURIDest() {
1471
		String[] args = new String[] {"-destination", destRepoLocation.toString(), "-source", sourceRepoLocation.toString()};
1472
1473
		try {
1474
			runMirrorApplication("Mirroring", args);
1475
			assertContentEquals("2.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
1476
		} catch (Exception e) {
1477
			fail("Error mirroring", e);
1478
		}
1479
	}
1467
}
1480
}
(-)src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java (-2 / +15 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.tests.mirror;
11
package org.eclipse.equinox.p2.tests.mirror;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
14
15
import java.io.File;
13
import java.io.File;
16
import java.net.*;
14
import java.net.*;
17
import java.util.HashMap;
15
import java.util.HashMap;
Lines 25-30 Link Here
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
27
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
25
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
26
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
28
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
27
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
29
import org.osgi.framework.Bundle;
28
import org.osgi.framework.Bundle;
30
29
Lines 978-981 Link Here
978
			fail("Could not load destination", e);
977
			fail("Could not load destination", e);
979
		}
978
		}
980
	}
979
	}
980
981
	/**
982
	 * Test how the mirror application handles a repository specified without a scheme (eg: /usr/ or C:/usr)
983
	 */
984
	public void testMetadataMirrorNonURIDest() {
985
		String[] args = new String[] {"-destination", destRepoLocation.toString(), "-source", sourceRepoLocation.toString()};
986
987
		try {
988
			runMirrorApplication("Mirroring", args);
989
			assertContentEquals("2.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null));
990
		} catch (Exception e) {
991
			fail("Error mirroring", e);
992
		}
993
	}
981
}
994
}

Return to bug 264110