Skip to content

Commit 136c18a

Browse files
#1024: Move urls into url-updater module (#1025)
Co-authored-by: Jörg Hohwiller <[email protected]>
1 parent 7688d17 commit 136c18a

File tree

106 files changed

+771
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+771
-199
lines changed

.github/workflows/build-pr.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
- name: Set up JDK
1212
uses: actions/setup-java@v1
1313
with:
14-
java-version: '17'
14+
java-version: '21'
1515
- name: Build project with Maven
1616
run: mvn -B -ntp -Dstyle.color=always install
1717
- name: Coveralls GitHub Action
18-
uses: coverallsapp/[email protected]
18+
uses: coverallsapp/[email protected]

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up JDK
1616
uses: actions/setup-java@v1
1717
with:
18-
java-version: '17'
18+
java-version: '21'
1919
- name: Build project with Maven
2020
run: mvn -B -ntp -Dstyle.color=always install
2121
- name: Coveralls GitHub Action

.github/workflows/nightly-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
- name: Set up JDK
7373
uses: actions/setup-java@v1
7474
with:
75-
java-version: '17'
75+
java-version: '21'
7676
- name: Download natives and build project
7777
uses: actions/download-artifact@v4
7878
with:

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
- name: Set up Apache Maven Central
7979
uses: actions/setup-java@v3
8080
with:
81-
java-version: 17
81+
java-version: 21
8282
distribution: 'temurin'
8383
cache: 'maven'
8484
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} # Value of the GPG private key to import

.github/workflows/update-urls.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ jobs:
2020
- name: Set up Java
2121
uses: actions/setup-java@v3
2222
with:
23-
java-version: 17
23+
java-version: 21
2424
distribution: 'temurin'
2525
cache: 'maven'
2626
- name: Build and run url updater
2727
run: |
28-
cd cli
29-
mvn -B -ntp -Dstyle.color=always install
30-
mvn -B -ntp -Dstyle.color=always exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="../ide-urls PT5H30M"
28+
mvn -B -ntp -Dstyle.color=always -pl url-updater -am install
29+
mvn -B -ntp -Dstyle.color=always -pl url-updater exec:java -Dexec.mainClass="com.devonfw.tools.ide.url.UpdateInitiator" -Dexec.args="ide-urls PT5H30M"
3130
- name: Commit and push to ide-urls
3231
run: |
3332
cd ide-urls

cli/pom.xml

+12-20
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<imageName>ideasy</imageName>
1717
<native.maven.plugin.version>0.10.4</native.maven.plugin.version>
1818
<assembly.maven.plugin.version>3.7.1</assembly.maven.plugin.version>
19-
<jline.version>3.24.1</jline.version>
20-
<jansi.version>2.4.1</jansi.version>
21-
<jackson.version>2.18.2</jackson.version>
2219
<build.helper.maven.plugin.version>3.6.0</build.helper.maven.plugin.version>
2320
</properties>
2421

@@ -27,39 +24,32 @@
2724
<dependency>
2825
<groupId>org.apache.commons</groupId>
2926
<artifactId>commons-compress</artifactId>
30-
<version>1.27.1</version>
3127
</dependency>
3228
<!-- JSON and XML support -->
3329
<dependency>
3430
<groupId>jakarta.json</groupId>
3531
<artifactId>jakarta.json-api</artifactId>
36-
<version>2.1.3</version>
3732
</dependency>
3833
<dependency>
3934
<groupId>org.eclipse.parsson</groupId>
4035
<artifactId>parsson</artifactId>
41-
<version>1.1.7</version>
4236
</dependency>
4337
<dependency>
4438
<groupId>com.fasterxml.jackson.core</groupId>
4539
<artifactId>jackson-databind</artifactId>
46-
<version>${jackson.version}</version>
4740
</dependency>
4841
<dependency>
4942
<groupId>com.fasterxml.jackson.datatype</groupId>
5043
<artifactId>jackson-datatype-jsr310</artifactId>
51-
<version>${jackson.version}</version>
5244
</dependency>
5345
<dependency>
5446
<groupId>com.fasterxml.jackson.dataformat</groupId>
5547
<artifactId>jackson-dataformat-xml</artifactId>
56-
<version>${jackson.version}</version>
5748
</dependency>
5849
<!-- Logging (only for URL-Updaters) -->
5950
<dependency>
6051
<groupId>org.slf4j</groupId>
6152
<artifactId>slf4j-api</artifactId>
62-
<version>2.0.17</version>
6353
<!--optional>true</optional-->
6454
</dependency>
6555
<dependency>
@@ -68,54 +58,56 @@
6858
<version>1.5.17</version>
6959
<!--optional>true</optional-->
7060
</dependency>
61+
<dependency>
62+
<groupId>org.junit.jupiter</groupId>
63+
<artifactId>junit-jupiter</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.assertj</groupId>
68+
<artifactId>assertj-core</artifactId>
69+
<scope>test</scope>
70+
</dependency>
7171
<dependency>
7272
<groupId>me.tongfei</groupId>
7373
<artifactId>progressbar</artifactId>
74-
<version>0.10.1</version>
7574
</dependency>
7675
<dependency>
7776
<groupId>org.jline</groupId>
7877
<artifactId>jline</artifactId>
79-
<version>${jline.version}</version>
8078
</dependency>
8179
<dependency>
8280
<groupId>org.fusesource.jansi</groupId>
8381
<artifactId>jansi</artifactId>
84-
<version>${jansi.version}</version>
8582
</dependency>
8683
<!-- Test dependencies -->
8784
<!-- Mockito for mocking -->
8885
<dependency>
8986
<groupId>org.mockito</groupId>
9087
<artifactId>mockito-core</artifactId>
91-
<version>5.15.2</version>
9288
<scope>test</scope>
9389
</dependency>
9490
<!-- Needed for WireMock test support -->
9591
<dependency>
96-
<groupId>com.github.tomakehurst</groupId>
97-
<artifactId>wiremock-jre8</artifactId>
98-
<version>2.35.2</version>
92+
<groupId>org.wiremock</groupId>
93+
<artifactId>wiremock</artifactId>
9994
<scope>test</scope>
10095
</dependency>
10196
<dependency>
10297
<!-- required for advanced mocking -->
10398
<groupId>net.bytebuddy</groupId>
10499
<artifactId>byte-buddy</artifactId>
105-
<version>1.17.1</version>
106100
<scope>test</scope>
107101
</dependency>
108102
<!-- required for XML assertion (XmlMergerTest) -->
109103
<dependency>
110104
<groupId>org.xmlunit</groupId>
111105
<artifactId>xmlunit-core</artifactId>
112-
<version>2.10.0</version>
113106
<scope>test</scope>
114107
</dependency>
115108
<dependency>
116109
<groupId>org.xmlunit</groupId>
117110
<artifactId>xmlunit-assertj3</artifactId>
118-
<version>2.10.0</version>
119111
<scope>test</scope>
120112
</dependency>
121113
</dependencies>

cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelper.java

-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ static WindowsHelper get(IdeContext context) {
4040
// IdeContext API is already too large
4141
return ((AbstractIdeContext) context).getWindowsHelper();
4242
}
43-
4443
}

cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelperImpl.java

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public String getRegistryValue(String path, String key) {
5757

5858
ProcessResult result = this.context.newProcess().executable("reg").addArgs("query", path, "/v", key).run(ProcessMode.DEFAULT_CAPTURE);
5959
List<String> out = result.getOut();
60+
return retrieveRegString(key, out);
61+
}
62+
63+
/**
64+
* Parses the result of a registry query and outputs the given key.
65+
*
66+
* @param key the key to look for.
67+
* @param out List of keys from registry query result.
68+
* @return the registry value.
69+
*/
70+
protected String retrieveRegString(String key, List<String> out) {
6071
for (String line : out) {
6172
int i = line.indexOf(key);
6273
if (i >= 0) {

cli/src/test/java/com/devonfw/tools/ide/context/AbstractIdeTestContext.java

-1
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,4 @@ protected Path getIdeRootPathFromEnv() {
325325
}
326326
return null;
327327
}
328-
329328
}

cli/src/test/java/com/devonfw/tools/ide/io/FileAccessImplTest.java

+97
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
import java.nio.file.LinkOption;
99
import java.nio.file.NoSuchFileException;
1010
import java.nio.file.Path;
11+
import java.nio.file.StandardOpenOption;
1112
import java.nio.file.attribute.PosixFilePermission;
1213
import java.nio.file.attribute.PosixFilePermissions;
14+
import java.util.ArrayList;
15+
import java.util.List;
1316
import java.util.Set;
1417

18+
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
19+
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
20+
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
1521
import org.junit.jupiter.api.Test;
1622
import org.junit.jupiter.api.io.TempDir;
1723

@@ -579,4 +585,95 @@ public void testGeneratePermissionString() {
579585

580586
}
581587

588+
/**
589+
* Tests if extract was called with disabled extract param, the archive will be moved.
590+
*
591+
* @param tempDir temporary directory to use.
592+
*/
593+
@Test
594+
public void testDisabledExtractMovesArchive(@TempDir Path tempDir) {
595+
// arrange
596+
IdeContext context = IdeTestContextMock.get();
597+
FileAccessImpl fileAccess = new FileAccessImpl(context);
598+
Path downloadArchive = tempDir.resolve("downloaded.zip");
599+
fileAccess.touch(downloadArchive);
600+
Path installationPath = tempDir.resolve("installation");
601+
Path targetPath = installationPath.resolve("downloaded.zip");
602+
boolean extract = false;
603+
// act
604+
fileAccess.extract(downloadArchive, installationPath, this::postExtract, extract);
605+
// assert
606+
assertThat(targetPath).exists();
607+
}
608+
609+
/**
610+
* Tests if a tgz archive with a sub folder can be extracted to a target folder properly.
611+
*
612+
* @param tempDir temporary directory to use.
613+
* @throws IOException when a file could not be created.
614+
*/
615+
@Test
616+
public void testExtractTgzArchive(@TempDir Path tempDir) throws IOException {
617+
// arrange
618+
IdeContext context = IdeTestContextMock.get();
619+
FileAccessImpl fileAccess = new FileAccessImpl(context);
620+
Path downloadedTgz = tempDir.resolve("downloaded.tgz");
621+
fileAccess.touch(downloadedTgz);
622+
try (GzipCompressorOutputStream gzipOut = new GzipCompressorOutputStream(Files.newOutputStream(downloadedTgz, StandardOpenOption.WRITE));
623+
TarArchiveOutputStream tarOut = new TarArchiveOutputStream(gzipOut)) {
624+
625+
// Create a subfolder entry
626+
TarArchiveEntry subfolderEntry = new TarArchiveEntry("subfolder/");
627+
subfolderEntry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
628+
tarOut.putArchiveEntry(subfolderEntry);
629+
tarOut.closeArchiveEntry();
630+
631+
// Add a file to the subfolder
632+
TarArchiveEntry fileEntry = new TarArchiveEntry("subfolder/testfile2.txt");
633+
fileEntry.setSize(12);
634+
tarOut.putArchiveEntry(fileEntry);
635+
tarOut.write("Hello World2".getBytes());
636+
tarOut.closeArchiveEntry();
637+
638+
// create a file in the root of the archive
639+
TarArchiveEntry entry = new TarArchiveEntry("testfile.txt");
640+
entry.setSize(11);
641+
tarOut.putArchiveEntry(entry);
642+
tarOut.write("Hello World".getBytes());
643+
tarOut.closeArchiveEntry();
644+
}
645+
Path installationPath = tempDir.resolve("installation");
646+
// act
647+
fileAccess.extractTar(downloadedTgz, installationPath, TarCompression.GZ);
648+
// assert
649+
assertThat(installationPath.resolve("testfile.txt")).exists();
650+
assertThat(installationPath.resolve("subfolder").resolve("testfile2.txt")).exists();
651+
}
652+
653+
/**
654+
* Tests if a file can be found within a list of folders.
655+
*
656+
* @param tempDir temporary directory to use.
657+
*/
658+
@Test
659+
public void testFindExistingFileInFolders(@TempDir Path tempDir) {
660+
IdeContext context = IdeTestContextMock.get();
661+
FileAccessImpl fileAccess = new FileAccessImpl(context);
662+
Path subfolder1 = tempDir.resolve("subfolder1");
663+
fileAccess.mkdirs(subfolder1);
664+
fileAccess.touch(subfolder1.resolve("testfile"));
665+
Path subfolder2 = tempDir.resolve("subfolder2");
666+
fileAccess.mkdirs(subfolder2);
667+
fileAccess.touch(subfolder2.resolve("targetfile"));
668+
List<Path> pathList = new ArrayList<>();
669+
pathList.add(subfolder1);
670+
pathList.add(subfolder2);
671+
Path foundFile = fileAccess.findExistingFile("targetfile", pathList);
672+
assertThat(foundFile).exists();
673+
}
674+
675+
private void postExtract(Path path) {
676+
}
677+
678+
582679
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.devonfw.tools.ide.os;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
9+
import com.devonfw.tools.ide.context.AbstractIdeTestContext;
10+
import com.devonfw.tools.ide.context.IdeSlf4jContext;
11+
12+
/**
13+
* Tests for {@link WindowsHelperImpl}.
14+
*/
15+
public class WindowsHelperImplTest extends AbstractIdeContextTest {
16+
17+
/**
18+
* Tests if the USER_PATH registry entry can be parsed properly.
19+
*/
20+
@Test
21+
public void testWindowsHelperParseRegString() {
22+
// arrange
23+
AbstractIdeTestContext context = new IdeSlf4jContext();
24+
WindowsHelperImpl helper = new WindowsHelperImpl(context);
25+
List<String> output = new ArrayList<>();
26+
output.add("");
27+
output.add("HKEY_CURRENT_USER\\Environment");
28+
output.add(" PATH REG_SZ D:\\projects\\_ide\\installation\\bin;");
29+
output.add("");
30+
// act
31+
String regString = helper.retrieveRegString("PATH", output);
32+
// assert
33+
assertThat(regString).isEqualTo("D:\\projects\\_ide\\installation\\bin;");
34+
}
35+
36+
/**
37+
* Tests if an empty list of outputs will result in null.
38+
*/
39+
@Test
40+
public void testWindowsHelperParseEmptyRegStringReturnsNull() {
41+
// arrange
42+
AbstractIdeTestContext context = new IdeSlf4jContext();
43+
WindowsHelperImpl helper = new WindowsHelperImpl(context);
44+
List<String> output = new ArrayList<>();
45+
// act
46+
String regString = helper.retrieveRegString("PATH", output);
47+
// assert
48+
assertThat(regString).isNull();
49+
}
50+
51+
}

0 commit comments

Comments
 (0)