package com.perforce.p4simulink; /** * Copyright (C) 2014 Perforce Software. All rights reserved. * * Please see LICENSE.txt in top-level folder of this distribution. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import javax.swing.ImageIcon; import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.mathworks.cmlink.api.AdapterSupportedFeature; import com.mathworks.cmlink.api.ApplicationInteractor; import com.mathworks.cmlink.api.ConfigurationManagementException; import com.mathworks.cmlink.api.FileState; import com.mathworks.cmlink.api.IntegerRevision; import com.mathworks.cmlink.api.LocalStatus; import com.mathworks.cmlink.api.Revision; import com.mathworks.cmlink.api.customization.CoreAction; import com.mathworks.cmlink.api.customization.CustomizationWidgetFactory; import com.mathworks.cmlink.api.version.r14a.CMAdapter; 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.FileSpecBuilder; import com.perforce.p4java.core.file.FileSpecOpStatus; 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.AddFilesOptions; import com.perforce.p4java.option.client.DeleteFilesOptions; import com.perforce.p4java.option.client.EditFilesOptions; import com.perforce.p4java.option.client.ReconcileFilesOptions; import com.perforce.p4java.option.client.ReopenFilesOptions; import com.perforce.p4java.option.client.ResolveFilesAutoOptions; import com.perforce.p4java.option.client.RevertFilesOptions; import com.perforce.p4java.option.client.SyncOptions; import com.perforce.p4java.option.server.GetExtendedFilesOptions; import com.perforce.p4java.option.server.GetFileContentsOptions; 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.P4Config; import com.perforce.p4simulink.connection.P4FileState; import com.perforce.p4simulink.connection.P4Uri; import com.perforce.p4simulink.connection.P4UriType; import com.perforce.p4simulink.util.Files; import com.perforce.p4simulink.util.Logging; public class P4Adapter extends P4Interactor implements CMAdapter { private static final Logger log = LogManager.getLogger(P4Adapter.class); private final Collection<AdapterSupportedFeature> supportedFeatures; // private IChangelist currentChangelist; /** * Class constructor. * * @param applicationInteractor * @throws P4CMException */ public P4Adapter(ApplicationInteractor applicationInteractor, P4Uri uri) throws P4CMException { super(applicationInteractor, uri); log.debug("Construct P4Adapter() - {}", uri.getUri(P4UriType.P4)); supportedFeatures = EnumSet.of( AdapterSupportedFeature.FOLDERS_NOT_STORED, AdapterSupportedFeature.ALTERNATE_UPDATE, AdapterSupportedFeature.LOCK, AdapterSupportedFeature.GET_REVISION, AdapterSupportedFeature.IS_LATEST, AdapterSupportedFeature.MOVE, AdapterSupportedFeature.LATEST_REVISION, AdapterSupportedFeature.RESOLVE, AdapterSupportedFeature.GET_CONFLICT_REVISION, AdapterSupportedFeature.TAG); } @Override public boolean isFeatureSupported( AdapterSupportedFeature adapterSupportedFeature) { return supportedFeatures.contains(adapterSupportedFeature); } @Override public String getRepositorySpecifier(File sandboxDirectory) throws ConfigurationManagementException { log.debug("getRepositorySpecifier - {}", sandboxDirectory.getAbsolutePath()); P4Config config = new P4Config(sandboxDirectory.toPath()); String uriString = config.toUri(); return uriString; } @Override public Map<File, FileState> getFileState(Collection<File> files) throws ConfigurationManagementException { log.debug("getFileState() - {}", files); Map<File, FileState> map = new HashMap<File, FileState>(); for (File file : files) { // Skip directories if (file.isDirectory()) { continue; } try { // get FileSpec for file IFileSpec fileSpec = new FileSpec(file.getCanonicalPath()); List<IFileSpec> fileSpecs = Arrays.asList(fileSpec); // check for modified files isModified(fileSpecs); // get FileState for FileSpec for (P4FileState state : fstat(fileSpecs)) { if (state.getFile() == null) { state.setFile(file); } map.put(state.getFile(), state); log.debug("... {}", state); } } catch (IOException e) { throw new P4CMException("IOException" + e); } } return map; } @Override public Map<File, FileState> getStateForAllKnownFilesRecursively(File file) throws ConfigurationManagementException { log.debug("getStateForAllKnownFilesRecursively() - {}", file); Map<File, FileState> map = new HashMap<File, FileState>(); try { // get FileSpec for recursive path String path = file.getCanonicalPath() + File.separator + "..."; List<IFileSpec> pathSpec = FileSpecBuilder.makeFileSpecList(path); // get FileState for FileSpec for (P4FileState state : fstat(pathSpec)) { map.put(state.getFile(), state); log.debug("... {}", state); } } catch (IOException e) { throw new P4CMException("IOException" + e); } return map; } /** * Run a 'p4 fstat' on an individual file returning a file state object. * * @param file * @return P4FileState * @throws P4CMException */ private List<P4FileState> fstat(List<IFileSpec> fileSpecs) throws P4CMException { List<P4FileState> list = new ArrayList<P4FileState>(); try { // run 'p4 fstat' on FileSpec GetExtendedFilesOptions fstatOpts = new GetExtendedFilesOptions(); List<IExtendedFileSpec> stats = server.getExtendedFiles(fileSpecs, fstatOpts); // generate FileState and add to list for (IExtendedFileSpec exSpec : stats) { FileSpecOpStatus status = exSpec.getOpStatus(); if (status != FileSpecOpStatus.VALID) { exSpec = null; } P4FileState fstat = new P4FileState(exSpec); list.add(fstat); } } catch (P4JavaException e) { throw new P4CMException("fstat", e); } return list; } private boolean isModified(List<IFileSpec> fileSpecs) throws ConfigurationManagementException { try { ReconcileFilesOptions statusOpts = new ReconcileFilesOptions(); statusOpts.setOutsideEdit(true); statusOpts.setLocalSyntax(true); List<IFileSpec> status = client.reconcileFiles(fileSpecs, statusOpts); Files.validateFileSpecs(status, "no file(s) to reconcile"); for (IFileSpec s : status) { String path = s.getLocalPathString(); if (path != null) { return true; } } } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } return false; } /** * [p4 sync file#head] * * @param files * files for which we want the latest version * @throws ConfigurationManagementException */ @Override public void getLatest(Collection<File> files) throws ConfigurationManagementException { log.debug("getLatest() - {}", files); List<IFileSpec> specs = toSpec(files); try { // basic sync SyncOptions syncOpts = new SyncOptions(); List<IFileSpec> synced = client.sync(specs, syncOpts); // ignore cases where we've already got the latest, and/or there are // no files to check out Files.validateFileSpecs(synced, "file(s) up-to-date.", " - no such file(s).", "- file(s) not on client."); } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * Determines whether the user's workspace contains the latest version of * files from the depot. * * @param files * list of files to check * @return Mapping of file to boolean where true means the workspace has the * latest version, false if not * @throws ConfigurationManagementException */ @Override public Map<File, Boolean> isLatest(Collection<File> files) throws ConfigurationManagementException { log.debug("isLatest() - {}", files); // TODO: determine if this is truly necessary - with large numbers of // files, I was getting exceptions if (files.size() > 20) { files = Collections.singletonList(new File(client.getRoot())); } Map<File, Boolean> isLatest = new HashMap<>(); // no work if no files were asked for if (files.size() == 0) { return isLatest; } // get local file state, marking any modified/missing or out of date // files as not latest Map<File, FileState> states = getFileState(files); for (File file : states.keySet()) { FileState state = states.get(file); isLatest.put(file, !state.getRevision().getStringRepresentation() .contains("/") && state.getLocalStatus() == LocalStatus.UNMODIFIED); } return isLatest; } /** * [p4 sync file#rev] * * @param fileRevisionMap * List of files and revisions to sync. * @throws ConfigurationManagementException */ @Override public void getRevision(Map<File, Revision> fileRevisionMap) throws ConfigurationManagementException { log.debug("getRevision() - {}", fileRevisionMap); try { for (Map.Entry<File, Revision> entry : fileRevisionMap.entrySet()) { File file = entry.getKey(); Revision rev = entry.getValue(); String path = file.getAbsolutePath() + "#" + rev.toString(); List<IFileSpec> pathSpec = FileSpecBuilder .makeFileSpecList(path); SyncOptions options = new SyncOptions(); List<IFileSpec> synced = client.sync(pathSpec, options); Files.validateFileSpecs(synced, "file(s) up-to-date."); } } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * [p4 sync ...#head] * * @param file * Sync all files under the specified path. * @throws ConfigurationManagementException */ @Override public void update(File file) throws ConfigurationManagementException { log.debug("update() - {}", file); try { String path = file.getCanonicalPath() + File.separator + "..."; List<IFileSpec> pathSpec = FileSpecBuilder.makeFileSpecList(path); SyncOptions options = new SyncOptions(); List<IFileSpec> synced = client.sync(pathSpec, options); Files.validateFileSpecs(synced, "file(s) up-to-date."); } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * [p4 add] * * @param files * list of files to add to the depot * @throws ConfigurationManagementException */ @Override public void add(Collection<File> files) throws ConfigurationManagementException { log.debug("add() - {}", files); List<IFileSpec> specs = toSpec(files); try { if (!specs.isEmpty()) { AddFilesOptions opts = new AddFilesOptions(); opts.setChangelistId(getChangeID()); List<IFileSpec> added = client.addFiles(specs, opts); Files.validateFileSpecs(added, "empty, assuming text", "can't add existing file"); } } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * [p4 sync -f] and [p4 edit] * * @param files * Files to check out of source control (sync and open for edit). * @throws ConfigurationManagementException */ @Override public void checkout(Collection<File> files) throws ConfigurationManagementException { log.debug("checkout()"); log.debug(files); try { // sync the latest files down getLatest(files); // mark everything for edit edit(files); } catch (ConfigurationManagementException e) { Logging.logException(log, e, true); } } /** * Convenience method that opens files in Perforce for edit. * * @param files * Files to edit * @throws ConfigurationManagementException */ private void edit(Collection<File> files) throws ConfigurationManagementException { log.debug("edit() - {}", files); List<IFileSpec> specs = toSpec(files); try { if (!specs.isEmpty()) { EditFilesOptions editOpts = new EditFilesOptions(); editOpts.setChangelistId(getChangeID()); List<IFileSpec> edited = client.editFiles(specs, editOpts); Files.validateFileSpecs(edited, "empty, assuming text", " - currently opened for edit", " - file(s) not on client."); // move files open in another changelist // TODO don't think this is needed, change swap should update // status and then this should be tested for all operations! ReopenFilesOptions openOpts = new ReopenFilesOptions(); openOpts.setChangelistId(getChangeID()); client.reopenFiles(specs, openOpts); } } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * [p4 revert] * * @param files * List of files to revert. * @throws ConfigurationManagementException */ @Override public void uncheckout(Collection<File> files) throws ConfigurationManagementException { log.debug("uncheckout()"); log.debug(files); List<IFileSpec> specs = toSpec(files); try { ReopenFilesOptions openOpts = new ReopenFilesOptions(); openOpts.setChangelistId(getChangeID()); List<IFileSpec> open = client.reopenFiles(specs, openOpts); Files.validateFileSpecs(open, "file(s) not opened on this client"); RevertFilesOptions options = new RevertFilesOptions(); options.setChangelistId(getChangeID()); List<IFileSpec> reverted = client.revertFiles(specs, options); Files.validateFileSpecs(reverted, "file(s) not opened on this client"); } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * uncheckout() then [p4 delete -k] * * @param files * List of files to remove from source control. * @throws ConfigurationManagementException */ @Override public void remove(Collection<File> files) throws ConfigurationManagementException { log.debug("remove() - {}", files); List<IFileSpec> specs = toSpec(files); try { // reopen and revert file uncheckout(files); // delete, but leave content? DeleteFilesOptions delOpts = new DeleteFilesOptions(); delOpts.setChangelistId(getChangeID()); delOpts.setBypassClientDelete(true); List<IFileSpec> deleted = client.deleteFiles(specs, delOpts); Files.validateFileSpecs(deleted, "files(s) not on client", "clobber writable"); } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); } } /** * Moves file to file2 within the depot. This is used in renaming operations * within Simulink. * * @param src * Source file * @param dst * Destination file * @throws ConfigurationManagementException */ @Override public void moveFile(File src, File dst) throws ConfigurationManagementException { log.debug("moveFile() {} {}", src, dst); IFileSpec srcSpec = new FileSpec(src.getAbsolutePath()); IFileSpec dstSpec = new FileSpec(dst.getAbsolutePath()); try { // ensure file is opened for add or edit // TODO check if open and revert or error FileAction srcAct = srcSpec.getAction(); if (srcAct != FileAction.ADD && srcAct != FileAction.EDIT) { List<IFileSpec> files = Arrays.asList(srcSpec); EditFilesOptions editOpts = new EditFilesOptions(); editOpts.setChangelistId(getChangeID()); List<IFileSpec> edited = client.editFiles(files, editOpts); Files.validateFileSpecs(edited); } MoveFileOptions moveOpts = new MoveFileOptions(); moveOpts.setChangelistId(getChangeID()); List<IFileSpec> moved = server.moveFile(srcSpec, dstSpec, moveOpts); Files.validateFileSpecs(moved); } catch (Exception e) { if (e instanceof P4JavaException) { Logging.logException(log, new P4JavaException(e), true); } } } /** * According to the SVN example, this function simply resolves conflicts by * accepting the working file. Since this seems to be what Simulink expects, * this is what I implemented. * * @param file * File on which we are resolving the conflict. * @throws ConfigurationManagementException */ @Override public void resolveConflict(File file) throws ConfigurationManagementException { log.debug("resolveConflict() - {}", file); List<IFileSpec> spec = toSpec(file); // accept the working file try { ResolveFilesAutoOptions resolveOpts = new ResolveFilesAutoOptions(); resolveOpts.setForceResolve(true); resolveOpts.setAcceptYours(true); resolveOpts.setChangelistId(getChangeID()); List<IFileSpec> files = client.resolveFilesAuto(spec, resolveOpts); Files.validateFileSpecs(files); } catch (P4JavaException e) { Logging.logException(log, e, true); } catch (Exception e) { if (e instanceof P4JavaException) { Logging.logException(log, new P4JavaException(e), true); } } } /** * [p4 submit] * * @param files * Files to submit to Perforce * @param description * Description for this commit. * @throws com.mathworks.cmlink.api.ConfigurationManagementException */ @Override public void checkin(Collection<File> files, String description) throws ConfigurationManagementException { log.debug("checkin() {} {}", description, files); List<IFileSpec> specs = toSpec(files); try { IChangelist change = null; if (getChangeID() > 0) { // use existing pending change change = server.getChangelist(getChangeID()); change.setDescription(description); } else { // create new change for default change = new Changelist(); change.setDescription(description); change = client.createChangelist(change); // move files from default change ReopenFilesOptions reopenOpts = new ReopenFilesOptions(); reopenOpts.setChangelistId(change.getId()); client.reopenFiles(specs, reopenOpts); } // submit change SubmitOptions submitOpts = new SubmitOptions(); List<IFileSpec> submit = change.submit(submitOpts); Files.validateFileSpecs(submit); } catch (P4JavaException e) { Logging.logException(log, e, true); e.printStackTrace(); } catch (Exception e) { Logging.logException(log, new ConfigurationManagementException(e), true); e.printStackTrace(); } } /** * Check in a single file with the given description. * * @param file * File to submit to Perforce. * @param description * Description for this commit. * @throws ConfigurationManagementException */ @Override public void checkin(File file, String description) throws ConfigurationManagementException { log.debug("checkin() - Single File: {} {}", description, file.toString()); try { checkin(Collections.singletonList(file), description); } catch (ConfigurationManagementException e) { Logging.logException(log, e, true); } } @Override public boolean canCommitEmpty() throws ConfigurationManagementException { return true; } /** * Forbidden filenames * * http://www.perforce.com/perforce/r14.1/manuals/cmdref/filespecs.html * * @return List of strings representing illegal filename formats. */ @Override public Collection<String> getForbiddenFileNames() { Collection<String> names = new HashSet<>(); // Perforce-specific forbidden patterns names.add(".*@.*"); names.add(".*#.*"); names.add(".*\\*.*"); names.add(".*\\.\\.\\..*"); names.add(".*%.*"); names.add(".*\\/.*"); return names; } // ################################################################################ // TODO all functions below unchecked // ################################################################################ /** * Get a copy of the specified files at the specified revisions from the * repository and name them with the specified destination file name. The * adapter can assume that revisions and destinations are not null and are * the same size as files. */ @Override public void export(Map<File, Revision> fileRevisionMap, Map<File, File> fileFileMap) throws ConfigurationManagementException { log.debug("export() {} {}", fileRevisionMap.toString(), fileFileMap.toString()); } public void XXXexport(Map<File, Revision> fileRevisionMap, Map<File, File> fileFileMap) throws ConfigurationManagementException { try { for (File file : fileRevisionMap.keySet()) { Revision revision = fileRevisionMap.get(file); File newFile = fileFileMap.get(file); // use p4 'print' to get the specified revision GetFileContentsOptions options = new GetFileContentsOptions(); options.setNoHeaderLine(true); List<IFileSpec> specs = toSpec(file); for (IFileSpec spec : specs) { Integer revisionNumber = Integer.parseInt(revision .getStringRepresentation()); spec.setEndRevision(revisionNumber); spec.setStartToRev(revisionNumber); spec.setWorkRev(revisionNumber); spec.setStartFromRev(revisionNumber); spec.setEndFromRev(revisionNumber); spec.setStartToRev(revisionNumber); spec.setEndToRev(revisionNumber); spec.setStartRevision(revisionNumber); spec.setBaseRev(revisionNumber); } // stream the contents to the new file location InputStream stream = server.getFileContents(specs, options); FileOutputStream fos = new FileOutputStream(newFile); IOUtils.copy(stream, fos); stream.close(); fos.close(); } } catch (IOException e) { Logging.logException(log, new ConfigurationManagementException(e), true); } catch (P4JavaException e) { Logging.logException(log, e, true); } } @Override public Revision getRevisionCausingConflict(File file) throws ConfigurationManagementException { log.debug("getRevisionCausingConflict()"); log.debug(file); try { FileState fileState = getFileState(Collections.singletonList(file)) .get(file); return fileState.getRevision(); } catch (ConfigurationManagementException e) { Logging.logException(log, e, true); } return null; } @Override public void addTagRecursively(File directory, String tagName, String comment) throws ConfigurationManagementException { log.debug("addTagRecursively() {} {}", tagName, comment); try { addTag(Collections.singletonList(directory), tagName, comment); } catch (ConfigurationManagementException e) { Logging.logException(log, e, true); } } @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); if (server != null && !specs.isEmpty()) { server.tagFiles(specs, tagName, new TagFilesOptions()); ArrayList<File> f = new ArrayList<>(); f.addAll(files); log.debug("TAGS: " + getTags(f.get(0))); } } catch (P4JavaException e) { Logging.logException(log, e, true); } } @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 = server.getLabels(null, 1, null, toSpec(file)); for (ILabelSummary label : labels) { tags.add(label.getName()); } } catch (P4JavaException e) { Logging.logException(log, e, true); } return tags; } @Override public Collection<Revision> listRevisions(File file) throws ConfigurationManagementException { log.debug("listRevisions()"); log.debug(file); Collection<Revision> revisions = new ArrayList<>(); try { List<IFileSpec> spec = toSpec(file); if (server == null) { return revisions; } Map<IFileSpec, List<IFileRevisionData>> history = server .getRevisionHistory(spec, new GetRevisionHistoryOptions()); if (history.size() > 0) { IFileSpec ourSpec = history.keySet().iterator().next(); List<IFileRevisionData> revisionList = history .containsKey(ourSpec) ? history.get(ourSpec) : new ArrayList<IFileRevisionData>(); for (IFileRevisionData revision : revisionList) { DateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Map<String, String> revisionInfo = new HashMap<>(); revisionInfo.put("User", revision.getUserName()); revisionInfo.put("Description", revision.getDescription()); revisionInfo.put("Date", format.format(revision.getDate())); Revision r = new IntegerRevision(revision.getRevision(), revisionInfo); revisions.add(r); } } } catch (P4JavaException e) { Logging.logException(log, e, true); } 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<>(); try { List<IFileSpec> specs = toSpec(files); List<IExtendedFileSpec> extended = server.getExtendedFiles(specs, new GetExtendedFilesOptions()); for (IExtendedFileSpec spec : extended) { if (spec.getClientPathString() == null) { continue; } stored.put(new File(spec.getClientPathString()), spec.isMapped()); } } catch (P4JavaException e) { Logging.logException(log, e, true); } return stored; } @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); server.tagFiles(specs, tagName, options); } catch (P4JavaException e) { Logging.logException(log, e, true); } } @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); server.tagFiles(specs, tagName, options); } catch (P4JavaException e) { Logging.logException(log, e, true); } } @Override public void buildCustomActions(CustomizationWidgetFactory widgetFactory) { log.debug("buildCustomActions()"); // include buttons defined in the interactor super.buildCustomActions(widgetFactory); // Create widget to edit the active Client Workspace URL syncUrl = getClass().getResource("/icons/sync_toolbar_icon.png"); ImageIcon syncIcon = new ImageIcon(syncUrl); widgetFactory.createActionWidget("Get Revisions", syncIcon, new CoreAction() { @Override public void execute() throws ConfigurationManagementException { populateClient(client, parentFrame); } @Override public String getDescription() { return "Get Revisions"; } @Override public boolean canCancel() { return true; } }); // Create widget to edit the active Client Workspace URL clientUrl = getClass().getResource("/icons/clients_icon.png"); ImageIcon clientIcon = new ImageIcon(clientUrl); widgetFactory.createActionWidget("Workspace", clientIcon, new CoreAction() { @Override public void execute() throws ConfigurationManagementException { client = updateClient(client, parentFrame); } @Override public String getDescription() { return "Edit Workspace"; } @Override public boolean canCancel() { return true; } }); // Create widget to select the active Pending Changelist URL pendingUrl = getClass().getResource("/icons/pending_icon.png"); ImageIcon pendingIcon = new ImageIcon(pendingUrl); widgetFactory.createActionWidget("Pending", pendingIcon, new CoreAction() { @Override public void execute() throws ConfigurationManagementException { int c = selectPendingChange(getChangeID(), parentFrame); setChangeID(c); } @Override public String getDescription() { return "Current Changelist"; } @Override public boolean canCancel() { return true; } }); // line separation after Perforce widgets widgetFactory.createLineBreak(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 11966 | Paul Allen | Clean up isModified method. | ||
#6 | 11944 | Paul Allen | Added [Get Revisions] button to sync files | ||
#5 | 11930 | Paul Allen |
Fix remove file operation. MatLab opened a project file for edit, then tries to delete it. Added a reopen and revert in uncheckout() method to help clean up before a delete. |
||
#4 | 11927 | Paul Allen |
Detect local edits (isModified) and add to pending change. Fix revert (uncheckout) if file is open in another change. |
||
#3 | 11925 | Paul Allen | Select pending changelist from table. | ||
#2 | 11899 | Paul Allen | Inprogress development - moved work to branch | ||
#1 | 11898 | Paul Allen |
Populate -o //guest/perforce_software/p4sl/main/... //guest/paul_allen/p4sl/.... |
||
//guest/perforce_software/p4sl/main/src/main/java/com/perforce/p4simulink/P4Adapter.java | |||||
#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 |