diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse')
6 files changed, 326 insertions, 147 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 new file mode 100644 index 000000000..19ce2f005 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.io.File; +import java.net.URI; +import java.util.*; +import org.apache.tools.ant.*; +import org.apache.tools.ant.types.FileSet; +import org.eclipse.core.runtime.Path; +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.p2.internal.repository.tools.AbstractApplication; + +public abstract class AbstractRepositoryTask extends Task { + protected AbstractApplication application; + protected List iuTasks = new ArrayList(); + protected List sourceRepos = new ArrayList(); + protected List destinations = new ArrayList(); + + /* + * Create a special file set since the user specified a "source" sub-element. + */ + public FileSet createSource() { + MyFileSet set = new MyFileSet(); + sourceRepos.add(set); + return set; + } + + protected void addMetadataSourceRepository(URI repoLocation) { + application.addSourceMetadataRepository(repoLocation); + } + + protected void addArtifactSourceRepository(URI repoLocation) { + application.addSourceArtifactRepository(repoLocation); + } + + /* + * Create an object to hold IU information since the user specified an "iu" sub-element. + */ + public Object createIu() { + IUDescription iu = new IUDescription(); + iuTasks.add(iu); + return iu; + } + + /* + * If the repositories are co-located then the user just has to set one + * argument to specify both the artifact and metadata repositories. + */ + public void setSource(String location) { + application.addSourceArtifactRepository(location); + application.addSourceMetadataRepository(location); + } + + /* + * If the repositories are co-located then the user just has to set one + * argument to specify both the artifact and metadata repositories. + */ + public void setDestination(String location) { + DestinationRepository metadata = new DestinationRepository(); + metadata.setLocation(new Path(location).toFile().toURI().toString()); + metadata.setKind("metadata"); //$NON-NLS-1$ + application.addDestination(metadata.getDescriptor()); + destinations.add(metadata); + + DestinationRepository artifact = new DestinationRepository(); + artifact.setLocation(new Path(location).toFile().toURI().toString()); + metadata.setKind("artifact"); //$NON-NLS-1$ + application.addDestination(artifact.getDescriptor()); + destinations.add(artifact); + } + + public DestinationRepository createDestination() { + DestinationRepository destination = new DestinationRepository(); + destinations.add(destination); + application.addDestination(destination.getDescriptor()); + return destination; + } + + /* + * New FileSet subclass which adds an optional "location" attribute. + */ + public class MyFileSet extends FileSet { + String location; + + public MyFileSet() { + super(); + } + + public void setLocation(String value) { + this.location = value; + } + } + + /* + * If the user specified some source repositories via sub-elements + * then add them to the transformer for consideration. + */ + protected void prepareSourceRepos() { + if (sourceRepos == null || sourceRepos.isEmpty()) + return; + for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) { + Object next = iter.next(); + if (next instanceof MyFileSet) { + MyFileSet fileset = (MyFileSet) next; + // determine if the user set a "location" attribute or used a fileset + if (fileset.location == null) { + DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); + String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()}; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < elements[i].length; j++) { + URI uri = new File(fileset.getDir(), elements[i][j]).toURI(); + application.addSourceArtifactRepository(uri); + application.addSourceMetadataRepository(uri); + } + } + } else { + application.addSourceArtifactRepository(fileset.location); + application.addSourceMetadataRepository(fileset.location); + } + } + } + } + + protected List prepareIUs() { + if (iuTasks == null || iuTasks.isEmpty()) + return null; + + IMetadataRepository repository = application.getCompositeMetadataRepository(); + List result = new ArrayList(); + for (Iterator iter = iuTasks.iterator(); iter.hasNext();) { + IUDescription iu = (IUDescription) iter.next(); + String id = iu.getId(); + Version version = null; + 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); + } + + if (collector.isEmpty()) + throw new BuildException("Unable to find: " + id + (version != null ? " " + version : "")); + result.add(collector.iterator().next()); + } + return result; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/DestinationRepository.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/DestinationRepository.java new file mode 100644 index 000000000..351529930 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/DestinationRepository.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.net.URISyntaxException; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.DataType; +import org.eclipse.core.runtime.URIUtil; +import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; + +public class DestinationRepository extends DataType { + + private RepositoryDescriptor descriptor = new RepositoryDescriptor(); + + public void setCompressed(boolean compress) { + descriptor.setCompressed(compress); + } + + public void setName(String repoName) { + descriptor.setName(repoName); + } + + public void setLocation(String repoLocation) throws BuildException { + try { + descriptor.setLocation(URIUtil.fromString(repoLocation)); + } catch (URISyntaxException e) { + throw new BuildException(e); + } + } + + public void setFormat(String format) { + descriptor.setFormat(format); + } + + public void setAppend(boolean appendMode) { + descriptor.setAppend(appendMode); + } + + public void setKind(String repoKind) { + descriptor.setKind(repoKind); + } + + RepositoryDescriptor getDescriptor() { + return descriptor; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java index 4f5417c22..2e928a142 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java @@ -10,17 +10,17 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; -import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.DataType; /** * @since 1.0 */ -public class IUTask extends Task { +public class IUDescription extends DataType { private String id; private String version; - public IUTask() { + public IUDescription() { super(); } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java new file mode 100644 index 000000000..c4d2f9e11 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java @@ -0,0 +1,36 @@ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.util.List; +import org.apache.tools.ant.BuildException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; +import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; + +public class MirrorTask extends AbstractRepositoryTask { + + public MirrorTask() { + application = new MirrorApplication(); + } + + public void execute() throws BuildException { + try { + prepareSourceRepos(); + application.initializeRepos(null); + List ius = prepareIUs(); + if (ius == null || ius.size() == 0) + throw new BuildException("Need to specify one or more IUs."); + application.setSourceIUs(ius); + IStatus result = application.run(null); + if (result.matches(IStatus.ERROR)) + throw new ProvisionException(result); + } catch (ProvisionException e) { + throw new BuildException("Error occurred while transforming repository.", e); + } + } + + public SlicingOption createSlicingOptions() { + SlicingOption options = new SlicingOption(); + ((MirrorApplication) application).setSlicingOptions(options.getOptions()); + return options; + } +} diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java index 00e75e64d..f8fb89e26 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java @@ -10,19 +10,10 @@ *******************************************************************************/ package org.eclipse.equinox.p2.internal.repository.tools.tasks; -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.*; -import org.apache.tools.ant.*; -import org.apache.tools.ant.types.FileSet; +import java.util.List; +import org.apache.tools.ant.BuildException; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; -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.query.*; import org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable; /** @@ -34,11 +25,7 @@ import org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable; * * @since 1.0 */ -public class Repo2RunnableTask extends Task { - - private final Repo2Runnable application; - private List iuTasks = new ArrayList(); - private List sourceRepos = new ArrayList(); +public class Repo2RunnableTask extends AbstractRepositoryTask { /* * Constructor for the class. Create a new instance of the application @@ -49,17 +36,13 @@ public class Repo2RunnableTask extends Task { this.application = new Repo2Runnable(); } - public Repo2RunnableTask(Repo2Runnable application) { - super(); - this.application = application; - } - /* (non-Javadoc) * @see org.apache.tools.ant.Task#execute() */ public void execute() throws BuildException { try { prepareSourceRepos(); + application.initializeRepos(null); List ius = prepareIUs(); if (ius == null || ius.size() == 0) throw new BuildException("Need to specify either a non-empty source metadata repository or a valid list of IUs."); @@ -69,129 +52,6 @@ public class Repo2RunnableTask extends Task { throw new ProvisionException(result); } catch (ProvisionException e) { throw new BuildException("Error occurred while transforming repository.", e); - } catch (URISyntaxException e) { - throw new BuildException("Error occurred while transforming repository.", e); - } - } - - /* - * If the user specified some source repositories via sub-elements - * then add them to the transformer for consideration. - */ - private void prepareSourceRepos() { - if (sourceRepos == null || sourceRepos.isEmpty()) - return; - for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) { - Object next = iter.next(); - if (next instanceof MyFileSet) { - MyFileSet fileset = (MyFileSet) next; - // determine if the user set a "location" attribute or used a fileset - if (fileset.location == null) { - DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); - String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()}; - for (int i = 0; i < 2; i++) { - for (int j = 0; j < elements[i].length; j++) { - URI uri = new File(fileset.getDir(), elements[i][j]).toURI(); - application.addSourceArtifactRepository(uri); - application.addSourceMetadataRepository(uri); - } - } - } else { - application.addSourceArtifactRepository(fileset.location); - application.addSourceMetadataRepository(fileset.location); - } - } - } - } - - protected void addMetadataSourceRepository(URI repoLocation) { - application.addSourceMetadataRepository(repoLocation); - } - - protected void addArtifactSourceRepository(URI repoLocation) { - application.addSourceArtifactRepository(repoLocation); - } - - protected List prepareIUs() throws URISyntaxException { - if (iuTasks == null || iuTasks.isEmpty()) - return null; - - CompositeMetadataRepository repository = new CompositeMetadataRepository(new URI("memory:/composite"), "parent metadata repo", null); //$NON-NLS-1$ //$NON-NLS-2$ - for (Iterator iter = application.getSourceMetadataRepositories().iterator(); iter.hasNext();) { - repository.addChild((URI) iter.next()); - } - List result = new ArrayList(); - for (Iterator iter = iuTasks.iterator(); iter.hasNext();) { - IUTask iu = (IUTask) iter.next(); - String id = iu.getId(); - Version version = null; - 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); - } - - if (collector.isEmpty()) - System.err.println("Unable to find " + id + version != null ? " " + version : ""); - else - result.add(collector.iterator().next()); - } - return result; - } - - /* - * If the repositories are co-located then the user just has to set one - * argument to specify both the artifact and metadata repositories. - */ - public void setSource(String location) { - application.addSourceArtifactRepository(location); - application.addSourceMetadataRepository(location); - } - - /* - * If the repositories are co-located then the user just has to set one - * argument to specify both the artifact and metadata repositories. - */ - public void setDestination(String location) { - application.setDestinationArtifactRepository(location); - application.setDestinationMetadataRepository(location); - } - - /* - * Create an object to hold IU information since the user specified an "iu" sub-element. - */ - public Object createIu() { - IUTask iu = new IUTask(); - iuTasks.add(iu); - return iu; - } - - /* - * Create a special file set since the user specified a "source" sub-element. - */ - public FileSet createSource() { - MyFileSet set = new MyFileSet(); - sourceRepos.add(set); - return set; - } - - /* - * New FileSet subclass which adds an optional "location" attribute. - */ - public class MyFileSet extends FileSet { - String location; - - public MyFileSet() { - super(); - } - - public void setLocation(String value) { - this.location = value; } } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java new file mode 100644 index 000000000..48ed185f8 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java @@ -0,0 +1,65 @@ +package org.eclipse.equinox.p2.internal.repository.tools.tasks; + +import java.util.*; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.equinox.p2.internal.repository.tools.SlicingOptions; + +public class SlicingOption extends Task { + + SlicingOptions options = null; + + public SlicingOption() { + options = new SlicingOptions(); + options.forceFilterTo(true); + options.considerStrictDependencyOnly(false); + options.everythingGreedy(true); + options.includeOptionalDependencies(true); + } + + /** + * Setting this to true will cause the optional dependencies to be considered. + */ + public void setIncludeOptional(boolean optional) { + options.includeOptionalDependencies(optional); + } + + /** + * + */ + public void setPlatformFilter(String platformFilter) { + if (platformFilter == null || platformFilter.trim().equals("")) //$NON-NLS-1$ + return; + if (platformFilter.equalsIgnoreCase("true")) { //$NON-NLS-1$ + options.forceFilterTo(true); + return; + } + if (platformFilter.equalsIgnoreCase("false")) { //$NON-NLS-1$ + options.forceFilterTo(false); + return; + } + StringTokenizer tok = new StringTokenizer(platformFilter, ","); //$NON-NLS-1$ + if (tok.countTokens() != 3) + throw new BuildException("Invalid platform filter format: " + platformFilter + "."); + Dictionary filter = new Properties(); + filter.put("osgi.os", tok.nextToken().trim()); //$NON-NLS-1$ + filter.put("osgi.ws", tok.nextToken().trim()); //$NON-NLS-1$ + filter.put("osgi.arch", tok.nextToken().trim()); //$NON-NLS-1$ + } + + public void setIncludeNonGreedy(boolean greed) { + options.everythingGreedy(greed); + } + + /** + * Set this property to true if only strict dependencies must be followed. A strict dependency is defined by a version range only including one version (e.g. [1.0.0.v2009, 1.0.0.v2009]) + * The default value is false. + */ + public void setFollowStrict(boolean strict) { + options.considerStrictDependencyOnly(strict); + } + + public SlicingOptions getOptions() { + return options; + } +} |