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 274576 | Differences between
and this patch

Collapse All | Expand All

(-).externalToolBuilders/Build Publisher Ant Tasks.launch (-5 / +4 lines)
Lines 1-13 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
2
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
4
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
3
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
5
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
4
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
6
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
5
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
7
<listEntry value="/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml"/>
6
<listEntry value="/org.eclipse.equinox.p2.publisher"/>
8
</listAttribute>
7
</listAttribute>
9
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
8
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
10
<listEntry value="1"/>
9
<listEntry value="4"/>
11
</listAttribute>
10
</listAttribute>
12
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
11
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
13
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
12
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
Lines 17-20 Link Here
17
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml}"/>
16
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.equinox.p2.publisher/scripts/buildExtraJAR.xml}"/>
18
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
17
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
19
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
18
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
20
</launchConfiguration>
19
</launchConfiguration>
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/messages.properties (+9 lines)
Lines 12-14 Link Here
12
exception_errorOccurredCallingGenerator = An error occurred when calling generator.
12
exception_errorOccurredCallingGenerator = An error occurred when calling generator.
13
exception_errorArtifactRepo = Error setting artifact repository {0}.
13
exception_errorArtifactRepo = Error setting artifact repository {0}.
14
exception_errorMetadataRepo = Error setting metadata repository {0}.
14
exception_errorMetadataRepo = Error setting metadata repository {0}.
15
16
AbstractApplication_no_valid_destinations=Unable to locate a valid destination repository.
17
exception_invalidDestination=Invalid destination repository location: {0}.
18
exception_invalidSource=Invalid source repository location: {0}.
19
unknown_repository_type=Repository is of an unknown type: {0}
20
21
DestinationNotModifiable=Destination repository is not modifiable: {0}
22
locationMustBeAbsolute=Location must be absolute
23
schemeNotSupported=Scheme not supported
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/TaskMessages.java (+9 lines)
Lines 19-24 Link Here
19
	public static String exception_errorArtifactRepo;
19
	public static String exception_errorArtifactRepo;
20
	public static String exception_errorMetadataRepo;
20
	public static String exception_errorMetadataRepo;
21
21
22
	public static String AbstractApplication_no_valid_destinations;
23
	public static String exception_invalidDestination;
24
	public static String exception_invalidSource;
25
	public static String unknown_repository_type;
26
27
	public static String DestinationNotModifiable;
28
	public static String locationMustBeAbsolute;
29
	public static String schemeNotSupported;
