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

#1024: Move urls into url-updater module #1025

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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 .github/workflows/update-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
cache: 'maven'
- name: Build and run url updater
run: |
cd cli
cd url-updater
mvn -B -ntp -Dstyle.color=always install
mvn -B -ntp -Dstyle.color=always exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls PT5H30M"
- name: Commit and push to ide-urls
Expand Down
11 changes: 8 additions & 3 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>parsson</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -93,9 +98,9 @@
</dependency>
<!-- Needed for WireMock test support -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.2</version>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ static WindowsHelper get(IdeContext context) {
// IdeContext API is already too large
return ((AbstractIdeContext) context).getWindowsHelper();
}

}
11 changes: 11 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public String getRegistryValue(String path, String key) {

ProcessResult result = this.context.newProcess().executable("reg").addArgs("query", path, "/v", key).run(ProcessMode.DEFAULT_CAPTURE);
List<String> out = result.getOut();
return retrieveRegString(key, out);
}

/**
* Parses the result of a registry query and outputs the given key.
*
* @param key the key to look for.
* @param out List of keys from registry query result.
* @return the registry value.
*/
protected String retrieveRegString(String key, List<String> out) {
for (String line : out) {
int i = line.indexOf(key);
if (i >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,7 @@ protected Path getIdeRootPathFromEnv() {
return null;
}

public void setUserEnvironmentVariable(String userEnvironmentVariable) {

}
}
97 changes: 97 additions & 0 deletions cli/src/test/java/com/devonfw/tools/ide/io/FileAccessImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand Down Expand Up @@ -579,4 +585,95 @@ public void testGeneratePermissionString() {

}

/**
* Tests if extract was called with disabled extract param, the archive will be moved.
*
* @param tempDir temporary directory to use.
*/
@Test
public void testDisabledExtractMovesArchive(@TempDir Path tempDir) {
// arrange
IdeContext context = IdeTestContextMock.get();
FileAccessImpl fileAccess = new FileAccessImpl(context);
Path downloadArchive = tempDir.resolve("downloaded.zip");
fileAccess.touch(downloadArchive);
Path installationPath = tempDir.resolve("installation");
Path targetPath = installationPath.resolve("downloaded.zip");
boolean extract = false;
// act
fileAccess.extract(downloadArchive, installationPath, this::postExtract, extract);
// assert
assertThat(targetPath).exists();
}

/**
* Tests if a tgz archive with a sub folder can be extracted to a target folder properly.
*
* @param tempDir temporary directory to use.
* @throws IOException when a file could not be created.
*/
@Test
public void testExtractTgzArchive(@TempDir Path tempDir) throws IOException {
// arrange
IdeContext context = IdeTestContextMock.get();
FileAccessImpl fileAccess = new FileAccessImpl(context);
Path downloadedTgz = tempDir.resolve("downloaded.tgz");
fileAccess.touch(downloadedTgz);
try (GzipCompressorOutputStream gzipOut = new GzipCompressorOutputStream(Files.newOutputStream(downloadedTgz, StandardOpenOption.WRITE));
TarArchiveOutputStream tarOut = new TarArchiveOutputStream(gzipOut)) {

// Create a subfolder entry
TarArchiveEntry subfolderEntry = new TarArchiveEntry("subfolder/");
subfolderEntry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
tarOut.putArchiveEntry(subfolderEntry);
tarOut.closeArchiveEntry();

// Add a file to the subfolder
TarArchiveEntry fileEntry = new TarArchiveEntry("subfolder/testfile2.txt");
fileEntry.setSize(12);
tarOut.putArchiveEntry(fileEntry);
tarOut.write("Hello World2".getBytes());
tarOut.closeArchiveEntry();

// create a file in the root of the archive
TarArchiveEntry entry = new TarArchiveEntry("testfile.txt");
entry.setSize(11);
tarOut.putArchiveEntry(entry);
tarOut.write("Hello World".getBytes());
tarOut.closeArchiveEntry();
}
Path installationPath = tempDir.resolve("installation");
// act
fileAccess.extractTar(downloadedTgz, installationPath, TarCompression.GZ);
// assert
assertThat(installationPath.resolve("testfile.txt")).exists();
assertThat(installationPath.resolve("subfolder").resolve("testfile2.txt")).exists();
}

/**
* Tests if a file can be found within a list of folders.
*
* @param tempDir temporary directory to use.
*/
@Test
public void testFindExistingFileInFolders(@TempDir Path tempDir) {
IdeContext context = IdeTestContextMock.get();
FileAccessImpl fileAccess = new FileAccessImpl(context);
Path subfolder1 = tempDir.resolve("subfolder1");
fileAccess.mkdirs(subfolder1);
fileAccess.touch(subfolder1.resolve("testfile"));
Path subfolder2 = tempDir.resolve("subfolder2");
fileAccess.mkdirs(subfolder2);
fileAccess.touch(subfolder2.resolve("targetfile"));
List<Path> pathList = new ArrayList<>();
pathList.add(subfolder1);
pathList.add(subfolder2);
Path foundFile = fileAccess.findExistingFile("targetfile", pathList);
assertThat(foundFile).exists();
}

private void postExtract(Path path) {
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.devonfw.tools.ide.os;

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.AbstractIdeTestContext;
import com.devonfw.tools.ide.context.IdeSlf4jContext;

/**
* Tests for {@link WindowsHelperImpl}.
*/
public class WindowsHelperImplTest extends AbstractIdeContextTest {

/**
* Tests if the USER_PATH registry entry can be parsed properly.
*/
@Test
public void testWindowsHelperParseRegString() {
// arrange
AbstractIdeTestContext context = new IdeSlf4jContext();
WindowsHelperImpl helper = new WindowsHelperImpl(context);
List<String> output = new ArrayList<>();
output.add("");
output.add("HKEY_CURRENT_USER\\Environment");
output.add(" PATH REG_SZ D:\\projects\\_ide\\installation\\bin;");
output.add("");
// act
String regString = helper.retrieveRegString("PATH", output);
// assert
assertThat(regString).isEqualTo("D:\\projects\\_ide\\installation\\bin;");
}

/**
* Tests if an empty list of outputs will result in null.
*/
@Test
public void testWindowsHelperParseEmptyRegStringReturnsNull() {
// arrange
AbstractIdeTestContext context = new IdeSlf4jContext();
WindowsHelperImpl helper = new WindowsHelperImpl(context);
List<String> output = new ArrayList<>();
// act
String regString = helper.retrieveRegString("PATH", output);
// assert
assertThat(regString).isNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.devonfw.tools.ide.version.VersionRange;

/**
* Test of {@link com.devonfw.tools.ide.url.model.file.json.ToolDependencies} and {@link AbstractUrlToolOrEdition#getDependencyFile()}.
* Test of {@link ToolDependencies} and {@link AbstractUrlToolOrEdition#getDependencyFile()}.
*/
public class ToolDependenciesTest extends AbstractUrlModelTest {

Expand All @@ -23,7 +23,8 @@ public void testEditionSpecific() {
IdeContext context = newContext();

// act
Collection<ToolDependency> dependencies = context.getDefaultToolRepository().findDependencies("tomcat", "tomcat", VersionIdentifier.of("11.0.0"));
Collection<ToolDependency> dependencies = context.getDefaultToolRepository()
.findDependencies("tomcat", "tomcat", VersionIdentifier.of("11.0.0"));

// assert
assertThat(dependencies).containsExactly(new ToolDependency("java", VersionRange.of("[17,)")));
Expand All @@ -36,10 +37,12 @@ public void testEditionFallback() {
IdeContext context = newContext();

// act
Collection<ToolDependency> dependencies = context.getDefaultToolRepository().findDependencies("tomcat", "undefined", VersionIdentifier.of("11.0.0"));
Collection<ToolDependency> dependencies = context.getDefaultToolRepository()
.findDependencies("tomcat", "undefined", VersionIdentifier.of("11.0.0"));

// assert
assertThat(dependencies).containsExactly(new ToolDependency("this-is-the-wrong-file-only-for-testing", VersionRange.of("[1.0,2.0]")));
assertThat(dependencies).containsExactly(
new ToolDependency("this-is-the-wrong-file-only-for-testing", VersionRange.of("[1.0,2.0]")));
}

@Test
Expand All @@ -49,7 +52,8 @@ public void testEditionUnspecific() {
IdeContext context = newContext();

// act
Collection<ToolDependency> dependencies = context.getDefaultToolRepository().findDependencies("mvn", "undefined", VersionIdentifier.of("3.9.0"));
Collection<ToolDependency> dependencies = context.getDefaultToolRepository()
.findDependencies("mvn", "undefined", VersionIdentifier.of("3.9.0"));

// assert
assertThat(dependencies).containsExactly(new ToolDependency("java", VersionRange.of("[8,)")));
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<module>documentation</module>
<module>cli</module>
<module>gui</module>
<module>url-updater</module>
</modules>

<build>
Expand Down
42 changes: 42 additions & 0 deletions url-updater/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 http://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>url-updater</artifactId>
<version>${revision}</version>
<name>${project.artifactId}</name>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ide-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.16</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.devonfw.tools.ide.tool.androidstudio;
package com.devonfw.tools.ide.url.tool.androidstudio;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.tools.ide.tool.androidstudio.AndroidJsonDownload;
import com.devonfw.tools.ide.tool.androidstudio.AndroidJsonItem;
import com.devonfw.tools.ide.tool.androidstudio.AndroidJsonObject;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.tool.aws;
package com.devonfw.tools.ide.url.tool.aws;

import com.devonfw.tools.ide.os.OperatingSystem;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
Expand All @@ -9,6 +9,8 @@
*/
public class AwsUrlUpdater extends GithubUrlUpdater {

private static final String BASE_URL = "https://awscli.amazonaws.com/";

@Override
protected String getTool() {

Expand All @@ -27,6 +29,13 @@ protected String getGithubRepository() {
return "aws-cli";
}

/**
* @return the base url.
*/
protected String getBaseUrl() {
return BASE_URL;
}

@Override
protected String mapVersion(String version) {

Expand All @@ -52,7 +61,7 @@ protected String mapVersion(String version) {
@Override
protected void addVersion(UrlVersion urlVersion) {

String baseUrl = "https://awscli.amazonaws.com/";
String baseUrl = getBaseUrl();
boolean ok = doAddVersion(urlVersion, baseUrl + "AWSCLIV2-${version}.msi", OperatingSystem.WINDOWS);
if (!ok) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.tool.az;
package com.devonfw.tools.ide.url.tool.az;

import com.devonfw.tools.ide.os.OperatingSystem;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.tool.docker;
package com.devonfw.tools.ide.url.tool.docker;

import java.util.Set;
import java.util.regex.Matcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devonfw.tools.ide.tool.docker;
package com.devonfw.tools.ide.url.tool.docker;

import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.url.updater.GithubUrlUpdater;
Expand Down
Loading