< prev index next >

test/src/main/java/org/openjdk/skara/test/CheckableRepository.java

Print this page

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.skara.test;
 24 
 25 import org.openjdk.skara.vcs.*;
 26 
 27 import java.io.*;
 28 import java.nio.charset.StandardCharsets;
 29 import java.nio.file.*;

 30 
 31 public class CheckableRepository {
 32     private static String markerLine = "The very first line\n";
 33 
 34     private static Path checkableFile(Path path) throws IOException {
 35         try (var checkable = Files.newBufferedReader(path.resolve(".checkable/name.txt"), StandardCharsets.UTF_8)) {
 36             var checkableName = checkable.readLine();
 37             return path.resolve(checkableName);
 38         }
 39     }
 40 
 41     public static Repository init(Path path, VCS vcs, Path appendableFilePath) throws IOException {
 42         var repo = Repository.init(path, vcs);
 43 
 44         Files.createDirectories(path.resolve(".checkable"));
 45         try (var output = Files.newBufferedWriter(path.resolve(".checkable/name.txt"))) {
 46             output.write(appendableFilePath.toString());
 47         }
 48         repo.add(path.resolve(".checkable/name.txt"));
 49 
 50         var initialFile = path.resolve(appendableFilePath);
 51         try (var output = Files.newBufferedWriter(initialFile)) {
 52             output.append(markerLine);
 53         }
 54         repo.add(initialFile);
 55 
 56         Files.createDirectories(path.resolve(".jcheck"));
 57         var checkConf = path.resolve(".jcheck/conf");
 58         try (var output = Files.newBufferedWriter(checkConf)) {
 59             output.append("[general]\n");
 60             output.append("project=test\n");
 61             output.append("\n");
 62             output.append("[checks]\n");
 63             output.append("error=author,reviewers,whitespace\n");
 64             output.append("\n");

 65             output.append("[census]\n");
 66             output.append("version=0\n");
 67             output.append("domain=openjdk.java.net\n");
 68             output.append("\n");
 69             output.append("[checks \"whitespace\"]\n");
 70             output.append("files=.*\\.txt\n");
 71             output.append("\n");
 72             output.append("[checks \"reviewers\"]\n");
 73             output.append("minimum=1\n");
 74         }
 75         repo.add(checkConf);
 76 
 77         repo.commit("Initial commit", "testauthor", "ta@none.none");
 78 
 79         return repo;
 80     }
 81 




 82     public static Repository init(Path path, VCS vcs) throws IOException {
 83         return init(path, vcs, Path.of("appendable.txt"));
 84     }
 85 
 86     public static Hash appendAndCommit(Repository repo) throws IOException {
 87         return appendAndCommit(repo, "This is a new line");
 88     }
 89 
 90     public static Hash appendAndCommit(Repository repo, String body) throws IOException {
 91         return appendAndCommit(repo, body, "Append commit");
 92     }
 93 
 94     public static Hash appendAndCommit(Repository repo, String body, String message) throws IOException {
 95         return appendAndCommit(repo, body, message, "testauthor", "ta@none.none");
 96     }
 97 
 98     public static Hash appendAndCommit(Repository repo, String body, String message, String authorName, String authorEmail) throws IOException {
 99         return appendAndCommit(repo, body, message, authorName, authorEmail, authorName, authorEmail);
100     }
101 

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.skara.test;
 24 
 25 import org.openjdk.skara.vcs.*;
 26 
 27 import java.io.IOException;
 28 import java.nio.charset.StandardCharsets;
 29 import java.nio.file.*;
 30 import java.util.Set;
 31 
 32 public class CheckableRepository {
 33     private static String markerLine = "The very first line\n";
 34 
 35     private static Path checkableFile(Path path) throws IOException {
 36         try (var checkable = Files.newBufferedReader(path.resolve(".checkable/name.txt"), StandardCharsets.UTF_8)) {
 37             var checkableName = checkable.readLine();
 38             return path.resolve(checkableName);
 39         }
 40     }
 41 
 42     public static Repository init(Path path, VCS vcs, Path appendableFilePath, Set<String> checks) throws IOException {
 43         var repo = Repository.init(path, vcs);
 44 
 45         Files.createDirectories(path.resolve(".checkable"));
 46         try (var output = Files.newBufferedWriter(path.resolve(".checkable/name.txt"))) {
 47             output.write(appendableFilePath.toString());
 48         }
 49         repo.add(path.resolve(".checkable/name.txt"));
 50 
 51         var initialFile = path.resolve(appendableFilePath);
 52         try (var output = Files.newBufferedWriter(initialFile)) {
 53             output.append(markerLine);
 54         }
 55         repo.add(initialFile);
 56 
 57         Files.createDirectories(path.resolve(".jcheck"));
 58         var checkConf = path.resolve(".jcheck/conf");
 59         try (var output = Files.newBufferedWriter(checkConf)) {
 60             output.append("[general]\n");
 61             output.append("project=test\n");
 62             output.append("\n");
 63             output.append("[checks]\n");
 64             output.append("error=");
 65             output.append(String.join(",", checks));
 66             output.append("\n\n");
 67             output.append("[census]\n");
 68             output.append("version=0\n");
 69             output.append("domain=openjdk.java.net\n");
 70             output.append("\n");
 71             output.append("[checks \"whitespace\"]\n");
 72             output.append("files=.*\\.txt\n");
 73             output.append("\n");
 74             output.append("[checks \"reviewers\"]\n");
 75             output.append("minimum=1\n");
 76         }
 77         repo.add(checkConf);
 78 
 79         repo.commit("Initial commit", "testauthor", "ta@none.none");
 80 
 81         return repo;
 82     }
 83 
 84     public static Repository init(Path path, VCS vcs, Path appendableFilePath) throws IOException {
 85         return init(path, vcs, appendableFilePath, Set.of("author", "reviewers", "whitespace"));
 86     }
 87 
 88     public static Repository init(Path path, VCS vcs) throws IOException {
 89         return init(path, vcs, Path.of("appendable.txt"));
 90     }
 91 
 92     public static Hash appendAndCommit(Repository repo) throws IOException {
 93         return appendAndCommit(repo, "This is a new line");
 94     }
 95 
 96     public static Hash appendAndCommit(Repository repo, String body) throws IOException {
 97         return appendAndCommit(repo, body, "Append commit");
 98     }
 99 
100     public static Hash appendAndCommit(Repository repo, String body, String message) throws IOException {
101         return appendAndCommit(repo, body, message, "testauthor", "ta@none.none");
102     }
103 
104     public static Hash appendAndCommit(Repository repo, String body, String message, String authorName, String authorEmail) throws IOException {
105         return appendAndCommit(repo, body, message, authorName, authorEmail, authorName, authorEmail);
106     }
107 
< prev index next >