Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 265550 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+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/RepositoryDescriptor.java (-4 / +6 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
16
17
public class RepositoryDescriptor {
17
public class RepositoryDescriptor {
18
18
19
	public static final int TYPE_BOTH = -1;
20
19
	private boolean compressed = true;
21
	private boolean compressed = true;
20
	private boolean append = true;
22
	private boolean append = true;
21
	private String name = null;
23
	private String name = null;
22
	private URI location = null;
24
	private URI location = null;
23
	private String format = null;
25
	private String format = null;
24
	private int kind;
26
	private int kind = TYPE_BOTH;
25
27
26
	public void setCompressed(boolean compress) {
28
	public void setCompressed(boolean compress) {
27
		compressed = compress;
29
		compressed = compress;
Lines 32-38 Link Here
32
	}
34
	}
33
35
34
	public void setLocation(URI repoLocation) {
36
	public void setLocation(URI repoLocation) {
35
		location = repoLocation;
37
		location = RepositoryHelper.localRepoURIHelper(repoLocation);
36
	}
38
	}
37
39
38
	public void setFormat(String format) {
40
	public void setFormat(String format) {
(-)src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java (-20 / +63 lines)
Lines 10-18 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.*;
Lines 24-34 Link Here
24
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
25
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
26
import org.eclipse.osgi.util.NLS;
27
27
28
public abstract class AbstractApplication {
28
public abstract class AbstractApplication {
29
29
30
	protected boolean removeUnknownRepositories = true;
31
30
	protected List sourceArtifactRepositories = new ArrayList();
32
	protected List sourceArtifactRepositories = new ArrayList();
31
	protected List sourceMetadataRepositories = new ArrayList();
33
	protected List sourceMetadataRepositories = new ArrayList();
34
	protected List sourceRepositories = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
35
	protected List artifactReposToRemove = new ArrayList();
33
	protected List metadataReposToRemove = new ArrayList();
36
	protected List metadataReposToRemove = new ArrayList();
34
	protected List sourceIUs = new ArrayList();
37
	protected List sourceIUs = new ArrayList();
Lines 71-85 Link Here
71
	}
74
	}
72
75
73
	protected void finalizeRepositories() throws ProvisionException {
76
	protected void finalizeRepositories() throws ProvisionException {
74
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
77
		if (removeUnknownRepositories) {
75
		for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
78
			IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
76
			artifactRepositoryManager.removeRepository((URI) iter.next());
79
			for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
77
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
80
				artifactRepositoryManager.removeRepository((URI) iter.next());
78
		for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
81
			IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
79
			metadataRepositoryManager.removeRepository((URI) iter.next());
82
			for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
83
				metadataRepositoryManager.removeRepository((URI) iter.next());
84
		}
80
	}
85
	}
81
86
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
87
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
88
		for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
89
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
90
			if (repo.getKind() == IRepository.TYPE_ARTIFACT) {
91
				sourceArtifactRepositories.add(repo.getRepoLocation());
92
			} else if (repo.getKind() == IRepository.TYPE_METADATA) {
93
				sourceMetadataRepositories.add(repo.getRepoLocation());
94
			} else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) {
95
				sourceArtifactRepositories.add(repo.getRepoLocation());
96
				sourceMetadataRepositories.add(repo.getRepoLocation());
97
			} else
98
				throw new ProvisionException(NLS.bind(Messages.unknown_repo_type, repo.getRepoLocation()));
99
		}
83
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
100
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
101
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
102
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
Lines 101-128 Link Here
101
		}
118
		}
102
119
103
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
120
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
104
105
	}
121
	}
106
122
107
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
123
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
108
		if (destinationRepos.size() != 2) {
124
		RepositoryDescriptor artifactRepoDescriptor = null;
109
			throw new ProvisionException("Too many or too few destination repositories.");
125
		RepositoryDescriptor metadataRepoDescriptor = null;
126
127
		Iterator iter = destinationRepos.iterator();
128
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
129
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
130
			int kind = repo.getKind();
131
			if (kind == IRepository.TYPE_ARTIFACT && artifactRepoDescriptor == null)
132
				artifactRepoDescriptor = repo;
133
			else if (kind == IRepository.TYPE_METADATA && metadataRepoDescriptor == null)
134
				metadataRepoDescriptor = repo;
135
			else if (kind == RepositoryDescriptor.TYPE_BOTH) {
136
				if (artifactRepoDescriptor == null)
137
					artifactRepoDescriptor = repo;
138
				if (metadataRepoDescriptor == null)
139
					metadataRepoDescriptor = repo;
140
			}
110
		}