30
22
	static {
31
	static {
23
		// load message values from bundle file
32
		// load message values from bundle file
24
		NLS.initializeMessages(BUNDLE_NAME, TaskMessages.class);
33
		NLS.initializeMessages(BUNDLE_NAME, TaskMessages.class);
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java (-21 / +47 lines)
Lines 8-25 Link Here
8
 ******************************************************************************/
8
 ******************************************************************************/
9
package org.eclipse.equinox.internal.p2.publisher.ant;
9
package org.eclipse.equinox.internal.p2.publisher.ant;
10
10
11
import org.eclipse.equinox.internal.p2.publisher.ant.repository.*;
12
11
import java.net.URI;
13
import java.net.URI;
12
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
13
import java.util.*;
15
import java.util.*;
14
import org.apache.tools.ant.Task;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
17
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
17
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
18
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
18
import org.eclipse.equinox.internal.p2.publisher.Messages;
19
import org.eclipse.equinox.internal.p2.publisher.Messages;
20
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
23
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
20
import org.eclipse.equinox.p2.publisher.*;
24
import org.eclipse.equinox.p2.publisher.*;
21
25
22
public abstract class AbstractPublishTask extends Task {
26
public abstract class AbstractPublishTask extends AbstractRepositoryTask {
23
	protected static final String ANT_PROPERTY_PREFIX = "${"; //$NON-NLS-1$
27
	protected static final String ANT_PROPERTY_PREFIX = "${"; //$NON-NLS-1$
24
28
25
	/**
29
	/**
Lines 83-120 Link Here
83
	protected String artifactRepoName;
87
	protected String artifactRepoName;
84
	protected PublisherInfo provider = null;
88
	protected PublisherInfo provider = null;
85
	protected List contextRepositories = new ArrayList();
89
	protected List contextRepositories = new ArrayList();
90
	protected PublisherApplication app;
91
92
	public AbstractPublishTask() {
93
		app = new PublisherApplication();
94
		application = app;
95
	}
86
96
87
	protected IStatus createConfigurationEror(String message) {
97
	protected IStatus createConfigurationEror(String message) {
88
		return new Status(IStatus.ERROR, "org.eclipse.equinox.p2.publisher", message); //$NON-NLS-1$
98
		return new Status(IStatus.ERROR, "org.eclipse.equinox.p2.publisher", message); //$NON-NLS-1$
89
	}
99
	}
90
100
91
	protected void initializeRepositories(PublisherInfo info) throws ProvisionException {
101
	protected void initializeRepositories(PublisherInfo info) throws ProvisionException {
92
		if (artifactLocation != null)
102
		prepareSourceRepos();
103
		app.initializeRepos(new NullProgressMonitor());
104
105
		if (app.getArtifactRepository() != null) {
106
			IArtifactRepository repo = app.getArtifactRepository();
107
			info.setArtifactRepository(Publisher.createArtifactRepository(repo.getLocation(), artifactRepoName, append, (repo.getProperties().get(IRepository.PROP_COMPRESSED) == null) ? compress : Boolean.valueOf((String) repo.getProperties().get(IRepository.PROP_COMPRESSED)).booleanValue(), reusePackedFiles));
108
		} else if (artifactLocation != null)
93
			info.setArtifactRepository(Publisher.createArtifactRepository(artifactLocation, artifactRepoName, append, compress, reusePackedFiles));
109
			info.setArtifactRepository(Publisher.createArtifactRepository(artifactLocation, artifactRepoName, append, compress, reusePackedFiles));
94
		else if ((info.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
110
		else if ((info.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
95
			throw new ProvisionException(createConfigurationEror(Messages.exception_noArtifactRepo));
111
			throw new ProvisionException(createConfigurationEror(Messages.exception_noArtifactRepo));
96
		if (metadataLocation == null)
97
			throw new ProvisionException(createConfigurationEror(Messages.exception_noMetadataRepo));
98
		info.setMetadataRepository(Publisher.createMetadataRepository(metadataLocation, metadataRepoName, append, compress));
99
112
100
		if (contextRepositories.size() > 0) {
113
		if (app.getMetadataRepository() != null) {
101
			CompositeMetadataRepository contextMetadata = CompositeMetadataRepository.createMemoryComposite();
114
			IMetadataRepository repo = app.getMetadataRepository();
102
			CompositeArtifactRepository contextArtifact = CompositeArtifactRepository.createMemoryComposite();
115
			info.setMetadataRepository(Publisher.createMetadataRepository(repo.getLocation(), metadataRepoName, append, (repo.getProperties().get(IRepository.PROP_COMPRESSED) == null) ? compress : Boolean.valueOf((String) repo.getProperties().get(IRepository.PROP_COMPRESSED)).booleanValue()));
103
116
		} else if (metadataLocation != null)
104
			for (Iterator iterator = contextRepositories.iterator(); iterator.hasNext();) {
117
			info.setMetadataRepository(Publisher.createMetadataRepository(metadataLocation, metadataRepoName, append, compress));
105
				RepoEntry entry = (RepoEntry) iterator.next();
118
		else
106
				if (contextMetadata != null && entry.isMetadataRepository())
119
			throw new ProvisionException(createConfigurationEror(Messages.exception_noMetadataRepo));
107
					contextMetadata.addChild(entry.getRepositoryLocation());
108
				if (contextArtifact != null && entry.isArtifactRepository())
109
					contextArtifact.addChild(entry.getRepositoryLocation());
110
			}
111
120
112
			if (contextMetadata != null && contextMetadata.getChildren().size() > 0)
121
		CompositeArtifactRepository contextArtifact = (CompositeArtifactRepository) app.getCompositeArtifactRepository();
113
				info.setContextMetadataRepository(contextMetadata);
122
		CompositeMetadataRepository contextMetadata = (CompositeMetadataRepository) app.getCompositeMetadataRepository();
114
123
115
			if (contextArtifact != null && contextArtifact.getChildren().size() > 0)
124
		for (Iterator iterator = contextRepositories.iterator(); iterator.hasNext();) {
116
				info.setContextArtifactRepository(contextArtifact);
125
			RepoEntry entry = (RepoEntry) iterator.next();
126
			if (contextMetadata != null && entry.isMetadataRepository())
127
				contextMetadata.addChild(entry.getRepositoryLocation());
128
			if (contextArtifact != null && entry.isArtifactRepository())
129
				contextArtifact.addChild(entry.getRepositoryLocation());
117
		}
130
		}
131
132
		if (contextMetadata != null && contextMetadata.getChildren().size() > 0)
133
			info.setContextMetadataRepository(contextMetadata);
134
135
		if (contextArtifact != null && contextArtifact.getChildren().size() > 0)
136
			info.setContextArtifactRepository(contextArtifact);
118
	}
137
	}
119
138
120
	protected PublisherInfo getInfo() {
139
	protected PublisherInfo getInfo() {
Lines 180-183 Link Here
180
	public void addConfiguredContextRepository(RepoEntry repo) {
199
	public void addConfiguredContextRepository(RepoEntry repo) {
181
		contextRepositories.add(repo);
200
		contextRepositories.add(repo);
182
	}
201
	}
202
203
	/*
204
	 * Allows a list of <repository> elements
205
	 */
206
	public void addConfiguredContext(RepositoryList list) {
207
		addConfiguredSource(list);
208
	}
183
}
209
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/DestinationRepository.java (+60 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.internal.p2.publisher.ant.repository;
12
13
import java.net.URISyntaxException;
14
import org.apache.tools.ant.BuildException;
15
import org.apache.tools.ant.types.DataType;
16
import org.eclipse.core.runtime.URIUtil;
17
18
/*
19
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.DestinationRepository
20
 */
21
public class DestinationRepository extends DataType {
22
23
	private RepositoryDescriptor descriptor = new RepositoryDescriptor();
24
25
	public void setCompressed(boolean compress) {
26
		descriptor.setCompressed(compress);
27
	}
28
29
	public void setName(String repoName) {
30
		descriptor.setName(repoName);
31
	}
32
33
	public void setLocation(String repoLocation) throws BuildException {
34
		try {
35
			descriptor.setLocation(URIUtil.fromString(repoLocation));
36
		} catch (URISyntaxException e) {
37
			throw new BuildException(e);
38
		}
39
	}
40
41
	public void setFormat(String formatLocation) {
42
		try {
43
			descriptor.setFormat(URIUtil.fromString(formatLocation));
44
		} catch (URISyntaxException e) {
45
			throw new BuildException(e);
46
		}
47
	}
48
49
	public void setAppend(boolean appendMode) {
50
		descriptor.setAppend(appendMode);
51
	}
52
53
	public void setKind(String repoKind) {
54
		descriptor.setKind(repoKind);
55
	}
56
57
	public RepositoryDescriptor getDescriptor() {
58
		return descriptor;
59
	}
60
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/PublisherApplication.java (+213 lines)
Added Link Here
1
package org.eclipse.equinox.internal.p2.publisher.ant.repository;
2
3
import java.net.*;
4
import java.util.*;
5
import org.eclipse.core.runtime.IProgressMonitor;
6
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
7
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
8
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
9
import org.eclipse.equinox.internal.p2.publisher.Activator;
10
import org.eclipse.equinox.internal.p2.publisher.ant.TaskMessages;
11
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
12
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
13
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
14
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
16
import org.eclipse.equinox.internal.provisional.p2.repository.*;
17
import org.eclipse.osgi.util.NLS;
18
19
/*
20
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.PublisherApplication
21
 */
22
public class PublisherApplication {
23
24
	private IArtifactRepository destinationArtifactRepository = null;
25
	private IMetadataRepository destinationMetadataRepository = null;
26
27
	private CompositeMetadataRepository compositeMetadataRepository = null;
28
	private CompositeArtifactRepository compositeArtifactRepository = null;
29
30
	private List sourceRepositories = new ArrayList();
31
	private List destinationRepos = new ArrayList();
32
	private List artifactReposToRemove = new ArrayList();
33
	private List metadataReposToRemove = new ArrayList();
34
35
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
36
		IArtifactRepositoryManager artifactRepositoryManager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
37
		IMetadataRepositoryManager metadataRepositoryManager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
38
		URI curLocation = null;
39
		try {
40
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
41
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
42
				curLocation = repo.getRepoLocation();
43
				if (repo.isBoth()) {
44
					addRepository(artifactRepositoryManager, curLocation, 0, progress);
45
					addRepository(metadataRepositoryManager, curLocation, 0, progress);
46
				} else if (repo.isArtifact())
47
					addRepository(artifactRepositoryManager, curLocation, 0, progress);
48
				else if (repo.isMetadata())
49
					addRepository(metadataRepositoryManager, curLocation, 0, progress);
50
				else
51
					throw new ProvisionException(NLS.bind(TaskMessages.unknown_repository_type, repo.getRepoLocation()));
52
			}
53
		} catch (ProvisionException e) {
54
			if (e.getCause() instanceof MalformedURLException) {
55
				throw new ProvisionException(NLS.bind(TaskMessages.exception_invalidSource, curLocation), e);
56
			}
57
			throw e;
58
		}
59
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
60
	}
61
62
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
63
		RepositoryDescriptor artifactRepoDescriptor = null;
64
		RepositoryDescriptor metadataRepoDescriptor = null;
65
66
		Iterator iter = destinationRepos.iterator();
67
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
68
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
69
			if (repo.isArtifact() && artifactRepoDescriptor == null)
70
				artifactRepoDescriptor = repo;
71
			if (repo.isMetadata() && metadataRepoDescriptor == null)
72
				metadataRepoDescriptor = repo;
73
		}
74
75
		if (artifactRepoDescriptor != null)
76
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
77
		if (metadataRepoDescriptor != null)
78
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
79
	}
80
81
	protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
82
		try {
83
			IMetadataRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
84
			if (initDestinationRepository(repository, toInit))
85
				return repository;
86
		} catch (ProvisionException e) {
87
			//fall through and create a new repository below
88
		}
89
90
		IMetadataRepository source = null;
91
		try {
92
			if (toInit.getFormat() != null)
93
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
94
		} catch (ProvisionException e) {
95
			//Ignore.
96
		}
97
		//This code assumes source has been successfully loaded before this point
98
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
99
		try {
100
			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);
101
			if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
102
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
103
			return (IMetadataRepository) RepositoryHelper.validDestinationRepository(result);
104
		} catch (UnsupportedOperationException e) {
105
			throw new ProvisionException(NLS.bind(TaskMessages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
106
		}
107
	}
108
109
	protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
110
		try {
111
			IArtifactRepository repository = addRepository(mgr, toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
112
			if (initDestinationRepository(repository, toInit))
113
				return repository;
114
		} catch (ProvisionException e) {
115
			//fall through and create a new repository below
116
		}
117
		IArtifactRepository source = null;
118
		try {
119
			if (toInit.getFormat() != null)
120
				source = mgr.loadRepository(toInit.getFormat(), 0, null);
121
		} catch (ProvisionException e) {
122
			//Ignore.
123
		}
124
		//This code assumes source has been successfully loaded before this point
125
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
126
		// TODO for now create a Simple repo by default.
127
		try {
128
			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);
129
			if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
130
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
131
			return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result);
132
		} catch (UnsupportedOperationException e) {
133
			throw new ProvisionException(NLS.bind(TaskMessages.exception_invalidDestination, toInit.getRepoLocation()), e.getCause());
134
		}
135
	}
