Skip to content

Commit

Permalink
Check ECU-TEST license (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGroscheTT committed Sep 11, 2020
1 parent 38ef0b5 commit d0c59e9
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 20 deletions.
Binary file modified docs/images/downstream_post_build_steps.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2015-2020 TraceTronic GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package de.tracetronic.jenkins.plugins.ecutest.tool;

import de.tracetronic.jenkins.plugins.ecutest.ETPluginException;
import de.tracetronic.jenkins.plugins.ecutest.log.TTConsoleLogger;
import de.tracetronic.jenkins.plugins.ecutest.tool.client.ETClient;
import de.tracetronic.jenkins.plugins.ecutest.tool.installation.ETInstallation;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.List;

/**
* Builder providing the license check of ECU-TEST.
*/
public class LicenseETBuilder extends AbstractToolBuilder {

/**
* Instantiates a new {@link LicenseETBuilder}.
*
* @param toolName the tool name identifying the {@link ETInstallation} to be used
*/
@DataBoundConstructor
public LicenseETBuilder(@Nonnull final String toolName) {
super(toolName);
}

@Override
public int getDefaultTimeout() {
return 0;
}

@Override
public void performTool(final Run<?, ?> run, final FilePath workspace, final Launcher launcher,
final TaskListener listener) throws InterruptedException, IOException, ETPluginException {
// Check running instance
final List<String> foundProcesses = ETClient.checkProcesses(launcher, listener, false);
if (!foundProcesses.isEmpty()) {
final TTConsoleLogger logger = new TTConsoleLogger(listener);
logger.logInfo("Running ECU-TEST instance found, therefore a license is available...");
} else {
// Verify selected ECU-TEST installation
final EnvVars envVars = run.getEnvironment(listener);
// Verify selected ECU-TEST installation
if (!isInstallationVerified(envVars)) {
setInstallation(configureToolInstallation(workspace.toComputer(), listener, envVars));
}

// Check license of ECU-TEST
final String installPath = getInstallation().getExecutable(launcher);
final String toolName = getInstallation().getName();
final ETClient etClient = new ETClient(toolName, installPath, "", "", getDefaultTimeout(), false);
etClient.setLicenseCheck(true);
final TTConsoleLogger logger = new TTConsoleLogger(listener);

if (!etClient.checkLicense(launcher, listener)) {
logger.logError(String.format("-> No valid license for '%s' found.", toolName));
throw new ETPluginException(String.format("License check '%s' failed.", toolName));
} else {
logger.logInfo(String.format("-> Valid license for '%s' found.", toolName));
}
}
}

/**
* DescriptorImpl for {@link LicenseETBuilder}.
*/
@Symbol("checkETLicense")
@Extension(ordinal = 10012)
public static final class DescriptorImpl extends AbstractToolDescriptor {

@Override
public int getDefaultTimeout() {
return 0;
}

@Nonnull
@Override
public String getDisplayName() {
return Messages.LicenseETBuilder_DisplayName();
}
}
}
Expand Up @@ -42,6 +42,7 @@ public class ETClient extends AbstractToolClient {
private String version;
private String lastTbc;
private String lastTcf;
private boolean licenseCheck;

/**
* Instantiates a new {@link ETClient}.
Expand All @@ -62,6 +63,7 @@ public ETClient(final String toolName, final String installPath, final String wo
version = "";
lastTbc = "";
lastTcf = "";
licenseCheck = false;
}

/**
Expand All @@ -78,6 +80,7 @@ public ETClient(final String toolName, final int timeout) {
version = "";
lastTbc = "";
lastTcf = "";
licenseCheck = false;
}

/**
Expand Down Expand Up @@ -124,6 +127,26 @@ public static ToolVersion getComVersion(final Launcher launcher, final TaskListe
return launcher.getChannel().call(new VersionCallable(listener));
}

/**
* Check license of ECU-TEST.
*
* @param launcher the launcher
* @param listener the listener
* @return {@code true} if ECU-TEST instance has been stopped successfully
* @throws IOException the io exception
* @throws InterruptedException the interrupted exception
*/
public boolean checkLicense(final Launcher launcher, final TaskListener listener) throws IOException,
InterruptedException {
final ArgumentListBuilder args = createCmdLine();
final TTConsoleLogger logger = new TTConsoleLogger(listener);
logger.logInfo(args.toString());

// Launch tool process with arg -p
final int exitCode = launcher.launch().cmds(args).quiet(true).join();
return exitCode == 0;
}

public String getWorkspaceDir() {
return workspaceDir;
}
Expand All @@ -148,6 +171,14 @@ public String getLastTcf() {
return lastTcf;
}

public boolean isLicenseCheck() {
return licenseCheck;
}

public void setLicenseCheck(final boolean licenseCheck) {
this.licenseCheck = licenseCheck;
}

@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
@Override
public boolean start(final boolean checkProcesses, final FilePath workspace, final Launcher launcher,
Expand Down Expand Up @@ -263,20 +294,25 @@ protected ArgumentListBuilder createCmdLine() {
final ArgumentListBuilder args = new ArgumentListBuilder();
args.add(getInstallPath());

if (!getWorkspaceDir().isEmpty()) {
args.add("--workspaceDir", getWorkspaceDir());
}
if (isLicenseCheck()) {
args.add("--startupAutomated=True");
args.add("-p");
} else {
if (!getWorkspaceDir().isEmpty()) {
args.add("--workspaceDir", getWorkspaceDir());
}

if (!getSettingsDir().isEmpty()) {
args.add("-s", getSettingsDir());
}
if (!getSettingsDir().isEmpty()) {
args.add("-s", getSettingsDir());
}

if (isDebugMode()) {
args.add("-d");
}
if (isDebugMode()) {
args.add("-d");
}

// Create full workspace automatically
args.add("--startupAutomated=CreateDirs");
// Create full workspace automatically
args.add("--startupAutomated=CreateDirs");
}

return args;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2019 TraceTronic GmbH
* Copyright (c) 2015-2020 TraceTronic GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -57,5 +57,4 @@ boolean stop(boolean checkProcesses, FilePath workspace, Launcher launcher, Task
*/
boolean restart(boolean checkProcesses, FilePath workspace, Launcher launcher, TaskListener listener)
throws IOException, InterruptedException;

}
@@ -0,0 +1,10 @@
<!--
Copyright (c) 2015-2020 TraceTronic GmbH
SPDX-License-Identifier: BSD-3-Clause
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<st:include class="de.tracetronic.jenkins.plugins.ecutest.tool.installation.ETInstallation" page="select.jelly"/>
</j:jelly>
@@ -0,0 +1,24 @@
<!--
Copyright (c) 2015-2020 TraceTronic GmbH
SPDX-License-Identifier: BSD-3-Clause
-->

<div>
<p>Check ECU-TEST license.</p>
<strong>Pipelines usage:</strong>
<dl>Signatures:
<dd>
<pre>
checkETLicense(String toolName) : void
</pre>
</dd>
</dl>
<dl>Examples:
<dd>
<pre>
checkETLicense('ECU-TEST')
</pre>
</dd>
</dl>
</div>
@@ -0,0 +1,24 @@
<!--
Copyright (c) 2015-2020 TraceTronic GmbH
SPDX-License-Identifier: BSD-3-Clause
-->

<div>
<p>Lizenzüberprüfung von ECU-TEST.</p>
<strong>Verwendung in Pipelines:</strong>
<dl>Signaturen:
<dd>
<pre>
checkETLicense(String toolName) : void
</pre>
</dd>
</dl>
<dl>Beispiele:
<dd>
<pre>
checkETLicense('ECU-TEST')
</pre>
</dd>
</dl>
</div>
@@ -1,11 +1,12 @@
#
# Copyright (c) 2015-2019 TraceTronic GmbH
# Copyright (c) 2015-2020 TraceTronic GmbH
#
# SPDX-License-Identifier: BSD-3-Clause
#
Builder.DisabledTimeout=Disabling the timeout will possibly cause this build step to run forever.
Builder.NoValidatedValue=Value cannot be resolved at validation-time, be sure to allocate with a valid value.
CacheBuilder.DisplayName=[TT] Generate Caches
LicenseETBuilder.DisplayName = [TT] Check ECU-TEST License
StartETBuilder.DisplayName=[TT] Start ECU-TEST
StartTSBuilder.DisplayName=[TT] Start Tool-Server
StartTSBuilder.NoAbsolutePath=Explicit ToolLibs.ini path has to absolute.
Expand Down
@@ -1,11 +1,12 @@
#
# Copyright (c) 2015-2019 TraceTronic GmbH
# Copyright (c) 2015-2020 TraceTronic GmbH
#
# SPDX-License-Identifier: BSD-3-Clause
#
Builder.DisabledTimeout=Ohne Zeitbeschr\u00e4nkung kann dieser Buildschritt m\u00f6glicherweise unendlich lang laufen.
Builder.NoValidatedValue=Wert kann nicht direkt \u00fcberpr\u00fcft werden, Variablenzuweisung muss g\u00fcltig sein.
Builder.DisabledTimeout=Ohne Zeitbeschr\u00E4nkung kann dieser Buildschritt m\u00F6glicherweise unendlich lang laufen.
Builder.NoValidatedValue=Wert kann nicht direkt \u00FCberpr\u00FCft werden, Variablenzuweisung muss g\u00FCltig sein.
CacheBuilder.DisplayName=[TT] Generiere Caches
LicenseETBuilder.DisplayName = [TT] ECU-TEST Lizenz \u00FCberpr\u00FCfen
StartETBuilder.DisplayName=[TT] ECU-TEST starten
StartTSBuilder.DisplayName=[TT] Tool-Server starten
StartTSBuilder.NoAbsolutePath=Explizite Pfadangabe zur ToolLibs.ini muss absolut sein.
Expand Down

0 comments on commit d0c59e9

Please sign in to comment.