Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 80cb0cd

Browse files
committed
Added version finding capability with Contents file.
1 parent bbdc930 commit 80cb0cd

File tree

3 files changed

+157
-7
lines changed

3 files changed

+157
-7
lines changed

src/main/java/com/mathworks/ci/MatlabBuilder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class MatlabBuilder extends Builder implements SimpleBuildStep {
5353
private TestRunTypeList testRunTypeList;
5454
private String matlabRoot;
5555
private EnvVars env;
56-
private FilePath nodeSpecificMatlabRoot;
56+
private MatlabReleaseInfo matlabRel;
5757
private String nodeSpecificfileSeparator;
5858

5959
@DataBoundConstructor
@@ -478,7 +478,10 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
478478
throws InterruptedException, IOException {
479479
//Set the environment variable specific to the this build
480480
setEnv(build.getEnvironment(listener));
481-
nodeSpecificMatlabRoot = new FilePath(launcher.getChannel(),getLocalMatlab());
481+
482+
// Get node specific matlabroot to get MATLAB version information
483+
FilePath nodeSpecificMatlabRoot = new FilePath(launcher.getChannel(),getLocalMatlab());
484+
matlabRel = new MatlabReleaseInfo(nodeSpecificMatlabRoot);
482485
nodeSpecificfileSeparator = getNodeSpecificFileSeperator(launcher);
483486

484487
// Invoke MATLAB command and transfer output to standard
@@ -496,9 +499,8 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
496499
throws IOException, InterruptedException {
497500
ProcStarter matlabLauncher;
498501
try {
499-
MatlabReleaseInfo rel = new MatlabReleaseInfo(this.nodeSpecificMatlabRoot);
500502
matlabLauncher = launcher.launch().pwd(workspace).envs(this.env);
501-
if (rel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) {
503+
if (matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_BATCH_SUPPORT)) {
502504
ListenerLogDecorator outStream = new ListenerLogDecorator(listener);
503505
matlabLauncher = matlabLauncher.cmds(constructDefaultMatlabCommand(launcher.isUnix())).stderr(outStream);
504506
} else {
@@ -560,8 +562,7 @@ private String[] getPreRunnerSwitches() throws MatlabVersionNotFoundException {
560562
String[] preRunnerSwitches =
561563
{getLocalMatlab() + nodeSpecificfileSeparator + "bin" + nodeSpecificfileSeparator + "matlab", "-nosplash",
562564
"-nodesktop"};
563-
MatlabReleaseInfo rel = new MatlabReleaseInfo(this.nodeSpecificMatlabRoot);
564-
if(!rel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_NO_APP_ICON_SUPPORT)) {
565+
if(!matlabRel.verLessThan(MatlabBuilderConstants.BASE_MATLAB_VERSION_NO_APP_ICON_SUPPORT)) {
565566
preRunnerSwitches = (String[]) ArrayUtils.add(preRunnerSwitches, "-noAppIcon");
566567
}
567568
return preRunnerSwitches;

src/main/java/com/mathworks/ci/MatlabReleaseInfo.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
*/
77

88
import java.io.File;
9+
import java.io.FileInputStream;
910
import java.io.IOException;
11+
import java.io.InputStream;
12+
import java.nio.file.Files;
1013
import java.nio.file.NotDirectoryException;
14+
import java.nio.file.Paths;
1115
import java.util.HashMap;
16+
import java.util.List;
1217
import java.util.Map;
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
20+
1321
import javax.xml.parsers.DocumentBuilder;
1422
import javax.xml.parsers.DocumentBuilderFactory;
1523
import org.apache.commons.collections.MapUtils;
@@ -26,6 +34,8 @@
2634
public class MatlabReleaseInfo {
2735
private FilePath matlabRoot;
2836
private static final String VERSION_INFO_FILE = "VersionInfo.xml";
37+
private static final String CONTENTS_FILE = "Contents.m";
38+
private static final String VERSION_PATTERN = "(\\d+)\\.(\\d+)";
2939
private static final String VERSION_INFO_ROOT_TAG = "MathWorks_version_info";
3040
private static final String RELEASE_TAG = "release";
3141
private static final String VERSION_TAG = "version";
@@ -107,7 +117,18 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
107117
else if(!this.matlabRoot.exists()){
108118
throw new NotDirectoryException("Invalid matlabroot path");
109119
}else {
110-
versionInfoCache.putAll(VERSION_OLDER_THAN_17A);
120+
// Get the version information from Contents.m file
121+
String versionLine = this.matlabRoot.act(new ContentsVersion());
122+
123+
// Setting actual version to default R2016b
124+
String actualVersion = VERSION_16B;
125+
Pattern p = Pattern.compile(VERSION_PATTERN);
126+
Matcher m = p.matcher(versionLine);
127+
if(m.find()) {
128+
actualVersion = m.group();
129+
}
130+
// Update the versionInfoCache with actual version extracted from Contents.m file
131+
versionInfoCache.put(VERSION_TAG, actualVersion);
111132
}
112133

113134
} catch (Exception e) {
@@ -118,3 +139,22 @@ else if(!this.matlabRoot.exists()){
118139
return versionInfoCache;
119140
}
120141
}
142+
143+
//Below piece of code will be executed on the specific node in case of job is running on remote agent.
144+
final class ContentsVersion implements FileCallable<String> {
145+
private static final long serialVersionUID = 1;
146+
147+
// File path of Contents.m on specific node
148+
private static String CONTENTS_FILE = "toolbox" + File.separator + "matlab" + File.separator + "general" + File.separator + "Contents.m";
149+
@Override
150+
public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
151+
List<String> line = Files.readAllLines(Paths.get(f.getPath() + File.separator + CONTENTS_FILE));
152+
// Get second line from Contents.m file
153+
return line.get(1);
154+
}
155+
@Override
156+
public void checkRoles(RoleChecker checker) throws SecurityException {
157+
// No Roles to check
158+
159+
}
160+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
% General purpose commands.
2+
% MATLAB Version 9.1 (R2016b) 25-Aug-2016
3+
%
4+
% General information.
5+
% syntax - Help on MATLAB command syntax.
6+
% demo - Run demonstrations.
7+
% ver - MATLAB, Simulink and toolbox version information.
8+
% version - MATLAB version information.
9+
% verLessThan - Compare version of toolbox to specified version string.
10+
% logo - Plot the L-shaped membrane logo with MATLAB lighting.
11+
% membrane - Generates the MATLAB logo.
12+
% bench - MATLAB Benchmark.
13+
%
14+
% Managing the workspace.
15+
% who - List current variables.
16+
% whos - List current variables, long form.
17+
% clear - Clear variables and functions from memory.
18+
% onCleanup - Specify cleanup work to be done on function completion.
19+
% pack - Consolidate workspace memory.
20+
% load - Load workspace variables from disk.
21+
% save - Save workspace variables to disk.
22+
% saveas - Save Figure or model to desired output format.
23+
% memory - Help for memory limitations.
24+
% recycle - Set option to move deleted files to recycle folder.
25+
% quit - Quit MATLAB session.
26+
% exit - Exit from MATLAB.
27+
%
28+
% Managing commands and functions.
29+
% what - List MATLAB-specific files in directory.
30+
% type - Display MATLAB program file.
31+
% open - Open files by extension.
32+
% which - Locate functions and files.
33+
% pcode - Create pre-parsed pseudo-code file (P-file).
34+
% mex - Compile MEX-function.
35+
% inmem - List functions in memory.
36+
% namelengthmax - Maximum length of MATLAB function or variable name.
37+
%
38+
% Managing the search path.
39+
% path - Get/set search path.
40+
% addpath - Add directory to search path.
41+
% rmpath - Remove directory from search path.
42+
% rehash - Refresh function and file system caches.
43+
% import - Import packages into the current scope.
44+
% finfo - Identify file type against standard file handlers on path.
45+
% genpath - Generate recursive toolbox path.
46+
% savepath - Save the current MATLAB path in the pathdef.m file.
47+
%
48+
% Managing the java search path.
49+
% javaaddpath - Add directories to the dynamic java path.
50+
% javaclasspath - Get and set java path.
51+
% javarmpath - Remove directory from dynamic java path.
52+
%
53+
% Controlling the command window.
54+
% echo - Display statements during function execution.
55+
% more - Control paged output in command window.
56+
% diary - Save text of MATLAB session.
57+
% format - Set output format.
58+
% beep - Produce beep sound.
59+
% desktop - Start and query the MATLAB Desktop.
60+
% preferences - Bring up MATLAB user settable preferences dialog.
61+
%
62+
% Operating system commands.
63+
% cd - Change current working directory.
64+
% copyfile - Copy file or directory.
65+
% movefile - Move file or directory.
66+
% delete - Delete file or graphics object.
67+
% pwd - Show (print) current working directory.
68+
% dir - List directory.
69+
% ls - List directory.
70+
% fileattrib - Set or get attributes of files and directories.
71+
% isdir - True if argument is a directory.
72+
% mkdir - Make new directory.
73+
% rmdir - Remove directory.
74+
% getenv - Get environment variable.
75+
% ! - Execute operating system command (see PUNCT).
76+
% dos - Execute DOS command and return result.
77+
% unix - Execute UNIX command and return result.
78+
% system - Execute system command and return result.
79+
% perl - Execute Perl command and return the result.
80+
% computer - Computer type.
81+
% isunix - True for the UNIX version of MATLAB.
82+
% ispc - True for the PC (Windows) version of MATLAB.
83+
%
84+
% Debugging.
85+
% debug - List debugging commands.
86+
%
87+
% Tools to locate dependent functions of a program file.
88+
% depfun - Locate dependent functions of program file.
89+
% depdir - Locate dependent directories of program file.
90+
%
91+
% Loading and calling shared libraries.
92+
% calllib - Call a function in an external library.
93+
% libpointer - Creates a pointer object for use with external libraries.
94+
% libstruct - Creates a structure pointer for use with external libraries.
95+
% libisloaded - True if the specified shared library is loaded.
96+
% loadlibrary - Load a shared library into MATLAB.
97+
% libfunctions - Return information on functions in an external library.
98+
% libfunctionsview - View the functions in an external library.
99+
% unloadlibrary - Unload a shared library loaded with LOADLIBRARY.
100+
% java - Using Java from within MATLAB.
101+
% usejava - True if the specified Java feature is supported in MATLAB.
102+
%
103+
% See also LANG, DATATYPES, IOFUN, GRAPHICS, OPS, STRFUN, TIMEFUN,
104+
% MATFUN, DEMOS, GRAPHICS, DATAFUN, UITOOLS, DOC, PUNCT, ARITH.
105+
106+
% Controlling multithreading setting.
107+
% maxNumCompThreads - Controls the maximum number of computational threads.
108+
109+
% Copyright 1984-2016 The MathWorks, Inc.

0 commit comments

Comments
 (0)