136
137
	protected boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) {
138
		if (repository != null && repository.isModifiable()) {
139
			if (descriptor.getName() != null)
140
				repository.setName(descriptor.getName());
141
			if (repository instanceof ICompositeRepository && !descriptor.isAppend())
142
				((ICompositeRepository) repository).removeAllChildren();
143
			else if (repository instanceof IMetadataRepository && !descriptor.isAppend())
144
				((IMetadataRepository) repository).removeAll();
145
			else if (repository instanceof IArtifactRepository && !descriptor.isAppend())
146
				((IArtifactRepository) repository).removeAll();
147
			return true;
148
		}
149
		return false;
150
	}
151
152
	public IArtifactRepository getArtifactRepository() {
153
		return destinationArtifactRepository;
154
	}
155
156
	public IMetadataRepository getMetadataRepository() {
157
		return destinationMetadataRepository;
158
	}
159
160
	public List getContextRepositories() {
161
		return sourceRepositories;
162
	}
163
164
	public void addSource(RepositoryDescriptor descriptor) {
165
		sourceRepositories.add(descriptor);
166
	}
167
168
	public IMetadataRepository getCompositeMetadataRepository() {
169
		if (compositeMetadataRepository == null) {
170
			try {
171
				compositeMetadataRepository = new CompositeMetadataRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$
172
			} catch (URISyntaxException e) {
173
				//Can't happen
174
			}
175
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
176
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
177
				if (repo.isMetadata())
178
					compositeMetadataRepository.addChild(repo.getRepoLocation());
179
			}
180
		}
