Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2010-02-12 17:40:02 -0500
committerAndrew Niefer2010-02-12 17:40:02 -0500
commitc20d73802e27611b2d2a283849460b6026116a2f (patch)
tree4b3b26a923afa99c8c9249b318c3d2f673e20864
parent6ae321bc086ab15df01723e4f6183b57255b9cc1 (diff)
downloadrt.equinox.p2-c20d73802e27611b2d2a283849460b6026116a2f.tar.gz
rt.equinox.p2-c20d73802e27611b2d2a283849460b6026116a2f.tar.xz
rt.equinox.p2-c20d73802e27611b2d2a283849460b6026116a2f.zip
bug 291696 - get rid of metadata generator
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/plugin.xml50
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Messages.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java124
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java50
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/messages.properties2
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java26
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherApplication.java27
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java30
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java100
15 files changed, 359 insertions, 73 deletions
diff --git a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
index 9c72f9279..a89735ecb 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.publisher/META-INF/MANIFEST.MF
@@ -39,6 +39,7 @@ Import-Package: javax.xml.parsers,
org.eclipse.osgi.service.resolver;version="1.2.0",
org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.4.0",
+ org.osgi.service.application;version="1.1.0",
org.osgi.service.packageadmin;version="1.2.0",
org.xml.sax,
org.xml.sax.helpers
@@ -49,6 +50,7 @@ Export-Package: org.eclipse.equinox.internal.p2.publisher;
org.eclipse.equinox.p2.directorywatcher,
org.eclipse.equinox.p2.touchpoint.eclipse,
org.eclipse.equinox.p2.ui.sdk",
+ org.eclipse.equinox.internal.p2.publisher.compatibility,
org.eclipse.equinox.internal.p2.publisher.eclipse;
x-friends:="org.eclipse.equinox.p2.updatesite,
org.eclipse.equinox.p2.directorywatcher,
diff --git a/bundles/org.eclipse.equinox.p2.publisher/plugin.xml b/bundles/org.eclipse.equinox.p2.publisher/plugin.xml
index c09b4d19b..210c1d9e8 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/plugin.xml
+++ b/bundles/org.eclipse.equinox.p2.publisher/plugin.xml
@@ -1,36 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.5"?>
<plugin>
- <extension id="InstallPublisher" point="org.eclipse.core.runtime.applications">
- <application
- cardinality="1"
- thread="any"
- visible="true">
- <run
- class="org.eclipse.equinox.p2.publisher.eclipse.InstallPublisherApplication">
- </run>
- </application>
- </extension>
- <extension id="ProductPublisher" point="org.eclipse.core.runtime.applications">
- <application
- cardinality="1"
- thread="any"
- visible="true">
- <run
- class="org.eclipse.equinox.p2.publisher.eclipse.ProductPublisherApplication">
- </run>
- </application>
- </extension>
- <extension id="FeaturesAndBundlesPublisher" point="org.eclipse.core.runtime.applications">
- <application
- cardinality="1"
- thread="any"
- visible="true">
- <run
- class="org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication">
- </run>
- </application>
- </extension>
+ <extension id="InstallPublisher" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="any" visible="true">
+ <run class="org.eclipse.equinox.p2.publisher.eclipse.InstallPublisherApplication" />
+ </application>
+ </extension>
+ <extension id="org.eclipse.equinox.p2.publisher.EclipseGenerator" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="main" visible="true">
+ <run class="org.eclipse.equinox.internal.p2.publisher.compatibility.GeneratorApplication" />
+ </application>
+ </extension>
+ <extension id="ProductPublisher" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="any" visible="true">
+ <run class="org.eclipse.equinox.p2.publisher.eclipse.ProductPublisherApplication" />
+ </application>
+ </extension>
+ <extension id="FeaturesAndBundlesPublisher" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="any" visible="true">
+ <run class="org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication" />
+ </application>
+ </extension>
<extension point="org.eclipse.ant.core.antTasks">
<antTask
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Messages.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Messages.java
index 91f5221b6..52637b19c 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/Messages.java
@@ -31,6 +31,8 @@ public class Messages extends NLS {
public static String message_generationCompleted;
public static String message_noSimpleconfigurator;
+ public static String exception_artifactRepoNoAppendDestroysInput;
+
public static String error_rootIU_generation;
static {
// load message values from bundle file
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java
new file mode 100644
index 000000000..b74727e01
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/GeneratorApplication.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.publisher.compatibility;
+
+import java.io.File;
+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.publisher.Activator;
+import org.osgi.service.application.*;
+
+/**
+ * @since 1.1
+ */
+public class GeneratorApplication implements IApplication {
+ protected static final String APP_ID = "app.id"; //$NON-NLS-1$
+
+ public static final String UPDATE_SITE_APPLICATION = "org.eclipse.equinox.p2.publisher.UpdateSitePublisher"; //$NON-NLS-1$
+ public static final String INSTALL_APPLICATION = "org.eclipse.equinox.p2.publisher.InstallPublisher"; //$NON-NLS-1$
+ public static final String FEATURES_BUNDLES_APPLICATION = "org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher"; //$NON-NLS-1$
+
+ public Object start(IApplicationContext context) throws Exception {
+ return run((String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS));
+ }
+
+ public void stop() {
+ // TODO Auto-generated method stub
+ }
+
+ public Object run(String[] arguments) {
+ Map<String, Object> argumentMap = parseArguments(arguments);
+ return launchApplication(argumentMap);
+ }
+
+ protected Object launchApplication(Map<String, Object> applicationMap) {
+ String applicationId = (String) applicationMap.get(APP_ID);
+ String filter = "(service.pid=" + applicationId + ")"; //$NON-NLS-1$//$NON-NLS-2$
+ ApplicationDescriptor descriptor = (ApplicationDescriptor) ServiceHelper.getService(Activator.getContext(), ApplicationDescriptor.class.getName(), filter);
+ try {
+ ApplicationHandle handle = descriptor.launch(applicationMap);
+ return handle.getExitValue(0);
+ } catch (ApplicationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private Map<String, Object> parseArguments(String[] arguments) {
+ Map<String, Object> applicationMap = new HashMap<String, Object>();
+ Map<String, String> args = new HashMap<String, String>(arguments.length);
+ for (int i = 0; i < arguments.length; i++) {
+ if (i == arguments.length - 1 || arguments[i + 1].startsWith(IGeneratorConstants.DASH))
+ args.put(arguments[i], null);
+ else
+ args.put(arguments[i], arguments[++i]);
+ }
+
+ //adjust the short forms
+ if (args.containsKey(IGeneratorConstants.AR))
+ args.put(IGeneratorConstants.ARTIFACT_REPO, args.remove(IGeneratorConstants.AR));
+ if (args.containsKey(IGeneratorConstants.MR))
+ args.put(IGeneratorConstants.METADATA_REPO, args.remove(IGeneratorConstants.MR));
+ if (args.containsKey(IGeneratorConstants.PA))
+ args.put(IGeneratorConstants.PUBLISH_ARTIFACTS, args.remove(IGeneratorConstants.PA));
+ if (args.containsKey(IGeneratorConstants.PAR))
+ args.put(IGeneratorConstants.PUBLISH_ATIFACT_REPOSITORY, args.remove(IGeneratorConstants.PAR));
+
+ String source = null;
+ // -inplace and -updateSite become -source, and imply -append
+ if (args.containsKey(IGeneratorConstants.UPDATE_SITE))
+ source = args.remove(IGeneratorConstants.UPDATE_SITE);
+ if (args.containsKey(IGeneratorConstants.INPLACE))
+ source = args.remove(IGeneratorConstants.INPLACE);
+ if (source != null) {
+ args.put(IGeneratorConstants.SOURCE, source);
+ args.put(IGeneratorConstants.APPEND, null);
+
+ //if not specified, repo locations are based on source
+ String repoLocation = URIUtil.toUnencodedString(new File(source).toURI());
+ if (!args.containsKey(IGeneratorConstants.ARTIFACT_REPO))
+ args.put(IGeneratorConstants.ARTIFACT_REPO, repoLocation);
+ if (!args.containsKey(IGeneratorConstants.METADATA_REPO))
+ args.put(IGeneratorConstants.METADATA_REPO, repoLocation);
+ }
+
+ if (args.containsKey(IGeneratorConstants.SITE)) {
+ applicationMap.put(APP_ID, UPDATE_SITE_APPLICATION);
+ } else if (args.containsKey(IGeneratorConstants.CONFIG)) {
+ applicationMap.put(APP_ID, INSTALL_APPLICATION);
+ } else {
+ applicationMap.put(APP_ID, FEATURES_BUNDLES_APPLICATION);
+ }
+
+ applicationMap.put(IApplicationContext.APPLICATION_ARGS, flattenMap(args));
+ return applicationMap;
+ }
+
+ private String[] flattenMap(Map<String, String> map) {
+ ArrayList<String> list = new ArrayList<String>(map.size());
+ for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();) {
+ String key = iterator.next();
+ String value = map.get(key);
+ list.add(key);
+ if (value != null)
+ list.add(value);
+ }
+ return list.toArray(new String[list.size()]);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java
new file mode 100644
index 000000000..c3d5c1e77
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/compatibility/IGeneratorConstants.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.publisher.compatibility;
+
+/**
+ * @since 1.1
+ */
+public interface IGeneratorConstants {
+ public static final String DASH = "-"; //$NON-NLS-1$
+
+ //arguments understood by the old metadata generator application
+ public static final String PUBLISH_ARTIFACTS = "-publishArtifacts"; //$NON-NLS-1$
+ public static final String PA = "-pa"; //$NON-NLS-1$
+ public static final String PUBLISH_ATIFACT_REPOSITORY = "-publishArtifactRepository"; //$NON-NLS-1$
+ public static final String PAR = "-par"; //$NON-NLS-1$
+ public static final String APPEND = "-append"; //$NON-NLS-1$
+ public static final String NO_DEFAULT_IUS = "-noDefaultIUs"; //$NON-NLS-1$
+ public static final String COMPRESS = "-compress"; //$NON-NLS-1$
+ public static final String REUSE_PACK200 = "-reusePack200Files"; //$NON-NLS-1$
+ public static final String SOURCE = "-source"; //$NON-NLS-1$
+ public static final String INPLACE = "-inplace"; //$NON-NLS-1$
+ public static final String CONFIG = "-config"; //$NON-NLS-1$
+ public static final String UPDATE_SITE = "-updateSite"; //$NON-NLS-1$
+ public static final String EXE = "-exe"; //$NON-NLS-1$
+ public static final String LAUNCHER_CONFIG = "-launcherConfig"; //$NON-NLS-1$
+ public static final String METADATA_REPO_NAME = "-metadataRepositoryName"; //$NON-NLS-1$
+ public static final String METADATA_REPO = "-metadataRepository"; //$NON-NLS-1$
+ public static final String MR = "-mr"; //$NON-NLS-1$
+ public static final String ARTIFACT_REPO = "-artifactRepository"; //$NON-NLS-1$
+ public static final String AR = "-ar"; //$NON-NLS-1$
+ public static final String ARTIFACT_REPO_NAME = "-artifactRepositoryName"; //$NON-NLS-1$
+ public static final String FLAVOR = "-flavor"; //$NON-NLS-1$
+ public static final String PRODUCT_FILE = "-productFile"; //$NON-NLS-1$
+ public static final String FEATURES = "-features"; //$NON-NLS-1$
+ public static final String BUNDLES = "-bundles"; //$NON-NLS-1$
+ public static final String BASE = "-base"; //$NON-NLS-1$
+ public static final String ROOT = "-root"; //$NON-NLS-1$
+ public static final String ROOT_VERSION = "-rootVersion"; //$NON-NLS-1$
+ public static final String P2_OS = "-p2.os"; //$NON-NLS-1$
+ public static final String SITE = "-site"; //$NON-NLS-1$
+}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/messages.properties b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/messages.properties
index d0382034c..fb2d606b2 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/internal/p2/publisher/messages.properties
@@ -24,5 +24,5 @@ exception_sourcePath=Source location ({0}) must be a valid file-system path.
message_generatingMetadata = Generating metadata for {0}.
message_generationCompleted = Generation completed with success [{0} seconds].
message_noSimpleconfigurator = Could not find simpleconfigurator bundle.
-
+exception_artifactRepoNoAppendDestroysInput = Not appending to artifact repository ({0}) may destroy input files.
error_rootIU_generation = Could not generate root IU {0}, {1}, {2}.. \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java
index ead5cfe9e..56999c5c6 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherAction.java
@@ -411,9 +411,14 @@ public abstract class AbstractPublisherAction implements IPublisherAction {
if (destination == null || destination.contains(descriptor))
return;
+ // if all we are doing is indexing things then add the descriptor and get on with it
+ if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) == 0) {
+ destination.addDescriptor(descriptor);
+ return;
+ }
+
+ // if the file is already in the same location the repo will put it, just add the descriptor and exit
if (destination instanceof IFileArtifactRepository) {
- // TODO need to review this logic to ensure it makes sense.
- // if the file is already in the same location the repo will put it, just add the descriptor and exit
File descriptorFile = ((IFileArtifactRepository) destination).getArtifactFile(descriptor);
if (inclusion.equals(descriptorFile)) {
destination.addDescriptor(descriptor);
@@ -421,24 +426,7 @@ public abstract class AbstractPublisherAction implements IPublisherAction {
}
}
- // if all we are doing is indexing things then add the descriptor and get on with it
- if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) == 0) {
- destination.addDescriptor(descriptor);
- return;
- }
try {
- if (destination instanceof IFileArtifactRepository) {
- // TODO need to review this logic to ensure it makes sense.
- // if the file is already in the same location the repo will put it, just add the descriptor and exit
- File descriptorFile = ((IFileArtifactRepository) destination).getArtifactFile(descriptor);
- if (inclusion.equals(descriptorFile)) {
- destination.addDescriptor(descriptor);
- return;
- }
- }
-
- // TODO need to implement the overwrite story in the repos
- // boolean overwrite = (info.getArtifactOptions() & IPublisherInfo.A_OVERWRITE) > 0;
OutputStream output = destination.getOutputStream(descriptor);
if (output == null)
return;
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherApplication.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherApplication.java
index b65b976be..74734e269 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherApplication.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/AbstractPublisherApplication.java
@@ -22,6 +22,10 @@ import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepo
import org.eclipse.equinox.internal.p2.publisher.Activator;
import org.eclipse.equinox.internal.p2.publisher.Messages;
import org.eclipse.equinox.p2.core.*;
+import org.eclipse.equinox.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.LimitQuery;
+import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.osgi.util.NLS;
@@ -84,10 +88,26 @@ public abstract class AbstractPublisherApplication implements IApplication {
return new Status(IStatus.ERROR, "org.eclipse.equinox.p2.publisher", message); //$NON-NLS-1$
}
+ private boolean isEmpty(IArtifactRepository repo) {
+ IQueryResult<IArtifactKey> result = repo.query(new LimitQuery<IArtifactKey>(ArtifactKeyQuery.ALL_KEYS, 1), null);
+ return result.isEmpty();
+ }
+
protected void initializeRepositories(PublisherInfo publisherInfo) throws ProvisionException {
- if (artifactLocation != null)
- publisherInfo.setArtifactRepository(Publisher.createArtifactRepository(agent, artifactLocation, artifactRepoName, append, compress, reusePackedFiles));
- else if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
+ if (artifactLocation != null) {
+ IArtifactRepository repo = Publisher.createArtifactRepository(agent, artifactLocation, artifactRepoName, compress, reusePackedFiles);
+ if (!append && !isEmpty(repo)) {
+ File repoLocation = URIUtil.toFile(artifactLocation);
+ if (repoLocation != null && source != null) {
+ if (repoLocation.isFile())
+ repoLocation = repoLocation.getParentFile();
+ if (repoLocation.equals(new File(source)))
+ throw new IllegalArgumentException(NLS.bind(Messages.exception_artifactRepoNoAppendDestroysInput, URIUtil.toUnencodedString(artifactLocation)));
+ }
+ repo.removeAll();
+ }
+ publisherInfo.setArtifactRepository(repo);
+ } else if ((publisherInfo.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
throw new ProvisionException(createConfigurationEror(Messages.exception_noArtifactRepo));
if (metadataLocation == null)
throw new ProvisionException(createConfigurationEror(Messages.exception_noMetadataRepo));
@@ -129,6 +149,7 @@ public abstract class AbstractPublisherApplication implements IApplication {
}
}
+ @SuppressWarnings("unused")
protected void processParameter(String arg, String parameter, PublisherInfo publisherInfo) throws URISyntaxException {
try {
if (arg.equalsIgnoreCase("-metadataRepository") || arg.equalsIgnoreCase("-mr")) //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java
index b722a2671..d949ca5c5 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/Publisher.java
@@ -100,15 +100,13 @@ public class Publisher {
* @return the discovered or created repository
* @throws ProvisionException
*/
- public static IArtifactRepository createArtifactRepository(IProvisioningAgent agent, URI location, String name, boolean append, boolean compress, boolean reusePackedFiles) throws ProvisionException {
+ public static IArtifactRepository createArtifactRepository(IProvisioningAgent agent, URI location, String name, boolean compress, boolean reusePackedFiles) throws ProvisionException {
try {
IArtifactRepository result = loadArtifactRepository(agent, location, true, true);
if (result != null && result.isModifiable()) {
result.setProperty(IRepository.PROP_COMPRESSED, compress ? "true" : "false"); //$NON-NLS-1$//$NON-NLS-2$
if (reusePackedFiles)
result.setProperty(PUBLISH_PACK_FILES_AS_SIBLINGS, "true"); //$NON-NLS-1$
- if (!append)
- result.removeAll();
return result;
}
} catch (ProvisionException e) {
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java
index c0ab308ac..6204a46aa 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/AbstractPublishTask.java
@@ -8,6 +8,7 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.publisher.ant;
+import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -21,7 +22,13 @@ import org.eclipse.equinox.internal.p2.publisher.Activator;
import org.eclipse.equinox.internal.p2.publisher.Messages;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.publisher.*;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.LimitQuery;
+import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
+import org.eclipse.osgi.util.NLS;
public abstract class AbstractPublishTask extends Task {
protected static final String ANT_PROPERTY_PREFIX = "${"; //$NON-NLS-1$
@@ -81,6 +88,7 @@ public abstract class AbstractPublishTask extends Task {
protected boolean reusePackedFiles = false;
protected boolean append = true;
protected boolean publish = true;
+ protected String source = null;
protected URI metadataLocation;
protected String metadataRepoName;
protected URI artifactLocation;
@@ -96,10 +104,26 @@ public abstract class AbstractPublishTask extends Task {
return new Status(IStatus.ERROR, "org.eclipse.equinox.p2.publisher", message); //$NON-NLS-1$
}
+ private boolean isEmpty(IArtifactRepository repo) {
+ IQueryResult<IArtifactKey> result = repo.query(new LimitQuery<IArtifactKey>(ArtifactKeyQuery.ALL_KEYS, 1), null);
+ return result.isEmpty();
+ }
+
protected void initializeRepositories(PublisherInfo info) throws ProvisionException {
- if (artifactLocation != null)
- info.setArtifactRepository(Publisher.createArtifactRepository(getProvisioningAgent(), artifactLocation, artifactRepoName, append, compress, reusePackedFiles));
- else if ((info.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
+ if (artifactLocation != null) {
+ IArtifactRepository repo = Publisher.createArtifactRepository(getProvisioningAgent(), artifactLocation, artifactRepoName, compress, reusePackedFiles);
+ if (!append && !isEmpty(repo)) {
+ File repoLocation = URIUtil.toFile(artifactLocation);
+ if (repoLocation != null && source != null) {
+ if (repoLocation.isFile())
+ repoLocation = repoLocation.getParentFile();
+ if (repoLocation.equals(new File(source)))
+ throw new IllegalArgumentException(NLS.bind(Messages.exception_artifactRepoNoAppendDestroysInput, URIUtil.toUnencodedString(artifactLocation)));
+ }
+ repo.removeAll();
+ }
+ info.setArtifactRepository(repo);
+ } else if ((info.getArtifactOptions() & IPublisherInfo.A_PUBLISH) > 0)
throw new ProvisionException(createConfigurationEror(Messages.exception_noArtifactRepo));
if (metadataLocation == null)
throw new ProvisionException(createConfigurationEror(Messages.exception_noMetadataRepo));
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java
index 495071c2d..0c8bcab19 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/FeaturesAndBundlesPublisherTask.java
@@ -78,6 +78,7 @@ public class FeaturesAndBundlesPublisherTask extends AbstractPublishTask {
}
public void setSource(String source) {
+ super.source = source;
features.add(new File(source, "features")); //$NON-NLS-1$
bundles.add(new File(source, "plugins")); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java
index 4b9a3fd3c..2a4af026b 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/ProductPublisherTask.java
@@ -61,7 +61,6 @@ public class ProductPublisherTask extends AbstractPublishTask {
private String flavor;
private String productFile;
private String executables;
- private String source;
private List<ConfigElement> configurations = new ArrayList<ConfigElement>(3);
private List<AdviceElement> advice = new ArrayList<AdviceElement>(3);
@@ -125,7 +124,7 @@ public class ProductPublisherTask extends AbstractPublishTask {
}
public void setSource(String source) {
- this.source = source;
+ super.source = source;
}
public void addConfiguredConfig(ConfigElement config) {
diff --git a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java
index 3fb4fa88f..fd625b9cd 100644
--- a/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java
+++ b/bundles/org.eclipse.equinox.p2.publisher/src_ant/org/eclipse/equinox/internal/p2/publisher/ant/PublisherTask.java
@@ -110,6 +110,7 @@ public class PublisherTask extends AbstractPublishTask {
}
public void setSource(String location) {
+ super.source = location;
operation = "-source"; //$NON-NLS-1$
operationValue = location;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
index 16e8fe2dc..a550d820b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java
@@ -8,8 +8,6 @@
******************************************************************************/
package org.eclipse.equinox.p2.tests;
-import org.eclipse.equinox.p2.planner.IPlanner;
-
import java.io.*;
import java.lang.reflect.Field;
import java.net.URI;
@@ -34,6 +32,7 @@ import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil;
import org.eclipse.equinox.p2.metadata.query.FragmentQuery;
import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.eclipse.*;
import org.eclipse.equinox.p2.query.*;
@@ -836,6 +835,13 @@ public abstract class AbstractProvisioningTest extends TestCase {
return repo;
}
+ protected IArtifactRepository loadArtifactRepository(URI location) throws ProvisionException {
+ IArtifactRepositoryManager manager = getArtifactRepositoryManager();
+ IArtifactRepository repo = manager.loadRepository(location, null);
+ manager.removeRepository(location);
+ return repo;
+ }
+
protected IInstallableUnit getIU(IMetadataRepository repository, String name) {
IQueryResult queryResult = repository.query(new InstallableUnitQuery(name), null);
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
index 455796652..4fc56b22f 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/generator/GeneratorTests.java
@@ -11,9 +11,18 @@
package org.eclipse.equinox.p2.tests.generator;
import java.io.File;
+import java.util.Map;
import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.equinox.internal.p2.metadata.generator.EclipseGeneratorApplication;
-import org.eclipse.equinox.internal.p2.metadata.generator.Messages;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.eclipse.equinox.internal.p2.publisher.Messages;
+import org.eclipse.equinox.internal.p2.publisher.compatibility.GeneratorApplication;
+import org.eclipse.equinox.internal.p2.updatesite.UpdateSitePublisherApplication;
+import org.eclipse.equinox.internal.simpleconfigurator.utils.URIUtil;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication;
+import org.eclipse.equinox.p2.publisher.eclipse.InstallPublisherApplication;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.eclipse.osgi.util.NLS;
@@ -21,32 +30,65 @@ import org.osgi.framework.BundleContext;
public class GeneratorTests extends AbstractProvisioningTest {
+ protected class TestGeneratorApplication extends GeneratorApplication {
+ protected Object launchApplication(Map<String, Object> applicationMap) {
+ try {
+ String appId = (String) applicationMap.get(APP_ID);
+ if (UPDATE_SITE_APPLICATION.equals(appId)) {
+ UpdateSitePublisherApplication app = new UpdateSitePublisherApplication();
+ return app.run((String[]) applicationMap.get(IApplicationContext.APPLICATION_ARGS));
+ } else if (FEATURES_BUNDLES_APPLICATION.equals(appId)) {
+ FeaturesAndBundlesPublisherApplication app = new FeaturesAndBundlesPublisherApplication();
+ return app.run((String[]) applicationMap.get(IApplicationContext.APPLICATION_ARGS));
+ } else if (INSTALL_APPLICATION.equals(appId)) {
+ InstallPublisherApplication app = new InstallPublisherApplication();
+ return app.run((String[]) applicationMap.get(IApplicationContext.APPLICATION_ARGS));
+ }
+ } catch (Exception e) {
+ return e;
+ }
+ return null;
+ }
+
+ public Object go(String[] arguments) throws Exception {
+ Object result = run(arguments);
+ if (result instanceof Exception)
+ throw (Exception) result;
+ return result;
+ }
+ }
+
public void test233240_artifactsDeleted() throws Exception {
//this also covers 220494
- File rootFolder = getTempFolder();
+ File rootFolder = getTestFolder("artifactsDeleted");
//copy some bundles over
File plugins = new File(rootFolder, "plugins");
plugins.mkdir();
- for (int i = 0; i < 3; i++) {
+ int limit = 3;
+ for (int i = 0; i < limit; i++) {
BundleContext context = TestActivator.getContext();
File bundle = FileLocator.getBundleFile(context.getBundle(i));
-
+ if (!bundle.isFile()) {
+ //only jars please
+ ++limit;
+ continue;
+ }
copy("1.0 Populating input bundles.", bundle, new File(plugins, bundle.getName()));
}
String[] arguments = new String[] {"-metadataRepository", rootFolder.toURL().toExternalForm().toString(), "-artifactRepository", rootFolder.toURL().toExternalForm().toString(), "-source", rootFolder.getAbsolutePath(), "-publishArtifacts", "-noDefaultIUs"};
- EclipseGeneratorApplication application = new EclipseGeneratorApplication();
- application.run(arguments);
+ TestGeneratorApplication application = new TestGeneratorApplication();
+ application.go(arguments);
assertTrue("2.0 - initial artifact repo existance", new File(rootFolder, "artifacts.xml").exists());
assertTrue("2.1 - initial artifact repo contents", plugins.listFiles().length > 0);
//Taunt you one more time
- application = new EclipseGeneratorApplication();
+ application = new TestGeneratorApplication();
try {
- application.run(arguments);
+ application.go(arguments);
fail("3.0 - Expected Illegal Argument Exception not thrown.");
} catch (IllegalArgumentException e) {
assertTrue("3.0 - Expected Illegal Argument", e.getMessage().equals(NLS.bind(Messages.exception_artifactRepoNoAppendDestroysInput, rootFolder.toURI())));
@@ -56,11 +98,49 @@ public class GeneratorTests extends AbstractProvisioningTest {
//with -updateSite
arguments = new String[] {"-metadataRepository", rootFolder.toURL().toExternalForm().toString(), "-artifactRepository", rootFolder.toURL().toExternalForm().toString(), "-updateSite", rootFolder.getAbsolutePath(), "-publishArtifacts", "-noDefaultIUs"};
- application.run(arguments);
+ application.go(arguments);
assertTrue("4.0 - artifact repo existance", new File(rootFolder, "artifacts.xml").exists());
assertTrue("4.1 - artifact repo contents", plugins.listFiles().length > 0);
+ assertEquals(new File(rootFolder, "plugins").list().length, 3);
delete(rootFolder);
}
+
+ public void testBasicUpdateSite() throws Exception {
+ File rootFolder = getTestFolder("basicUpdateSite");
+
+ File updateSite = getTestData("1.0 finding update site", "testData/testRepos/updateSite");
+ copy("2.0 copying update site", updateSite, rootFolder);
+
+ new File(rootFolder, "content.xml").delete();
+ new File(rootFolder, "artifacts.xml").delete();
+
+ String[] arguments = {"-updateSite", rootFolder.getAbsolutePath(), "-site", new File(rootFolder, "site.xml").getAbsolutePath(), "-metadataRepository", URIUtil.toUnencodedString(rootFolder.toURI()), "-artifactRepository", URIUtil.toUnencodedString(rootFolder.toURI()), "-metadataRepositoryName", "Basic Metadata Test Site", "-artifactRepositoryName", "Basic Artifact Test Site", "-compress", "-reusePack200Files", "-noDefaultIUs"};
+
+ TestGeneratorApplication app = new TestGeneratorApplication();
+ app.go(arguments);
+
+ assertTrue(new File(rootFolder, "artifacts.jar").exists());
+ assertTrue(new File(rootFolder, "content.jar").exists());
+
+ IMetadataRepository metadataRepo = loadMetadataRepository(rootFolder.toURI());
+ assertEquals(metadataRepo.getName(), "Basic Metadata Test Site");
+
+ File siteXml = new File(rootFolder, "site.xml");
+ IInstallableUnit iu = getIU(metadataRepo, URIUtil.toUnencodedString(siteXml.toURI()) + ".More Examples");
+ assertNotNull(iu);
+ assertEquals(iu.getRequiredCapabilities().size(), 3);
+ assertEquals(iu.getProperty("org.eclipse.equinox.p2.type.category"), "true");
+ assertEquals(iu.getProperty("org.eclipse.equinox.p2.name"), "More Fine Examples");
+
+ iu = getIU(metadataRepo, URIUtil.toUnencodedString(siteXml.toURI()) + ".Examples");
+ assertNotNull(iu);
+ assertEquals(iu.getRequiredCapabilities().size(), 5);
+ assertEquals(iu.getProperty("org.eclipse.equinox.p2.type.category"), "true");
+ assertEquals(iu.getProperty("org.eclipse.equinox.p2.name"), "Platform Examples");
+
+ IArtifactRepository artifactRepo = loadArtifactRepository(rootFolder.toURI());
+ assertEquals(artifactRepo.getName(), "Basic Artifact Test Site");
+ }
}

Back to the top