package com.perforce.p4simulink.connection; /** * Perforce SCM Integration */ import com.perforce.p4simulink.P4CMException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.HashSet; import java.util.Properties; public class Config { private static final Logger log = LogManager.getLogger(Config.class.getName()); private static final String[] P4VARS = {"P4PORT", "P4CLIENT", "P4USER"}; private static final String P4CONFIG = System.getenv("P4CONFIG") != null ? System.getenv("P4CONFIG") : ".p4rc"; private static final String P4SIMULINK = ".p4simulink"; private Path path = null; private Properties properties = new Properties(); /** * Check if a config file named P4CONFIG or P4SIMULINK exists in the specified path. * * @param path Local file path to check for a Perforce config file. * @return true if a config file was found in the named path, otherwise false. */ public boolean exists(Path path) { Path configPath = null; Path simulinkPath = path.resolve(P4SIMULINK); if (P4CONFIG != null) { configPath = path.resolve(P4CONFIG); } if (configPath != null && Files.exists(configPath)) { this.path = configPath; log.trace("Found config file {}", configPath.toString()); return true; } else if (Files.exists(simulinkPath)) { this.path = simulinkPath; log.trace("Found config file {}", simulinkPath); return true; } else { return false; } } /** * Load the config file into memory, making sure that at least P4PORT, P4USER and P4CLIENT are set. * * @throws com.perforce.p4simulink.P4CMException */ public void load() throws P4CMException { try (FileInputStream in = new FileInputStream(path.toFile())) { load(in); } catch (IOException e) { throw new P4CMException("Error loading config file " + path.toString(), e); } } public void load(String string) throws P4CMException { load(new ByteArrayInputStream(string.getBytes())); } public void load(InputStream is) throws P4CMException { properties = new Properties(); try { properties.load(is); if (properties == null) { throw new P4CMException("Invalid config file."); } for (String var : P4VARS) { if (properties.getProperty(var) == null) { throw new P4CMException("Missing required key " + var); } } log.trace("Perforce configuration loaded: {}", properties.toString()); } catch (IOException e) { throw new P4CMException("Error loading config file " + path.toString(), e); } } /** * Return a collection of the config names that P4Config could be working with. * * @return List of config file names. */ public Collection<String> getConfigNames() { Collection<String> configNames = new HashSet<>(); configNames.add(P4SIMULINK); if (P4CONFIG != null) { configNames.add(P4CONFIG); } log.trace("Config File Names: {}", configNames.toString()); return configNames; } /** * Extracts P4PORT from the loaded config and returns a P4Java suitable URI. * * @return P4PORT converted to a P4Java URI * @throws P4CMException */ public String getAddress() throws P4CMException { String port = properties.getProperty("P4PORT"); String[] parts = port.split(":", 2); if (parts.length != 2) { throw new P4CMException("Invalid P4PORT: " + port); } StringBuilder address = new StringBuilder(); if (parts[0].startsWith("ssl")) { address.append("p4javassl://"); address.append(parts[1]); } else { address.append("p4java://"); address.append(port); } log.trace("Perforce Server: {}", address.toString()); return address.toString(); } public String getPort() throws P4CMException { String address = getAddress(); if (address.lastIndexOf(":") > 0) { return address.substring(address.lastIndexOf(":")); } return ""; } public String getClient() { return properties.getProperty("P4CLIENT"); } public String getUser() { return properties.getProperty("P4USER"); } public void setAddress(String address) { properties.setProperty("P4PORT", address); } public void setClient(String client) { properties.setProperty("P4CLIENT", client); } public void setUser(String user) { properties.setProperty("P4USER", user); } @Override public String toString() { String port = properties.getProperty("P4PORT"); String user = properties.getProperty("P4USER"); String client = properties.getProperty("P4CLIENT"); return "CLIENT: '" + client + "' USER: '" + user + "' PORT: '" + port + "'"; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#20 | 12023 | Paul Allen | Copying using p4Simulink_dev->main | ||
#19 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#18 | 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 |
||
#17 | 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 |
||
#16 | 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 |
||
#15 | 11647 | Paul Allen |
New project creation fixes. Transferred from p4://perforce.perforce.com:1666@958305 |
||
#14 | 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 |
||
#13 | 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 |
||
#12 | 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 |
||
#11 | 11642 | Paul Allen |
More fixes from discussion with Paul and after looking at other integrations work. Transferred from p4://perforce.perforce.com:1666@953553 |
||
#10 | 11641 | Paul Allen |
Fixes from chat with Paul. Transferred from p4://perforce.perforce.com:1666@953389 |
||
#9 | 11640 | Paul Allen |
Fixes to project integrity checks within Simulink. Transferred from p4://perforce.perforce.com:1666@952945 |
||
#8 | 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 |
||
#7 | 11638 | Paul Allen |
General cleanup, fixed some logging issues, fixed getFileState. Transferred from p4://perforce.perforce.com:1666@950492 |
||
#6 | 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 |
||
#5 | 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 |
||
#4 | 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 |
||
#3 | 11634 | Paul Allen |
Debugging actual adapter functionality and starting to integrate with Simulink. Transferred from p4://perforce.perforce.com:1666@938961 |
||
#2 | 11633 | Paul Allen |
Various fixes including workaround for no “admin” commands in p4java. Transferred from p4://perforce.perforce.com:1666@938159 |
||
#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 |