Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

TEMP

  • Loading branch information...
commit 0e5a03282315f2b048615e02fa6e5b4c770ea2f8 1 parent 2953354
Arnaud Heritier authored November 22, 2013
15  acceptance-webapp/pom.xml
@@ -88,6 +88,13 @@
88 88
       <artifactId>validation-api</artifactId>
89 89
     </dependency>
90 90
     <!-- **************************************** -->
  91
+    <!-- JGit -->
  92
+    <!-- **************************************** -->
  93
+    <dependency>
  94
+      <groupId>org.eclipse.jgit</groupId>
  95
+      <artifactId>org.eclipse.jgit</artifactId>
  96
+    </dependency>
  97
+    <!-- **************************************** -->
91 98
     <!-- Juzu -->
92 99
     <!-- **************************************** -->
93 100
     <dependency>
@@ -222,6 +229,14 @@
222 229
       <scope>runtime</scope>
223 230
     </dependency>
224 231
     <!-- **************************************** -->
  232
+    <!-- JGit -->
  233
+    <!-- **************************************** -->
  234
+    <dependency>
  235
+      <groupId>org.eclipse.jgit</groupId>
  236
+      <artifactId>org.eclipse.jgit.java7</artifactId>
  237
+      <scope>runtime</scope>
  238
+    </dependency>
  239
+    <!-- **************************************** -->
225 240
     <!-- Required by logback for colorized console on windows -->
226 241
     <!-- **************************************** -->
227 242
     <dependency>
149  acceptance-webapp/src/main/java/org/exoplatform/acceptance/model/vcs/VCSBranch.java
@@ -20,153 +20,24 @@
20 20
 
21 21
 import org.exoplatform.acceptance.model.StorableObject;
22 22
 
23  
-import com.google.common.base.Objects;
24 23
 import javax.validation.constraints.NotNull;
  24
+import org.springframework.data.mongodb.core.mapping.Document;
25 25
 
26 26
 /**
27  
- *
  27
+ * a VCS Branch
28 28
  */
