Skip to content
Snippets Groups Projects
Commit b6d0ff62 authored by david_williams's avatar david_williams
Browse files

add ability to write stats URI

parent 0eae2a9b
No related branches found
No related tags found
No related merge requests found
...@@ -18,10 +18,13 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository; ...@@ -18,10 +18,13 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
public class AddMirrorsURL extends Task { public class AddMirrorsURL extends Task {
private static final String ARTIFACT_REPO_DIRECTORY = "artifactRepoDirectory"; private static final String IREPOSITORY_P2_STATS_URI = "p2.statsURI";
private static final String P2_MIRRORS_URL = "p2MirrorsURL"; private static final String ARTIFACT_REPO_DIRECTORY = "artifactRepoDirectory";
private static final String P2_MIRRORS_URL = "p2MirrorsURL";
private static final String P2_STATS_URI = "p2StatsURI";
private String artifactRepoDirectory; private String artifactRepoDirectory;
private String p2MirrorsURL; private String p2MirrorsURL;
private String p2StatsURI;
public void rewriteMirrorURL() throws ProvisionException, URISyntaxException { public void rewriteMirrorURL() throws ProvisionException, URISyntaxException {
try { try {
...@@ -51,7 +54,7 @@ public class AddMirrorsURL extends Task { ...@@ -51,7 +54,7 @@ public class AddMirrorsURL extends Task {
String pathPart = getArtifactRepoDirectory(); String pathPart = getArtifactRepoDirectory();
if ((pathPart == null) || (pathPart.length() == 0)) { if ((pathPart == null) || (pathPart.length() == 0)) {
infoOutput("The repository direcotry needs to be specified for this task. Try setting system property '" + ARTIFACT_REPO_DIRECTORY + "'?"); infoOutput("The repository directory needs to be specified for this task. Try setting system property '" + ARTIFACT_REPO_DIRECTORY + "'?");
} }
else { else {
String repoURI = "file:/" + pathPart; String repoURI = "file:/" + pathPart;
...@@ -59,54 +62,15 @@ public class AddMirrorsURL extends Task { ...@@ -59,54 +62,15 @@ public class AddMirrorsURL extends Task {
SimpleArtifactRepositoryFactory simpleArtifactRepositoryFactory = new SimpleArtifactRepositoryFactory(); SimpleArtifactRepositoryFactory simpleArtifactRepositoryFactory = new SimpleArtifactRepositoryFactory();
// NPE is thrown during "reload" if repository is written, and // NPE is thrown during "reload" if repository is written, and
// agent // agent is not set
// is not set
simpleArtifactRepositoryFactory.setAgent(Activator.getProvisioningAgent()); simpleArtifactRepositoryFactory.setAgent(Activator.getProvisioningAgent());
IArtifactRepository artifactRepository = simpleArtifactRepositoryFactory.load(new URI(repoURI), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, new NullProgressMonitor()); IArtifactRepository artifactRepository = simpleArtifactRepositoryFactory.load(new URI(repoURI), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, new NullProgressMonitor());
if (artifactRepository != null) { if (artifactRepository != null) {
String existingMirrorURL = artifactRepository.getProperty(IRepository.PROP_MIRRORS_URL);
if (existingMirrorURL != null) {
infoOutput("the repository had existing mirrorURL: " + existingMirrorURL);
} result = processMirrorsURL(result, artifactRepository);
else { result = processStatsURI(result, artifactRepository);
infoOutput("the repository had no existing mirrorURL");
}
String newMirrorURL = null;
newMirrorURL = getP2MirrorsURL();
// if property given to us is empty string, assume that is
// the same as "removal" which is done by passing in null.
if ((newMirrorURL != null) && (newMirrorURL.length() == 0)) {
newMirrorURL = null;
}
boolean needrewrite = false;
String reasonForNoWrite = null;
if (newMirrorURL != null) {
// if they are the same, don't bother
if (!newMirrorURL.equals(existingMirrorURL)) {
needrewrite = true;
}
else {
reasonForNoWrite = "new value and existing value of mirrorURL are the same";
}
}
else {
// newMirror is null, means removal is desired
if (existingMirrorURL != null) {
needrewrite = true;
}
else {
reasonForNoWrite = "removal of mirrorURL was indicated, but repository has no existing value.";
}
}
if (needrewrite) {
result = new PublisherInfo();
artifactRepository.setProperty(IRepository.PROP_MIRRORS_URL, newMirrorURL);
result.setArtifactRepository(artifactRepository);
result.setArtifactOptions(IPublisherInfo.A_OVERWRITE);
}
else {
infoOutput(reasonForNoWrite);
}
} }
else { else {
infoOutput("repository was null, not local, or otherwise not modifiable"); infoOutput("repository was null, not local, or otherwise not modifiable");
...@@ -115,6 +79,54 @@ public class AddMirrorsURL extends Task { ...@@ -115,6 +79,54 @@ public class AddMirrorsURL extends Task {
return result; return result;
} }
private PublisherInfo processMirrorsURL(PublisherInfo result, IArtifactRepository artifactRepository) {
String existingMirrorURL = artifactRepository.getProperty(IRepository.PROP_MIRRORS_URL);
if (existingMirrorURL != null) {
infoOutput("the repository had existing mirrorURL: " + existingMirrorURL);
}
else {
infoOutput("the repository had no existing mirrorURL");
}
String newMirrorURL = getP2MirrorsURL();
// if property given to us is empty string, assume that is
// the same as "removal" which is done by passing in null.
if ((newMirrorURL != null) && (newMirrorURL.length() == 0)) {
newMirrorURL = null;
}
boolean needrewrite = false;
String reasonForNoWrite = null;
if (newMirrorURL != null) {
// if they are the same, don't bother
if (!newMirrorURL.equals(existingMirrorURL)) {
needrewrite = true;
}
else {
reasonForNoWrite = "new value and existing value of mirrorURL are the same";
}
}
else {
// newMirror is null, means removal is desired
if (existingMirrorURL != null) {
needrewrite = true;
}
else {
reasonForNoWrite = "removal of mirrorURL was indicated, but repository has no existing value.";
}
}
if (needrewrite) {
if (result == null) {
result = initRepoOverwrite(artifactRepository);
}
artifactRepository.setProperty(IRepository.PROP_MIRRORS_URL, newMirrorURL);
}
else {
infoOutput(reasonForNoWrite);
}
return result;
}
private IPublisherAction[] createActions() { private IPublisherAction[] createActions() {
IPublisherAction[] result = new IPublisherAction[0]; IPublisherAction[] result = new IPublisherAction[0];
return result; return result;
...@@ -155,6 +167,10 @@ public class AddMirrorsURL extends Task { ...@@ -155,6 +167,10 @@ public class AddMirrorsURL extends Task {
this.p2MirrorsURL = mirrorURLString; this.p2MirrorsURL = mirrorURLString;
} }
public void setP2StatsURI(String statsURIString) {
this.p2StatsURI = statsURIString;
}
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
try { try {
...@@ -171,4 +187,74 @@ public class AddMirrorsURL extends Task { ...@@ -171,4 +187,74 @@ public class AddMirrorsURL extends Task {
} }
} }
private PublisherInfo processStatsURI(PublisherInfo result, IArtifactRepository artifactRepository) {
/*
* <property name='p2.statsURI'
* value='http://your.stats.server/stats'/>
*/
String existingStatsURI = artifactRepository.getProperty(IREPOSITORY_P2_STATS_URI);
if (existingStatsURI != null) {
infoOutput("the repository had existing statsURI: " + existingStatsURI);
}
else {
infoOutput("the repository had no existing statsURI");
}
String newStatsURI = getP2StatsURI();
// if property given to us is empty string, assume that is
// the same as "removal" which is done by passing in null.
if ((newStatsURI != null) && (newStatsURI.length() == 0)) {
newStatsURI = null;
}
boolean needrewrite = false;
String reasonForNoWrite = null;
if (newStatsURI != null) {
// if they are the same, don't bother
if (!newStatsURI.equals(existingStatsURI)) {
needrewrite = true;
}
else {
reasonForNoWrite = "new value and existing value of statsURI are the same";
}
}
else {
// newStatsURI is null, means removal is desired
if (existingStatsURI != null) {
needrewrite = true;
}
else {
reasonForNoWrite = "removal of statusURI was indicated, but repository has no existing value.";
}
}
if (needrewrite) {
if (result == null) {
result = initRepoOverwrite(artifactRepository);
}
artifactRepository.setProperty(IREPOSITORY_P2_STATS_URI, newStatsURI);
}
else {
infoOutput(reasonForNoWrite);
}
return result;
}
public String getP2StatsURI() {
if (p2StatsURI == null) {
p2StatsURI = System.getProperty(P2_STATS_URI);
infoOutput("stats URI value set from '" + P2_STATS_URI + "': " + p2StatsURI);
}
return p2StatsURI;
}
private PublisherInfo initRepoOverwrite(IArtifactRepository artifactRepository) {
PublisherInfo result;
result = new PublisherInfo();
result.setArtifactRepository(artifactRepository);
result.setArtifactOptions(IPublisherInfo.A_OVERWRITE);
return result;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment