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

Commit c88eb0d

Browse files
authored
Merge pull request #64 from mathworks/CI-448-version-details
Version search capability from Contents file for version older than 17b
2 parents 324f71a + 11fa19b commit c88eb0d

File tree

2 files changed

+142
-16
lines changed

2 files changed

+142
-16
lines changed

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

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
package com.mathworks.ci;
22

3+
import java.io.BufferedReader;
4+
35
/*
46
* Copyright 2019 The MathWorks, Inc. This Class provides MATLAB release information in the form of
57
* Version numbers. Class constructor requires MATLAB root as input parameter
68
*/
79

8-
import java.io.File;
9-
import java.io.IOException;
10+
import java.io.InputStream;
11+
import java.io.InputStreamReader;
12+
import java.nio.charset.StandardCharsets;
1013
import java.nio.file.NotDirectoryException;
1114
import java.util.HashMap;
1215
import java.util.Map;
16+
import java.util.regex.Matcher;
17+
import java.util.regex.Pattern;
18+
1319
import javax.xml.parsers.DocumentBuilder;
1420
import javax.xml.parsers.DocumentBuilderFactory;
1521
import org.apache.commons.collections.MapUtils;
16-
import org.jenkinsci.remoting.RoleChecker;
1722
import org.w3c.dom.Document;
1823
import org.w3c.dom.Element;
1924
import org.w3c.dom.Node;
2025
import org.w3c.dom.NodeList;
2126
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2227
import hudson.FilePath;
23-
import hudson.FilePath.FileCallable;
24-
import hudson.remoting.VirtualChannel;
2528

2629
public class MatlabReleaseInfo {
2730
private FilePath matlabRoot;
2831
private static final String VERSION_INFO_FILE = "VersionInfo.xml";
32+
private static final String CONTENTS_FILE = "toolbox/matlab/general/Contents.m";
33+
private static final String VERSION_PATTERN = "(\\d+)\\.(\\d+)";
2934
private static final String VERSION_INFO_ROOT_TAG = "MathWorks_version_info";
3035
private static final String RELEASE_TAG = "release";
3136
private static final String VERSION_TAG = "version";
3237
private static final String DESCRIPTION_TAG = "description";
3338
private static final String DATE_TAG = "date";
34-
private static final String VERSION_16B = "9.1.0.888888";
35-
private static final Map<String, String> VERSION_OLDER_THAN_17A = new HashMap<String, String>(){
36-
{
37-
put(VERSION_TAG,VERSION_16B);
38-
}
39-
};
4039

4140
private Map<String, String> versionInfoCache = new HashMap<String, String>();
4241

@@ -107,14 +106,31 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
107106
else if(!this.matlabRoot.exists()){
108107
throw new NotDirectoryException("Invalid matlabroot path");
109108
}else {
110-
versionInfoCache.putAll(VERSION_OLDER_THAN_17A);
111-
}
112-
109+
// Get the version information from Contents.m file when VersionInfo.xml is not
110+
// present.
111+
FilePath contentFile = new FilePath(this.matlabRoot, CONTENTS_FILE);
112+
String actualVersion = null;
113+
try (InputStream in = contentFile.read();
114+
BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
115+
116+
// Skip first line and capture the second line.
117+
br.readLine();
118+
String versionLine = br.readLine();
119+
120+
Pattern p = Pattern.compile(VERSION_PATTERN);
121+
Matcher m = p.matcher(versionLine);
122+
if (m.find()) {
123+
actualVersion = m.group();
124+
}
125+
}
126+
// Update the versionInfoCache with actual version extracted from Contents.m
127+
versionInfoCache.put(VERSION_TAG, actualVersion);
128+
}
113129
} catch (Exception e) {
114130
throw new MatlabVersionNotFoundException(
115131
Message.getValue("Releaseinfo.matlab.version.not.found.error"), e);
116-
}
132+
}
117133
}
118134
return versionInfoCache;
119135
}
120-
}
136+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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.
110+

0 commit comments

Comments
 (0)