Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSusan McCourt2014-06-01 21:38:44 +0000
committerPascal Rapicault2014-06-25 19:18:45 +0000
commit775d3353cbbd08cb5605f993b32081438f5674b3 (patch)
tree9215015d7b39eef72b4b9f19ad11abe4c89c9968
parentc3a68791a332e6cb68958bb7691617bc574fca8e (diff)
downloadrt.equinox.p2-775d3353cbbd08cb5605f993b32081438f5674b3.tar.gz
rt.equinox.p2-775d3353cbbd08cb5605f993b32081438f5674b3.tar.xz
rt.equinox.p2-775d3353cbbd08cb5605f993b32081438f5674b3.zip
Bug 436318 - [category] Specify repository references in category.xml
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java44
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java24
-rw-r--r--bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java7
3 files changed, 75 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
index 88801dbfd..ece98b7db 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java
@@ -14,12 +14,15 @@ package org.eclipse.equinox.internal.p2.updatesite;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.*;
import javax.xml.parsers.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;
+import org.eclipse.equinox.p2.repository.IRepository;
+import org.eclipse.equinox.p2.repository.spi.RepositoryReference;
import org.eclipse.osgi.util.NLS;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
@@ -43,6 +46,7 @@ public class CategoryParser extends DefaultHandler {
private static final String QUERY = "query"; //$NON-NLS-1$
private static final String EXPRESSION = "expression"; //$NON-NLS-1$
private static final String PARAM = "param"; //$NON-NLS-1$
+ private static final String REPOSITORY_REF = "repository-reference"; //$NON-NLS-1$
private static final int STATE_ARCHIVE = 3;
private static final int STATE_CATEGORY = 4;
@@ -58,6 +62,7 @@ public class CategoryParser extends DefaultHandler {
private static final int STATE_PARAM = 10;
private static final int STATE_QUERY = 11;
private static final int STATE_SITE = 1;
+ private static final int STATE_REPOSITORY_REF = 13;
private boolean DESCRIPTION_SITE_ALREADY_SEEN = false;
// Current object stack (used to hold the current object we are
@@ -235,6 +240,11 @@ public class CategoryParser extends DefaultHandler {
objectStack.pop();
break;
+ case STATE_REPOSITORY_REF :
+ stateStack.pop();
+ // do not pop object as we did not push the reference
+ break;
+
case STATE_DESCRIPTION_SITE :
stateStack.pop();
text = ""; //$NON-NLS-1$
@@ -379,6 +389,9 @@ public class CategoryParser extends DefaultHandler {
case STATE_DESCRIPTION_SITE :
return "Description / Site"; //$NON-NLS-1$
+ case STATE_REPOSITORY_REF :
+ return "Repository Reference"; //$NON-NLS-1$
+
default :
return Messages.DefaultSiteParser_UnknownState;
}
@@ -456,6 +469,9 @@ public class CategoryParser extends DefaultHandler {
} else if (elementName.equals(CATEGORY_DEF)) {
stateStack.push(new Integer(STATE_CATEGORY_DEF));
processCategoryDef(attributes);
+ } else if (elementName.equals(REPOSITORY_REF)) {
+ stateStack.push(new Integer(STATE_REPOSITORY_REF));
+ processRepositoryReference(attributes);
} else
internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, (new String[] {elementName, getState(currentState())})));
}
@@ -610,6 +626,34 @@ public class CategoryParser extends DefaultHandler {
}
/*
+ * process repository reference info
+ */
+ private void processRepositoryReference(Attributes attributes) {
+ String location = attributes.getValue("location"); //$NON-NLS-1$
+ String nickname = attributes.getValue("name"); //$NON-NLS-1$
+ URI uri;
+ try {
+ uri = URIUtil.fromString(location);
+ boolean enabled = Boolean.parseBoolean(attributes.getValue("enabled")); //$NON-NLS-1$
+ // First add a metadata repository
+ RepositoryReference metadata = new RepositoryReference(uri, nickname, IRepository.TYPE_METADATA, enabled ? IRepository.ENABLED : IRepository.NONE);
+ // Now a colocated artifact repository
+ RepositoryReference artifact = new RepositoryReference(uri, nickname, IRepository.TYPE_ARTIFACT, enabled ? IRepository.ENABLED : IRepository.NONE);
+
+ SiteModel site = (SiteModel) objectStack.peek();
+ site.addRepositoryReference(metadata);
+ site.addRepositoryReference(artifact);
+ // we do not push the references onto the object stack as we do not go deeper, and
+ // references are not SiteModel objects.
+ } catch (URISyntaxException e) {
+ // UI should have already caught this
+ }
+
+ if (Tracing.DEBUG_GENERATOR_PARSING)
+ debug("End processing Repository Reference: location:" + location); //$NON-NLS-1$
+ }
+
+ /*
* process feature info
*/
private void processFeature(Attributes attributes) {
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java
index 02237f440..d2c1c2cbf 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java
@@ -14,6 +14,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;
+import org.eclipse.equinox.p2.repository.spi.RepositoryReference;
/**
* A model of an update site.
@@ -43,6 +44,7 @@ public class SiteModel {
private String digestURIString;
private List<String> messageKeys;
private Map<Locale, Map<String, String>> localizations;
+ private List<RepositoryReference> repositoryReferences;
/**
* Creates an uninitialized site model object.
@@ -116,6 +118,17 @@ public class SiteModel {
}
/**
+ * Adds a repository reference to the site
+ *
+ * @param ref repository reference
+ */
+ public void addRepositoryReference(RepositoryReference ref) {
+ if (this.repositoryReferences == null)
+ this.repositoryReferences = new ArrayList<RepositoryReference>();
+ this.repositoryReferences.add(ref);
+ }
+
+ /**
* Returns an array of plug-in and non-plug-in archive reference models
* on this site
*
@@ -197,6 +210,17 @@ public class SiteModel {
}
/**
+ * Returns an array of repository references for this site.
+ *
+ * @return an array of repository references, or an empty array.
+ */
+ public RepositoryReference[] getRepositoryReferences() {
+ if (repositoryReferences == null || repositoryReferences.size() == 0)
+ return new RepositoryReference[0];
+ return repositoryReferences.toArray(new RepositoryReference[repositoryReferences.size()]);
+ }
+
+ /**
* Gets the localizations for the site as a map from locale
* to the set of translated properties for that locale.
*
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
index af9171700..df31e3062 100644
--- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
+++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java
@@ -401,6 +401,13 @@ public class SiteXMLAction extends AbstractPublisherAction {
publisherInfo.getMetadataRepository().addReferences(refs);
}
+ //publish repository references from category file
+ IRepositoryReference[] refs = site.getRepositoryReferences();
+ if (refs != null) {
+ ArrayList<IRepositoryReference> toAdd = new ArrayList<IRepositoryReference>(Arrays.asList(refs));
+ publisherInfo.getMetadataRepository().addReferences(toAdd);
+ }
+
File siteFile = URIUtil.toFile(updateSite.getLocation());
if (siteFile != null && siteFile.exists()) {
File siteParent = siteFile.getParentFile();

Back to the top