Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2009-12-09 21:31:26 +0000
committerAndrew Niefer2009-12-09 21:31:26 +0000
commit7e8159bf30f6e1b86153bcfd17e30a0ed3f90428 (patch)
tree9f69f8aff8e48565a6dcad5fe6b83464aee9bfe0
parenta705d67b2ab563c07af5bdee3f05eeb2292220f3 (diff)
downloadrt.equinox.p2-7e8159bf30f6e1b86153bcfd17e30a0ed3f90428.tar.gz
rt.equinox.p2-7e8159bf30f6e1b86153bcfd17e30a0ed3f90428.tar.xz
rt.equinox.p2-7e8159bf30f6e1b86153bcfd17e30a0ed3f90428.zip
bug 293340 - repo packages - move mirroring to repo.tools
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/p2 tools - mirror metadata.launch24
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/plugin.xml19
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java175
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/Mirroring.java62
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/RangeQuery.java49
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/VersionRangedName.java53
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src_ant/org/eclipse/equinox/internal/p2/metadata/repository/ant/MirrorApplicationTask.java128
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml14
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java49
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java94
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java52
13 files changed, 158 insertions, 565 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
index 3a5641e44..bdca71bae 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
@@ -5,8 +5,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-Version: 1.0.100.qualifier
-Export-Package: org.eclipse.equinox.internal.p2.metadata.mirror;x-internal:=true,
- org.eclipse.equinox.internal.p2.metadata.repository;
+Export-Package: org.eclipse.equinox.internal.p2.metadata.repository;
x-friends:="org.eclipse.equinox.p2.engine,
org.eclipse.equinox.p2.metadata.generator,
org.eclipse.equinox.p2.publisher,
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/p2 tools - mirror metadata.launch b/bundles/org.eclipse.equinox.p2.metadata.repository/p2 tools - mirror metadata.launch
deleted file mode 100644
index 4d7cb3c6a..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/p2 tools - mirror metadata.launch
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
-<booleanAttribute key="append.args" value="true"/>
-<booleanAttribute key="automaticAdd" value="false"/>
-<booleanAttribute key="automaticValidate" value="false"/>
-<stringAttribute key="bootstrap" value=""/>
-<stringAttribute key="checked" value="[NONE]"/>
-<booleanAttribute key="clearConfig" value="false"/>
-<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/p2 tools - mirror metadata"/>
-<booleanAttribute key="default_auto_start" value="false"/>
-<intAttribute key="default_start_level" value="4"/>
-<booleanAttribute key="includeOptional" value="false"/>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.JAVA_COMMAND" value="java"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-console -consolelog -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication&#13;&#10;-source http://download.eclipse.org/eclipse/updates/3.4milestones/&#13;&#10;-destination file:c:/p2"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<booleanAttribute key="show_selected_only" value="false"/>
-<stringAttribute key="target_bundles" value="org.eclipse.equinox.security@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.app@default:true,org.eclipse.osgi.services@default:default,org.eclipse.osgi@:,org.eclipse.equinox.launcher@default:default,org.eclipse.equinox.common@default:default,org.eclipse.equinox.registry@default:default,javax.servlet@default:default,org.eclipse.core.jobs@default:default"/>
-<booleanAttribute key="tracing" value="false"/>
-<booleanAttribute key="useDefaultConfigArea" value="true"/>
-<booleanAttribute key="useNamedJRE" value="true"/>
-<stringAttribute key="workspace_bundles" value="org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.ecf.filetransfer@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.sat4j.pb@default:default,org.eclipse.equinox.simpleconfigurator@default:true,org.eclipse.equinox.p2.director@default:default,org.sat4j.core@default:default,org.eclipse.ecf.identity@default:default,org.eclipse.equinox.p2.artifact.repository@default:default,org.eclipse.equinox.p2.console@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.ecf@default:default,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.p2.jarprocessor@default:default"/>
-</launchConfiguration>
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/plugin.xml b/bundles/org.eclipse.equinox.p2.metadata.repository/plugin.xml
index c1bac455c..1476dabec 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/plugin.xml
@@ -6,18 +6,7 @@
<filter suffix="content.xml"/>
<factory class="org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.SimpleMetadataRepositoryFactory"/>
</extension>
- <extension
- id="mirrorApplication"
- point="org.eclipse.core.runtime.applications">
- <application
- cardinality="1"
- thread="main"
- visible="true">
- <run
- class="org.eclipse.equinox.internal.p2.metadata.mirror.MirrorApplication">
- </run>
- </application>
- </extension>
+
<extension id="compositeRepository" point="org.eclipse.equinox.p2.metadata.repository.metadataRepositories">
<filter suffix="compositeContent.xml"/>
<factory class="org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepositoryFactory"/>
@@ -36,12 +25,6 @@
class="org.eclipse.equinox.internal.p2.metadata.repository.ant.CreateCompositeMetadataRepositoryTask">
</antTask>
- <antTask
- library="ant_tasks/metadataRepository-ant.jar"
- name="p2.metadata.mirror"
- class="org.eclipse.equinox.internal.p2.metadata.repository.ant.MirrorApplicationTask">
- </antTask>
-
<antTask
library="ant_tasks/metadataRepository-ant.jar"
name="p2.composite.metadata.repository.remove"
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java
deleted file mode 100644
index 744b874da..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Code 9 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:
- * Code 9 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.metadata.mirror;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
-import org.eclipse.core.runtime.URIUtil;
-import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.p2.metadata.repository.Activator;
-import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
-import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.repository.IRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-
-/**
- * An application that performs mirroring of artifacts between repositories.
- */
-public class MirrorApplication implements IApplication {
-
- private String[] rootSpecs;
- private URI sourceLocation;
- private URI destinationLocation;
- private IMetadataRepository source;
- private IMetadataRepository destination;
- private boolean transitive = false;
- private boolean append = true;
- private IMetadataRepositoryManager cachedManager;
- private boolean sourceLoaded = false;
- private boolean destinationLoaded = false;
- private String destinationName;
-
- /**
- * Convert a list of tokens into an array. The list separator has to be
- * specified.
- */
- public static String[] getArrayArgsFromString(String list, String separator) {
- if (list == null || list.trim().equals("")) //$NON-NLS-1$
- return new String[0];
- List result = new ArrayList();
- for (StringTokenizer tokens = new StringTokenizer(list, separator); tokens.hasMoreTokens();) {
- String token = tokens.nextToken().trim();
- if (!token.equals("")) { //$NON-NLS-1$
- if ((token.indexOf('[') >= 0 || token.indexOf('(') >= 0) && tokens.hasMoreTokens())
- result.add(token + separator + tokens.nextToken());
- else
- result.add(token);
- }
- }
- return (String[]) result.toArray(new String[result.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
- */
- public Object start(IApplicationContext context) throws Exception {
- try {
- initializeFromArguments((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
- setupRepositories();
- new Mirroring().mirror(source, destination, rootSpecs, transitive);
- return IApplication.EXIT_OK;
- } catch (Exception e) {
- System.err.println(e.getMessage());
- throw e;
- } finally {
- //if the repository was not already loaded before the mirror application started, close it.
- if (!sourceLoaded && sourceLocation != null)
- getManager().removeRepository(sourceLocation);
- if (!destinationLoaded && destinationLocation != null)
- getManager().removeRepository(destinationLocation);
- }
- }
-
- private void setupRepositories() throws ProvisionException {
- if (destinationLocation == null || sourceLocation == null)
- throw new IllegalStateException("Must specify a source and destination"); //$NON-NLS-1$
-
- //Check if repositories are already loaded
- //TODO modify the contains statement once the API is available
- sourceLoaded = getManager().contains(sourceLocation);
- //TODO modify the contains statement once the API is available
- destinationLoaded = getManager().contains(destinationLocation);
-
- //must execute before initializeDestination is called
- source = getManager().loadRepository(sourceLocation, 0, null);
- destination = initializeDestination();
- }
-
- /*
- * Return the metadata repository manager. We need to check the service here
- * as well as creating one manually in case we are running a stand-alone application
- * in which no one has registered a manager yet.
- */
- private IMetadataRepositoryManager getManager() {
- if (cachedManager != null)
- return cachedManager;
- IMetadataRepositoryManager result = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
- // service not available... create one and hang onto it
- if (result == null) {
- cachedManager = new MetadataRepositoryManager();
- result = cachedManager;
- }
- return result;
- }
-
- private IMetadataRepository initializeDestination() throws ProvisionException {
- try {
- IMetadataRepository repository = getManager().loadRepository(destinationLocation, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
- if (repository != null && repository.isModifiable()) {
- if (destinationName != null)
- repository.setName(destinationName);
- if (!append)
- repository.removeAll();
- return repository;
- }
- } catch (ProvisionException e) {
- //fall through and create repo
- }
- //This code assumes source has been successfully loaded before this point
- //No existing repository; create a new repository at destinationLocation but with source's attributes.
- // TODO for now create a Simple repo by default.
- return (IMetadataRepository) RepositoryHelper.validDestinationRepository(getManager().createRepository(destinationLocation, destinationName == null ? source.getName() : destinationName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source.getProperties()));
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.equinox.app.IApplication#stop()
- */
- public void stop() {
- //do nothing
- }
-
- public void initializeFromArguments(String[] args) throws Exception {
- if (args == null)
- return;
- for (int i = 0; i < args.length; i++) {
- // check for args with parameters. If we are at the last argument or
- // if the next one has a '-' as the first character, then we can't have
- // an arg with a param so continue.
- if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$
- continue;
- String arg = args[++i];
-
- if (args[i - 1].equalsIgnoreCase("-destinationName")) //$NON-NLS-1$
- destinationName = arg;
- if (args[i - 1].equalsIgnoreCase("-writeMode")) //$NON-NLS-1$
- if (args[i].equalsIgnoreCase("clean")) //$NON-NLS-1$
- append = false;
-
- try {
- if (args[i - 1].equalsIgnoreCase("-source")) //$NON-NLS-1$
- sourceLocation = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg));
- if (args[i - 1].equalsIgnoreCase("-destination")) //$NON-NLS-1$
- destinationLocation = RepositoryHelper.localRepoURIHelper(URIUtil.fromString(arg));
- } catch (URISyntaxException e) {
- throw new IllegalArgumentException("Repository location (" + arg + ") must be a URL."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- if (args[i - 1].equalsIgnoreCase("-roots")) //$NON-NLS-1$
- rootSpecs = getArrayArgsFromString(arg, ","); //$NON-NLS-1$
- if (args[i - 1].equalsIgnoreCase("-transitive")) //$NON-NLS-1$
- transitive = true;
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/Mirroring.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/Mirroring.java
deleted file mode 100644
index 0da0ae21c..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/Mirroring.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Code 9 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:
- * Code 9 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.metadata.mirror;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.metadata.query.IQuery;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-
-/**
- * A utility class that performs mirroring of metadatas between repositories.
- */
-public class Mirroring {
-
- public void validate(IMetadataRepository source, IMetadataRepository destination) {
- if (source == null)
- throw new IllegalStateException("Source repository is null."); //$NON-NLS-1$
- if (destination == null)
- throw new IllegalStateException("Destination repository is null."); //$NON-NLS-1$
- if (!destination.isModifiable())
- throw new IllegalStateException("Destination repository must be modifiable: " + destination.getLocation()); //$NON-NLS-1$
- }
-
- public void mirror(IMetadataRepository source, IMetadataRepository destination, String[] rootSpecs, boolean transitive) {
- if (rootSpecs == null)
- mirror(source, destination, InstallableUnitQuery.ANY, transitive);
- else {
- VersionRangedName[] roots = new VersionRangedName[rootSpecs.length];
- for (int i = 0; i < rootSpecs.length; i++)
- roots[i] = VersionRangedName.parse(rootSpecs[i]);
- mirror(source, destination, new RangeQuery(roots), transitive);
- }
- }
-
- public void mirror(IMetadataRepository source, IMetadataRepository destination, IQuery query, boolean transitive) {
- validate(source, destination);
- Collector result = source.query(query, null);
- mirror(source, destination, (IInstallableUnit[]) result.toArray(IInstallableUnit.class), transitive);
- }
-
- private void mirror(IMetadataRepository source, IMetadataRepository destination, IInstallableUnit[] roots, boolean transitive) {
- if (transitive)
- roots = addTransitiveIUs(source, roots);
- destination.addInstallableUnits(roots);
- }
-
- protected IInstallableUnit[] addTransitiveIUs(IMetadataRepository source, IInstallableUnit[] roots) {
- // TODO Here we should create a profile from the source repo and discover all the
- // IUs that are needed to support the given roots. For now just assume that the
- // given roots are enough.
- return roots;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/RangeQuery.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/RangeQuery.java
deleted file mode 100644
index 6f8bcb00b..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/RangeQuery.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 Code 9 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:
- * Code 9 - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.metadata.mirror;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.MatchQuery;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-
-/**
- * A convenience query that will match any {@link IInstallableUnit}
- * it encounters.
- */
-public class RangeQuery extends MatchQuery {
- private VersionRangedName[] targets;
-
- /**
- * Creates a query that will match any {@link IInstallableUnit} with the given
- * VerionRangedName.
- *
- * @param targets The installable unit names with versions to match, or <code>null</code> to match any id
- */
- public RangeQuery(VersionRangedName[] targets) {
- this.targets = targets;
- }
-
- /**
- * Returns true if the <code>IInstallableUnit</code> object is contained in the <code>VerionRangedName</code>'s or targets is null.
- */
- public boolean isMatch(Object object) {
- if (!(object instanceof IInstallableUnit))
- return false;
- if (targets == null)
- return true;
- IInstallableUnit candidate = (IInstallableUnit) object;
- for (int i = 0; i < targets.length; i++) {
- VersionRangedName entry = targets[i];
- if (entry.getId().equalsIgnoreCase(candidate.getId()) && entry.getVersionRange().isIncluded(candidate.getVersion()))
- return true;
- }
- return false;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/VersionRangedName.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/VersionRangedName.java
deleted file mode 100644
index 13c104f2c..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/mirror/VersionRangedName.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Code 9 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:
- * Code 9 - initial API and implementation
- * IBM - ongoing development
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.metadata.mirror;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange;
-
-public class VersionRangedName {
- private final String id;
- private final VersionRange range;
-
- /**
- * Creates and returns a new version ranged id from the given spec. The spec should be
- * id/version range.
- * @param spec the spec for the version ranged id to create
- * @return the parsed versioned id
- */
- public static VersionRangedName parse(String spec) {
- String[] segments = MirrorApplication.getArrayArgsFromString(spec, "/"); //$NON-NLS-1$
- return new VersionRangedName(segments[0], segments.length == 1 ? null : segments[1]);
- }
-
- public VersionRangedName(String id, String rangeSpec) {
- this(id, new VersionRange(rangeSpec));
- }
-
- public VersionRangedName(String id, VersionRange range) {
- if (id == null)
- throw new IllegalArgumentException("id cannot be null"); //$NON-NLS-1$
- this.id = id;
- this.range = range != null ? range : new VersionRange(null);
- }
-
- public String getId() {
- return id;
- }
-
- public VersionRange getVersionRange() {
- return range;
- }
-
- public String toString() {
- return id + "/" + (range == null ? VersionRange.emptyRange.toString() : range.toString()); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src_ant/org/eclipse/equinox/internal/p2/metadata/repository/ant/MirrorApplicationTask.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src_ant/org/eclipse/equinox/internal/p2/metadata/repository/ant/MirrorApplicationTask.java
deleted file mode 100644
index 07ef39edf..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src_ant/org/eclipse/equinox/internal/p2/metadata/repository/ant/MirrorApplicationTask.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 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.internal.p2.metadata.repository.ant;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Task;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.equinox.internal.p2.metadata.mirror.MirrorApplication;
-import org.osgi.framework.Bundle;
-
-/**
- * Ant task for running the metadata mirror application.
- */
-public class MirrorApplicationTask extends Task {
-
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- private static final String ARG_DESTINATION = "-destination"; //$NON-NLS-1$
- private static final String ARG_DESTINATION_NAME = "-destinationName"; //$NON-NLS-1$
- private static final String ARG_SOURCE = "-source"; //$NON-NLS-1$
- private static final String ARG_WRITE_MODE = "-writeMode"; //$NON-NLS-1$
- URL source;
- URL destination;
- String destinationName;
- String writeMode;
-
- //TODO add transitive and roots attributed when implemented.
-
- /*
- * Run the mirror application with the given arguments.
- */
- private void runMirrorApplication(final String[] args) throws Exception {
- new MirrorApplication().start(new IApplicationContext() {
-
- public void applicationRunning() {
- // nothing to do
- }
-
- public Map getArguments() {
- Map arguments = new HashMap();
- arguments.put(IApplicationContext.APPLICATION_ARGS, args);
- return arguments;
- }
-
- public String getBrandingApplication() {
- return null;
- }
-
- public Bundle getBrandingBundle() {
- return null;
- }
-
- public String getBrandingDescription() {
- return null;
- }
-
- public String getBrandingId() {
- return null;
- }
-
- public String getBrandingName() {
- return null;
- }
-
- public String getBrandingProperty(String key) {
- return null;
- }
- });
- }
-
- /* (non-Javadoc)
- * @see org.apache.tools.ant.Task#execute()
- */
- public void execute() {
- // create arguments
- String[] args = new String[] { //
- ARG_SOURCE, source.toExternalForm(), //
- ARG_DESTINATION, destination.toExternalForm(), //
- ARG_WRITE_MODE, writeMode == null ? EMPTY_STRING : writeMode, //
- destinationName == null ? EMPTY_STRING : ARG_DESTINATION_NAME, //
- destinationName == null ? EMPTY_STRING : destinationName};
-
- try {
- runMirrorApplication(args);
- } catch (Exception e) {
- throw new BuildException("Error occurred while running metadata mirror application.", e);
- }
- }
-
- /*
- * Set the source location.
- */
- public void setSource(String value) throws MalformedURLException {
- source = new URL(value);
- }
-
- /*
- * Set the destination location.
- */
- public void setDestination(String value) throws MalformedURLException {
- destination = new URL(value);
- }
-
- /*
- * Set the destination name.
- */
- public void setDestinationName(String value) {
- destinationName = value;
- }
-
- /*
- * Set the write mode for the application. (e.g. clean or append)
- */
- public void setWriteMode(String value) {
- writeMode = value;
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml b/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml
index ca19dae77..d2a4e6b81 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml
@@ -53,6 +53,12 @@
name="p2.artifact.mirror"
class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorArtifactsTask">
</antTask>
+
+ <antTask
+ library="lib/repository-tools-ant.jar"
+ name="p2.metadata.mirror"
+ class="org.eclipse.equinox.p2.internal.repository.tools.tasks.MirrorMetadataTask">
+ </antTask>
<antTask
class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CompositeRepositoryTask"
@@ -102,5 +108,13 @@
</run>
</application>
</extension>
+
+ <extension id="org.eclipse.equinox.p2.metadata.repository.mirrorApplication" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="main" visible="true">
+ <run class="org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication">
+ <parameter name="metadataOrArtifacts" value="metadata" />
+ </run>
+ </application>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
index 214787e16..9122919cb 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
@@ -21,6 +21,7 @@ import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
+import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
import org.eclipse.equinox.p2.internal.repository.mirroring.*;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
@@ -43,12 +44,33 @@ public class MirrorApplication extends AbstractApplication implements IApplicati
private boolean verbose = false;
private boolean validate = false;
private String metadataOrArtifacts = null;
+ private String[] rootIUs = null;
private File mirrorLogFile; // file to log mirror output to (optional)
private File comparatorLogFile; // file to comparator output to (optional)
private IArtifactMirrorLog mirrorLog;
private IArtifactMirrorLog comparatorLog;
+ /**
+ * Convert a list of tokens into an array. The list separator has to be
+ * specified.
+ */
+ public static String[] getArrayArgsFromString(String list, String separator) {
+ if (list == null || list.trim().equals("")) //$NON-NLS-1$
+ return new String[0];
+ List result = new ArrayList();
+ for (StringTokenizer tokens = new StringTokenizer(list, separator); tokens.hasMoreTokens();) {
+ String token = tokens.nextToken().trim();
+ if (!token.equals("")) { //$NON-NLS-1$
+ if ((token.indexOf('[') >= 0 || token.indexOf('(') >= 0) && tokens.hasMoreTokens())
+ result.add(token + separator + tokens.nextToken());
+ else
+ result.add(token);
+ }
+ }
+ return (String[]) result.toArray(new String[result.size()]);
+ }
+
public Object start(IApplicationContext context) throws Exception {
Map args = context.getArguments();
initializeFromArguments((String[]) args.get(IApplicationContext.APPLICATION_ARGS));
@@ -63,7 +85,7 @@ public class MirrorApplication extends AbstractApplication implements IApplicati
/*
* The old "org.eclipse.equinox.p2.artifact.repository.mirrorApplication" application only does artifacts
- * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
+ * Similary, "org.eclipse.equinox.p2.metadata.repository.mirrorApplication" only does metadata
*/
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) {
if (data instanceof Map && ((Map) data).containsKey(MIRROR_MODE)) {
@@ -120,6 +142,8 @@ public class MirrorApplication extends AbstractApplication implements IApplicati
destination.setAppend(false);
} else if (args[i - 1].equalsIgnoreCase("-log")) { //$NON-NLS-1$
mirrorLogLocation = new File(arg);
+ } else if (args[i - 1].equalsIgnoreCase("-roots")) { //$NON-NLS-1$
+ rootIUs = getArrayArgsFromString(arg, ","); //$NON-NLS-1$
} else {
try {
if (args[i - 1].equalsIgnoreCase("-source")) { //$NON-NLS-1$
@@ -233,17 +257,22 @@ public class MirrorApplication extends AbstractApplication implements IApplicati
* If no IUs have been specified we want to mirror them all
*/
private void initializeIUs() throws ProvisionException {
- if (sourceIUs == null || sourceIUs.isEmpty()) {
- sourceIUs = new ArrayList();
- IMetadataRepository metadataRepo = getCompositeMetadataRepository();
- Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, null);
+ IMetadataRepository metadataRepo = getCompositeMetadataRepository();
- for (Iterator iter = collector.iterator(); iter.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iter.next();
- sourceIUs.add(iu);
+ if (rootIUs != null) {
+ sourceIUs = new ArrayList();
+ for (int i = 0; i < rootIUs.length; i++) {
+ String[] segments = getArrayArgsFromString(rootIUs[i], "/"); //$NON-NLS-1$
+ VersionRange range = segments.length > 1 ? new VersionRange(segments[i]) : null;
+ Collector collector = metadataRepo.query(new InstallableUnitQuery(segments[i], range), null);
+ sourceIUs.addAll(collector.toCollection());
}
-
- if (collector.size() == 0 && destinationMetadataRepository != null)
+ } else if (sourceIUs == null || sourceIUs.isEmpty()) {
+ sourceIUs = new ArrayList();
+ Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, null);
+ sourceIUs.addAll(collector.toCollection());
+ /* old metadata mirroring app did not throw an exception here */
+ if (sourceIUs.size() == 0 && destinationMetadataRepository != null && metadataOrArtifacts == null)
throw new ProvisionException(Messages.MirrorApplication_no_IUs);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java
new file mode 100644
index 000000000..3680b6f7c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorMetadataTask.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 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.URI;
+import java.net.URISyntaxException;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
+import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
+
+/**
+ * Ant task for running the metadata mirror application.
+ */
+public class MirrorMetadataTask extends Task {
+ URI source;
+ URI destination;
+ String destinationName;
+ String writeMode;
+
+ /* (non-Javadoc)
+ * @see org.apache.tools.ant.Task#execute()
+ */
+ public void execute() {
+ RepositoryDescriptor destinationRepo = new RepositoryDescriptor();
+ destinationRepo.setName(destinationName);
+ destinationRepo.setLocation(destination);
+ destinationRepo.setKind(RepositoryDescriptor.KIND_METADATA);
+ if (writeMode != null && writeMode.equals("clean")) //$NON-NLS-1$
+ destinationRepo.setAppend(false);
+
+ RepositoryDescriptor sourceRepo = new RepositoryDescriptor();
+ sourceRepo.setLocation(source);
+ sourceRepo.setKind(RepositoryDescriptor.KIND_METADATA);
+
+ MirrorApplication app = new MirrorApplication();
+ app.addDestination(destinationRepo);
+ app.addSource(sourceRepo);
+ try {
+ IStatus result = app.run(null);
+ if (result.getSeverity() != IStatus.OK)
+ log(result.getMessage());
+ } catch (ProvisionException e) {
+ throw new BuildException(e);
+ }
+ }
+
+ /*
+ * Set the source location.
+ */
+ public void setSource(String value) {
+ try {
+ source = URIUtil.fromString(value);
+ } catch (URISyntaxException e) {
+ throw new BuildException(e);
+ }
+ }
+
+ /*
+ * Set the destination location.
+ */
+ public void setDestination(String value) {
+ try {
+ destination = URIUtil.fromString(value);
+ } catch (URISyntaxException e) {
+ throw new BuildException(e);
+ }
+ }
+
+ /*
+ * Set the destination name.
+ */
+ public void setDestinationName(String value) {
+ destinationName = value;
+ }
+
+ /*
+ * Set the write mode for the application. (e.g. clean or append)
+ */
+ public void setWriteMode(String value) {
+ writeMode = value;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
index fab8299b2..5c4522a03 100644
--- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
@@ -20,7 +20,6 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.internal.p2.jarprocessor,
org.eclipse.equinox.internal.p2.jarprocessor.verifier,
org.eclipse.equinox.internal.p2.metadata,
- org.eclipse.equinox.internal.p2.metadata.mirror,
org.eclipse.equinox.internal.p2.metadata.repository,
org.eclipse.equinox.internal.p2.metadata.repository.io,
org.eclipse.equinox.internal.p2.persistence,
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java
index afaedbb00..0f9d265d2 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java
@@ -14,18 +14,16 @@ import java.io.File;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.equinox.internal.p2.metadata.mirror.MirrorApplication;
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.metadata.query.Collector;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.osgi.framework.Bundle;
/**
* Test API of the basic mirror application functionality's implementation.
@@ -74,43 +72,11 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest {
*/
private void runMirrorApplication(String message, final String[] args) throws Exception {
MirrorApplication application = new MirrorApplication();
- application.start(new IApplicationContext() {
-
- public void applicationRunning() {
- }
-
- public Map getArguments() {
- Map arguments = new HashMap();
-
- arguments.put(IApplicationContext.APPLICATION_ARGS, args);
-
- return arguments;
- }
-
- public String getBrandingApplication() {
- return null;
- }
-
- public Bundle getBrandingBundle() {
- return null;
- }
-
- public String getBrandingDescription() {
- return null;
- }
-
- public String getBrandingId() {
- return null;
- }
-
- public String getBrandingName() {
- return null;
- }
-
- public String getBrandingProperty(String key) {
- return null;
- }
- });
+ Map map = new HashMap();
+ map.put("metadataOrArtifacts", "metadata");
+ application.setInitializationData(null, null, map);
+ application.initializeFromArguments(args);
+ application.run(null);
}
/**
@@ -704,7 +670,7 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest {
runMirrorApplication("21.1", args);
//We expect the IllegalStateException to be thrown
fail("21.3 IllegalStateException not thrown");
- } catch (IllegalStateException e) {
+ } catch (IllegalArgumentException e) {
return; //expected type of exception has been thrown
} catch (Exception e) {
fail("21.2", e);
@@ -723,7 +689,7 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest {
runMirrorApplication("22.1", args);
//We expect the IllegalStateException to be thrown
fail("22.3 IllegalStateException not thrown");
- } catch (IllegalStateException e) {
+ } catch (ProvisionException e) {
return; //expected type of exception has been thrown
} catch (Exception e) {
fail("22.2", e);
@@ -741,7 +707,7 @@ public class MetadataMirrorApplicationTest extends AbstractProvisioningTest {
runMirrorApplication("23.0", args);
//We expect the IllegalStateException to be thrown
fail("23.2 IllegalStateException not thrown");
- } catch (IllegalStateException e) {
+ } catch (IllegalArgumentException e) {
return; //expected type of exception has been thrown
} catch (Exception e) {
fail("23.1", e);

Back to the top