Skip to content

Commit

Permalink
Merge branch 'main' into devonfw#420-create-win-installer
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Feb 27, 2025
2 parents 3c78781 + 2360c2f commit d292a7f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Drevision=2025.02.002-beta-SNAPSHOT
-Drevision=2025.02.002-SNAPSHOT
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.3</version>
<version>1.5.16</version>
<!--optional>true</optional-->
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void createStartScript(String ide, String workspace) {
scriptContent = "#!/usr/bin/env bash\n"
+ "cd \"$(dirname \"$0\")\"\n"
+ "cd workspaces/" + workspace + "\n"
+ "ide " + ide + "\n";
+ "ideasy " + ide + "\n";
}
FileAccess fileAccess = this.context.getFileAccess();
fileAccess.writeFileContent(scriptContent, scriptPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.devonfw.tools.ide.commandlet;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.function.Function;
Expand All @@ -10,6 +8,7 @@
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesPropertiesFile;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.merge.DirectoryMerger;
import com.devonfw.tools.ide.tool.mvn.Mvn;
import com.devonfw.tools.ide.tool.repository.CustomToolsJson;
Expand Down Expand Up @@ -55,16 +54,16 @@ private void updateLegacyFolders() {
}

private void updateLegacyFolder(Path folder, String legacyName, String newName) {

FileAccess fileAccess = this.context.getFileAccess();
Path legacyFolder = folder.resolve(legacyName);
Path newFolder = folder.resolve(newName);
if (Files.isDirectory(legacyFolder)) {
if (fileAccess.isExpectedFolder(legacyFolder)) {
try {
if (!Files.exists(newFolder)) {
Files.move(legacyFolder, newFolder, StandardCopyOption.REPLACE_EXISTING);
if (!fileAccess.exists(newFolder)) {
fileAccess.move(legacyFolder, newFolder, StandardCopyOption.REPLACE_EXISTING);
this.context.success("Successfully renamed folder '{}' to '{}' in {}.", legacyName, newName, folder);
}
} catch (IOException e) {
} catch (IllegalStateException e) {
this.context.error(e, "Error renaming folder {} to {} in {}", legacyName, newName, folder);
}
}
Expand All @@ -73,15 +72,16 @@ private void updateLegacyFolder(Path folder, String legacyName, String newName)
private void updateWorkspaceTemplates() {
this.context.info("Updating workspace templates (replace legacy variables and change variable syntax)...");

FileAccess fileAccess = this.context.getFileAccess();
DirectoryMerger merger = this.context.getWorkspaceMerger();
Path settingsDir = this.context.getSettingsPath();
Path workspaceDir = settingsDir.resolve(IdeContext.FOLDER_WORKSPACE);
if (Files.isDirectory(workspaceDir)) {
if (fileAccess.isExpectedFolder(workspaceDir)) {
merger.upgrade(workspaceDir);
}
this.context.getFileAccess().listChildrenMapped(settingsDir, child -> {
fileAccess.listChildrenMapped(settingsDir, child -> {
Path childWorkspaceDir = child.resolve(IdeContext.FOLDER_WORKSPACE);
if (Files.isDirectory(childWorkspaceDir)) {
if (fileAccess.isExpectedFolder(childWorkspaceDir)) {
merger.upgrade(childWorkspaceDir);
}
return null;
Expand All @@ -106,8 +106,9 @@ private void updateProperties() {
}
environmentVariables = environmentVariables.getParent();
}
FileAccess fileAccess = this.context.getFileAccess();
Path templatePropertiesDir = this.context.getSettingsTemplatePath().resolve(IdeContext.FOLDER_CONF);
if (Files.exists(templatePropertiesDir)) {
if (fileAccess.exists(templatePropertiesDir)) {
EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.CONF,
templatePropertiesDir, null, this.context);
updateProperties(environmentVariablesProperties);
Expand Down
21 changes: 12 additions & 9 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,21 +609,24 @@ default String getMavenArgs() {
*/
default Path getMavenConfigurationFolder() {

if (getIdeHome() != null) {
Path confPath = getConfPath();
Path m2Folder = confPath.resolve(Mvn.MVN_CONFIG_FOLDER);
if (!Files.isDirectory(m2Folder)) {
Path confPath = getConfPath();
Path mvnConfFolder = null;
if (confPath != null) {
mvnConfFolder = confPath.resolve(Mvn.MVN_CONFIG_FOLDER);
if (!Files.isDirectory(mvnConfFolder)) {
Path m2LegacyFolder = confPath.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
if (Files.isDirectory(m2LegacyFolder)) {
m2Folder = m2LegacyFolder;
mvnConfFolder = m2LegacyFolder;
} else {
// fallback to USER_HOME/.m2 folder
m2Folder = getUserHome().resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
mvnConfFolder = null; // see fallback below
}
}
return m2Folder;
}
return null;
if (mvnConfFolder == null) {
// fallback to USER_HOME/.m2 folder
mvnConfFolder = getUserHome().resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
}
return mvnConfFolder;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Reader;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.time.Duration;
import java.util.List;
Expand Down Expand Up @@ -43,6 +44,12 @@ public interface FileAccess {
*/
boolean isFile(Path file);

/**
* @param file the {@link Path} to check.
* @return {@code true} if the given {@code file} points to an existing file, {@code false} otherwise (the given {@link Path} does not exist
*/
boolean exists(Path file);

/**
* @param folder the {@link Path} to check.
* @return {@code true} if the given {@code folder} points to an existing directory, {@code false} otherwise (a warning is logged in this case).
Expand All @@ -67,8 +74,9 @@ public interface FileAccess {
/**
* @param source the source {@link Path file or folder} to move.
* @param targetDir the {@link Path} with the directory to move {@code source} into.
* @param copyOptions the {@link java.nio.file.CopyOption} which specify how the move should be done
*/
void move(Path source, Path targetDir);
void move(Path source, Path targetDir, StandardCopyOption... copyOptions);

/**
* Creates a symbolic link. If the given {@code targetLink} already exists and is a symbolic link or a Windows junction, it will be replaced. In case of
Expand Down
10 changes: 8 additions & 2 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.PosixFilePermission;
Expand Down Expand Up @@ -219,6 +220,11 @@ public boolean isFile(Path file) {
return true;
}

@Override
public boolean exists(Path file) {
return Files.exists(file);
}

@Override
public boolean isExpectedFolder(Path folder) {

Expand Down Expand Up @@ -300,11 +306,11 @@ private static Path appendParentPath(Path path, Path parent, int max) {
}

@Override
public void move(Path source, Path targetDir) {
public void move(Path source, Path targetDir, StandardCopyOption... copyOptions) {

this.context.trace("Moving {} to {}", source, targetDir);
try {
Files.move(source, targetDir);
Files.move(source, targetDir, copyOptions);
} catch (IOException e) {
String fileType = Files.isSymbolicLink(source) ? "symlink" : isJunction(source) ? "junction" : Files.isDirectory(source) ? "directory" : "file";
String message = "Failed to move " + fileType + ": " + source + " to " + targetDir + ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public ProcessResult run(ProcessMode processMode) {
}
}
this.arguments.clear();
return new ProcessResultImpl("git", command.toString(), exitCode, this.outputMessages);
List<OutputMessage> outputMessagesCopy = List.copyOf(this.outputMessages);
this.outputMessages.clear();
return new ProcessResultImpl("git", command.toString(), exitCode, outputMessagesCopy);
}

}

0 comments on commit d292a7f

Please sign in to comment.