141
		}
111
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
142
112
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
143
		if (artifactRepoDescriptor != null)
113
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
144
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
114
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
145
		if (metadataRepoDescriptor != null)
146
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
147
148
		if (destinationMetadataRepository == null && destinationArtifactRepository == null)
149
			throw new ProvisionException(Messages.no_destination_repo);
115
	}
150
	}
116
151
117
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
152
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
118
		try {
153
		try {
119
			if (mgr.contains(toInit.getRepoLocation()))
154
			if (!mgr.contains(toInit.getRepoLocation()))
120
				metadataReposToRemove.add(toInit.getRepoLocation());
155
				metadataReposToRemove.add(toInit.getRepoLocation());
121
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
156
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
122
			if (repository != null && repository.isModifiable()) {
157
			if (repository != null && repository.isModifiable()) {
123
				if (toInit.getName() != null)
158
				if (toInit.getName() != null)
124
					repository.setName(toInit.getName());
159
					repository.setName(toInit.getName());
125
				if (!toInit.isAppend())
160
				if (repository instanceof CompositeMetadataRepository && !toInit.isAppend())
161
					((CompositeMetadataRepository) repository).removeAllChildren();
162
				else if (!toInit.isAppend())
126
					repository.removeAll();
163
					repository.removeAll();
127
				return repository;
164
				return repository;
128
			}
165
			}
Lines 149-161 Link Here
149
186
150
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
187
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
151
		try {
188
		try {
152
			if (mgr.contains(toInit.getRepoLocation()))
189
			if (!mgr.contains(toInit.getRepoLocation()))
153
				artifactReposToRemove.add(toInit.getRepoLocation());
190
				artifactReposToRemove.add(toInit.getRepoLocation());
154
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
191
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
155
			if (repository != null && repository.isModifiable()) {
192
			if (repository != null && repository.isModifiable()) {
156
				if (toInit.getName() != null)
193
				if (toInit.getName() != null)
157
					repository.setName(toInit.getName());
194
					repository.setName(toInit.getName());
158
				if (!toInit.isAppend())
195
				if (repository instanceof CompositeArtifactRepository && !toInit.isAppend())
196
					((CompositeArtifactRepository) repository).removeAllChildren();
197
				else if (!toInit.isAppend())
159
					repository.removeAll();
198
					repository.removeAll();
160
				return repository;
199
				return repository;
161
			}
200
			}
Lines 213-216 Link Here
213
	public void addDestination(RepositoryDescriptor descriptor) {
252
	public void addDestination(RepositoryDescriptor descriptor) {
214
		destinationRepos.add(descriptor);
253
		destinationRepos.add(descriptor);
215
	}
254
	}
255
256
	public void addSource(RepositoryDescriptor repo) {
257
		sourceRepositories.add(repo);
258
	}
216
}
259
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java (+4 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
	public static String CompositeRepository_default_artifactRepo_name;
18
	public static String CompositeRepository_default_metadataRepo_name;
17
	public static String exception_destinationNotModifiable;
19
	public static String exception_destinationNotModifiable;
18
	public static String exception_unableToRemoveRepo;
20
	public static String exception_unableToRemoveRepo;
19
	public static String exception_notLocalFileRepo;
21
	public static String exception_notLocalFileRepo;
22
	public static String no_destination_repo;
23
	public static String unknown_repo_type;
20
	static {
24
	static {
21
		// initialize resource bundles
25
		// initialize resource bundles
22
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
(-)src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties (-1 / +5 lines)
Lines 1-3 Link Here
1
CompositeRepository_default_metadataRepo_name=Composite Metadata Repository
1
###############################################################################
2
###############################################################################
2
# Copyright (c) 2009 IBM Corporation and others.
3
# Copyright (c) 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# All rights reserved. This program and the accompanying materials
Lines 8-14 Link Here
8
# Contributors:
9
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
###############################################################################
12
CompositeRepository_default_artifactRepo_name=Composite Artifact Repository
11
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
13
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
12
14
13
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
15
exception_unableToRemoveRepo=Unable to remove artifact repository file: {0}.
14
exception_notLocalFileRepo= {0} is not a local file based repository.
16
exception_notLocalFileRepo= {0} is not a local file based repository.
17
no_destination_repo=Unable to locate a valid destiation repository.
18
unknown_repo_type=Repository of unknown type: {0}.
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java (+104 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.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
17
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
18
19
public class AntMirrorLog {
20
21
	private boolean consoleMessage = false;
22
	private Method log;
23
	private Object task;
24
25
	public AntMirrorLog(Object task) throws NoSuchMethodException {
26
		this.task = task;
27
		try {
28
			log = task.getClass().getMethod("log", new Class[] {String.class, int.class}); //$NON-NLS-1$
29
		} catch (SecurityException e) {
30
			exceptionOccurred(null, e);
31
		}
32
	}
33
34
	public void log(IArtifactDescriptor descriptor, IStatus status) {
35
		log(descriptor.toString(), status.getSeverity());
36
		log(status);
37
	}
38
39
	public void log(IStatus status) {
40
		int severity = status.getSeverity();
41
		// Log the status message
42
		log(status.getMessage(), severity);
43
		// Log the exception if applicable
44
		if (status.getException() != null)
45
			log(status.getException().getMessage(), severity);
46
47
		// Log any children of this status
48
		IStatus[] nestedStatus = status.getChildren();
49
		if (nestedStatus != null)
50
			for (int i = 0; i < nestedStatus.length; i++)
51
				log(nestedStatus[i]);
52
	}
53
54
	public void close() {
55
		// nothing to do here
56
	}
57
58
	/*
59
	 * Log a message to the Ant Task
60
	 */
61
	private void log(String message, int statusSeverity) {
62
		try {
63
			log.invoke(task, new Object[] {message, new Integer(mapLogLevels(statusSeverity))});
64
		} catch (IllegalArgumentException e) {
65
			exceptionOccurred(message, e);
66
		} catch (IllegalAccessException e) {
67
			exceptionOccurred(message, e);
68
		} catch (InvocationTargetException e) {
69
			exceptionOccurred(message, e);
70
		}
71
	}
72
73
	/*
74
	 * Show an error message if this the first time, and print status messages.
75
	 */
76
	private void exceptionOccurred(String message, Exception e) {
77
		if (!consoleMessage) {
78
			System.err.println(Messages.MirrorLog_Exception_Occurred);
79
			e.printStackTrace(System.err);
80
			System.err.println(Messages.MirrorLog_Console_Log);
81
			consoleMessage = true;
82
		}
83
		if (message != null)
84
			System.out.println(message);
85
	}
86
87
	/**
88
	 * Copied from AntLogAdapter in pde build.
89
	 */
90
	private int mapLogLevels(int iStatusLevel) {
91
		switch (iStatusLevel) {
92
			case IStatus.ERROR :
93
				return 0;
94
			case IStatus.OK :
95
				return 2;
96
			case IStatus.INFO :
97
				return 2;
98
			case IStatus.WARNING :
99
				return 1;
100
			default :
101
				return 1;
102
		}
103
	}
104
}
(-)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_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java (+36 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_BOTH = RepositoryDescriptor.TYPE_BOTH;
19
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
20
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
21
22
	int kind = TYPE_BOTH;
23
24
	public void setKind(String repoKind) {
25
		if (repoKind.startsWith("m") || repoKind.startsWith("M")) //$NON-NLS-1$//$NON-NLS-2$
26
			kind = IRepository.TYPE_METADATA;
27
28
		if (repoKind.startsWith("a") || repoKind.startsWith("A")) //$NON-NLS-1$//$NON-NLS-2$
29
			kind = IRepository.TYPE_ARTIFACT;
30
	}
31
32
	public int getKind() {
33
		return kind;
34
	}
35
36
}
(-)src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java (+284 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.tests.ant;
12
13
import java.io.*;
14
import java.net.URI;
15
import java.util.Iterator;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.URIUtil;
18
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
19
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.Version;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
27
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
28
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
29
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
30
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
31
import org.eclipse.osgi.util.NLS;
32
33
public class MirrorTaskTest extends AbstractAntProvisioningTest {
34
	private URI destinationRepo;
35
	private URI sourceRepo2;
36
37
	public void setUp() throws Exception {
38
		super.setUp();
39
		// Get a random location to create a repository
40
		destinationRepo = (new File(getTempFolder(), getUniqueString())).toURI();
41
		sourceRepo2 = getTestData("loading error data", "testData/mirror/mirrorSourceRepo2").toURI();
42
	}
43
44
	public void tearDown() throws Exception {
45
		// Remove repository manager references
46
		getArtifactRepositoryManager().removeRepository(destinationRepo);
47
		getMetadataRepositoryManager().removeRepository(destinationRepo);
48
		getArtifactRepositoryManager().removeRepository(sourceRepo2);
49
		getMetadataRepositoryManager().removeRepository(sourceRepo2);
50
		// Cleanup disk
51
		delete(new File(destinationRepo));
52
		super.tearDown();
53
	}
54
55
	/*
56
	 * Test that all IUs can be mirrored
57
	 */
58
	public void testMirrorAllIUSpecified() throws ProvisionException {
59
		AntTaskElement mirror = createMirrorTask();
60
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
61
		addAllIUs(mirror, getMetadataRepositoryManager().loadRepository(sourceRepo2, null));
62
		runAntTask();
63
64
		try {
65
			assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo));
66
			assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo));
67
		} catch (ProvisionException e) {
68
			fail("Failed to load Repository", e);
69
		}
70
	}
71
72
	/*
73
	 * Test that we only mirror specified IUs & Artifacts
74
	 */
75
	public void testMirrorSomeIUSpecified() {
76
		AntTaskElement mirror = createMirrorTask();
77
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
78
		mirror.addElement(createIUElement("anotherplugin", "1.0.0"));
79
80
		runAntTask();
81
82
		try {
83
			assertEquals("Wrong number of Artifact Keys", 1, getArtifactKeyCount(destinationRepo));
84
			assertEquals("Wrong number of IUs", 1, getIUCount(destinationRepo));
85
		} catch (ProvisionException e) {
86
			fail("Failed to load Repository", e);
87
		}
88
	}
89
90
	/*
91
	 * Test that the proper exception is thrown when no IU is provided
92
	 */
93
	public void testMirrorNoIUNoRepo() {
94
		AntTaskElement mirror = createMirrorTask();
95
		mirror.addElement(createSourceElement(sourceRepo2, null));
96
97
		Exception exception = null;
98
		try {
99
			runAntTaskWithExceptions();
100
		} catch (CoreException e) {
101
			exception = e;
102
		}
103
		if (exception == null)
104
			fail("No exception thrown");
105
		if (!(rootCause(exception) instanceof ProvisionException) && !rootCause(exception).getMessage().contains("No IUs"))
106
			fail("Exception is of an unexpected type or message", rootCause(exception));
107
108
	}
109
110
	/*
111
	 * Test that all IUs are mirrored when none are specified
112
	 */
113
	public void testMirrorNoIUSpecified() {
114
		AntTaskElement mirror = createMirrorTask();
115
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
116
117
		runAntTask();
118
119
		try {
120
			assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo));
121
			assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo));
122
		} catch (ProvisionException e) {
123
			fail("Failed to load Repository", e);
124
		}
125
	}
126
127
	/*
128
	 * 
129
	 */
130
	public void testBaselineCompareUsingMD5Comparator() {
131
		//Setup create descriptors with different md5 values
132
		IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3"));
133
		File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/content.xml");
134
		File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/content.xml");
135
136
		//Setup Copy the file to the baseline
137
		File repoLocation = getTestFolder(getUniqueString());
138
		File baselineLocation = getTestFolder(getUniqueString());
139
		File baselineBinaryDirectory = new File(baselineLocation, "binary");
140
		baselineBinaryDirectory.mkdir();
141
		File baselineContentLocation = new File(baselineBinaryDirectory, "testKeyId_1.2.3");
142
		AbstractProvisioningTest.copy("Copying File to baseline", artifact2, baselineContentLocation);
143
144
		IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1);
145
		IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, baselineContentLocation);
