diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse')
2 files changed, 120 insertions, 20 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java index 3dd4c8e73..638c2bb77 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java @@ -18,11 +18,9 @@ import org.apache.tools.ant.*; import org.apache.tools.ant.types.FileSet; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.URIUtil; -import org.eclipse.equinox.internal.provisional.p2.core.Version; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; -import org.eclipse.equinox.internal.provisional.p2.metadata.query.LatestIUVersionQuery; import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; -import org.eclipse.equinox.internal.provisional.p2.query.*; +import org.eclipse.equinox.internal.provisional.p2.query.Collector; +import org.eclipse.equinox.internal.provisional.p2.query.Query; import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication; public abstract class AbstractRepositoryTask extends Task { @@ -154,22 +152,14 @@ public abstract class AbstractRepositoryTask extends Task { List result = new ArrayList(); for (Iterator iter = iuTasks.iterator(); iter.hasNext();) { IUDescription iu = (IUDescription) iter.next(); - String id = iu.getId(); - Version version = null; + Query iuQuery = iu.createQuery(); Collector collector = new Collector(); - if (iu.getVersion() == null || iu.getVersion().length() == 0 || iu.getVersion().startsWith("${")) {//$NON-NLS-1$ - // Get the latest version of the iu - Query query = new CompositeQuery(new Query[] {new InstallableUnitQuery(id), new LatestIUVersionQuery()}); - repository.query(query, collector, null); - } else { - version = new Version(iu.getVersion()); - repository.query(new InstallableUnitQuery(id, version), collector, null); - } + repository.query(iuQuery, collector, null); - if (collector.isEmpty()) - throw new BuildException("Unable to find: " + id + (version != null ? " " + version : "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - result.add(collector.iterator().next()); + if (iu.isRequired() && collector.isEmpty()) + throw new BuildException("Unable to find: " + iu.toString()); //$NON-NLS-1$ + result.addAll(collector.toCollection()); } return result; } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java index 2e928a142..9cc87f102 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java @@ -10,26 +10,55 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; +import java.util.*; import org.apache.tools.ant.types.DataType; +import org.eclipse.equinox.internal.provisional.p2.core.Version; +import org.eclipse.equinox.internal.provisional.p2.metadata.query.*; +import org.eclipse.equinox.internal.provisional.p2.query.CompositeQuery; +import org.eclipse.equinox.internal.provisional.p2.query.Query; /** * @since 1.0 */ public class IUDescription extends DataType { - + static private final String QUERY_PROPERTY = "property"; //$NON-NLS-1$ + static private final String QUERY_NAME = "name"; //$NON-NLS-1$ + static private final String QUERY_VALUE = "value"; //$NON-NLS-1$ + static private final String ANT_PREFIX = "${"; //$NON-NLS-1$ private String id; private String version; + private String queryString; + private boolean required = true; public IUDescription() { super(); } public void setId(String value) { - this.id = value; + if (value != null && !value.startsWith(ANT_PREFIX)) + this.id = value; } public void setVersion(String value) { - this.version = value; + if (value != null && !value.startsWith(ANT_PREFIX)) + this.version = value; + } + + public void setQuery(String query) { + if (query != null && !query.startsWith(ANT_PREFIX)) + this.queryString = query; + } + + public void setRequired(boolean required) { + this.required = required; + } + + public boolean isRequired() { + return required; + } + + public String getQueryString() { + return queryString; } public String getId() { @@ -39,4 +68,85 @@ public class IUDescription extends DataType { public String getVersion() { return version; } + + public String toString() { + StringBuffer buffer = new StringBuffer("IU["); //$NON-NLS-1$ + if (id != null) { + buffer.append(" id="); //$NON-NLS-1$ + buffer.append(id); + } + if (version != null) { + buffer.append(" version="); //$NON-NLS-1$ + buffer.append(version); + } + if (queryString != null) { + buffer.append(" query="); //$NON-NLS-1$ + buffer.append(queryString); + } + return super.toString(); + } + + public Query createQuery() { + List queries = new ArrayList(); + if (id != null) { + if (version == null || version.length() == 0) { + // Get the latest version of the iu + queries.add(new InstallableUnitQuery(id)); + queries.add(new LatestIUVersionQuery()); + } else { + Version iuVersion = new Version(version); + queries.add(new InstallableUnitQuery(id, iuVersion)); + } + } + + Query iuQuery = processQueryString(); + if (iuQuery != null) + queries.add(iuQuery); + + if (queries.size() == 1) + return (Query) queries.get(0); + return new CompositeQuery((Query[]) queries.toArray(new Query[queries.size()])); + } + + private Query processQueryString() { + if (queryString == null) + return null; + int startIdx = queryString.indexOf('['); + int endIdx = queryString.lastIndexOf(']'); + if (startIdx == -1 || endIdx == -1 || endIdx < startIdx) + return null; + String element = queryString.substring(0, startIdx); + Map attributes = processQueryAttributes(queryString.substring(startIdx + 1, endIdx)); + if (element.equals(QUERY_PROPERTY)) { + String name = (String) attributes.get(QUERY_NAME); + String value = (String) attributes.get(QUERY_VALUE); + if (name == null) + return null; + return new IUPropertyQuery(name, value); + } + + return null; + } + + private Map processQueryAttributes(String attributes) { + if (attributes == null || attributes.length() == 0) + return Collections.EMPTY_MAP; + + Map result = new HashMap(); + int start = 0; + int idx = 0; + while ((idx = attributes.indexOf('@', start)) > -1) { + int equals = attributes.indexOf('=', idx); + int startQuote = attributes.indexOf('\'', equals); + int endQuote = attributes.indexOf('\'', startQuote + 1); + if (equals == -1 || startQuote <= equals || endQuote <= startQuote) + break; + String key = attributes.substring(idx + 1, equals).trim(); + String value = attributes.substring(startQuote + 1, endQuote); + result.put(key, value); + + start = endQuote + 1; + } + return result; + } } |