Skip to content

Commit

Permalink
Merge branch 'devonfw:main' into feature/131-support-for-tool-depende…
Browse files Browse the repository at this point in the history
…cies
  • Loading branch information
aBega2000 authored Mar 12, 2024
2 parents 0a9b2b5 + 1cab8d4 commit 8f04879
Show file tree
Hide file tree
Showing 23 changed files with 410 additions and 197 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ jobs:
java-version: '17'
- name: Build project with Maven
run: mvn -B -ntp -Dstyle.color=always install
- name: Deploy to OSSRH nexus
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: mvn --settings .mvn/settings.xml -DskipTests=true -Darchetype.test.skip=true -Dmaven.install.skip=true -Dstyle.color=always -B -ntp deploy
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
uses: coverallsapp/[email protected]
5 changes: 3 additions & 2 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Nightly CI Build and Snapshot Release
on:
on:
workflow_dispatch:
schedule:
- cron: '0 2 * * *'

Expand Down Expand Up @@ -65,7 +66,7 @@ jobs:
- name: Make natives available and build project
run: |
mvn -B -ntp -Dstyle.color=always install
mv ./natives/* ./cli/target/
mv ./natives/* ./cli/target/package/bin/
- name: Deploy to OSSRH nexus
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
git tag -a "release/${next_version}" -m "tagged version ${next_version}"
export GPG_TTY=$TTY
mvn --settings .mvn/settings.xml -B -ntp deploy -Pdeploy -Dgpg.pin.entry.mode=loopback -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}
mv ./natives/* ./cli/target/
mv ./natives/* ./cli/target/package/bin/
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
Expand Down
95 changes: 59 additions & 36 deletions cli/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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">
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>
Expand Down Expand Up @@ -107,48 +107,71 @@
</archive>
</configuration>
</plugin>
<!-- Copy Resources -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/package</outputDirectory>
<resources>
<resource>
<directory>src/main/package</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/${project.artifactId}-linux-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>linux</classifier>
</artifact>
<artifact>
<file>target/${project.artifactId}-windows-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>windows</classifier>
</artifact>
<artifact>
<file>target/${project.artifactId}-mac-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>mac</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/${project.artifactId}-linux-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>linux</classifier>
</artifact>
<artifact>
<file>target/${project.artifactId}-windows-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>windows</classifier>
</artifact>
<artifact>
<file>target/${project.artifactId}-mac-x64.tar.gz</file>
<type>tar.gz</type>
<classifier>mac</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
Expand Down
16 changes: 2 additions & 14 deletions cli/src/main/assembly/exec.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<excludes>
<exclude>*</exclude>
<exclude>*/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./bin</outputDirectory>
<includes>
<include>${imageName}.exe</include>
<include>${imageName}</include>
</includes>
<directory>${project.build.directory}/package</directory>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.devonfw.tools.ide.tool.node.Node;
import com.devonfw.tools.ide.tool.oc.Oc;
import com.devonfw.tools.ide.tool.quarkus.Quarkus;
import com.devonfw.tools.ide.tool.sonar.Sonar;
import com.devonfw.tools.ide.tool.terraform.Terraform;
import com.devonfw.tools.ide.tool.vscode.Vscode;