146
147
		assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2);
148
		assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5));
149
150
		//Setup make repositories
151
		IArtifactRepository repo = null;
152
		IArtifactRepository baseline = null;
153
		try {
154
			repo = createAndAddIU(repoLocation.toURI(), descriptor1);
155
			baseline = createAndAddIU(baselineLocation.toURI(), descriptor2);
156
		} catch (ProvisionException e) {
157
			fail("Error creating repositories", e);
158
		}
159
160
		//Comparator prints to stderr, redirect that to a file
161
		PrintStream oldErr = System.err;
162
		PrintStream newErr = null;
163
		PrintStream oldOut = System.out;
164
		PrintStream newOut = null;
165
		try {
166
			(new File(destinationRepo)).mkdir();
167
			newErr = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.err")));
168
			newOut = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.out")));
169
		} catch (FileNotFoundException e) {
170
			fail("Error redirecting outputs", e);
171
		}
172
173
		try {
174
			System.setErr(newErr);
175
			System.setOut(newOut);
176
177
			AntTaskElement mirror = createMirrorTask();
178
			mirror.addElement(createSourceElement(repoLocation.toURI(), repoLocation.toURI()));
179
			mirror.addAttribute("baseline", URIUtil.toUnencodedString(baselineLocation.toURI()));
180
			mirror.addAttribute("verbose", String.valueOf(true));
181
			mirror.addAttribute("compare", String.valueOf(true));
182
183
			runAntTaskWithExceptions();
184
			//Set compareAgaist
185
			//String[] args = new String[] {"-source", repoLocation.toURL().toExternalForm(), "-destination", destinationRepo.toURL().toExternalForm(), "-compareAgainst", baselineLocation.toURL().toExternalForm(), "-verbose", "-compare"};
186
			//run the mirror application
187
			//runMirrorApplication("Running with baseline compare", args);
188
		} catch (Exception e) {
189
			fail("Running mirror application with baseline compare", rootCause(e));
190
		} finally {
191
			System.setErr(oldErr);
192
			newErr.close();
193
			System.setOut(oldOut);
194
			newOut.close();
195
		}