181
		return compositeMetadataRepository;
182
	}
183
184
	public IArtifactRepository getCompositeArtifactRepository() {
185
		if (compositeArtifactRepository == null) {
186
			try {
187
				compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$
188
			} catch (URISyntaxException e) {
189
				//Can't happen
190
			}
191
			for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
192
				RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
193
				if (repo.isArtifact())
194
					compositeArtifactRepository.addChild(repo.getRepoLocation());
195
			}
196
		}
197
		return compositeArtifactRepository;
198
	}
199
200
	//Helper to add a repository. It takes care of adding the repos to the deletion list and loading it
201
	protected IArtifactRepository addRepository(IArtifactRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
202
		if (!manager.contains(location))
203
			artifactReposToRemove.add(location);
204
		return manager.loadRepository(location, flags, monitor);
205
	}
206
207
	//Helper to add a repository. It takes care of adding the repos to the deletion list and loading it 
208
	protected IMetadataRepository addRepository(IMetadataRepositoryManager manager, URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
209
		if (!manager.contains(location))
210
			metadataReposToRemove.add(location);
211
		return manager.loadRepository(location, flags, monitor);
212
	}
213
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/AbstractRepositoryTask.java (+86 lines)
Added Link Here
1
package org.eclipse.equinox.internal.p2.publisher.ant.repository;
2
3
import java.io.File;
4
import java.net.URI;
5
import java.util.*;
6
import org.apache.tools.ant.*;
7
import org.apache.tools.ant.types.FileSet;
8
import org.eclipse.core.runtime.URIUtil;
9
import org.eclipse.equinox.internal.p2.publisher.ant.TaskMessages;
10
import org.eclipse.osgi.util.NLS;
11
12
/*
13
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.AbstractRepositoryTask
14
 */
