Skip to content

Commit

Permalink
Merge branch 'main' into xml-merger
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Jun 20, 2024
2 parents a2190a2 + fa37227 commit 6fc5b3c
Show file tree
Hide file tree
Showing 37 changed files with 702 additions and 327 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: graalvm/setup-graalvm@v1
with:
java-version: '21.0.2'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'

- name: Build native images with nativ maven plugin and extract in tar.gz
shell: bash
run: |
mvn -B -ntp -Pnative -DskipTests=true package
mvn -B -ntp -Pnative -DskipTests=true package -pl cli
- uses: actions/upload-artifact@v3
with:
name: natives
Expand Down Expand Up @@ -72,17 +69,3 @@ jobs:
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 -Dgpg.skip=true -Dstyle.color=always -B -ntp -P deploy deploy

cancel:
name: Cancel this workflow
runs-on: ubuntu-latest
needs: verify_commit
if: ${{ needs.verify_commit.outputs.RUN_BUILD == 'false' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
RUN_ID: ${{ github.run_id }}
steps:
- run: |
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/cancel"
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Drevision=2024.06.001-alpha-SNAPSHOT
-Drevision=2024.06.002-alpha-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devonfw.tools.ide.context.GitContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.StringProperty;
import com.devonfw.tools.ide.repo.CustomTool;
import com.devonfw.tools.ide.step.Step;
Expand All @@ -23,6 +24,9 @@ public abstract class AbstractUpdateCommandlet extends Commandlet {
/** {@link StringProperty} for the settings repository URL. */
protected final StringProperty settingsRepo;

/** {@link FlagProperty} for skipping installation/updating of tools */
protected final FlagProperty skipTools;

/**
* The constructor.
*
Expand All @@ -31,15 +35,27 @@ public abstract class AbstractUpdateCommandlet extends Commandlet {
public AbstractUpdateCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
this.skipTools = add(new FlagProperty("--skip-tools", false, null));
this.settingsRepo = new StringProperty("", false, "settingsRepository");
}

@Override
public void run() {

updateSettings();
Path templatesFolder = this.context.getSettingsPath().resolve(IdeContext.FOLDER_TEMPLATES);
updateConf();

if (skipTools.isTrue()) {
this.context.info("Skipping installation/update of tools as specified by the user.");
} else {
updateSoftware();
}
}

private void updateConf() {

Path templatesFolder = this.context.getSettingsPath().resolve(IdeContext.FOLDER_TEMPLATES);
if (!Files.exists(templatesFolder)) {
Path legacyTemplatesFolder = this.context.getSettingsPath().resolve(IdeContext.FOLDER_LEGACY_TEMPLATES);
if (Files.exists(legacyTemplatesFolder)) {
Expand All @@ -57,7 +73,6 @@ public void run() {
} finally {
step.end();
}
updateSoftware();
}

private void setupConf(Path template, Path conf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ public List<Property<?>> getValues() {
}

/**
* @param nameOrAlias the potential {@link Property#getName() name} or {@link Property#getAlias() alias} of the requested {@link Property}.
* Clear the set values on all properties of the {@link Commandlet#propertiesList}
*/
public void clearProperties() {

for (Property<?> property : this.propertiesList) {
property.clearValue();
}
}

/**
* @param nameOrAlias the potential {@link Property#getName() name} or {@link Property#getAlias() alias} of the
* requested {@link Property}.
* @return the requested {@link Property property} or {@code null} if not found.
*/
public Property<?> getOption(String nameOrAlias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.property.StringProperty;

import java.nio.file.Path;
Expand All @@ -11,8 +12,12 @@
*/
public class CreateCommandlet extends AbstractUpdateCommandlet {

/** {@link StringProperty} for the name of the new project */
public final StringProperty newProject;

/** {@link FlagProperty} for skipping the setup of git repositories */
public final FlagProperty skipRepositories;

/**
* The constructor.
*
Expand All @@ -21,8 +26,8 @@ public class CreateCommandlet extends AbstractUpdateCommandlet {
public CreateCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
newProject = add(new StringProperty("", true, "project"));
this.skipRepositories = add(new FlagProperty("--skip-repositories", false, null));
add(this.settingsRepo);
}

Expand Down Expand Up @@ -54,7 +59,11 @@ public void run() {
initializeProject(newProjectPath);
this.context.setIdeHome(newProjectPath);
super.run();
updateRepositories();
if (this.skipRepositories.isTrue()) {
this.context.info("Skipping the cloning of project repositories as specified by the user.");
} else {
updateRepositories();
}
this.context.success("Successfully created new project '{}'.", newProjectName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.commandlet;

import java.util.Collection;

import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.VariableLine;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
import com.devonfw.tools.ide.property.FlagProperty;
import com.devonfw.tools.ide.variable.IdeVariables;

import java.util.Collection;

/**
* {@link Commandlet} to print the environment variables.
Expand Down Expand Up @@ -49,46 +49,22 @@ public boolean isSuppressStepSuccess() {
@Override
public void run() {

WindowsPathSyntax pathSyntax = null;
if (this.context.getSystemInfo().isWindows()) {
if (this.bash.isTrue()) {
pathSyntax = WindowsPathSyntax.MSYS;
} else {
pathSyntax = WindowsPathSyntax.WINDOWS;
}
}
((AbstractIdeContext) this.context).setPathSyntax(pathSyntax);
Collection<VariableLine> variables = this.context.getVariables().collectVariables();
for (VariableLine line : variables) {
if (this.context.getSystemInfo().isWindows()) {
line = normalizeWindowsValue(line);
}
String lineValue = line.getValue();
if (IdeVariables.PATH.getName().equals(line.getName())) {
lineValue = this.context.getPath().toString(this.bash.isTrue());
}
lineValue = "\"" + lineValue + "\"";
line = line.withValue(lineValue);
this.context.info(line.toString());
}
}

VariableLine normalizeWindowsValue(VariableLine line) {

String value = line.getValue();
String normalized = normalizeWindowsValue(value);
if (normalized != value) {
line = line.withValue(normalized);
}
return line;
}

String normalizeWindowsValue(String value) {

WindowsPathSyntax pathSyntax;
if (this.bash.isTrue()) {
pathSyntax = WindowsPathSyntax.MSYS;
} else {
pathSyntax = WindowsPathSyntax.WINDOWS;
}
String drive = WindowsPathSyntax.WINDOWS.getDrive(value);
if (drive == null) {
drive = WindowsPathSyntax.MSYS.getDrive(value);
}
if (drive != null) {
value = pathSyntax.replaceDrive(value, drive);
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public void run() {
collectOptions(options, cmd, bundle);
}
options.print();
if (cmd == null) {
this.context.info("");
this.context.info(bundle.getDetail(this.context.getCommandletManager().getCommandlet(HelpCommandlet.class)));
}
}

private void printCommandletHelp(NlsBundle bundle, Commandlet cmd) {
Expand Down Expand Up @@ -115,6 +119,7 @@ private void printCommandletHelp(NlsBundle bundle, Commandlet cmd) {
}
this.context.info(usage.toString());
this.context.info(bundle.get(cmd));
this.context.info(bundle.getDetail(cmd));
this.context.info("");
this.context.info(bundle.get("values"));
values.print();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class UpdateCommandlet extends AbstractUpdateCommandlet {
public UpdateCommandlet(IdeContext context) {

super(context);
addKeyword(getName());
}

@Override
Expand Down
61 changes: 23 additions & 38 deletions cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.os.SystemInfoImpl;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
import com.devonfw.tools.ide.variable.IdeVariables;

import java.io.File;
Expand Down Expand Up @@ -30,6 +31,8 @@
*/
public class SystemPath {

private static final Pattern REGEX_WINDOWS_PATH = Pattern.compile("([a-zA-Z]:)?(\\\\[a-zA-Z0-9\\s_.-]+)+\\\\?");

private final String envPath;

private final char pathSeparator;
Expand Down Expand Up @@ -66,9 +69,9 @@ public SystemPath(IdeContext context, String envPath) {
/**
* The constructor.
*
* @param context {@link IdeContext} for the output of information.
* @param envPath the value of the PATH variable.
* @param ideRoot the {@link IdeContext#getIdeRoot() IDE_ROOT}.
* @param context {@link IdeContext} for the output of information.
* @param envPath the value of the PATH variable.
* @param ideRoot the {@link IdeContext#getIdeRoot() IDE_ROOT}.
* @param softwarePath the {@link IdeContext#getSoftwarePath() software path}.
*/
public SystemPath(IdeContext context, String envPath, Path ideRoot, Path softwarePath) {
Expand All @@ -79,10 +82,10 @@ public SystemPath(IdeContext context, String envPath, Path ideRoot, Path softwar
/**
* The constructor.
*
* @param context {@link IdeContext} for the output of information.
* @param envPath the value of the PATH variable.
* @param ideRoot the {@link IdeContext#getIdeRoot() IDE_ROOT}.
* @param softwarePath the {@link IdeContext#getSoftwarePath() software path}.
* @param context {@link IdeContext} for the output of information.
* @param envPath the value of the PATH variable.
* @param ideRoot the {@link IdeContext#getIdeRoot() IDE_ROOT}.
* @param softwarePath the {@link IdeContext#getSoftwarePath() software path}.
* @param pathSeparator the path separator char (';' for Windows and ':' otherwise).
*/
public SystemPath(IdeContext context, String envPath, Path ideRoot, Path softwarePath, char pathSeparator) {
Expand Down Expand Up @@ -219,62 +222,45 @@ public void setPath(String tool, Path path) {
@Override
public String toString() {

return toString(false);
return toString(null);
}

/**
* @param bash - {@code true} to convert the PATH to bash syntax (relevant for git-bash or cygwin on windows),
* {@code false} otherwise.
* @param pathSyntax the {@link WindowsPathSyntax} to convert to.
* @return this {@link SystemPath} as {@link String} for the PATH environment variable.
*/
public String toString(boolean bash) {
public String toString(WindowsPathSyntax pathSyntax) {

char separator;
if (bash) {
if (pathSyntax == WindowsPathSyntax.MSYS) {
separator = ':';
} else {
separator = this.pathSeparator;
}
StringBuilder sb = new StringBuilder(this.envPath.length() + 128);
for (Path path : this.tool2pathMap.values()) {
appendPath(path, sb, separator, bash);
appendPath(path, sb, separator, pathSyntax);
}
for (Path path : this.paths) {
appendPath(path, sb, separator, bash);
appendPath(path, sb, separator, pathSyntax);
}
return sb.toString();
}

private static void appendPath(Path path, StringBuilder sb, char separator, boolean bash) {
private static void appendPath(Path path, StringBuilder sb, char separator, WindowsPathSyntax pathSyntax) {

if (sb.length() > 0) {
sb.append(separator);
}
String pathString = path.toString();
if (bash && (pathString.length() > 3) && (pathString.charAt(1) == ':')) {
pathString = convertWindowsPathToUnixPath(pathString);
String pathString;
if (pathSyntax == null) {
pathString = path.toString();
} else {
pathString = pathSyntax.format(path);
}
sb.append(pathString);
}

/**
* Method to convert a valid Windows path string representation to its corresponding one in Unix format.
*
* @param pathString The Windows path string to convert.
* @return The converted Unix path string.
*/
public static String convertWindowsPathToUnixPath(String pathString) {

char slash = pathString.charAt(2);
if ((slash == '\\') || (slash == '/')) {
char drive = Character.toLowerCase(pathString.charAt(0));
if ((drive >= 'a') && (drive <= 'z')) {
pathString = "/" + drive + pathString.substring(2).replace('\\', '/');
}
}
return pathString;
}

/**
* Method to validate if a given path string is a Windows path or not
*
Expand All @@ -283,7 +269,6 @@ public static String convertWindowsPathToUnixPath(String pathString) {
*/
public static boolean isValidWindowsPath(String pathString) {

String windowsFilePathRegEx = "([a-zA-Z]:)?(\\\\[a-zA-Z0-9\\s_.-]+)+\\\\?";
return Pattern.matches(windowsFilePathRegEx, pathString);
return REGEX_WINDOWS_PATH.matcher(pathString).matches();
}
}
Loading

0 comments on commit 6fc5b3c

Please sign in to comment.