Skip to content

Commit

Permalink
Merge branch 'main' into fix/331-cobigen-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Jun 13, 2024
2 parents b68abff + 6713fca commit 67cdd7a
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 7 deletions.
1 change: 0 additions & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<mainClass>com.devonfw.tools.ide.cli.Ideasy</mainClass>
<imageName>ideasy</imageName>
<releaseName>${project.artifactId}-${os.detected.classifier}-${os.detected.arch}</releaseName>
<java.version>17</java.version>
<native.maven.plugin.version>0.9.28</native.maven.plugin.version>
<jline.version>3.24.1</jline.version>
<jansi.version>2.4.0</jansi.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ default int addAllMatches(String text, String[] sortedCandidates, Property<?> pr
index++;
count++;
} else {
index = -index;
index = -index - 1;
}
while ((index >= 0) && (index < sortedCandidates.length)) {
if (sortedCandidates[index].startsWith(text)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand Down Expand Up @@ -598,7 +599,13 @@ public boolean isOnline() {
boolean online = false;
try {
int timeout = 1000;
online = InetAddress.getByName("github.com").isReachable(timeout);
//open a connection to github.com and try to retrieve data
//getContent fails if there is no connection
URLConnection connection = new URL("https://www.github.com").openConnection();
connection.setConnectTimeout(timeout);
connection.getContent();
online = true;

} catch (Exception ignored) {

}
Expand Down
13 changes: 13 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,19 @@ default String getMavenArgs() {

}

/**
* @return the String value for the variable M2_REPO, or null if called outside an IDEasy installation.
*/
default String getMavenRepoEnvVariable() {

if (getIdeHome() != null) {
Path m2Repo = getConfPath().resolve(Mvn.M2_CONFIG_FOLDER).resolve("repository");
return m2Repo.toString();
}
return null;

}

/**
* Updates the current working directory (CWD) and configures the environment paths according to the specified parameters. This method is central to changing
* the IDE's notion of where it operates, affecting where configurations, workspaces, settings, and other resources are located or loaded from.
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class Mvn extends PluginBasedCommandlet {
/** The name of the settings.xml */
public static final String SETTINGS_FILE = "settings.xml";

private static final String M2_CONFIG_FOLDER = ".m2";
/** The name of the m2 repository */
public static final String M2_CONFIG_FOLDER = ".m2";

private static final String SETTINGS_SECURITY_FILE = "settings-security.xml";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public interface IdeVariables {
/** {@link VariableDefinition} for version of maven (mvn). */
VariableDefinitionVersion MVN_VERSION = new VariableDefinitionVersion("MVN_VERSION", "MAVEN_VERSION");

/** {@link VariableDefinition} arguments for maven to set the m2 repo location. */
/** {@link VariableDefinition} arguments for maven to locate the settings file. */
VariableDefinitionString MAVEN_ARGS = new VariableDefinitionString("MAVEN_ARGS", null, c -> c.getMavenArgs(), false, true);

/** {@link VariableDefinition} arguments for maven to set the m2 repo location. */
VariableDefinitionString M2_REPO = new VariableDefinitionString("M2_REPO", null, c -> c.getMavenRepoEnvVariable(), false, true);

/** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */
VariableDefinitionString DOCKER_EDITION = new VariableDefinitionString("DOCKER_EDITION", null, c -> "rancher");

Expand All @@ -58,7 +61,7 @@ public interface IdeVariables {

/** A {@link Collection} with all pre-defined {@link VariableDefinition}s. */
Collection<VariableDefinition<?>> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE, IDE_TOOLS, CREATE_START_SCRIPTS,
IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME);
IDE_MIN_VERSION, MVN_VERSION, M2_REPO, DOCKER_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME);

/**
* @param name the name of the requested {@link VariableDefinition}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public VersionComparisonResult compareVersion(VersionSegment other) {
if (!lettersResult.isEqual()) {
return lettersResult;
}
if (!"_".equals(this.separator) && "_".equals(other.separator)) {
return VersionComparisonResult.GREATER;
} else if ("_".equals(this.separator) && !"_".equals(other.separator)) {
return VersionComparisonResult.LESS;
}

if (this.number < other.number) {
return VersionComparisonResult.LESS;
} else if (this.number > other.number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.devonfw.tools.ide.completion;

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.commandlet.VersionCommandlet;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.context.IdeTestContextMock;
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.property.VersionProperty;
import org.junit.jupiter.api.Test;

class CompletionCandidateCollectorDefaultTest extends AbstractIdeContextTest {

/**
* Test of {@link CompletionCandidateCollectorDefault#addAllMatches(String, String[], Property, Commandlet)}
*/
@Test
public void testAddAllMatches() {

String[] sortedCandidates = { "1", "2.0", "2.1", "3" };
String input = "2";
String[] expectedCandidates = { "2.0", "2.1" };

VersionProperty versionProperty = new VersionProperty("", false, "version");
IdeContext context = IdeTestContextMock.get();
CompletionCandidateCollector collector = new CompletionCandidateCollectorDefault(context);

int matches = collector.addAllMatches(input, sortedCandidates, versionProperty, new VersionCommandlet(context));

assertThat(matches).isEqualTo(2);
assertThat(collector.getCandidates().stream().map(CompletionCandidate::text)).containsExactly(expectedCandidates);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,15 @@ public void testMatchAny() {
assertThat(pattern.matches(VersionIdentifier.of("17.0-SNAPSHOT"))).isTrue();
}

@Test
public void testCompareJavaVersions() {

VersionIdentifier v21_35 = VersionIdentifier.of("21_35");
VersionIdentifier v21_0_2_13 = VersionIdentifier.of("21.0.2_13");
VersionIdentifier v21_0_3_9 = VersionIdentifier.of("21.0.3_9");
assertThat(v21_35).isLessThan(v21_0_2_13);
assertThat(v21_0_2_13).isLessThan(v21_0_3_9);
assertThat(v21_0_3_9).isGreaterThan(v21_35);
}

}
82 changes: 82 additions & 0 deletions gui/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.devonfw.tools.IDEasy.dev</groupId>
<artifactId>ide</artifactId>
<version>dev-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.devonfw.tools.IDEasy</groupId>
<artifactId>gui</artifactId>
<version>${revision}</version>
<name>gui</name>

<properties>
<mainClass>com.devonfw.ide.gui.AppLauncher</mainClass>
<javafx.version>21</javafx.version>
<testfx.version>4.0.18</testfx.version>
<javafx.maven.plugin.version>0.0.8</javafx.maven.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ide-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>testfx-core</artifactId>
<version>${testfx.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>testfx-junit5</artifactId>
<version>${testfx.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>17.0.10</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.maven.plugin.version}</version>
<executions>
<execution>
<configuration>
<mainClass>${mainClass}</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
38 changes: 38 additions & 0 deletions gui/src/main/java/com/devonfw/ide/gui/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.devonfw.ide.gui;

import com.devonfw.tools.ide.version.IdeVersion;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;

import java.io.IOException;

/**
* GUI Application for IDEasy
*/
public class App extends Application {

Parent root;

@Override
public void start(Stage primaryStage) throws IOException {

root = FXMLLoader.load(App.class.getResource("main-view.fxml"));

Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(root, bounds.getWidth() / 2, bounds.getHeight() / 2);

primaryStage.setTitle("IDEasy - version " + IdeVersion.get());
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {

launch(args);
}
}
15 changes: 15 additions & 0 deletions gui/src/main/java/com/devonfw/ide/gui/AppLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.devonfw.ide.gui;

/**
* Launcher class for the App.
* Workaround for "Error: JavaFX runtime components are missing, and are required to run this application."
* Inspired by
* <ahref=https://stackoverflow.com/questions/56894627/how-to-fix-error-javafx-runtime-components-are-missing-and-are-required-to-ru>StackOverflow</a>
*/
public class AppLauncher {
public static void main(final String[] args) {

App.main(args);
}

}
13 changes: 13 additions & 0 deletions gui/src/main/resources/com/devonfw/ide/gui/main-view.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</padding>

<Label text="welcome to IDEasy" fx:id="hellomessage"/>
<!--Button text="Hello!" onAction="#onHelloButtonClick"/-->
</VBox>
54 changes: 54 additions & 0 deletions gui/src/test/java/com/devonfw/ide/gui/AppBaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.devonfw.ide.gui;

import javafx.stage.Stage;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.ApplicationTest;
import org.testfx.matcher.base.NodeMatchers;

import java.io.IOException;

import static org.testfx.api.FxAssert.verifyThat;

/**
* Base Test
*/
public class AppBaseTest extends ApplicationTest {

@Override
public void start(Stage stage) throws IOException {

new App().start(stage);
}

/**
* Set up headless testing
*
* @throws IOException
*/
@BeforeAll
public static void setupHeadlessMode() {

//Enable headless testing. Should be moved as a system property "-Dheadless=true" into workflows to only affect CI
System.setProperty("headless", "true");

if (Boolean.getBoolean("headless")) {
System.setProperty("testfx.robot", "glass");
System.setProperty("glass.platform", "Monocle");
System.setProperty("testfx.headless", "true");
System.setProperty("prism.order", "sw");
System.setProperty("java.awt.headless", "true");
}

}

/**
* Test if welcome message is shown when GUI is started
*/
@Test
public void ensureHelloMessageIsShownOnStartUp() {

verifyThat("#hellomessage", NodeMatchers.isNotNull());
}

}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<properties>
<github.repository>IDEasy</github.repository>
<ide_version>${revision}</ide_version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -51,6 +52,7 @@
<modules>
<module>documentation</module>
<module>cli</module>
<module>gui</module>
</modules>

<build>
Expand Down

0 comments on commit 67cdd7a

Please sign in to comment.