package com.perforce.p4simulink; /** * Perforce SCM Integration */ import com.mathworks.cmlink.api.*; import com.mathworks.cmlink.api.version.r14a.CMAdapter; import com.mathworks.cmlink.util.adapter.FileCollection; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.IChangelist; import com.perforce.p4java.core.ILabelSummary; import com.perforce.p4java.core.file.FileAction; import com.perforce.p4java.core.file.IExtendedFileSpec; import com.perforce.p4java.core.file.IFileRevisionData; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.impl.generic.core.Changelist; import com.perforce.p4java.impl.generic.core.file.FileSpec; import com.perforce.p4java.option.changelist.SubmitOptions; import com.perforce.p4java.option.client.*; import com.perforce.p4java.option.server.GetExtendedFilesOptions; import com.perforce.p4java.option.server.GetRevisionHistoryOptions; import com.perforce.p4java.option.server.MoveFileOptions; import com.perforce.p4java.option.server.TagFilesOptions; import com.perforce.p4simulink.connection.Config; import com.perforce.p4simulink.workspace.WorkspaceState; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; import java.util.*; public class P4Adapter extends P4Interactor implements CMAdapter { private static final Logger log = LogManager.getLogger(P4Adapter.class); private final Collection<AdapterSupportedFeature> supportedFeatures; public P4Adapter(ApplicationInteractor applicationInteractor, Config config) throws P4CMException { super(applicationInteractor, config); supportedFeatures = EnumSet.of( AdapterSupportedFeature.FOLDERS_NOT_STORED, AdapterSupportedFeature.ALTERNATE_UPDATE, AdapterSupportedFeature.LOCK, AdapterSupportedFeature.GET_REVISION, AdapterSupportedFeature.MOVE ); } @Override public boolean isFeatureSupported(AdapterSupportedFeature adapterSupportedFeature) { log.trace("isFeatureSupported() - {}", adapterSupportedFeature.toString()); return supportedFeatures.contains(adapterSupportedFeature); } @Override public String getRepositorySpecifier(File sandboxDirectory) throws ConfigurationManagementException { return sandboxDirectory.getAbsolutePath(); } @Override public void moveFile(File file, File file2) throws ConfigurationManagementException { log.debug("moveFile() {} {}", file.toString(), file2.toString()); IFileSpec spec = new FileSpec(file.getAbsolutePath()); IFileSpec spec2 = new FileSpec(file2.getAbsolutePath()); try { // ensure file is opened for add or edit if (spec.getAction() != FileAction.ADD && spec.getAction() != FileAction.EDIT) { List<IFileSpec> files = new ArrayList<>(); files.add(spec); getClient().editFiles(files, new EditFilesOptions()); } getServer().moveFile(spec, spec2, new MoveFileOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void add(Collection<File> files) throws ConfigurationManagementException { log.debug("add()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { getClient().addFiles(specs, new AddFilesOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void remove(Collection<File> files) throws ConfigurationManagementException { log.debug("remove()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { getClient().deleteFiles(specs, new DeleteFilesOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void checkout(Collection<File> files) throws ConfigurationManagementException { log.debug("checkout()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { getClient().editFiles(specs, new EditFilesOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void uncheckout(Collection<File> files) throws ConfigurationManagementException { log.debug("uncheckout()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { getClient().revertFiles(specs, new RevertFilesOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void checkin(Collection<File> files, String s) throws ConfigurationManagementException { log.debug("checkin() - Collection Files: {} {}", s, files.toString()); List<IFileSpec> specs = toSpec(files); try { IClient client = getClient(""); IChangelist changelist = client.createChangelist(new Changelist()); if (changelist == null) { throw new ConfigurationManagementException("Failed to create changelist."); } SubmitOptions submitOptions = new SubmitOptions(); AddFilesOptions options = new AddFilesOptions(); options.setChangelistId(changelist.getId()); client.addFiles(specs, options); changelist.setDescription(s); changelist.submit(submitOptions); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void checkin(File file, String s) throws ConfigurationManagementException { log.debug("checkin() - Single File: {} {}", s, file.toString()); checkin(toFileList(file), s); } @Override public void getLatest(Collection<File> files) throws ConfigurationManagementException { log.debug("getLatest()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { IClient client = getClient(); client.sync(specs, new SyncOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public Map<File, Boolean> isLatest(Collection<File> files) throws ConfigurationManagementException { log.debug("isLatest()"); log.debug(files); Map<File, Boolean> isLatest = new HashMap<>(); List<IFileSpec> specs = toSpec(files); try { IClient client = getClient(); Map<String, IFileSpec> haveList = toMap(client.haveList(specs)); for (IFileSpec file : specs) { String localPath = file.getLocalPathString(); IFileSpec haveFile = haveList.get(localPath); boolean latest = haveFile != null && haveFile.getWorkRev() == file.getEndRevision(); isLatest.put(new File(file.getLocalPathString()), latest); } } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } return isLatest; } @Override public void update(File file) throws ConfigurationManagementException { log.debug("update()"); log.debug(file.getAbsoluteFile()); try { IClient client = getClient(); SyncOptions options = new SyncOptions(); options.setForceUpdate(true); client.sync(toSpec(file), options); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void getRevision(Map<File, Revision> fileRevisionMap) throws ConfigurationManagementException { log.debug("getRevision()"); log.debug(fileRevisionMap); try { List<IFileSpec> files = new ArrayList<IFileSpec>(); IClient client = getClient(); for (File file : fileRevisionMap.keySet()) { String revision = fileRevisionMap.get(file).getStringRepresentation(); IFileSpec spec = new FileSpec(file.getAbsolutePath()); spec.setWorkRev(Integer.parseInt(revision)); files.add(spec); } SyncOptions options = new SyncOptions(); options.setForceUpdate(true); client.sync(files, new SyncOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public Map<File, FileState> getFileState(Collection<File> files) throws ConfigurationManagementException { log.trace("getFileState - {}", files.toString()); WorkspaceState workspaceState = new WorkspaceState(files, config); return workspaceState.getFileStateMap(); } @Override public Map<File, FileState> getStateForAllKnownFilesRecursively(File file) throws ConfigurationManagementException { log.debug("getStateForAllKnownFilesRecursively()"); log.debug(file); WorkspaceState workspaceState = new WorkspaceState(file, config); return workspaceState.getFileStateMap(); } @Override public void export(Map<File, Revision> fileRevisionMap, Map<File, File> fileFileMap) throws ConfigurationManagementException { log.debug("export() {} {}", fileRevisionMap.toString(), fileFileMap.toString()); // @todo: figure out what export is supposed to do and implement it } @Override public Revision getRevisionCausingConflict(File file) throws ConfigurationManagementException { log.debug("getRevisionCausingConflict()"); log.debug(file); // @todo: this needs to call what? return null; } @Override public void addTag(Collection<File> files, String tagName, String comment) throws ConfigurationManagementException { log.debug("addTag() {} {} {}", tagName, comment, files.toString()); try { List<IFileSpec> specs = toSpec(files); getServer().tagFiles(specs, tagName, new TagFilesOptions()); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public boolean doTagsNeedComments() { log.debug("doTagsNeedComments()"); return false; } @Override public Collection<String> getTags(File file) throws ConfigurationManagementException { log.debug("getTags()"); log.debug(file); Collection<String> tags = new ArrayList<>(); try { List<ILabelSummary> labels = getServer().getLabels(null, 1, null, toSpec(file)); for (ILabelSummary label : labels) { tags.add(label.getName()); } } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } return tags; } @Override public Collection<Revision> listRevisions(File file) throws ConfigurationManagementException { log.debug("listRevisions()"); log.debug(file); Collection<Revision> revisions = new ArrayList<>(); List<IFileSpec> spec = toSpec(file); try { Map<IFileSpec, List<IFileRevisionData>> history = getServer().getRevisionHistory(spec, new GetRevisionHistoryOptions()); if (history.size() > 0) { List<IFileRevisionData> revisionList = history.get(spec.get(0)); for (IFileRevisionData revision : revisionList) { revisions.add(new IntegerRevision(revision.getRevision())); } } } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } return revisions; } @Override public Map<File, Boolean> isStored(Collection<File> files) throws ConfigurationManagementException { log.debug("isStored()"); log.debug(files); Map<File, Boolean> stored = new HashMap<>(); for (File file : files) { stored.put(file, Boolean.FALSE); } try { List<IFileSpec> specs = toSpec(files); List<IExtendedFileSpec> extended = getServer().getExtendedFiles(specs, new GetExtendedFilesOptions()); for (IExtendedFileSpec filespec : extended) { stored.put(new File(filespec.getBaseFile()), filespec.isMapped()); } } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } return stored; } @Override public Collection<String> getForbiddenFileNames() { Collection<String> names = new HashSet<>(); names.add(".*@.*"); names.add(".*#.*"); names.add(".*\\*.*"); names.add(".*\\.\\.\\..*"); names.add(".*%.*"); names.add(".*\\/.*"); return names; } @Override public void removeTag(Collection<File> files, String tagName, String comment) throws ConfigurationManagementException { log.debug("removeTag() {} {}", tagName, comment); try { List<IFileSpec> specs = toSpec(files); TagFilesOptions options = new TagFilesOptions(); options.setDelete(true); getServer().tagFiles(specs, tagName, options); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void removeTag(String tagName, String comment, File file) throws ConfigurationManagementException { log.debug("removeTag() {} {}", tagName, comment); try { List<IFileSpec> specs = toSpec(file); TagFilesOptions options = new TagFilesOptions(); options.setDelete(true); getServer().tagFiles(specs, tagName, options); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public void addTagRecursively(File directory, String tagName, String comment) throws ConfigurationManagementException { log.debug("addTagRecursively() {} {}", tagName, comment); addTag(new FileCollection(directory), tagName, comment); } @Override public void resolveConflict(File file) throws ConfigurationManagementException { log.debug("resolveConflict()"); log.debug(file); // accept the working file try { List<IFileSpec> spec = toSpec(file); ResolveFilesAutoOptions options = new ResolveFilesAutoOptions(); options.setAcceptYours(true); getClient().resolveFilesAuto(spec, options); } catch (P4JavaException e) { throw new ConfigurationManagementException(e); } } @Override public boolean canCommitEmpty() throws ConfigurationManagementException { log.debug("canCommitEmpty()"); return false; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#35 | 16675 | Paul Allen | Use same object (File) passed in for map when getting file status. | ||
#34 | 15727 | Paul Allen | Update docs for Matlab/Simulink install. | ||
#33 | 13842 | Paul Allen |
New P4Adapter setup designed to avoid passing the URI. #review-13782 |
||
#32 | 12439 | Paul Allen | Test conflict/resolve | ||
#31 | 12419 | Paul Allen | Update tests - basic add, edit, delete and move. | ||
#30 | 12155 | Paul Allen |
Several improvments to: - isLatest - revert/resolve/submit workflow On submit files are synced to latest (forcing any resolves) If a submit fails then the active change is switched to the new pending change. On a sucessfull submit the active change is switched back to the default. Files are resolved -ay (previous modifications can be recovered by syncing back and opening for edit). |
||
#29 | 12144 | Paul Allen |
Updated export and getRevision methods. - Diff against an old revision working. |
||
#28 | 12023 | Paul Allen | Copying using p4Simulink_dev->main | ||
#27 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#26 | 11663 | Paul Allen |
Fixing issues reported by Tim Hosey at Mathworks: fixed check project button by making getFileState function use the client root instead of a list of files for large file sets. Also investigated error messaging formats and determined that they and the "could not create new file" error are both controlled by MATLAB and not P4Simulink. All calls to "p4 reconcile" will strip the "No file(s) to reconcile." message as well. Transferred from p4://perforce.perforce.com:1666@991730 |
||
#25 | 11662 | Paul Allen |
Fix NPE in changelist selector, remove reference to "Simulink project" from error messages. Transferred from p4://perforce.perforce.com:1666@988672 |
||
#24 | 11661 | Paul Allen |
Finishing up unit tests. Transferred from p4://perforce.perforce.com:1666@985194 |
||
#23 | 11659 | Paul Allen |
Performance improvements, continued: improved performance of getFileState() by replacing the client haveList call with a direct server command. Also improved isLatest by removing fstat calls and replacing with simpler calls to diff and sync. Transferred from p4://perforce.perforce.com:1666@983506 |
||
#22 | 11657 | Paul Allen |
Additional changes from Scania meeting: * Current changelist pane: added description * Started investigation into performance Transferred from p4://perforce.perforce.com:1666@980859 |
||
#21 | 11656 | Paul Allen |
Additional functionality from Scania meeting, including current changelist selector (still needs descriptions added) as well as .p4ignore editor. Transferred from p4://perforce.perforce.com:1666@978388 |
||
#20 | 11653 | Paul Allen |
Fixes for R2014b of MATLAB/Simulink, including: * No longer prompting for connection information in isDirSandboxForThisAdapter * Fixed up commit logic, so it no longer uses the current changelist * Added back logic to walk the directory tree to find a .p4config file, rather than needing one in the sandbox directory * Added new buttons for re-connecting to p4d, and editing .p4config * Investigated conflict issues - fixed some, better logic coming * Removed .p4ignore generation - wrong spot for it Transferred from p4://perforce.perforce.com:1666@976888 |
||
#19 | 11652 | Paul Allen |
Added boilerplate to code, fixed build issues (NPEs on plugin load), removed Mathworks classes from plugin jar, fixed delete vs missing issue on remove() call. Transferred from p4://perforce.perforce.com:1666@970498 |
||
#18 | 11651 | Paul Allen |
Finalizing alpha code changes - adding jar for release. Transferred from p4://perforce.perforce.com:1666@962486 |
||
#17 | 11650 | Paul Allen |
Adding README.txt, added revision number changes for files that have changed in the depot (have/head style) and added build version and type to build process as well as version string within the plugin. Transferred from p4://perforce.perforce.com:1666@959461 |
||
#16 | 11649 | Paul Allen |
Fixes to file management that Paul found during his walkthrough. Transferred from p4://perforce.perforce.com:1666@958829 |
||
#15 | 11648 | Paul Allen |
Final changes after demo with PM, including removal of depot path from the connection dialogue, and fixing of the p4 print issue. Transferred from p4://perforce.perforce.com:1666@958518 |
||
#14 | 11647 | Paul Allen |
New project creation fixes. Transferred from p4://perforce.perforce.com:1666@958305 |
||
#13 | 11645 | Paul Allen |
Refactoring and additional work on UI: Removed Connection class and went with global server/client objects. Implemented panes for connection, depot path and passwords. Passwords are only requested when required. Transferred from p4://perforce.perforce.com:1666@957149 |
||
#12 | 11644 | Paul Allen |
Paul's changes: Refactor getAddress and getAddressForConfig to getPort and getP4JavaURI. There were a few cases when the wrong value was written + getPort was not working. Password had a null password object (now initilised) P4PaswordPane needs some work - must talk to Perfoce to see if it needs a pass or is already logged in. There are still sync -f (this is very bad) Think I miss understood the checkout method after finding and reading the JavaDoc. You were right to start. Looks like a p4 edit. Would like to set a break point and find out when it is used. Elliot's changes: * Changed export() to use p4 'print' * Connect/login now looks for P4TICKETS env var * Config no longer stores P4PASSWD or P4TICKETS * Removed P4TICKET functionality (was only for P4Jenkins) * Ensured we're using a global IServer object * checkout() now uses editFiles() (opens all files for edit) * Changed all "sync -f" to plain "sync" * Removed final client update with force flag * Removed error dialogues regarding login issues * Investigated use of P4IGNORE - I'll need to write my own filter, no big deal Transferred from p4://perforce.perforce.com:1666@955247 |
||
#11 | 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 |
||
#10 | 11642 | Paul Allen |
More fixes from discussion with Paul and after looking at other integrations work. Transferred from p4://perforce.perforce.com:1666@953553 |
||
#9 | 11641 | Paul Allen |
Fixes from chat with Paul. Transferred from p4://perforce.perforce.com:1666@953389 |
||
#8 | 11640 | Paul Allen |
Fixes to project integrity checks within Simulink. Transferred from p4://perforce.perforce.com:1666@952945 |
||
#7 | 11639 | Paul Allen |
Integrate code from the P4Jenkins plugin, add ability to authenticate with tickets or ticket file. Worked through some issues with getting current file state. Transferred from p4://perforce.perforce.com:1666@952289 |
||
#6 | 11638 | Paul Allen |
General cleanup, fixed some logging issues, fixed getFileState. Transferred from p4://perforce.perforce.com:1666@950492 |
||
#5 | 11637 | Paul Allen |
Fix up isLatest, uncheckout, add back code that searched for a .p4rc file within the sandbox directory first, then looks in ~/.p4simulink/ and finally ~/. Transferred from p4://perforce.perforce.com:1666@950121 |
||
#4 | 11636 | Paul Allen |
Updates to integrate with Simulink, merging into one directory. Added auto submits to add, remove, etc since this is what Simulink expects. Transferred from p4://perforce.perforce.com:1666@947024 |
||
#3 | 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 |
||
#2 | 11634 | Paul Allen |
Debugging actual adapter functionality and starting to integrate with Simulink. Transferred from p4://perforce.perforce.com:1666@938961 |
||
#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 |