Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve latest release issue #393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>matlab</artifactId>
<version>2.16.0-SNAPSHOT</version>
<version>2.15.1-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>MATLAB Plugin</name>
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/com/mathworks/ci/tools/MatlabInstaller.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mathworks.ci.tools;

/**
* Copyright 2024, The MathWorks, Inc.
* Copyright 2024-2025, The MathWorks, Inc.
*/

import com.mathworks.ci.MatlabInstallation;
Expand Down Expand Up @@ -49,7 +49,7 @@ public MatlabInstaller(String id) {
}

public String getRelease() {
return this.release.trim();
return this.release;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What cases caused the removal of the trim here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, it's just trimmed later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, mostly just that it seems weird for a getter to change the value of the property. We were already trimming later so I just removed it.

}

@DataBoundSetter
Expand All @@ -75,10 +75,12 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen
String extension = "";
String[] systemProperties = getSystemProperties(node);
FilePath matlabRoot;
MatlabRelease release = parseRelease(this.getRelease());

if (systemProperties[0].toLowerCase().contains("os x")) {
matlabRoot = new FilePath(toolRoot, this.getRelease() + ".app");
matlabRoot = new FilePath(toolRoot, release.name + ".app");
} else {
matlabRoot = new FilePath(toolRoot, this.getRelease());
matlabRoot = new FilePath(toolRoot, release.name);
}
String platform = getPlatform(systemProperties[0], systemProperties[1]);
if (platform == "win64") {
Expand All @@ -93,7 +95,7 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen
FilePath matlabBatch = fetchMatlabBatch(platform, tempDir);

// Install with mpm
mpmInstall(mpm, this.getRelease(), this.getProducts(), matlabRoot, node, log);
mpmInstall(mpm, release, this.getProducts(), matlabRoot, node, log);

// Copy downloaded matlab-batch to tool directory
FilePath matlabBin = new FilePath(matlabRoot, "bin");
Expand All @@ -105,7 +107,7 @@ public FilePath performInstallation(ToolInstallation tool, Node node, TaskListen
return matlabRoot;
}

private void mpmInstall(FilePath mpmPath, String release, String products, FilePath destination, Node node,
private void mpmInstall(FilePath mpmPath, MatlabRelease release, String products, FilePath destination, Node node,
TaskListener log)
throws IOException, InterruptedException {
makeDir(destination);
Expand All @@ -115,7 +117,10 @@ private void mpmInstall(FilePath mpmPath, String release, String products, FileP
ArgumentListBuilder args = new ArgumentListBuilder();
args.add(mpmPath.getRemote());
args.add("install");
appendReleaseToArguments(release, args, log);
args.add("--release=" + release.name);
if (release.isPrerelease) {
args.add("--release-status=Prerelease");
}
args.add("--destination=" + destination.getRemote());
addMatlabProductsToArgs(args, products);

Expand Down Expand Up @@ -145,29 +150,25 @@ private void makeDir(FilePath path) throws IOException, InterruptedException {
}
}

private void appendReleaseToArguments(String release, ArgumentListBuilder args, TaskListener log) {
String trimmedRelease = release.trim();
String actualRelease = trimmedRelease;
private MatlabRelease parseRelease(String release) throws InstallationFailedException {
String name = release.trim();
boolean isPrerelease = false;

if (trimmedRelease.equalsIgnoreCase("latest") || trimmedRelease.equalsIgnoreCase(
"latest-including-prerelease")) {
String releaseInfoUrl = Message.getValue("matlab.release.info.url") + trimmedRelease;
String releaseVersion = null;
if (name.equalsIgnoreCase("latest") || name.equalsIgnoreCase("latest-including-prerelease")) {
String releaseInfoUrl = Message.getValue("matlab.release.info.url") + name;
try {
releaseVersion = IOUtils.toString(new URL(releaseInfoUrl),
StandardCharsets.UTF_8).trim();
name = IOUtils.toString(new URL(releaseInfoUrl), StandardCharsets.UTF_8).trim();
} catch (IOException e) {
log.getLogger().println("Failed to fetch release version: " + e.getMessage());
throw new InstallationFailedException("Failed to fetch release version: " + e.getMessage());
}

if (releaseVersion != null && releaseVersion.contains("prerelease")) {
actualRelease = releaseVersion.replace("prerelease", "");
args.add("--release-status=Prerelease");
} else {
actualRelease = releaseVersion;
if (name.contains("prerelease")) {
name = name.replace("prerelease", "");
isPrerelease = true;
}
}
args.add("--release=" + actualRelease);

return new MatlabRelease(name, isPrerelease);
}

private FilePath fetchMpm(String platform, FilePath destination)
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/mathworks/ci/tools/MatlabRelease.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mathworks.ci.tools;

/**
* Copyright 2025, The MathWorks, Inc.
*/

public class MatlabRelease {
public String name;
public boolean isPrerelease;

public MatlabRelease(String name, boolean isPrerelease) {
this.name = name;
this.isPrerelease = isPrerelease;
}
}
Loading