196
197
		IArtifactRepository destination = null;
198
		try {
199
			destination = getArtifactRepositoryManager().loadRepository(destinationRepo, null);
200
		} catch (ProvisionException e) {
201
			fail("Error loading destination", e);
202
		}
203
204
		IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor2.getArtifactKey());
205
		assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length);
206
		assertEquals("Ensuring destination contains the descriptor from the baseline", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5));
207
		String msg = NLS.bind("have different MD5 sums for {2}", new Object[] {baseline, repo, descriptor1});
208
		assertLogContains(msg);
209
	}
210
211
	/*
212
	 * Create an IU for a descriptor and the IU+descriptor to the specified repo
213
	 */
214
	protected IArtifactRepository createAndAddIU(URI repoLocation, IArtifactDescriptor descriptor) throws ProvisionException {
215
		IArtifactRepository artifactRepo = getArtifactRepositoryManager().createRepository(repoLocation, "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
216
		artifactRepo.addDescriptor(descriptor);
217
218
		IMetadataRepository metaRepo = getMetadataRepositoryManager().createRepository(repoLocation, "Repo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
219
		InstallableUnit iu = new InstallableUnit();
220
		iu.setId(descriptor.getArtifactKey().getId() + "IU");
221
		iu.setVersion(descriptor.getArtifactKey().getVersion());
222
		iu.setArtifacts(new IArtifactKey[] {descriptor.getArtifactKey()});
223
		metaRepo.addInstallableUnits(new IInstallableUnit[] {iu});
224
225
		return artifactRepo;
226
	}
227
228
	/*
229
	 * Get the number of artifact keys in a repository
230
	 */
231
	protected int getArtifactKeyCount(URI location) throws ProvisionException {
232
		return getArtifactRepositoryManager().loadRepository(location, null).getArtifactKeys().length;
233
	}
234
235
	/*
236
	 * Get the number of IUs in a repository
237
	 */
238
	protected int getIUCount(URI location) throws ProvisionException {
239
		return getMetadataRepositoryManager().loadRepository(location, null).query(InstallableUnitQuery.ANY, new Collector(), null).size();
240
	}
241
242
	/*
243
	 * Add all IUs to the parent element
244
	 */
245
	protected void addAllIUs(AntTaskElement parent, IMetadataRepository repo) {
246
		Collector collector = repo.query(InstallableUnitQuery.ANY, new Collector(), null);
247
248
		for (Iterator iter = collector.iterator(); iter.hasNext();) {
249
			IInstallableUnit iu = (IInstallableUnit) iter.next();
250
			parent.addElement(createIUElement(iu.getId(), iu.getVersion().toString()));
251
		}
252
	}
253
254
	/*
255
	 * Create an element from the specified information
256
	 */
257
	protected AntTaskElement createIUElement(String id, String version) {
258
		AntTaskElement iu = new AntTaskElement("iu");
259
		iu.addAttributes(new String[] {"id", id, "version", version});
260
		return iu;
261
	}
262
263
	/*
264
	 * Create the base mirror task & add it to the script
265
	 */
266
	protected AntTaskElement createMirrorTask() {
267
		AntTaskElement mirror = new AntTaskElement("p2.mirror");
268
		mirror.addElement(getRepositoryElement(destinationRepo, null));
269
		addTask(mirror);
270
		return mirror;
271
	}
272
273
	/*
274
	 * Create a source element with the specified repositories
275
	 */
276
	protected AntTaskElement createSourceElement(URI artifact, URI metadata) {
277
		AntTaskElement source = new AntTaskElement("source");
278
		if (artifact != null)
279
			source.addElement(getRepositoryElement(artifact, AbstractAntProvisioningTest.TYPE_ARTIFACT));
280
		if (metadata != null)
281
			source.addElement(getRepositoryElement(metadata, AbstractAntProvisioningTest.TYPE_METADATA));
282
		return source;
283
	}
284
}
(-)src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java (+199 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.tests.ant;
12
13
import java.io.File;
14
import java.net.URI;
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.p2.repository.helpers.RepositoryHelper;
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.IMetadataRepositoryManager;
21
import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository;
22
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
23
24
public class ModifyCompositeRepositoryTaskTest extends AbstractAntProvisioningTest {
25
	private static final String ADD_ELEMENT = "add";
26
	private static final String REMOVE_ELEMENT = "remove";
27
	private URI compositeSite;
28
	private static URI HTTP_SITE;
29
30
	public void setUp() throws Exception {
31
		super.setUp();
32
		// Get a random location to create a repository
33
		compositeSite = (new File(getTempFolder(), getUniqueString())).toURI();
34
		HTTP_SITE = new URI("http://download.eclipse.org/eclipse/updates/3.4/");
35
	}
36
37
	public void tearDown() throws Exception {
38
		// Remove repository manager references
39
		getArtifactRepositoryManager().removeRepository(compositeSite);
40
		getMetadataRepositoryManager().removeRepository(compositeSite);
41
		// Cleanup disk
42
		delete(new File(compositeSite));
43
		super.tearDown();
44
	}
45
46
	public void testAddChildArtifact() throws Exception {
47
		// Create repository
48
		createCompositeRepository(TYPE_ARTIFACT);
49
		// Create the modify repository task
50
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
51
		addTask(modify);
52
53
		// Create the Add element
54
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
55
		add.addElement(getRepositoryElement(HTTP_SITE, TYPE_ARTIFACT));
56
		modify.addElement(add);
57
58
		// Run the task
59
		runAntTask();
60
61
		CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
62
		assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE));
63
	}
64
65
	public void testAddChildMetadata() {
66
		// Create repository
67
		createCompositeRepository(TYPE_METADATA);
68
		// Create the modify repository task
69
		AntTaskElement modify = createModifyElement(TYPE_METADATA);
70
		addTask(modify);
71
72
		// Create the Add element
73
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
74
		add.addElement(getRepositoryElement(HTTP_SITE, TYPE_METADATA));
75
		modify.addElement(add);
76
77
		// Run the task
78
		runAntTask();
79
80
		CompositeMetadataRepository repo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA);
81
		assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE));
