diff options
author | Ryan D. Brooks | 2019-01-31 00:46:36 -0500 |
---|---|---|
committer | Ryan D. Brooks | 2019-01-31 02:15:18 -0500 |
commit | d0fc4ccbea9f8615c2c3e70a1182c4f8cb77dc46 (patch) | |
tree | a9cdfb1b92786b07bf4c29681e8b1212e860128d | |
parent | af00e6af63652f1ca3927179aa6f103855c5a9e6 (diff) | |
download | org.eclipse.osee-rbrooks/rebase.tar.gz org.eclipse.osee-rbrooks/rebase.tar.xz org.eclipse.osee-rbrooks/rebase.zip |
feature: Suport Certification Baselining strategyrbrooks/rebase
Change-Id: I00d0aa9369364cce5ccaa5aaf9c8688c0785cd5a
5 files changed, 250 insertions, 106 deletions
diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FastHistoryStrategy.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FastHistoryStrategy.java new file mode 100644 index 0000000000..b22b5e0be2 --- /dev/null +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FastHistoryStrategy.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2019 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.define.rest; + +import static org.eclipse.osee.framework.core.enums.CoreTupleTypes.GitLatest; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.UserId; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +public class FastHistoryStrategy extends FullHistoryTolerant { + private final Map<ArtifactId, ArtifactId> codeunitToCommitMap = new HashMap<>(10000); + private final TransactionBuilder tx; + + public FastHistoryStrategy(ArtifactId repository, TransactionBuilder tx) { + super(repository, null); + this.tx = tx; + } + + @Override + public void handleCodeUnit(BranchId branch, ArtifactId codeUnit, TransactionBuilder tx, ArtifactId repository, ArtifactId commit, String changeType) { + codeunitToCommitMap.put(codeUnit, commit); + + } + + @Override + public TransactionBuilder getTransactionBuilder(OrcsApi orcsApi, ArtifactId repository, BranchId branch, UserId account) { + return tx; + } + + @Override + public void finishImport() { + pathToCodeunitMap.forEach((path, codeUnit) -> tx.addTuple4(GitLatest, repository, codeUnit, + codeunitToCommitMap.get(codeUnit), ArtifactId.SENTINEL)); + tx.commit(); + } + + @Override + public void finishGitCommit(TransactionBuilder tx) { + // only finish transaction in finalize + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FullHistoryTolerant.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FullHistoryTolerant.java new file mode 100644 index 0000000000..3ee7b04ddf --- /dev/null +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/FullHistoryTolerant.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2019 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.define.rest; + +import static org.eclipse.osee.framework.core.enums.CoreTupleTypes.GitCommitFile; +import static org.eclipse.osee.framework.core.enums.CoreTupleTypes.GitLatest; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.UserId; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.search.TupleQuery; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +public class FullHistoryTolerant implements HistoryImportStrategy { + protected final Map<String, ArtifactId> pathToCodeunitMap = new HashMap<>(10000); + private final TupleQuery tupleQuery; + protected final ArtifactId repository; + + public FullHistoryTolerant(ArtifactId repository, TupleQuery tupleQuery) { + this.repository = repository; + this.tupleQuery = tupleQuery; + } + + @Override + public ArtifactId getCodeUnit(BranchId branch, TransactionBuilder tx, String commitSHA, String changeType, String path, String newPath) { + if (path.startsWith("Tools") || newPath.startsWith("Tools")) { + return ArtifactId.SENTINEL; + } + ArtifactId codeUnit = findCodeUnit(repository, branch, path); + + if (matchesChangeType(changeType, 'A')) { + if (codeUnit.isValid()) { + // throw new OseeStateException("Attempting to add already existing code unit [%s] for repository [%s]", path, + // repository); + System.out.printf("commit [%s] adds code unit [%s] but found existing code unit [%s]\n", commitSHA, path, + codeUnit); + } else { + codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, path); + pathToCodeunitMap.put(path, codeUnit); + } + } else if (matchesChangeType(changeType, 'C')) { + codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, newPath); + pathToCodeunitMap.put(newPath, codeUnit); + } else if (matchesChangeType(changeType, 'D')) { + if (codeUnit.isValid()) { + tx.deleteArtifact(codeUnit); + pathToCodeunitMap.remove(path); + } else { + System.out.printf("didn't find %s for deletion in commit %s\n", path, commitSHA); + } + } else if (matchesChangeType(changeType, 'R')) { + if (codeUnit.isValid()) { + tx.setName(codeUnit, newPath); + pathToCodeunitMap.remove(path); + pathToCodeunitMap.put(newPath, codeUnit); + } else { + System.out.printf("didn't find in commit [%s] for rename from [%s] to [%s]\n", commitSHA, path, newPath); + codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, newPath); + pathToCodeunitMap.put(newPath, codeUnit); + } + } else if (matchesChangeType(changeType, 'M')) { + // no change to the code unit (we add the GitCommitFile tuple entry elsewhere) + } else { + System.out.printf("unexpected change type [%s] on path [%s]\n", changeType, path); + } + if (codeUnit.isInvalid()) { + System.out.printf("unexpected invalid code unit with changeType [%s] in commit [%s] for path [%s]\n", + changeType, commitSHA, path); + } + return codeUnit; + } + + private ArtifactId findCodeUnit(ArtifactId repository, BranchId branch, String path) { + ArtifactId codeUnit = pathToCodeunitMap.get(path); + if (codeUnit != null) { + return codeUnit; + } + return ArtifactId.SENTINEL; + } + + @Override + public void handleCodeUnit(BranchId branch, ArtifactId codeUnit, TransactionBuilder tx, ArtifactId repository, ArtifactId commit, String changeType) { + tx.addTuple4(GitCommitFile, repository, codeUnit, commit, changeType); + + ArtifactId[] commitWraper = new ArtifactId[] {ArtifactId.SENTINEL}; + tupleQuery.getTuple4E3E4FromE1E2(GitLatest, branch, repository, codeUnit, + (ignore, baselineCommit) -> commitWraper[0] = baselineCommit); + + tx.deleteTuple4ByE1E2(GitLatest, repository, codeUnit); + + tx.addTuple4(GitLatest, repository, codeUnit, commit, commitWraper[0]); + } + + @Override + public TransactionBuilder getTransactionBuilder(OrcsApi orcsApi, ArtifactId repository, BranchId branch, UserId account) { + return orcsApi.getTransactionFactory().createTransaction(branch, account, + "TraceabilityOperationsImpl.parseGitHistory repo [" + repository.getIdString() + "]"); + } + + @Override + public void finishGitCommit(TransactionBuilder tx) { + tx.commit(); + } + + @Override + public void finishImport() { + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/GitTraceability.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/GitTraceability.java index 3d6aaec9fa..a5a3827e2e 100644 --- a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/GitTraceability.java +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/GitTraceability.java @@ -25,9 +25,7 @@ import static org.eclipse.osee.framework.core.enums.CoreTupleTypes.GitLatest; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -77,7 +75,6 @@ public final class GitTraceability { private final TupleQuery tupleQuery; private final ArtifactId repository; private final BranchId branch; - private Map<String, ArtifactId> pathToCodeunitMap; public GitTraceability(OrcsApi orcsApi, BranchId branch, ArtifactId repository) { this.orcsApi = orcsApi; @@ -122,7 +119,7 @@ public final class GitTraceability { } for (String path : baselineData.files) { - ArtifactId codeUnit = findCodeUnit(repository, branch, path); + ArtifactId codeUnit = loadCodeUnit(repository, branch, path); if (codeUnit.isInvalid()) { throw new OseeArgumentException("No code unit found for path [%s]", path); } @@ -134,6 +131,18 @@ public final class GitTraceability { return baselineEvent; } + private ArtifactId loadCodeUnit(ArtifactId repository, BranchId branch, String path) { + List<ArtifactId> codeUnits = + queryFactory.fromBranch(branch).andNameEquals(path).andTypeEquals(CodeUnit).loadArtifactIds(); + for (ArtifactId codeUnit : codeUnits) { + //TODO: if CoreTupleTypes.GitCommitFile for this repository and path matches then return this codeUnit + //tupleQuery.doesTuple3E3Exist(tupleType, e3); + return codeUnit; + } + + return ArtifactId.SENTINEL; + } + private void updateLGitLatestTuple(TransactionBuilder tx, ArtifactId codeUnit, ArtifactId baselineCommit) { ArtifactId[] commitWraper = new ArtifactId[1]; tupleQuery.getTuple4E3E4FromE1E2(GitLatest, branch, repository, codeUnit, @@ -144,19 +153,18 @@ public final class GitTraceability { tx.addTuple4(GitLatest, repository, codeUnit, commitWraper[0], baselineCommit); } - public void parseGitHistory(String gitHistory, BranchId branch, UserId account) { - pathToCodeunitMap = new HashMap<>(10000); + public void parseGitHistory(String gitHistory, BranchId branch, UserId account, HistoryImportStrategy importStrategy) { Scanner scanner = new Scanner(gitHistory); scanner.useDelimiter(delimiterPattern); while (scanner.hasNext()) { - parseGitCommit(repository, scanner, branch, account); + parseGitCommit(repository, scanner, branch, account, importStrategy); } + importStrategy.finishImport(); } - private void parseGitCommit(ArtifactId repository, Scanner scanner, BranchId branch, UserId account) { - TransactionBuilder tx = orcsApi.getTransactionFactory().createTransaction(branch, account, - "TraceabilityOperationsImpl.parseGitHistory repo [" + repository.getIdString() + "]"); + private void parseGitCommit(ArtifactId repository, Scanner scanner, BranchId branch, UserId account, HistoryImportStrategy importStrategy) { + TransactionBuilder tx = importStrategy.getTransactionBuilder(orcsApi, repository, branch, account); String commitSHA = parseLine(scanner, commitShaMatcher); System.out.println(commitSHA); @@ -176,7 +184,7 @@ public final class GitTraceability { StringBuilder commitMessage = new StringBuilder(400); String commitMessageFirstLine; - if (scanner.hasNext(filePattern)) { + if (scanner.hasNext(filePattern)) { // will find file pattern here if commit message is missing commitMessageFirstLine = ""; } else { commitMessageFirstLine = scanner.next(); @@ -188,14 +196,14 @@ public final class GitTraceability { tx.setSoleAttributeValue(commit, CoreAttributeTypes.UserArtifactId, SystemUser.OseeSystem); //TODO: this must convert author to the corresponding user artifact tx.setSoleAttributeValue(commit, CoreAttributeTypes.GitCommitAuthorDate, authorDate); - parseFileChanges(repository, commitSHA, commit, scanner, branch, tx, commitMessage); + parseFileChanges(repository, commitSHA, commit, scanner, branch, tx, commitMessage, importStrategy); tx.setSoleAttributeValue(commit, CoreAttributeTypes.GitCommitMessage, commitMessage); - tx.commit(); + importStrategy.finishGitCommit(tx); } - private void parseFileChanges(ArtifactId repository, String commitSHA, ArtifactId commit, Scanner scanner, BranchId branch, TransactionBuilder tx, StringBuilder commitMessage) { + private void parseFileChanges(ArtifactId repository, String commitSHA, ArtifactId commit, Scanner scanner, BranchId branch, TransactionBuilder tx, StringBuilder commitMessage, HistoryImportStrategy importStrategy) { String commitId = commitSHA; while (scanner.hasNext()) { String line = scanner.next(); @@ -205,24 +213,17 @@ public final class GitTraceability { String changeType = fileMatcher.group(1); String path = fileMatcher.group(2); String newPath = fileMatcher.group(3); - ArtifactId codeUnit = handleCodeUnit(repository, branch, tx, commitSHA, changeType, path, newPath); - if (codeUnit.isValid()) { - tx.addTuple4(GitCommitFile, repository, codeUnit, commit, changeType); - - ArtifactId[] commitWraper = new ArtifactId[] {ArtifactId.SENTINEL}; - tupleQuery.getTuple4E3E4FromE1E2(GitLatest, branch, repository, codeUnit, - (ignore, baselineCommit) -> commitWraper[0] = baselineCommit); - tx.deleteTuple4ByE1E2(GitLatest, repository, codeUnit); - - tx.addTuple4(GitLatest, repository, codeUnit, commit, commitWraper[0]); + ArtifactId codeUnit = importStrategy.getCodeUnit(branch, tx, commitSHA, changeType, path, newPath); + if (codeUnit.isValid()) { + importStrategy.handleCodeUnit(branch, codeUnit, tx, repository, commit, changeType); } } else if (signedOffMatcher.reset(line).matches()) { String signer = signedOffMatcher.group(1); } else if (changeIdMatcher.reset(line).matches()) { commitId = changeIdMatcher.group(1); if (tupleQuery.doesTuple4E3Exist(GitCommitFile, commit)) { - tx.abandon(); + tx.abandon(); // don't save the same commit twice } tx.setSoleAttributeValue(commit, GitChangeId, commitId); } else { @@ -232,86 +233,6 @@ public final class GitTraceability { } } - /** - * Possible status letters are:<br/> - * A: addition of a file<br/> - * C: copy of a file into a new one<br/> - * D: deletion of a file<br/> - * M: modification of the contents or mode of a file<br/> - * R: renaming of a file<br/> - * T: change in the type of the file<br/> - */ - private ArtifactId handleCodeUnit(ArtifactId repository, BranchId branch, TransactionBuilder tx, String commitSHA, String changeType, String path, String newPath) { - if (path.startsWith("Tools") || newPath.startsWith("Tools")) { - return ArtifactId.SENTINEL; - } - ArtifactId codeUnit = findCodeUnit(repository, branch, path); - - if (matchesChangeType(changeType, 'A')) { - if (codeUnit.isValid()) { - // throw new OseeStateException("Attempting to add already existing code unit [%s] for repository [%s]", path, - // repository); - System.out.printf("commit [%s] adds code unit [%s] but found existing code unit [%s]\n", commitSHA, path, - codeUnit); - } else { - codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, path); - pathToCodeunitMap.put(path, codeUnit); - } - } else if (matchesChangeType(changeType, 'C')) { - codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, newPath); - pathToCodeunitMap.put(newPath, codeUnit); - } else if (matchesChangeType(changeType, 'D')) { - if (codeUnit.isValid()) { - tx.deleteArtifact(codeUnit); - pathToCodeunitMap.put(path, null); - } else { - System.out.printf("didn't find %s for deletion in commit %s\n", path, commitSHA); - } - } else if (matchesChangeType(changeType, 'R')) { - if (codeUnit.isValid()) { - tx.setName(codeUnit, newPath); - pathToCodeunitMap.put(path, null); - pathToCodeunitMap.put(newPath, codeUnit); - } else { - System.out.printf("didn't find in commit [%s] for rename from [%s] to [%s]\n", commitSHA, path, newPath); - codeUnit = tx.createArtifact(CoreArtifactTypes.CodeUnit, newPath); - pathToCodeunitMap.put(newPath, codeUnit); - } - } else if (matchesChangeType(changeType, 'M')) { - // no change to the code unit (we add the GitCommitFile tuple entry elsewhere) - } else { - System.out.printf("unexpected change type [%s] on path [%s]\n", changeType, path); - } - if (codeUnit.isInvalid()) { - System.out.printf("unexpected invalid code unit with changeType [%s] in commit [%s] for path [%s]\n", - changeType, commitSHA, path); - } - return codeUnit; - } - - private boolean matchesChangeType(String changeType, char typeToMatch) { - return ((changeType.length() == 1 || changeType.length() == 4) && changeType.charAt( - 0) == typeToMatch) || (changeType.length() == 2 && changeType.charAt(1) == typeToMatch); - } - - private ArtifactId findCodeUnit(ArtifactId repository, BranchId branch, String path) { - if (pathToCodeunitMap == null) { - List<ArtifactId> codeUnits = - queryFactory.fromBranch(branch).andNameEquals(path).andTypeEquals(CodeUnit).loadArtifactIds(); - for (ArtifactId codeUnit : codeUnits) { - //TODO: if CoreTupleTypes.GitCommitFile for this repository and path then return this codeUnit - //tupleQuery.doesTuple3E3Exist(tupleType, e3); - return codeUnit; - } - } else { - ArtifactId codeUnit = pathToCodeunitMap.get(path); - if (codeUnit != null) { - return codeUnit; - } - } - return ArtifactId.SENTINEL; - } - private String parseLine(Scanner scanner, Matcher matcher) { String line = scanner.next(); if (matcher.reset(line).find()) { diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/HistoryImportStrategy.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/HistoryImportStrategy.java new file mode 100644 index 0000000000..8d389768fb --- /dev/null +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/HistoryImportStrategy.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2019 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.define.rest; + +import org.eclipse.osee.framework.core.data.ArtifactId; +import org.eclipse.osee.framework.core.data.BranchId; +import org.eclipse.osee.framework.core.data.UserId; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; + +/** + * @author Ryan D. Brooks + */ +public interface HistoryImportStrategy { + /** + * Possible status letters are:<br/> + * A: addition of a file<br/> + * C: copy of a file into a new one<br/> + * D: deletion of a file<br/> + * M: modification of the contents or mode of a file<br/> + * R: renaming of a file<br/> + * T: change in the type of the file<br/> + */ + ArtifactId getCodeUnit(BranchId branch, TransactionBuilder tx, String commitSHA, String changeType, String path, String newPath); + + void handleCodeUnit(BranchId branch, ArtifactId codeUnit, TransactionBuilder tx, ArtifactId repository, ArtifactId commit, String changeType); + + TransactionBuilder getTransactionBuilder(OrcsApi orcsApi, ArtifactId repository, BranchId branch, UserId account); + + default boolean matchesChangeType(String changeType, char typeToMatch) { + return ((changeType.length() == 1 || changeType.length() == 4) && changeType.charAt( + 0) == typeToMatch) || (changeType.length() == 2 && changeType.charAt(1) == typeToMatch); + } + + void finishGitCommit(TransactionBuilder tx); + + void finishImport(); +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/TraceabilityOperationsImpl.java b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/TraceabilityOperationsImpl.java index 6d72b9dba3..8578f36417 100644 --- a/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/TraceabilityOperationsImpl.java +++ b/plugins/org.eclipse.osee.define.rest/src/org/eclipse/osee/define/rest/TraceabilityOperationsImpl.java @@ -49,6 +49,7 @@ import org.eclipse.osee.orcs.OrcsApi; import org.eclipse.osee.orcs.data.ArtifactReadable; import org.eclipse.osee.orcs.search.QueryFactory; import org.eclipse.osee.orcs.search.TupleQuery; +import org.eclipse.osee.orcs.transaction.TransactionBuilder; /** * @author Ryan D. Brooks @@ -145,7 +146,11 @@ public class TraceabilityOperationsImpl implements TraceabilityOperations { @Override public void parseGitHistory(ArtifactId repository, String gitHistory, BranchId branch, UserId account) { - new GitTraceability(orcsApi, branch, repository).parseGitHistory(gitHistory, branch, account); + TransactionBuilder tx = orcsApi.getTransactionFactory().createTransaction(branch, account, + "TraceabilityOperationsImpl.parseGitHistory repo [" + repository.getIdString() + "]"); + HistoryImportStrategy importStrategy = new FastHistoryStrategy(repository, tx); + //new FullHistoryTolerant(repository, orcsApi.getQueryFactory().tupleQuery()); + new GitTraceability(orcsApi, branch, repository).parseGitHistory(gitHistory, branch, account, importStrategy); } @Override |