29  
-public class VCSBranch {
30  
-
31  
-  /**
32  
-   * The name to humanly identify the credential
33  
-   */
34  
-  @NotNull
35  
-  protected String name;
36  
-
37  
-  public VCSBranch(@NotNull String name) {
38  
-    this.name = name;
39  
-  }
  29
+@Document(collection = "vcsbranches")
  30
+public class VCSBranch extends StorableObject {
40 31
 
41  
-  public String getName() {
42  
-    return name;
  32
+  public VCSBranch() {
  33
+    super();
43 34
   }
44 35
 
45  
-  public void setName(@NotNull String name) {
46  
-    this.name = name;
47  
-  }
48  
-
49  
-  /**
50  
-   * Returns a string representation of the object. In general, the
51  
-   * {@code toString} method returns a string that
52  
-   * "textually represents" this object. The result should
53  
-   * be a concise but informative representation that is easy for a
54  
-   * person to read.
55  
-   * It is recommended that all subclasses override this method.
56  
-   * <p/>
57  
-   * The {@code toString} method for class {@code Object}
58  
-   * returns a string consisting of the name of the class of which the
59  
-   * object is an instance, the at-sign character `{@code @}', and
60  
-   * the unsigned hexadecimal representation of the hash code of the
61  
-   * object. In other words, this method returns a string equal to the
62  
-   * value of:
63  
-   * <blockquote>
64  
-   * <pre>
65  
-   * getClass().getName() + '@' + Integer.toHexString(hashCode())
66  
-   * </pre></blockquote>
67  
-   *
68  
-   * @return a string representation of the object.
69  
-   */
70  
-  @Override
71  
-  public String toString() {
72  
-    return Objects.toStringHelper(this).add("name", getName()).toString();
73  
-  }
74  
-
75  
-  /**
76  
-   * Indicates whether some other object is "equal to" this one.
77  
-   * <p/>
78  
-   * The {@code equals} method implements an equivalence relation
79  
-   * on non-null object references:
80  
-   * <ul>
81  
-   * <li>It is <i>reflexive</i>: for any non-null reference value
82  
-   * {@code x}, {@code x.equals(x)} should return
83  
-   * {@code true}.
84  
-   * <li>It is <i>symmetric</i>: for any non-null reference values
85  
-   * {@code x} and {@code y}, {@code x.equals(y)}
86  
-   * should return {@code true} if and only if
87  
-   * {@code y.equals(x)} returns {@code true}.
88  
-   * <li>It is <i>transitive</i>: for any non-null reference values
89  
-   * {@code x}, {@code y}, and {@code z}, if
90  
-   * {@code x.equals(y)} returns {@code true} and
91  
-   * {@code y.equals(z)} returns {@code true}, then
92  
-   * {@code x.equals(z)} should return {@code true}.
93  
-   * <li>It is <i>consistent</i>: for any non-null reference values
94  
-   * {@code x} and {@code y}, multiple invocations of
95  
-   * {@code x.equals(y)} consistently return {@code true}
96  
-   * or consistently return {@code false}, provided no
97  
-   * information used in {@code equals} comparisons on the
98  
-   * objects is modified.
99  
-   * <li>For any non-null reference value {@code x},
100  
-   * {@code x.equals(null)} should return {@code false}.
101  
-   * </ul>
102  
-   * <p/>
103  
-   * The {@code equals} method for class {@code Object} implements
104  
-   * the most discriminating possible equivalence relation on objects;
105  
-   * that is, for any non-null reference values {@code x} and
106  
-   * {@code y}, this method returns {@code true} if and only
107  
-   * if {@code x} and {@code y} refer to the same object
108  
-   * ({@code x == y} has the value {@code true}).
109  
-   * <p/>
110  
-   * Note that it is generally necessary to override the {@code hashCode}
111  
-   * method whenever this method is overridden, so as to maintain the
112  
-   * general contract for the {@code hashCode} method, which states
113  
-   * that equal objects must have equal hash codes.
114  
-   *
115  
-   * @param obj the reference object with which to compare.
116  
-   * @return {@code true} if this object is the same as the obj
117  
-   * argument; {@code false} otherwise.
118  
-   * @see #hashCode()
119  
-   * @see java.util.HashMap
120  
-   */
121  
-  @Override
122  
-  public boolean equals(Object obj) {
123  
-    if (obj == null) {
124  
-      return false;
125  
-    }
126  
-    if (getClass() != obj.getClass()) {
127  
-      return false;
128  
-    }
129  
-    final StorableObject other = (StorableObject) obj;
130  
-    return java.util.Objects.equals(this.getName(), other.getName());
  36
+  public VCSBranch(@NotNull String name) {
  37
+    super(name);
131 38
   }
132 39
 
133  
-  /**
134  
-   * Returns a hash code value for the object. This method is
135  
-   * supported for the benefit of hash tables such as those provided by
136  
-   * {@link java.util.HashMap}.
137  
-   * <p/>
138  
-   * The general contract of {@code hashCode} is:
139  
-   * <ul>
140  
-   * <li>Whenever it is invoked on the same object more than once during
141  
-   * an execution of a Java application, the {@code hashCode} method
142  
-   * must consistently return the same integer, provided no information
143  
-   * used in {@code equals} comparisons on the object is modified.
144  
-   * This integer need not remain consistent from one execution of an
145  
-   * application to another execution of the same application.
146  
-   * <li>If two objects are equal according to the {@code equals(Object)}
147  
-   * method, then calling the {@code hashCode} method on each of
148  
-   * the two objects must produce the same integer result.
149  
-   * <li>It is <em>not</em> required that if two objects are unequal
150  
-   * according to the {@link Object#equals(Object)}
151  
-   * method, then calling the {@code hashCode} method on each of the
152  
-   * two objects must produce distinct integer results.  However, the
153  
-   * programmer should be aware that producing distinct integer results
154  
-   * for unequal objects may improve the performance of hash tables.
155  
-   * </ul>
156  
-   * <p/>
157  
-   * As much as is reasonably practical, the hashCode method defined by
158  
-   * class {@code Object} does return distinct integers for distinct
159  
-   * objects. (This is typically implemented by converting the internal
160  
-   * address of the object into an integer, but this implementation
161  
-   * technique is not required by the
162  
-   * Java<font size="-2"><sup>TM</sup></font> programming language.)
163  
-   *
164  
-   * @return a hash code value for this object.
165  
-   * @see Object#equals(Object)
166  
-   * @see System#identityHashCode
167  
-   */
168  
-  @Override
169  
-  public int hashCode() {
170  
-    return java.util.Objects.hash(this.getName());
  40
+  public VCSBranch(@NotNull String name, @NotNull String id) {
  41
+    super(name, id);
171 42
   }
172 43
 }
108  acceptance-webapp/src/main/java/org/exoplatform/acceptance/model/vcs/VCSFileSet.java
@@ -20,40 +20,136 @@
20 20
 
21 21
 import com.google.common.base.Objects;
22 22
 import java.io.File;
  23
+import java.io.IOException;
  24
+import java.util.ArrayList;
  25
+import java.util.Collections;
  26
+import java.util.List;
23 27
 import javax.validation.constraints.NotNull;
  28
+import org.eclipse.jgit.api.Git;
  29
+import org.eclipse.jgit.api.errors.GitAPIException;
  30
+import org.eclipse.jgit.internal.storage.file.FileRepository;
  31
+import org.eclipse.jgit.lib.Ref;
  32
+import org.eclipse.jgit.lib.StoredConfig;
  33
+import org.eclipse.jgit.transport.RefSpec;
  34
+import org.eclipse.jgit.transport.TagOpt;
  35
+import org.slf4j.Logger;
  36
+import org.slf4j.LoggerFactory;
24 37
 
25 38
 /**
26 39
  *
27 40
  */
28 41
 public class VCSFileSet {
  42
+  private static final Logger LOGGER = LoggerFactory.getLogger(VCSFileSet.class);
29 43
   /**
30 44
    * Local base directory where the clone is created
31 45
    */
32  
-  @NotNull
33 46
   private File baseDir;
34 47
   /**
35 48
    * Identifier of the VCSRepository from which this local copy was created
36 49
    */
37  
-  @NotNull
38 50
   private VCSRepository repository;
  51
+  /**
  52
+   * Offers a "GitPorcelain"-like API to interact with a git repository.
  53
+   */
  54
+  private Git git;
39 55
 
40 56
   public VCSFileSet(@NotNull File baseDir, @NotNull VCSRepository repository) {
41 57
     this.baseDir = baseDir;
42 58
     this.repository = repository;
  59
+    initialize();
43 60
   }
44 61
 
45 62
   public File getBaseDir() {
46 63
     return baseDir;
47 64
   }
48 65
 
49  
-  public void setBaseDir(File baseDir) {
50  
-    this.baseDir = baseDir;
51  
-  }
52  
-
53 66
   public VCSRepository getRepository() {
54 67
     return repository;
55 68
   }
56 69
 
  70
+  private void initialize() {
  71
+    if (!baseDir.exists()) {
  72
+      if (this.repository.getRemoteRepositories().size() > 0) {
  73
+        LOGGER.debug("Cloning {} into {}", this.repository.getName(), baseDir);
  74
+        // Clone the first remote
  75
+        try {
  76
+          git = Git.cloneRepository()
  77
+              .setURI(this.repository.getRemoteRepositories().iterator().next().getUrl())
  78
+              .setDirectory(baseDir)
  79
+              .setBare(true)
  80
+              .call();
  81
+        } catch (GitAPIException e) {
  82
+          LOGGER.warn("Error while cloning {} : {}", this.repository, e.getMessage());
  83
+          return;
  84
+        }
  85
+        LOGGER.debug("{} cloned into {}", this.repository.getName());
  86
+      }
  87
+    } else {
  88
+      try {
  89
+        git = new Git(new FileRepository(baseDir));
  90
+      } catch (IOException e) {
  91
+        LOGGER.warn("Error while initializing {} : {}", this, e.getMessage());
  92
+        return;
  93
+      }
  94
+    }
  95
+    StoredConfig config = git.getRepository().getConfig();
  96
+    config.unsetSection("remote", "origin");
  97
+    try {
  98
+      config.save();
  99
+    } catch (IOException e) {
  100
+      LOGGER.warn("Error while updating local repository config");
  101
+    }
  102
+    for (VCSCoordinates remote : this.repository.getRemoteRepositories()) {
  103
+      config.setString("remote", remote.getName(), "url", remote.getUrl());
  104
+      try {
  105
+        config.save();
  106
+      } catch (IOException e) {
  107
+        LOGGER.warn("Error while updating local repository config");
  108
+        continue;
  109
+      }
  110
+      // Fetch
  111
+      try {
  112
+        LOGGER.debug("Fetching {} into {}", remote.getName(), this.baseDir);
  113
+        git.fetch()
  114
+            .setRemote(remote.getName())
  115
+            .setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/" + remote.getName() + "/*"))
  116
+            .setRemoveDeletedRefs(true)
  117
+            .setTagOpt(TagOpt.FETCH_TAGS)
  118
+            .call();
  119
+        LOGGER.debug("{} fetched into {}", remote.getName(), this.baseDir);
  120
+      } catch (Exception e) {
  121
+        LOGGER.warn("Error while fetching changes from remotes : {}", e.getMessage());
  122
+      }
  123
+
  124
+    }
  125
+  }
  126
+
  127
+  public List<VCSBranch> getBranches() {
  128
+    List<VCSBranch> branches = new ArrayList<>();
  129
+    try {
  130
+      for (Ref ref : git.branchList().call()) {
  131
+        branches.add(new VCSBranch(ref.getName().replaceAll("/refs/heads", "")));
  132
+      }
  133
+    } catch (GitAPIException e) {
  134
+      LOGGER.warn("Error while getting branches on {} : {}", this, e.getMessage());
  135
+      return Collections.emptyList();
  136
+    }
  137
+    return branches;
  138
+  }
  139
+
  140
+  public List<VCSTag> getTags() {
  141
+    List<VCSTag> tags = new ArrayList<>();
  142
+    try {
  143
+      for (Ref ref : git.tagList().call()) {
  144
+        tags.add(new VCSTag(ref.getName().replaceAll("/refs/tags/", "")));
  145
+      }
  146
+    } catch (GitAPIException e) {
  147
+      LOGGER.warn("Error while getting tags on {} : {}", this, e.getMessage());
  148
+      return Collections.emptyList();
  149
+    }
  150
+    return tags;
  151
+  }
  152
+
57 153
   /**
58 154
    * Returns a string representation of the object. In general, the
59 155
    * {@code toString} method returns a string that
24  acceptance-webapp/src/main/java/org/exoplatform/acceptance/model/vcs/VCSTag.java
... ...
@@ -0,0 +1,24 @@
  1
+package org.exoplatform.acceptance.model.vcs;
  2
+
  3
+import org.exoplatform.acceptance.model.StorableObject;
  4
+
  5
+import javax.validation.constraints.NotNull;
  6
+import org.springframework.data.mongodb.core.mapping.Document;
  7
+
  8
+/**
  9
+ * a VCS Tag
  10
+ */
  11
+@Document(collection = "vcstags")
  12
+public class VCSTag extends StorableObject {
  13
+  public VCSTag() {
  14
+    super();
  15
+  }
  16
+
  17
+  public VCSTag(@NotNull String name) {
  18
+    super(name);
  19
+  }
  20
+
  21
+  public VCSTag(@NotNull String name, @NotNull String id) {
  22
+    super(name, id);
  23
+  }
  24
+}
14  acceptance-webapp/src/main/java/org/exoplatform/acceptance/service/ConfigurationService.java
@@ -94,8 +94,11 @@ public File getDataDir() {
94 94
     }
95 95
     File dataDir = new File(dataDirPath);
96 96
     if (!dataDir.exists()) {
97  
-      boolean result = dataDir.mkdirs();
98  
-      LOGGER.info("Data directory {} creation [{}]", dataDirPath, result ? "OK" : "KO");
  97
+      if (dataDir.mkdirs()) {
  98
+        LOGGER.info("Data directory {} creation [OK]");
  99
+      } else {
  100
+        LOGGER.error("Data directory {} creation [KO]");
  101
+      }
99 102
     }
100 103
     return dataDir;
101 104
   }
@@ -106,8 +109,11 @@ public File getTmpDir() {
106 109
     }
107 110
     File tmpDir = new File(tmpDirPath);
108 111
     if (!tmpDir.exists()) {
109  
-      boolean result = tmpDir.mkdirs();
110  
-      LOGGER.info("Temporary directory {} creation [{}]", tmpDirPath, result ? "OK" : "KO");
  112
+      if (tmpDir.mkdirs()) {
  113
+        LOGGER.info("Temporary directory {} creation [OK]");
  114
+      } else {
  115
+        LOGGER.error("Temporary directory {} creation [KO]");
  116
+      }
111 117
     }
112 118
     return tmpDir;
113 119
   }
34  acceptance-webapp/src/main/java/org/exoplatform/acceptance/service/DevDataLoaderService.java
@@ -46,22 +46,28 @@ public void initializeData() {
46 46
     credentialService.updateOrCreate(new UsernamePasswordCredential("A username/password", "a_username", "a_password"));
47 47
     credentialService.updateOrCreate(new TokenCredential("A token", "a_token"));
48 48
     credentialService.updateOrCreate(new KeyPairCredential("A key pair", "a_private_key", "a_public_key"));
49  
-    createVCSRepository("Platform-UI");
50  
-    createVCSRepository("Commons");
51  
-    createVCSRepository("Content");
52  
-    createVCSRepository("Calendar");
53  
-    createVCSRepository("Social");
54  
-    createVCSRepository("Wiki");
55  
-    createVCSRepository("Forum");
56  
-    createVCSRepository("Integration");
57  
-    createVCSRepository("Platform");
  49
+    createVCSRepository("maven-depmgt-pom",false);
  50
+    createVCSRepository("platform-ui",true);
  51
+    createVCSRepository("commons",true);
  52
+    createVCSRepository("ecms",true);
  53
+    createVCSRepository("calendar",true);
  54
+    createVCSRepository("social",true);
  55
+    createVCSRepository("wiki",true);
  56
+    createVCSRepository("forum",true);
  57
+    createVCSRepository("integration",true);
  58
+    createVCSRepository("platform",true);
  59
+    createVCSRepository("platform-public-distributions",false);
  60
+    createVCSRepository("ide",true);
  61
+    createVCSRepository("platform-private-distributions",false);
58 62
   }
59 63
 
60  
-  private VCSRepository createVCSRepository(String name) {
61  
-    VCSRepository gitRepository = new VCSRepository(name.toLowerCase());
62  
-    gitRepository.addRemoteRepository("development", "https://github.com/exodev/" + name.toLowerCase() + ".git",
63  
-                                      Credential.NONE.getId());
64  
-    gitRepository.addRemoteRepository("blessed", "https://github.com/exoplatform/" + name.toLowerCase() + ".git",
  64
+  private VCSRepository createVCSRepository(String repoName, boolean hasDevRepo) {
  65
+    VCSRepository gitRepository = new VCSRepository(repoName);
  66
+    if (hasDevRepo) {
  67
+      gitRepository.addRemoteRepository("development", "https://github.com/exodev/" + repoName + ".git",
  68
+                                        Credential.NONE.getId());
  69
+    }
  70
+    gitRepository.addRemoteRepository("blessed", "https://github.com/exoplatform/" + repoName + ".git",
65 71
                                       Credential.NONE.getId());
66 72
     return VCSRepositoryService.updateOrCreate(gitRepository);
67 73
   }
37  acceptance-webapp/src/main/java/org/exoplatform/acceptance/service/vcs/VCSRepositoryService.java
@@ -18,18 +18,21 @@
18 18
  */
19 19
 package org.exoplatform.acceptance.service.vcs;
20 20
 
  21
+import org.exoplatform.acceptance.model.vcs.VCSBranch;
21 22
 import org.exoplatform.acceptance.model.vcs.VCSFileSet;
22 23
 import org.exoplatform.acceptance.model.vcs.VCSRepository;
  24
+import org.exoplatform.acceptance.model.vcs.VCSTag;
23 25
 import org.exoplatform.acceptance.service.AbstractMongoCRUDService;
24 26
 import org.exoplatform.acceptance.service.CRUDService;
25 27
 import org.exoplatform.acceptance.service.ConfigurationService;
26 28
 import org.exoplatform.acceptance.service.credential.CredentialService;
  29
+import org.exoplatform.acceptance.storage.vcs.VCSBranchMongoStorage;
27 30
 import org.exoplatform.acceptance.storage.vcs.VCSRepositoryMongoStorage;
  31
+import org.exoplatform.acceptance.storage.vcs.VCSTagMongoStorage;
28 32
 
29 33
 import java.io.File;
30 34
 import javax.inject.Inject;
31 35
 import javax.inject.Named;
32  
-import javax.validation.constraints.NotNull;
33 36
 import org.slf4j.Logger;
34 37
 import org.slf4j.LoggerFactory;
35 38
 import org.springframework.scheduling.annotation.Scheduled;
@@ -46,6 +49,10 @@
46 49
   @Inject
47 50
   private VCSRepositoryMongoStorage vcsRepositoryMongoStorage;
48 51
   @Inject
  52
+  private VCSBranchMongoStorage vcsBranchMongoStorage;
  53
+  @Inject
  54
+  private VCSTagMongoStorage vcsTagMongoStorage;
  55
+  @Inject
49 56
   private CredentialService credentialService;
50 57
 
51 58
   @Override
@@ -57,21 +64,25 @@ public VCSRepository findByName(String name) {
57 64
     return vcsRepositoryMongoStorage.findByName(name);
58 65
   }
59 66
 
60  
-  public VCSFileSet getFileSet(
61  
-      @NotNull File basedir,
62  
-      @NotNull VCSRepository repository) {
63  
-    return new VCSFileSet(basedir, repository);
64  
-  }
65  
-
66 67
   // Every minute
67  
-  @Scheduled(fixedRate = 60000)
  68
+  @Scheduled(fixedRate = 120000)
68 69
   public void extractSourceStatistics() {
69  
-    LOGGER.debug("Starting to process source repositories");
70  
-    for (VCSRepository VCSRepository : vcsRepositoryMongoStorage.findAll()) {
71  
-      LOGGER.debug("Processing sources repository {}", VCSRepository.getName());
72  
-      VCSFileSet localFileSet = getFileSet(new File(getCheckoutDirectory(), VCSRepository.getName()), VCSRepository);
  70
+    for (VCSRepository repository : vcsRepositoryMongoStorage.findAll()) {
  71
+      VCSFileSet localFileSet = new VCSFileSet(new File(getCheckoutDirectory(), repository.getName() + ".git"), repository);
  72
+      for (VCSBranch branch : localFileSet.getBranches()) {
  73
+        if (vcsBranchMongoStorage.findByName(branch.getName()) == null) {
  74
+          vcsBranchMongoStorage.save(branch);
  75
+          LOGGER.debug("Record new branch : {}", branch);
  76
+        }
  77
+      }
  78
+      for (VCSTag tag : localFileSet.getTags()) {
  79
+        if (vcsTagMongoStorage.findByName(tag.getName()) == null) {
  80
+          vcsTagMongoStorage.save(tag);
  81
+          LOGGER.debug("Record new tag : {}", tag);
  82
+        }
  83
+      }
73 84
     }
74  
-    LOGGER.debug("Source repositories processed");
  85
+    LOGGER.info("VCS data updated.");
75 86
   }
76 87
 
77 88
   public File getCheckoutDirectory() {
32  acceptance-webapp/src/main/java/org/exoplatform/acceptance/storage/vcs/VCSBranchMongoStorage.java
... ...
@@ -0,0 +1,32 @@
  1
+/*
  2
+ * Copyright (C) 2011-2013 eXo Platform SAS.
  3
+ *
  4
+ * This is free software; you can redistribute it and/or modify it
  5
+ * under the terms of the GNU Lesser General Public License as
  6
+ * published by the Free Software Foundation; either version 3 of
  7
+ * the License, or (at your option) any later version.
  8
+ *
  9
+ * This software is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12
+ * Lesser General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU Lesser General Public
  15
+ * License along with this software; if not, write to the Free
  16
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  17
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  18
+ */
  19
+package org.exoplatform.acceptance.storage.vcs;
  20
+
  21
+import org.exoplatform.acceptance.model.vcs.VCSBranch;
  22
+
  23
+import org.springframework.data.mongodb.repository.MongoRepository;
  24
+import org.springframework.stereotype.Repository;
  25
+
  26
+/**
  27
+ * CRUD operations managed by Mongo for VCSBranch classes
  28
+ */
  29
+@Repository
  30
+public interface VCSBranchMongoStorage extends MongoRepository<VCSBranch, String> {
  31
+  VCSBranch findByName(String name);
  32
+}
32  acceptance-webapp/src/main/java/org/exoplatform/acceptance/storage/vcs/VCSTagMongoStorage.java
... ...
@@ -0,0 +1,32 @@
  1
+/*
  2
+ * Copyright (C) 2011-2013 eXo Platform SAS.
  3
+ *
  4
+ * This is free software; you can redistribute it and/or modify it
  5
+ * under the terms of the GNU Lesser General Public License as
  6
+ * published by the Free Software Foundation; either version 3 of
  7
+ * the License, or (at your option) any later version.
  8
+ *
  9
+ * This software is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12
+ * Lesser General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU Lesser General Public
  15
+ * License along with this software; if not, write to the Free
  16
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  17
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  18
+ */
  19
+package org.exoplatform.acceptance.storage.vcs;
  20
+
  21
+import org.exoplatform.acceptance.model.vcs.VCSTag;
  22
+
  23
+import org.springframework.data.mongodb.repository.MongoRepository;
  24
+import org.springframework.stereotype.Repository;
  25
+
  26
+/**
  27
+ * CRUD operations managed by Mongo for VCSTag classes
  28
+ */
  29
+@Repository
  30
+public interface VCSTagMongoStorage extends MongoRepository<VCSTag, String> {
  31
+  VCSTag findByName(String name);
  32
+}
80  acceptance-webapp/src/test/java/org/exoplatform/acceptance/storage/vcs/VCSBranchMongoStorageTest.java
... ...
@@ -0,0 +1,80 @@
  1
+/*
  2
+ * Copyright (C) 2011-2013 eXo Platform SAS.
  3
+ *
  4
+ * This is free software; you can redistribute it and/or modify it
  5
+ * under the terms of the GNU Lesser General Public License as
  6
+ * published by the Free Software Foundation; either version 3 of
  7
+ * the License, or (at your option) any later version.
  8
+ *
  9
+ * This software is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12
+ * Lesser General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU Lesser General Public
  15
+ * License along with this software; if not, write to the Free
  16
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  17
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  18
+ */
  19
+package org.exoplatform.acceptance.storage.vcs;
  20
+
  21
+import static org.junit.Assert.assertEquals;
  22
+import static org.junit.Assert.assertNotNull;
  23
+
  24
+import org.exoplatform.acceptance.model.vcs.VCSBranch;
  25
+
  26
+import javax.inject.Inject;
  27
+import org.junit.After;
  28
+import org.junit.Before;
  29
+import org.junit.Test;
  30
+import org.junit.runner.RunWith;
  31
+import org.springframework.test.context.ActiveProfiles;
  32
+import org.springframework.test.context.ContextConfiguration;
  33
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  34
+
  35
+/**
  36
+ *
  37
+ */
  38
+@RunWith(SpringJUnit4ClassRunner.class)
  39
+@ContextConfiguration(locations = {"classpath:/org/exoplatform/acceptance/storage/spring-test.xml"})
  40
+@ActiveProfiles("test")
  41
+public class VCSBranchMongoStorageTest {
  42
+
  43
+  @Inject
  44
+  private VCSBranchMongoStorage vcsBranchMongoStorage;
  45
+
  46
+  @Before
  47
+  public void setUp() {
  48
+    // cleanup the collection if any Tenant
  49
+    vcsBranchMongoStorage.deleteAll();
  50
+  }
  51
+
  52
+  @After
  53
+  public void tearDown() {
  54
+    // cleanup the collection
  55
+    vcsBranchMongoStorage.deleteAll();
  56
+  }
  57
+
  58
+  @Test
  59
+  public void create() {
  60
+    VCSBranch savedVCSBranch = vcsBranchMongoStorage.save(new VCSBranch("a_branch"));
  61
+    assertNotNull("The reference ID should not be null", savedVCSBranch.getId());
  62
+    assertEquals("We should have exactly 1 reference", 1, vcsBranchMongoStorage.count());
  63
+  }
  64
+
  65
+  @Test
  66
+  public void delete() {
  67
+    VCSBranch savedVCSBranch = vcsBranchMongoStorage.save(new VCSBranch("a_branch"));
  68
+    vcsBranchMongoStorage.delete(savedVCSBranch);
  69
+    assertEquals("We should have exactly 0 reference", 0, vcsBranchMongoStorage.count());
  70
+  }
  71
+
  72
+  @Test
  73
+  public void update() {
  74
+    VCSBranch savedVCSBranch = vcsBranchMongoStorage.save(new VCSBranch("a_branch"));
  75
+    savedVCSBranch.setName("a_branch2");
  76
+    vcsBranchMongoStorage.save(savedVCSBranch);
  77
+    assertEquals("We should have exactly 1 reference", 1, vcsBranchMongoStorage.count());
  78
+    assertEquals("a_branch2", vcsBranchMongoStorage.findOne(savedVCSBranch.getId()).getName());
  79
+  }
  80
+}
80  acceptance-webapp/src/test/java/org/exoplatform/acceptance/storage/vcs/VCSTagMongoStorageTest.java
... ...
@@ -0,0 +1,80 @@
  1
+/*
  2
+ * Copyright (C) 2011-2013 eXo Platform SAS.
  3
+ *
  4
+ * This is free software; you can redistribute it and/or modify it
  5
+ * under the terms of the GNU Lesser General Public License as
  6
+ * published by the Free Software Foundation; either version 3 of
  7
+ * the License, or (at your option) any later version.
  8
+ *
  9
+ * This software is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12
+ * Lesser General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU Lesser General Public
  15
+ * License along with this software; if not, write to the Free
  16
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  17
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  18
+ */
  19
+package org.exoplatform.acceptance.storage.vcs;
  20
+
  21
+import static org.junit.Assert.assertEquals;
  22
+import static org.junit.Assert.assertNotNull;
  23
+
  24
+import org.exoplatform.acceptance.model.vcs.VCSTag;
  25
+
  26
+import javax.inject.Inject;
  27
+import org.junit.After;
  28
+import org.junit.Before;
  29
+import org.junit.Test;
  30
+import org.junit.runner.RunWith;
  31
+import org.springframework.test.context.ActiveProfiles;
  32
+import org.springframework.test.context.ContextConfiguration;
  33
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  34
+
  35
+/**
  36
+ *
  37
+ */
  38
+@RunWith(SpringJUnit4ClassRunner.class)
  39
+@ContextConfiguration(locations = {"classpath:/org/exoplatform/acceptance/storage/spring-test.xml"})
  40
+@ActiveProfiles("test")
  41
+public class VCSTagMongoStorageTest {
  42
+
  43
+  @Inject
  44
+  private VCSTagMongoStorage vcsTagMongoStorage;
  45
+
  46
+  @Before
  47
+  public void setUp() {
  48
+    // cleanup the collection if any Tenant
  49
+    vcsTagMongoStorage.deleteAll();
  50
+  }
  51
+
  52
+  @After
  53
+  public void tearDown() {
  54
+    // cleanup the collection
  55
+    vcsTagMongoStorage.deleteAll();
  56
+  }
  57
+
  58
+  @Test
  59
+  public void createTag() {
  60
+    VCSTag savedVCSTag = vcsTagMongoStorage.save(new VCSTag("a_tag"));
  61
+    assertNotNull("The reference ID should not be null", savedVCSTag.getId());
  62
+    assertEquals("We should have exactly 1 reference", 1, vcsTagMongoStorage.count());
  63
+  }
  64
+
  65
+  @Test
  66
+  public void deleteTag() {
  67
+    VCSTag savedVCSTag = vcsTagMongoStorage.save(new VCSTag("a_tag"));
  68
+    vcsTagMongoStorage.delete(savedVCSTag);
  69
+    assertEquals("We should have exactly 0 reference", 0, vcsTagMongoStorage.count());
  70
+  }
  71
+
  72
+  @Test
  73
+  public void updateTag() {
  74
+    VCSTag savedVCSTag = vcsTagMongoStorage.save(new VCSTag("a_tag"));
  75
+    savedVCSTag.setName("a_tag2");
  76
+    vcsTagMongoStorage.save(savedVCSTag);
  77
+    assertEquals("We should have exactly 1 reference", 1, vcsTagMongoStorage.count());
  78
+    assertEquals("a_tag2", vcsTagMongoStorage.findOne(savedVCSTag.getId()).getName());
  79
+  }
  80
+}
14  pom.xml
@@ -71,6 +71,7 @@
71 71
     <javax.jsr250.version>1.0</javax.jsr250.version>
72 72
     <javax.servlet.version>3.0.1</javax.servlet.version>
73 73
     <javax.validation.version>1.1.0.Final</javax.validation.version>
  74
+    <jgit.version>3.1.0.201310021548-r</jgit.version>
74 75
     <json-path.version>0.9.1</json-path.version>
75 76
     <junit.version>4.11</junit.version>
76 77
     <juzu.version>0.8.0-beta4</juzu.version>
@@ -241,6 +242,19 @@
241 242
         <version>${tomcat.version}</version>
242 243
       </dependency>
243 244
       <!-- **************************************** -->
  245
+      <!-- JGit -->
  246
+      <!-- **************************************** -->
  247
+      <dependency>
  248
+        <groupId>org.eclipse.jgit</groupId>
  249
+        <artifactId>org.eclipse.jgit</artifactId>
  250
+        <version>${jgit.version}</version>
  251
+      </dependency>
  252
+      <dependency>
  253
+        <groupId>org.eclipse.jgit</groupId>
  254
+        <artifactId>org.eclipse.jgit.java7</artifactId>
  255
+        <version>${jgit.version}</version>
  256
+      </dependency>
  257
+      <!-- **************************************** -->
244 258
       <!-- Build resource used to import license related files -->
245 259
       <!-- **************************************** -->
246 260
       <dependency>

0 notes on commit 0e5a032

Please sign in to comment.
Something went wrong with that request. Please try again.