82
	}
83
84
	public void testAddChildBoth() {
85
		// Create repository
86
		createCompositeRepository(null);
87
		// Create the modify repository task
88
		AntTaskElement modify = createModifyElement(null);
89
		addTask(modify);
90
91
		// Create the Add element
92
		AntTaskElement add = createAddElement(null, new URI[] {HTTP_SITE});
93
		modify.addElement(add);
94
95
		// Run the task
96
		runAntTask();
97
98
		CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
99
		assertTrue("Repository does not contain child", artifactRepo.getChildren().contains(HTTP_SITE));
100
101
		CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA);
102
		assertTrue("Repository does not contain child", metadataRepo.getChildren().contains(HTTP_SITE));
103
	}
104
105
	public void testRemoveAllChildren() {
106
		// Create repository
107
		ICompositeRepository parent = createCompositeRepository(TYPE_ARTIFACT);
108
		parent.addChild(HTTP_SITE);
109
110
		// Create the modify repository task
111
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
112
		addTask(modify);
113
		((AntTaskElement) modify.elements.get(0)).addAttributes(new String[] {"append", String.valueOf(false)});
114
115
		// Run the task
116
		runAntTask();
117
118
		CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
119
		assertTrue("Children not removed", artifactRepo.getChildren().isEmpty());
120
121
	}
