Skip to content

Commit

Permalink
devonfw#919: Require user to agree to license
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jan 17, 2025
1 parent 9b34319 commit c0d4281
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
*/
public final class HelpCommandlet extends Commandlet {

static final String LOGO = """
__ ___ ___ ___
╲ ╲ |_ _| ╲| __|__ _ ____ _
> > | || |) | _|/ _` (_-< || |
/_/ ___ |___|___/|___╲__,_/__/╲_, |
|___| |__/
""".replace('╲', '\\');

/** The optional commandlet to get help about. */
public final CommandletProperty commandlet;

Expand Down Expand Up @@ -54,15 +46,11 @@ public boolean isIdeRootRequired() {
return false;
}

private void printLogo() {

this.context.info(LOGO);
}

@Override
public void run() {

printLogo();
this.context.printLogo();
NlsBundle bundle = NlsBundle.of(this.context);
this.context.success(bundle.get("version-banner"), IdeVersion.get());
Commandlet cmd = this.commandlet.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -55,6 +56,7 @@
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.step.StepImpl;
import com.devonfw.tools.ide.url.model.UrlMetadata;
import com.devonfw.tools.ide.util.DateTimeUtil;
import com.devonfw.tools.ide.validation.ValidationResult;
import com.devonfw.tools.ide.validation.ValidationResultValid;
import com.devonfw.tools.ide.validation.ValidationState;
Expand All @@ -66,6 +68,8 @@
public abstract class AbstractIdeContext implements IdeContext {

private static final GitUrl IDE_URLS_GIT = new GitUrl("https://github.com/devonfw/ide-urls.git", null);

private static final String LICENSE_URL = "https://github.com/devonfw/IDEasy/blob/main/documentation/LICENSE.adoc";

private final IdeStartContextImpl startContext;

Expand Down Expand Up @@ -869,11 +873,13 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) {
Path settingsRepository = getSettingsGitRepository();
if (settingsRepository != null) {
if (getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()) ||
(getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(settingsRepository, getSettingsCommitIdPath()))) {
(getGitContext().fetchIfNeeded(settingsRepository) && getGitContext().isRepositoryUpdateAvailable(settingsRepository,
getSettingsCommitIdPath()))) {
interaction("Updates are available for the settings repository. If you want to apply the latest changes, call \"ide update\"");
}
}
}
ensureLicenseAgreement();
cmd.run();
} finally {
if (previousLogLevel != null) {
Expand All @@ -886,6 +892,61 @@ private ValidationResult applyAndRun(CliArguments arguments, Commandlet cmd) {
return result;
}

private void ensureLicenseAgreement() {

if ((this.ideRoot == null) || isTest()) {
return; // error: IDE_ROOT undefined
}
Path ideBase = this.ideRoot.resolve(FOLDER_IDE);
if (!Files.isDirectory(ideBase)) {
return; // error: $IDE_ROOT/_ide does not exist, broken installation
}
Path licenseAgreement = ideBase.resolve(FILE_LICENSE_AGREEMENT);
if (Files.isRegularFile(licenseAgreement)) {
return; // success, license already accepted
}
boolean logLevelInfoDisabled = !this.startContext.info().isEnabled();
if (logLevelInfoDisabled) {
this.startContext.setLogLevel(IdeLogLevel.INFO, true);
}
boolean logLevelInteractionDisabled = !this.startContext.interaction().isEnabled();
if (logLevelInteractionDisabled) {
this.startContext.setLogLevel(IdeLogLevel.INTERACTION, true);
}
StringBuilder sb = new StringBuilder(1180);
sb.append(LOGO).append("""
Welcome to IDEasy!
This product (with its included 3rd party components) is open-source software and can be used free (also commercially).
It supports automatic download and installation of arbitrary 3rd party tools.
By default only open-source 3rd party tools are used (downloaded, installed, executed).
But if explicitly configured, also commercial software that requires an additional license may be used.
This happens e.g. if you configure "ultimate" edition of IntelliJ or "docker" edition of Docker (Docker Desktop).
You are solely responsible for all risk implied by using this software.
Before using IDEasy you need to read and accept the license agreement with all involved licenses.
You will be able to find it online under the following URL:
""").append(LICENSE_URL)
.append("\n\nAlso it is included in the documentation that you can find here:\n").
append(ideBase.resolve("IDEasy.pdf").toString()).append("\n");
info(sb.toString());
askToContinue("Do you accept these terms of use and all license agreements?");

sb.setLength(0);
LocalDateTime now = LocalDateTime.now();
sb.append("On ").append(DateTimeUtil.formatDate(now, false)).append(" at ").append(DateTimeUtil.formatTime(now))
.append(" you accepted the IDEasy license.\n").append(LICENSE_URL);
try {
Files.writeString(licenseAgreement, sb);
} catch (Exception e) {
throw new RuntimeException("Failed to save license agreement!", e);
}
if (logLevelInfoDisabled) {
this.startContext.setLogLevel(IdeLogLevel.INFO, false);
}
if (logLevelInteractionDisabled) {
this.startContext.setLogLevel(IdeLogLevel.INTERACTION, false);
}
}

private void verifyIdeRoot() {
if (!isTest()) {
if (this.ideRoot == null) {
Expand Down
27 changes: 24 additions & 3 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public interface IdeContext extends IdeStartContext {
/** The file where the installed software version is written to as plain text. */
String FILE_LEGACY_SOFTWARE_VERSION = ".devon.software.version";

/** The file for the license agreement. */
String FILE_LICENSE_AGREEMENT = ".license.agreement";

/** The file extension for a {@link java.util.Properties} file. */
String EXT_PROPERTIES = ".properties";

Expand All @@ -140,9 +143,19 @@ public interface IdeContext extends IdeStartContext {
String FILE_CUSTOM_TOOLS = "ide-custom-tools.json";

/**
* file containing the current local commit hash of the settings repository. */
* file containing the current local commit hash of the settings repository.
*/
String SETTINGS_COMMIT_ID = ".commit.id";

/** The IDEasy ASCII logo. */
String LOGO = """
__ ___ ___ ___
╲ ╲ |_ _| ╲| __|__ _ ____ _
> > | || |) | _|/ _` (_-< || |
/_/ ___ |___|___/|___╲__,_/__/╲_, |
|___| |__/
""".replace('╲', '\\');

/**
* @return {@code true} if {@link #isOfflineMode() offline mode} is active or we are NOT {@link #isOnline() online}, {@code false} otherwise.
*/
Expand All @@ -156,6 +169,14 @@ default boolean isOffline() {
*/
boolean isOnline();

/**
* Print the IDEasy {@link #LOGO logo}.
*/
default void printLogo() {

info(LOGO);
}

/**
* Asks the user for a single string input.
*
Expand Down Expand Up @@ -359,8 +380,8 @@ default void requireOnline(String purpose) {
Path getSettingsPath();

/**
*
* @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project configuration only if the settings repository is in fact a git repository.
* @return the {@link Path} to the {@code settings} folder with the cloned git repository containing the project configuration only if the settings repository
* is in fact a git repository.
*/
Path getSettingsGitRepository();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ private void assertOptionLogMessages(IdeTestContext context) {
*/
private void assertLogoMessage(IdeTestContext context) {

assertThat(context).logAtInfo().hasMessage(HelpCommandlet.LOGO);
assertThat(context).logAtInfo().hasMessage(IdeContext.LOGO);
}
}

0 comments on commit c0d4281

Please sign in to comment.