From b6d0ff62c7bb3fe45f2913dab15be10d3c64fcbd Mon Sep 17 00:00:00 2001
From: david_williams <david_williams>
Date: Fri, 21 May 2010 13:07:57 +0000
Subject: [PATCH] add ability to write stats URI

---
 .../wtp/releng/tools/AddMirrorsURL.java       | 182 +++++++++++++-----
 1 file changed, 134 insertions(+), 48 deletions(-)

diff --git a/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/AddMirrorsURL.java b/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/AddMirrorsURL.java
index befb425a1..950a815fe 100644
--- a/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/AddMirrorsURL.java
+++ b/plugins/org.eclipse.wtp.releng.tools/src/org/eclipse/wtp/releng/tools/AddMirrorsURL.java
@@ -18,10 +18,13 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
 
 public class AddMirrorsURL extends Task {
 
-    private static final String ARTIFACT_REPO_DIRECTORY = "artifactRepoDirectory";
-    private static final String P2_MIRRORS_URL    = "p2MirrorsURL";
+    private static final String IREPOSITORY_P2_STATS_URI = "p2.statsURI";
+    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              p2MirrorsURL;
+    private String              p2StatsURI;
 
     public void rewriteMirrorURL() throws ProvisionException, URISyntaxException {
         try {
@@ -51,7 +54,7 @@ public class AddMirrorsURL extends Task {
 
         String pathPart = getArtifactRepoDirectory();
         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 {
             String repoURI = "file:/" + pathPart;
@@ -59,54 +62,15 @@ public class AddMirrorsURL extends Task {
 
             SimpleArtifactRepositoryFactory simpleArtifactRepositoryFactory = new SimpleArtifactRepositoryFactory();
             // NPE is thrown during "reload" if repository is written, and
-            // agent
-            // is not set
+            // agent is not set
             simpleArtifactRepositoryFactory.setAgent(Activator.getProvisioningAgent());
             IArtifactRepository artifactRepository = simpleArtifactRepositoryFactory.load(new URI(repoURI), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, new NullProgressMonitor());
             if (artifactRepository != null) {
-                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 = 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);
-                }
+
+
+
+                result = processMirrorsURL(result, artifactRepository);
+                result = processStatsURI(result, artifactRepository);
             }
             else {
                 infoOutput("repository was null, not local, or otherwise not modifiable");
@@ -115,6 +79,54 @@ public class AddMirrorsURL extends Task {
         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() {
         IPublisherAction[] result = new IPublisherAction[0];
         return result;
@@ -155,6 +167,10 @@ public class AddMirrorsURL extends Task {
         this.p2MirrorsURL = mirrorURLString;
     }
 
+    public void setP2StatsURI(String statsURIString) {
+        this.p2StatsURI = statsURIString;
+    }
+
     @Override
     public void execute() throws BuildException {
         try {
@@ -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;
+    }
+
 }
-- 
GitLab