15
public abstract class AbstractRepositoryTask extends Task {
16
	protected static final String ANT_PREFIX = "${"; //$NON-NLS-1$
17
	private List sourceRepos = new ArrayList();
18
	protected PublisherApplication application;
19
20
	/*
21
	 * Add source repositories to mirror from
22
	 */
23
	public void addConfiguredSource(RepositoryList sourceList) {
24
		for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) {
25
			DestinationRepository repo = (DestinationRepository) iter.next();
26
			application.addSource(repo.getDescriptor());
27
		}
28
29
		for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) {
30
			FileSet fileSet = (FileSet) iter.next();
31
			sourceRepos.add(fileSet);
32
			// Added to the application later through prepareSourceRepos
33
		}
34
	}
35
36
	/*
37
	 * If the user specified some source repositories via sub-elements
38
	 * then add them to the transformer for consideration.
39
	 */
40
	protected void prepareSourceRepos() {
41
		if (sourceRepos == null || sourceRepos.isEmpty())
42
			return;
43
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
44
			RepositoryFileSet fileset = (RepositoryFileSet) iter.next();
45
46
			if (fileset.getDir() != null) {
47
				DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
48
				String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
49
				for (int i = 0; i < 2; i++) {
50
					for (int j = 0; j < elements[i].length; j++) {
51
						File file = new File(fileset.getDir(), elements[i][j]);
52
						URI uri = file.toURI();
53
54
						if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
55
							uri = URIUtil.toJarURI(uri, null);
56
						}
57
						if (fileset.isBoth()) {
58
							addArtifactSourceRepository(uri);
59
							addMetadataSourceRepository(uri);
60
						} else if (fileset.isArtifact())
61
							addArtifactSourceRepository(uri);
62
						else if (fileset.isMetadata())
63
							addMetadataSourceRepository(uri);
64
						else
65
							throw new BuildException(NLS.bind(TaskMessages.unknown_repository_type, uri));
66
					}
67
				}
68
			}
69
		}
70
		sourceRepos.clear();
71
	}
72
73
	protected void addMetadataSourceRepository(URI repoLocation) {
74
		RepositoryDescriptor source = new RepositoryDescriptor();
75
		source.setLocation(repoLocation);
76
		source.setKind(RepositoryDescriptor.KIND_METADATA);
77
		application.addSource(source);
78
	}
79
80
	protected void addArtifactSourceRepository(URI repoLocation) {
81
		RepositoryDescriptor source = new RepositoryDescriptor();
82
		source.setLocation(repoLocation);
83
		source.setKind(RepositoryDescriptor.KIND_ARTIFACT);
84
		application.addSource(source);
85
	}
86
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/RepositoryFileSet.java (+44 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.internal.p2.publisher.ant.repository;
12
13
import org.apache.tools.ant.types.FileSet;
14
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
15
16
/*
17
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.RepositoryFileSet
18
 */
19
public class RepositoryFileSet extends FileSet {
20
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
21
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
22
23
	private int kind = RepositoryDescriptor.TYPE_BOTH;
24
25
	public void setKind(String repoKind) {
26
		kind = RepositoryDescriptor.determineKind(repoKind);
27
	}
28
29
	public int getKind() {
30
		return kind;
31
	}
32
33
	public boolean isBoth() {
34
		return kind == RepositoryDescriptor.TYPE_BOTH;
35
	}
36
37
	public boolean isArtifact() {
38
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
39
	}
40
41
	public boolean isMetadata() {
42
		return kind == RepositoryDescriptor.TYPE_BOTH || kind == IRepository.TYPE_METADATA;
43
	}
44
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/RepositoryDescriptor.java (+112 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.internal.p2.publisher.ant.repository;
12
13
import java.net.URI;
14
import org.eclipse.equinox.internal.p2.publisher.ant.TaskMessages;
15
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
16
import org.eclipse.osgi.util.NLS;
17
18
/*
19
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.RepositoryDescriptor
20
 */
21
public class RepositoryDescriptor {
22
23
	public static final int TYPE_BOTH = -1;
24
	public static final String KIND_ARTIFACT = "A"; //$NON-NLS-1$
25
	public static final String KIND_METADATA = "M"; //$NON-NLS-1$
26
27
	private boolean compressed = true;
28
	private boolean append = true;
29
	private String name = null;
30
	private URI location = null;
31
	private URI format = null;
32
	private int kind = TYPE_BOTH;
33
34
	public void setCompressed(boolean compress) {
35
		compressed = compress;
36
	}
37
38
	public void setName(String repoName) {
39
		name = repoName;
40
	}
41
42
	public void setLocation(URI repoLocation) {
43
		location = RepositoryHelper.localRepoURIHelper(repoLocation);
44
	}
45
46
	public void setFormat(URI format) {
47
		this.format = RepositoryHelper.localRepoURIHelper(format);
48
	}
49
50
	public void setAppend(boolean appendMode) {
51
		append = appendMode;
52
	}
53
54
	public boolean isCompressed() {
55
		return compressed;
56
	}
57
58
	public boolean isAppend() {
59
		return append;
60
	}
61
62
	public String getName() {
63
		return name;
64
	}
65
66
	public URI getRepoLocation() {
67
		return location;
68
	}
69
70
	public URI getFormat() {
71
		return format;
72
	}
73
74
	public int getKind() {
75
		return kind;
76
	}
77
78
	public boolean isBoth() {
79
		return kind == TYPE_BOTH;
80
	}
81
82
	public boolean isArtifact() {
83
		return kind == TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
84
	}
85
86
	public boolean isMetadata() {
87
		return kind == TYPE_BOTH || kind == IRepository.TYPE_METADATA;
88
	}
89
90
	public void setKind(String repoKind) {
91
		kind = determineKind(repoKind);
92
	}
93
94
	/*
95
	 * Determine the repository type
96
	 */
97
	public static int determineKind(String repoKind) {
98
		if (kindMatches(repoKind, KIND_METADATA))
99
			return IRepository.TYPE_METADATA;
100
		else if (kindMatches(repoKind, KIND_ARTIFACT))
101
			return IRepository.TYPE_ARTIFACT;
102
103
		throw new IllegalArgumentException(NLS.bind(TaskMessages.unknown_repository_type, repoKind));
104
	}
105
106
	/*
107
	 * Determine if the repository kind matches the identifier kind
108
	 */
109
	public static boolean kindMatches(String repoKind, String kindIdentifier) {
110
		return repoKind.startsWith(kindIdentifier) || repoKind.startsWith(kindIdentifier.toLowerCase());
111
	}
112
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/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.internal.p2.publisher.ant.repository;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
import org.apache.tools.ant.types.DataType;
16
17
/*
18
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.RepositoryFileSet
19
 */
20
public class RepositoryList extends DataType {
21
	List repositories = new ArrayList();
22
	List sourceFileSets = new ArrayList();
23
24
	public DestinationRepository createRepository() {
25
		DestinationRepository repo = new DestinationRepository();
26
		repositories.add(repo);
27
		return repo;
28
	}
29
30
	public RepositoryFileSet createFileSet() {
31
		RepositoryFileSet fileSet = new RepositoryFileSet();
32
		sourceFileSets.add(fileSet);
33
		return fileSet;
34
	}
35
36
	public List getRepositoryList() {
37
		return repositories;
38
	}
39
40
	public List getFileSetList() {
41
		return sourceFileSets;
42
	}
43
}
(-)src_ant/org/eclipse/equinox/internal/p2/publisher/ant/repository/RepositoryHelper.java (+85 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
 *     Cloudsmith Inc - ongoing implementation
11
 *******************************************************************************/
12
package org.eclipse.equinox.internal.p2.publisher.ant.repository;
13
14
import java.io.File;
15
import java.net.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.equinox.internal.p2.publisher.Activator;
18
import org.eclipse.equinox.internal.p2.publisher.ant.TaskMessages;
19
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
20
import org.eclipse.osgi.util.NLS;
21
22
/*
23
 * Methods copied from org.eclipse.equinox.p2.internal.repository.tools.tasks.RepositoryFileSet
24
 */
25
public class RepositoryHelper {
26
	protected static final String FILE_SCHEME = "file"; //$NON-NLS-1$
27
28
	/**
29
	 * If the provided URI can be interpreted as representing a local address (no schema, or one letter schema) 
30
	 * but is missing the file schema, a new URI is created which represents the local file. 
31
	 * 
32
	 * @param location the URI to convert
33
	 * @return the converted URI, or the original
34
	 */
35
	public static URI localRepoURIHelper(URI location) {
36
		if (location == null)
37
			return null;
38
		if (location.getScheme() == null)
39
			// Probably a local path:  /home/user/repo
40
			location = (new File(location.getPath())).getAbsoluteFile().toURI();
41
		else if (location.getScheme().length() == 1)
42
			// Probably a windows path:  C:\repo
43
			location = (new File(URIUtil.toUnencodedString(location))).toURI();
44
		else if (!FILE_SCHEME.equalsIgnoreCase(location.getScheme()))
45
			// This else must occur last!
46
			return location;
47
48
		// Zipped repository?
49
		String lowerCase = location.toString().toLowerCase();
50
		if (lowerCase.endsWith(".jar") || lowerCase.endsWith(".zip")) //$NON-NLS-1$//$NON-NLS-2$
51
			return URIUtil.toJarURI(location, null);
52
		return location;
53
	}
54
55
	/**
56
	 * Determine if the repository could be used as a valid destination (eg, it is modifiable)
57
	 * @param repository the repository to test
58
	 * @return the repository
59
	 */
60
	public static IRepository validDestinationRepository(IRepository repository) {
61
		if (!repository.isModifiable())
62
			throw new IllegalStateException(NLS.bind(TaskMessages.DestinationNotModifiable, repository.getLocation()));
63
		return repository;
64
	}
65
66
	/**
67
	 * Determine if the location is a syntactically correct repository location. Intended to be used
68
	 * from the UI when checking validity of user input.
69
	 * 
70
	 * @throws IllegalArgumentException if location is null
71
	 */
72
	public static IStatus checkRepositoryLocationSyntax(URI location) {
73
		if (location == null)
74
			throw new IllegalArgumentException("Location cannot be null"); //$NON-NLS-1$
75
		if (!location.isAbsolute())
76
			return new Status(IStatus.ERROR, Activator.ID, TaskMessages.locationMustBeAbsolute);
77
		try {
78
			new URL(location.getScheme(), "dummy.com", -1, "dummy.txt"); //$NON-NLS-1$ //$NON-NLS-2$
79
		} catch (MalformedURLException e) {
80
			return new Status(IStatus.ERROR, Activator.ID, TaskMessages.schemeNotSupported);
81
82
		}
83
		return Status.OK_STATUS;
84
	}
85
}

Return to bug 274576