package com.mathworks.cmlink.sdk.tests.util; import com.mathworks.cmlink.api.ConfigurationManagementException; import com.mathworks.cmlink.api.FileState; import com.mathworks.cmlink.api.LocalStatus; import com.mathworks.cmlink.api.Revision; import com.mathworks.cmlink.api.version.r14a.CMAdapter; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Map; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.matchers.JUnitMatchers.hasItem; public class StatusChecker { private final CMAdapter fAdapter; public StatusChecker(CMAdapter adapter) { fAdapter = adapter; } public CMAdapter getAdaptor() { return fAdapter; } public void checkStateIsAsExpected(Collection<File> files, Collection<LocalStatus> possibleStatus) throws ConfigurationManagementException { //Test whether the specified list of files all share the specified expected status. CMAdapter adapter = getAdaptor(); Map<File, FileState> statusMap = adapter.getFileState(files); for (File file : files) { LocalStatus actualStatus = statusMap.get(file).getLocalStatus(); assertThat("file :" + file, possibleStatus, hasItem(actualStatus)); } } public void checkStateIsAsExpected(Collection<File> files, LocalStatus expectedStatus) throws ConfigurationManagementException { files = stripDirectories(files); //Test whether the specified list of files all share the specified expected status. CMAdapter adapter = getAdaptor(); Map<File, FileState> statusMap = adapter.getFileState(files); for (File file : files) { LocalStatus actualStatus = statusMap.get(file).getLocalStatus(); assertThat("file status" + file, expectedStatus, is(equalTo(actualStatus))); } } private static Collection<File> stripDirectories(Collection<File> files) { Collection<File> filesNoDirs = new ArrayList<File>(); for (File file : files) { if (file.isFile() || !file.exists()) { filesNoDirs.add(file); } } return filesNoDirs; } public void checkAtLeastOneStateIsAsExpected(Collection<File> files, LocalStatus expectedStatus) throws ConfigurationManagementException { files = stripDirectories(files); CMAdapter adapter = getAdaptor(); Map<File, FileState> statusMap = adapter.getFileState(files); for (Map.Entry<File, FileState> entry : statusMap.entrySet()) { LocalStatus actualStatus = entry.getValue().getLocalStatus(); if (actualStatus == expectedStatus) { return; } } assertTrue("At least one status should have been " + expectedStatus, false); } public void checkedOut(Collection<File> files, boolean actualCheckedoutState) throws ConfigurationManagementException { files = stripDirectories(files); CMAdapter adapter = getAdaptor(); Map<File, FileState> fileStateMap = adapter.getFileState(files); for (Map.Entry<File, FileState> entry : fileStateMap.entrySet()) { assertEquals("Value mismatch", actualCheckedoutState, entry.getValue().hasLock()); } } public static void revisionsAllEqual(Collection<Revision> revisions, Revision expectedRevision) { for (Revision revision : revisions) { assertTrue( "Expected revision " + expectedRevision + " does not match revision " + revision, 0 == revision.compareTo(expectedRevision)); } } public static void revisionsAllLess(Collection<Revision> revisions, Revision benchmarkRevision) { for (Revision revision : revisions) { assertTrue( "Expected revision " + revision + " to be less than the bench mark revision " + benchmarkRevision, 0 > revision.compareTo(benchmarkRevision)); } } public static void revisionsAllGreater(Collection<Revision> revisions, Revision benchmarkRevision) { for (Revision revision : revisions) { assertTrue( "Expected revision " + revision + " to be greater than the bench mark revision " + benchmarkRevision, 0 < revision.compareTo(benchmarkRevision)); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#5 | 11643 | Paul Allen |
Unshelved from pending changelist '953729': Paul: Added: - getWorkspaceState() -- run a p4 status - getOpenedState() -- run p4 opened - getIgnoreState() -- run p4 add -n Modified: - add() -- seemed to call reopen? - P4FileState -- simple constructor for state Elliot: * global client and changelist object within the adapter * removed repeated client updates and changelist refreshes * removed 'reopen' in add * added calls to 'edit' where appropriate file states are found * made 'checkout' a pure sync, with no edits * commented a bunch of the @Override methods * added a call to haveList in getFileState so we can see versions of files in the project * changed the connection pane to look like p4v's * refactored a bit of the dialogue code, added calls to prompt for password (like p4v) * changed all log.trace() calls to log.debug() so the log file messiness can be controlled more easily Functionality that now works properly: * open project from source control, with properly-configured .p4config file * add new project to source control, with properly-configured .p4config file * add * edit * commit * revert * compare reversions (opens Simulink diff tool) Things to work on: * dialogues (particularily the password one, but the connection one is a bit dodge-y) * remove from project (possibly always making the Simulink project meta-data editable will fix this - it *almost* works) - the current issue is Simulink needs to edit the meta-data, but Perforce has made the files read-only, so Simulink throws up on itself Transferred from p4://perforce.perforce.com:1666@954622 |
||
#4 | 11642 | Paul Allen |
More fixes from discussion with Paul and after looking at other integrations work. Transferred from p4://perforce.perforce.com:1666@953553 |
||
#3 | 11640 | Paul Allen |
Fixes to project integrity checks within Simulink. Transferred from p4://perforce.perforce.com:1666@952945 |
||
#2 | 11635 | Paul Allen |
Updated gradle build to create a "fat jar", fixed some issues with the interfaces when it runs in Simulink itself. Added connection.configuration pane, switched the adapter to use a current changelist which gives a more svn-ish feel (which the Adapter is expecting). Added some more unit tests. General re-factoring. Transferred from p4://perforce.perforce.com:1666@946607 |
||
#1 | 11632 | Paul Allen |
Added commons-exec library, server startup/shutdown for unit tests, fixed a bunch of NPEs. Transferred from p4://perforce.perforce.com:1666@937331 |