122
123
	public void testRemoveChild() {
124
		createCompositeRepository(TYPE_ARTIFACT);
125
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
126
		addTask(modify);
127
128
		AntTaskElement add = createAddElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE});
129
		modify.addElement(add);
130
131
		modify = createModifyElement(TYPE_ARTIFACT);
132
		addTask(modify);
133
		AntTaskElement remove = createRemoveElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE});
134
		modify.addElement(remove);
135
136
		runAntTask();
137
138
		CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
139
		assertFalse(repo.getChildren().contains(HTTP_SITE));
140
	}
141
142
	protected ICompositeRepository getCompositeRepository(String type) {
143
		try {
144
			if (type == TYPE_ARTIFACT) {
145
				return (ICompositeRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null);
146
			} else if (type == TYPE_METADATA)
147
				return (ICompositeRepository) getMetadataRepositoryManager().loadRepository(compositeSite, null);
148
			else
149
				fail("No type specified");
150
		} catch (ProvisionException e) {
151
			fail("Failed to load repository", e);
152
		} catch (ClassCastException e) {
153
			fail("Repository is not composite", e);
154
		}
155
		// Will not occur
156
		return null;
157
	}
158
159
	protected AntTaskElement createRemoveElement(String type, URI[] addresses) {
160
		AntTaskElement add = new AntTaskElement(REMOVE_ELEMENT);
161
		for (int i = 0; i < addresses.length; i++)
162
			add.addElement(getRepositoryElement(addresses[i], type));
163
		return add;
164
	}
