From 0735dbb180483308a9c5449da9156a7b6edeeee0 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 3 Sep 2022 16:17:35 +0200 Subject: [PATCH 1/2] "study.yml" is static now --- .../jabref/logic/crawler/StudyRepository.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/logic/crawler/StudyRepository.java b/src/main/java/org/jabref/logic/crawler/StudyRepository.java index 19fdd7e4abe..2dbe61b0c2c 100644 --- a/src/main/java/org/jabref/logic/crawler/StudyRepository.java +++ b/src/main/java/org/jabref/logic/crawler/StudyRepository.java @@ -217,11 +217,8 @@ public Study getStudy() { */ public void persist(List crawlResults) throws IOException, GitAPIException, SaveException { updateWorkAndSearchBranch(); - persistStudy(); - gitHandler.createCommitOnCurrentBranch("Update search date", true); gitHandler.checkoutBranch(SEARCH_BRANCH); persistResults(crawlResults); - persistStudy(); try { // First commit changes to search branch and update remote String commitMessage = "Conducted search: " + LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS); @@ -245,10 +242,15 @@ public void persist(List crawlResults) throws IOException, GitAPIEx */ private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIException { String currentBranch = gitHandler.getCurrentlyCheckedOutBranch(); + + // update remote search branch gitHandler.checkoutBranch(SEARCH_BRANCH); gitHandler.pushCommitsToRemoteRepository(); + + // update remote work branch gitHandler.checkoutBranch(WORK_BRANCH); gitHandler.pushCommitsToRemoteRepository(); + gitHandler.checkoutBranch(currentBranch); } @@ -258,15 +260,16 @@ private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIExcepti */ private void updateWorkAndSearchBranch() throws IOException, GitAPIException { String currentBranch = gitHandler.getCurrentlyCheckedOutBranch(); + + // update search branch gitHandler.checkoutBranch(SEARCH_BRANCH); gitHandler.pullOnCurrentBranch(); + + // update work branch gitHandler.checkoutBranch(WORK_BRANCH); gitHandler.pullOnCurrentBranch(); - gitHandler.checkoutBranch(currentBranch); - } - private void persistStudy() throws IOException { - new StudyYamlParser().writeStudyYamlFile(study, studyDefinitionFile); + gitHandler.checkoutBranch(currentBranch); } /** From 3b59cabfb706421e39d2efa66ace849fc5a39977 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 3 Sep 2022 14:55:49 +0200 Subject: [PATCH 2/2] Replace "study.yml" by constant --- .../java/org/jabref/gui/slr/StartNewStudyAction.java | 3 ++- .../java/org/jabref/logic/crawler/StudyRepository.java | 5 +++-- src/main/java/org/jabref/logic/git/SlrGitHandler.java | 4 +++- .../java/org/jabref/logic/crawler/CrawlerTest.java | 4 ++-- .../crawler/StudyDatabaseToFetcherConverterTest.java | 4 ++-- .../org/jabref/logic/crawler/StudyRepositoryTest.java | 4 ++-- .../org/jabref/logic/crawler/StudyYamlParserTest.java | 10 +++++----- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java b/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java index 09a90666e2f..0bf2a4902c5 100644 --- a/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java +++ b/src/main/java/org/jabref/gui/slr/StartNewStudyAction.java @@ -8,6 +8,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.crawler.StudyRepository; import org.jabref.logic.crawler.StudyYamlParser; import org.jabref.model.study.Study; import org.jabref.model.util.FileUpdateMonitor; @@ -25,7 +26,7 @@ public StartNewStudyAction(JabRefFrame frame, FileUpdateMonitor fileUpdateMonito @Override protected void setupRepository(Path studyRepositoryRoot) throws IOException, GitAPIException { StudyYamlParser studyYAMLParser = new StudyYamlParser(); - studyYAMLParser.writeStudyYamlFile(newStudy, studyRepositoryRoot.resolve("study.yml")); + studyYAMLParser.writeStudyYamlFile(newStudy, studyRepositoryRoot.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME)); } @Override diff --git a/src/main/java/org/jabref/logic/crawler/StudyRepository.java b/src/main/java/org/jabref/logic/crawler/StudyRepository.java index 2dbe61b0c2c..63feea3d825 100644 --- a/src/main/java/org/jabref/logic/crawler/StudyRepository.java +++ b/src/main/java/org/jabref/logic/crawler/StudyRepository.java @@ -48,9 +48,10 @@ * the structured persistence of the crawling results for the study within the file based repository, * as well as the sharing, and versioning of results using git. */ -class StudyRepository { +public class StudyRepository { // Tests work with study.yml - private static final String STUDY_DEFINITION_FILE_NAME = "study.yml"; + public static final String STUDY_DEFINITION_FILE_NAME = "study.yml"; + private static final Logger LOGGER = LoggerFactory.getLogger(StudyRepository.class); private static final Pattern MATCHCOLON = Pattern.compile(":"); private static final Pattern MATCHILLEGALCHARACTERS = Pattern.compile("[^A-Za-z0-9_.\\s=-]"); diff --git a/src/main/java/org/jabref/logic/git/SlrGitHandler.java b/src/main/java/org/jabref/logic/git/SlrGitHandler.java index d9bb027d220..334f4c7feec 100644 --- a/src/main/java/org/jabref/logic/git/SlrGitHandler.java +++ b/src/main/java/org/jabref/logic/git/SlrGitHandler.java @@ -12,6 +12,8 @@ import java.util.Optional; import java.util.StringJoiner; +import org.jabref.logic.crawler.StudyRepository; + import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.diff.DiffEntry; @@ -101,7 +103,7 @@ Map parsePatchForAddedEntries(String patch) throws IOException, Gi if (currentToken.startsWith("diff --git a/")) { // If the diff is related to a different file, save the diff for the previous file if (!(Objects.isNull(relativePath) || Objects.isNull(joiner))) { - if (!relativePath.contains("study.yml")) { + if (!relativePath.contains(StudyRepository.STUDY_DEFINITION_FILE_NAME)) { diffsPerFile.put(Path.of(repositoryPath.toString(), relativePath), joiner.toString()); } } diff --git a/src/test/java/org/jabref/logic/crawler/CrawlerTest.java b/src/test/java/org/jabref/logic/crawler/CrawlerTest.java index 7f2c60405cc..a16d3b4469d 100644 --- a/src/test/java/org/jabref/logic/crawler/CrawlerTest.java +++ b/src/test/java/org/jabref/logic/crawler/CrawlerTest.java @@ -120,8 +120,8 @@ private void setUpRepository() throws Exception { } private void setUpTestStudyDefinitionFile() throws Exception { - Path destination = tempRepositoryDirectory.resolve("study.yml"); - URL studyDefinition = this.getClass().getResource("study.yml"); + Path destination = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME); + URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME); FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false); } } diff --git a/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java b/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java index 37829f6fb5d..78b557a6fe0 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyDatabaseToFetcherConverterTest.java @@ -58,7 +58,7 @@ void setUpMocks() { @Test public void getActiveFetcherInstances() throws Exception { - Path studyDefinition = tempRepositoryDirectory.resolve("study.yml"); + Path studyDefinition = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME); copyTestStudyDefinitionFileIntoDirectory(studyDefinition); StudyRepository studyRepository = new StudyRepository( @@ -83,7 +83,7 @@ public void getActiveFetcherInstances() throws Exception { } private void copyTestStudyDefinitionFileIntoDirectory(Path destination) throws Exception { - URL studyDefinition = this.getClass().getResource("study.yml"); + URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME); FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false); } } diff --git a/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java b/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java index 697b04958f6..5c6c14983d6 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyRepositoryTest.java @@ -190,8 +190,8 @@ private StudyRepository getTestStudyRepository() throws Exception { * Copies the study definition file into the test repository */ private void setUpTestStudyDefinitionFile() throws Exception { - Path destination = tempRepositoryDirectory.resolve("study.yml"); - URL studyDefinition = this.getClass().getResource("study.yml"); + Path destination = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME); + URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME); FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false); } diff --git a/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java b/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java index d4e63f64bc1..db2fb4f45e0 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java @@ -23,8 +23,8 @@ class StudyYamlParserTest { @BeforeEach void setupStudy() throws Exception { - Path destination = testDirectory.resolve("study.yml"); - URL studyDefinition = StudyYamlParser.class.getResource("study.yml"); + Path destination = testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME); + URL studyDefinition = StudyYamlParser.class.getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME); FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, true); List authors = List.of("Jab Ref"); @@ -39,14 +39,14 @@ void setupStudy() throws Exception { @Test public void parseStudyFileSuccessfully() throws Exception { - Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml")); + Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME)); assertEquals(expectedStudy, study); } @Test public void writeStudyFileSuccessfully() throws Exception { - new StudyYamlParser().writeStudyYamlFile(expectedStudy, testDirectory.resolve("study.yml")); - Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml")); + new StudyYamlParser().writeStudyYamlFile(expectedStudy, testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME)); + Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME)); assertEquals(expectedStudy, study); }