Expand Down Expand Up @@ -83,6 +84,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Aws(context));
add(new Cobigen(context));
add(new Jmc(context));
add(new Sonar(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getName() {
@Override
public boolean isIdeHomeRequired() {

return false;
return true;
}

@Override
Expand Down
70 changes: 37 additions & 33 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.os.SystemInfoImpl;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.url.model.file.UrlChecksum;
import com.devonfw.tools.ide.util.DateTimeUtil;
import com.devonfw.tools.ide.util.FilenameUtil;
import com.devonfw.tools.ide.util.HexUtil;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
Expand Down Expand Up @@ -223,22 +225,41 @@ public String checksum(Path file) {
}
}

private boolean isJunction(Path path) {

if (!SystemInfoImpl.INSTANCE.isWindows()) {
return false;
}

try {
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
return attr.isOther() && attr.isDirectory();
} catch (NoSuchFileException e) {
return false; // file doesn't exist
} catch (IOException e) {
// errors in reading the attributes of the file
throw new IllegalStateException(
"An unexpected error occurred whilst checking if the file: " + path + " is a junction", e);
}
}

@Override
public void backup(Path fileOrFolder) {

if (Files.isSymbolicLink(fileOrFolder)) {
if (Files.isSymbolicLink(fileOrFolder) || isJunction(fileOrFolder)) {
delete(fileOrFolder);
return;
} else {
// fileOrFolder is a directory
Path backupPath = this.context.getIdeHome().resolve(IdeContext.FOLDER_UPDATES).resolve(IdeContext.FOLDER_BACKUPS);
LocalDateTime now = LocalDateTime.now();
String date = DateTimeUtil.formatDate(now);
String time = DateTimeUtil.formatTime(now);
Path backupDatePath = backupPath.resolve(date);
mkdirs(backupDatePath);
Path target = backupDatePath.resolve(fileOrFolder.getFileName().toString() + "_" + time);
this.context.info("Creating backup by moving {} to {}", fileOrFolder, target);
move(fileOrFolder, target);
}
Path backupPath = this.context.getIdeHome().resolve(IdeContext.FOLDER_UPDATES).resolve(IdeContext.FOLDER_BACKUPS);
LocalDateTime now = LocalDateTime.now();
String date = DateTimeUtil.formatDate(now);
String time = DateTimeUtil.formatTime(now);
Path backupDatePath = backupPath.resolve(date);
mkdirs(backupDatePath);
Path target = backupDatePath.resolve(fileOrFolder.getFileName().toString() + "_" + time);
this.context.info("Creating backup by moving {} to {}", fileOrFolder, target);
move(fileOrFolder, target);
}

@Override
Expand Down Expand Up @@ -317,31 +338,14 @@ private void copyRecursive(Path source, Path target, FileCopyMode mode) throws I
*/
private void deleteLinkIfExists(Path path) throws IOException {

boolean exists = false;
boolean isJunction = false;
if (this.context.getSystemInfo().isWindows()) {
try { // since broken junctions are not detected by Files.exists(brokenJunction)
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
exists = true;
isJunction = attr.isOther() && attr.isDirectory();
} catch (NoSuchFileException e) {
// ignore, since there is no previous file at the location, so nothing to delete
return;
}
}
exists = exists || Files.exists(path);
boolean isSymlink = exists && Files.isSymbolicLink(path);
boolean isJunction = isJunction(path); // since broken junctions are not detected by Files.exists()
boolean isSymlink = Files.exists(path) && Files.isSymbolicLink(path);

assert !(isSymlink && isJunction);

if (exists) {
if (isJunction || isSymlink) {
this.context.info("Deleting previous " + (isJunction ? "junction" : "symlink") + " at " + path);
Files.delete(path);
} else {
throw new IllegalStateException(
"The file at " + path + " was not deleted since it is not a symlink or a Windows junction");
}
if (isJunction || isSymlink) {
this.context.info("Deleting previous " + (isJunction ? "junction" : "symlink") + " at " + path);
Files.delete(path);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public void log(String message) {
String startColor = null;
if (this.colored) {
startColor = this.level.getStartColor();
this.out.append(startColor);
if (startColor != null) {
this.out.append(startColor);
}
}
this.out.append(message);
if (startColor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ private String createCommandMessage(String interpreter, String suffix) {
sb.append(interpreter);
}
int size = this.arguments.size();
if (size > 1) {
if (size > 0) {
sb.append(" with arguments");
for (int i = 1; i < size; i++) {
for (int i = 0; i < size; i++) {
String arg = this.arguments.get(i);
sb.append(" '");
sb.append(arg);
Expand Down
59 changes: 59 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/property/EnumProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.devonfw.tools.ide.property;

import java.util.Locale;

import com.devonfw.tools.ide.commandlet.Commandlet;
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
import com.devonfw.tools.ide.context.IdeContext;

/**
* {@link Property} with {@link #getValueType() value type} {@link Boolean}.
*/
public class EnumProperty<V extends Enum<V>> extends Property<V> {

private final Class<V> valueType;

/**
* The constructor.
*
* @param name the {@link #getName() property name}.
* @param required the {@link #isRequired() required flag}.
* @param alias the {@link #getAlias() property alias}.
*/
public EnumProperty(String name, boolean required, String alias, Class<V> valueType) {

super(name, required, alias, null);
this.valueType = valueType;
}

@Override
public Class<V> getValueType() {

return this.valueType;
}

@Override
public V parse(String valueAsString, IdeContext context) {

for (V enumConstant : this.valueType.getEnumConstants()) {
String name = enumConstant.name().toLowerCase(Locale.ROOT);
if (name.equals(valueAsString)) {
return enumConstant;
}
}

throw new IllegalArgumentException(String.format("Invalid Enum option: %s", valueAsString));
}

@Override
protected void completeValue(String arg, IdeContext context, Commandlet commandlet,
CompletionCandidateCollector collector) {

for (V enumConstant : this.valueType.getEnumConstants()) {
String name = enumConstant.name().toLowerCase(Locale.ROOT);
if (name.startsWith(arg)) {
collector.add(name, null, this, commandlet);
}
}
}
}
Loading

0 comments on commit 8f04879

Please sign in to comment.