165
166
	protected AntTaskElement createAddElement(String type, URI[] addresses) {
167
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
168
		for (int i = 0; i < addresses.length; i++)
169
			add.addElement(getRepositoryElement(addresses[i], type));
170
		return add;
171
	}
172
173
	protected AntTaskElement createModifyElement(String type) {
174
		AntTaskElement modifyCompositeTask = new AntTaskElement("p2.modify.composite.repository.children");
175
		modifyCompositeTask.addElement(getRepositoryElement(compositeSite, type));
176
177
		return modifyCompositeTask;
178
	}
179
180
	protected ICompositeRepository createCompositeRepository(String type) {
181
		ICompositeRepository repo = null;
182
		try {
183
			if (TYPE_ARTIFACT.equals(type) || type == null) {
184
				repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getArtifactRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null));
185
			}
186
			if (TYPE_METADATA.equals(type) || type == null) {
187
				repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getMetadataRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null));
188
			}
189
		} catch (ProvisionException e) {
190
			fail("Failed to create composite repository", e);
191
		} catch (IllegalStateException e) {
192
			fail("failed to create writeable composite repository", e);
193
		}
194
		return repo;
195
		/*AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository");
196
		createCompositeTask.addElement(getRepositoryElement(compositeSite, type));
197
		addTask(createCompositeTask);*/
198
	}
199
}

Return to bug 265550