/* Copyright 2010-2011 The MathWorks, Inc. */ package com.mathworks.cmlink.sdk.tests.util; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; public class FileCreation { private FileCreation() { //Non-instantiable. } private final static String[] EXTENSIONS = {".txt", ".mdl", ".m", ".mat"}; private static int sExtensionIndex = 0; public static File createTempFileContainingText(File rootDirectory) throws IOException { if (!rootDirectory.exists()) { createDir(rootDirectory); } //Create a file and check it is not stored: File fileTemp = File.createTempFile("myfile", getExtension()); // in tempdir String filename = rootDirectory.getAbsolutePath() + File.separator + fileTemp.getName(); File file = new File(filename); createFileContainingText(file); return file; } private static String getExtension() { sExtensionIndex++; if (sExtensionIndex >= EXTENSIONS.length) { sExtensionIndex = 0; } return EXTENSIONS[sExtensionIndex]; } public static void createFilesContainingText(Collection<File> files) throws IOException { for (File file : files) { createFileContainingText(file); } } public static void createFileContainingText(File file) throws IOException { File parentDir = file.getParentFile(); if (!parentDir.exists()) { createDir(parentDir); } if (!file.createNewFile()) { throw new IOException("Could not create file " + file); } FileWriter w = new FileWriter(file); try { w.write("Created file: " + file + "\nfor use by TAdapter."); } finally { w.close(); } } public static void modifyFiles(Collection<File> files) throws IOException { for (File file : files) { if (file.isDirectory()) { continue; } FileWriter writer = new FileWriter(file); try { writer.write("MODIFIED for test " + Math.random()); } finally { writer.close(); } } } private static void createDir(File dir) throws IOException { if (!dir.mkdirs()) { throw new IOException("Could not create directory " + dir); } } public static File changeRoot(File file, File oldRoot, File newRoot) { String relativePath = getRelativePath(oldRoot, file); return new File(newRoot, relativePath); } public static String getRelativePath(File fileRoot, File fileChild) { return getRelativePath(fileRoot.getAbsolutePath(), fileChild.getAbsolutePath()); } public static String getRelativePath(String fileRootPath, String fileChildPath) { int rootLength = fileRootPath.length(); String relativePath; if (fileChildPath.length() == rootLength) { relativePath = ""; } else { relativePath = fileChildPath.substring(rootLength + 1); } return relativePath; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 11672 | Paul Allen |
Tidy up formatting and imports. No functional change. |
||
#6 | 11658 | Paul Allen |
Additional unit/functional tests. Transferred from p4://perforce.perforce.com:1666@980860 |
||
#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 |