Skip to content

Commit

Permalink
Merge branch 'main' into feature/439-refactor-tool-dependencies-and-t…
Browse files Browse the repository at this point in the history
…omcat
  • Loading branch information
jan-vcapgemini authored Aug 7, 2024
2 parents c5286e7 + 86e258c commit 8513f9f
Show file tree
Hide file tree
Showing 36 changed files with 583 additions and 188 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/check-for-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- cron: '0 2 * * *'

jobs:
# Checks if new commits since 24 hours of the last call of this workflow were found and adjusts the GITHUB_OUTPUT accordingly
verify_commit:
runs-on: ubuntu-latest
outputs:
Expand All @@ -15,11 +16,12 @@ jobs:
- id: verify_commit
run: |
if git log --since='24 hours ago' --oneline | grep '.'; then
echo "::set-output name=RUN_BUILD::true"
echo "RUN_BUILD=true" >> $GITHUB_OUTPUT
else
echo "::set-output name=RUN_BUILD::false"
echo "RUN_BUILD=false" >> $GITHUB_OUTPUT
fi
# Starts nightly_build workflow when new commits were found
trigger_build:
runs-on: ubuntu-latest
needs: verify_commit
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,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 -Pdeploy deploy

check_status:
runs-on: ubuntu-latest
steps:
- name: Check last workflow status
id: check_status
run: |
workflow_filename="nightly-build.yml"
last_workflow=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/$workflow_filename/runs?per_page=1" | jq -r '.workflow_runs[0]')
conclusion=$(echo $last_workflow | jq -r '.conclusion')
echo "conclusion=$conclusion" >> $GITHUB_ENV
- name: Print and handle the status
run: |
echo "The status of the last workflow run is: ${{ env.conclusion }}"
if [ "${{ env.conclusion }}" != "success" ]; then
echo "The last workflow did not succeed. Failing this workflow."
exit 1
else
echo "The last workflow succeeded. This workflow will succeed."
fi
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.devonfw.tools.ide.commandlet;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
import com.devonfw.tools.ide.environment.VariableLine;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
import com.devonfw.tools.ide.property.FlagProperty;
Expand Down Expand Up @@ -50,32 +53,51 @@ public boolean isProcessableOutput() {
@Override
public void run() {

boolean winCmd = false;
WindowsPathSyntax pathSyntax = null;
if (this.context.getSystemInfo().isWindows()) {
if (this.bash.isTrue()) {
pathSyntax = WindowsPathSyntax.MSYS;
} else {
winCmd = true;
pathSyntax = WindowsPathSyntax.WINDOWS;
}
}
((AbstractIdeContext) this.context).setPathSyntax(pathSyntax);
Collection<VariableLine> variables = this.context.getVariables().collectVariables();
List<VariableLine> variables = this.context.getVariables().collectVariables();
if (this.context.debug().isEnabled()) {
for (String source : variables.stream().map(VariableLine::getSource).collect(Collectors.toSet())) {
this.context.debug("from {}:", source);
for (VariableLine line : variables) {
if (line.getSource().equals(source)) {
Map<EnvironmentVariablesType, List<VariableLine>> type2lines = variables.stream().collect(Collectors.groupingBy(l -> l.getSource().type()));
for (EnvironmentVariablesType type : EnvironmentVariablesType.values()) {
List<VariableLine> lines = type2lines.get(type);
if (lines != null) {
boolean sourcePrinted = false;
sortVariables(lines);
for (VariableLine line : lines) {
if (!sourcePrinted) {
this.context.debug("from {}:", line.getSource());
sourcePrinted = true;
}
printEnvLine(line);
}
}
}
} else {
sortVariables(variables);
for (VariableLine line : variables) {
printEnvLine(line);
if (winCmd) {
// MS-Dos (aka CMD) has no concept of exported variables
this.context.info(line.getName() + "=" + line.getValue() + "");
} else {
printEnvLine(line);
}
}
}
}

private static void sortVariables(List<VariableLine> lines) {
Collections.sort(lines, (c1, c2) -> c1.getName().compareTo(c2.getName()));
}

private void printEnvLine(VariableLine line) {
String lineValue = line.getValue();
lineValue = "\"" + lineValue + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public void run() {
if (installedVersion == null) {
this.context.info("No installation of tool {} was found.", commandlet.getName());
toolInstallInfo(commandlet.getName(), configuredVersion);
} else {
this.context.info(installedVersion.toString());
}
this.context.info(installedVersion.toString());

} else if (!this.installed.isTrue() && this.configured.isTrue()) {// get configured version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ private static String getTool(Path path, Path ideRoot) {
return null;
}
if (path.startsWith(ideRoot)) {
int i = ideRoot.getNameCount();
if (path.getNameCount() > i) {
return path.getName(i).toString();
Path relativized = ideRoot.relativize(path);
int count = relativized.getNameCount();
if (count >= 3) {
if (relativized.getName(1).toString().equals("software")) {
return relativized.getName(2).toString();
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public boolean isMock() {
return false;
}

private SystemPath computeSystemPath() {
protected SystemPath computeSystemPath() {

return new SystemPath(this);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ private Path getParentPath(Path dir) {

private EnvironmentVariables createVariables() {

AbstractEnvironmentVariables system = EnvironmentVariables.ofSystem(this);
AbstractEnvironmentVariables system = createSystemVariables();
AbstractEnvironmentVariables user = extendVariables(system, this.userHomeIde, EnvironmentVariablesType.USER);
AbstractEnvironmentVariables settings = extendVariables(user, this.settingsPath, EnvironmentVariablesType.SETTINGS);
// TODO should we keep this workspace properties? Was this feature ever used?
Expand All @@ -361,7 +361,12 @@ private EnvironmentVariables createVariables() {
return conf.resolved();
}

private AbstractEnvironmentVariables extendVariables(AbstractEnvironmentVariables envVariables, Path propertiesPath, EnvironmentVariablesType type) {
protected AbstractEnvironmentVariables createSystemVariables() {

return EnvironmentVariables.ofSystem(this);
}

protected AbstractEnvironmentVariables extendVariables(AbstractEnvironmentVariables envVariables, Path propertiesPath, EnvironmentVariablesType type) {

Path propertiesFile = null;
if (propertiesPath == null) {
Expand Down
41 changes: 33 additions & 8 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,25 @@ default void requireOnline(String purpose) {
*/
Path getSettingsPath();

/**
* @return the {@link Path} to the templates folder inside the {@link #getSettingsPath() settings}. The relative directory structure in this templates folder
* is to be applied to {@link #getIdeHome() IDE_HOME} when the project is set up.
*/
default Path getSettingsTemplatePath() {
Path settingsFolder = getSettingsPath();
Path templatesFolder = settingsFolder.resolve(IdeContext.FOLDER_TEMPLATES);
if (!Files.isDirectory(templatesFolder)) {
Path templatesFolderLegacy = settingsFolder.resolve(IdeContext.FOLDER_LEGACY_TEMPLATES);
if (Files.isDirectory(templatesFolderLegacy)) {
templatesFolder = templatesFolderLegacy;
} else {
warning("No templates found in settings git repo neither in {} nor in {} - configuration broken", templatesFolder, templatesFolderLegacy);
return null;
}
}
return templatesFolder;
}

/**
* @return the {@link Path} to the {@code conf} folder with instance specific tool configurations and the
* {@link EnvironmentVariablesType#CONF user specific project configuration}.
Expand Down Expand Up @@ -439,13 +458,11 @@ default String getMavenArgs() {
if (getIdeHome() == null) {
return null;
}
Path confFolder = getConfPath();
Path mvnSettingsFile = confFolder.resolve(Mvn.MVN_CONFIG_FOLDER).resolve(Mvn.SETTINGS_FILE);
Mvn mvn = getCommandletManager().getCommandlet(Mvn.class);
Path mavenConfFolder = mvn.getMavenConfFolder(false);
Path mvnSettingsFile = mavenConfFolder.resolve(Mvn.SETTINGS_FILE);
if (!Files.exists(mvnSettingsFile)) {
mvnSettingsFile = confFolder.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER).resolve(Mvn.SETTINGS_FILE);
if (!Files.exists(mvnSettingsFile)) {
return null;
}
return null;
}
String settingsPath;
WindowsPathSyntax pathSyntax = getPathSyntax();
Expand All @@ -460,10 +477,18 @@ default String getMavenArgs() {
/**
* @return the String value for the variable M2_REPO, or null if called outside an IDEasy installation.
*/
default Path getMavenRepoEnvVariable() {
default Path getMavenRepository() {

if (getIdeHome() != null) {
return getConfPath().resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER).resolve("repository");
Path confPath = getConfPath();
Path m2Folder = confPath.resolve(Mvn.MVN_CONFIG_FOLDER);
if (!Files.isDirectory(m2Folder)) {
Path m2LegacyFolder = confPath.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
if (Files.isDirectory(m2LegacyFolder)) {
m2Folder = m2LegacyFolder;
}
}
return m2Folder.resolve("repository");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -39,7 +38,7 @@ public abstract class AbstractEnvironmentVariables implements EnvironmentVariabl
*/
protected final IdeContext context;

private String source;
private VariableSource source;

/**
* The constructor.
Expand Down Expand Up @@ -74,14 +73,10 @@ public Path getPropertiesFilePath() {
}

@Override
public String getSource() {
public VariableSource getSource() {

if (this.source == null) {
this.source = getType().toString();
Path propertiesPath = getPropertiesFilePath();
if (propertiesPath != null) {
this.source = this.source + "@" + propertiesPath;
}
this.source = new VariableSource(getType(), getPropertiesFilePath());
}
return this.source;
}
Expand All @@ -101,44 +96,46 @@ protected boolean isExported(String name) {
}

@Override
public final Collection<VariableLine> collectVariables() {
public final List<VariableLine> collectVariables() {

return collectVariables(false);
}

@Override
public final Collection<VariableLine> collectExportedVariables() {
public final List<VariableLine> collectExportedVariables() {

return collectVariables(true);
}

private final Collection<VariableLine> collectVariables(boolean onlyExported) {
private final List<VariableLine> collectVariables(boolean onlyExported) {

Map<String, String> variableNames = new HashMap<>();
collectVariables(variableNames);
List<VariableLine> variables = new ArrayList<>(variableNames.size());
for (String name : variableNames.keySet()) {
boolean export = isExported(name);
if (!onlyExported || export) {
String value = get(name, false);
if (value != null) {
variables.add(VariableLine.of(export, name, value, variableNames.get(name)));
}
}
}
return variables;
Map<String, VariableLine> variables = new HashMap<>();
collectVariables(variables, onlyExported, this);
return new ArrayList<>(variables.values());
}

/**
* @param variables the {@link Map} where to add the names of the variables defined here as keys, and their corresponding source as value.
*/
protected void collectVariables(Map<String, String> variables) {
protected void collectVariables(Map<String, VariableLine> variables, boolean onlyExported, AbstractEnvironmentVariables resolver) {

if (this.parent != null) {
this.parent.collectVariables(variables);
this.parent.collectVariables(variables, onlyExported, resolver);
}
}

protected VariableLine createVariableLine(String name, boolean onlyExported, AbstractEnvironmentVariables resolver) {

boolean export = resolver.isExported(name);
if (!onlyExported || export) {
String value = resolver.get(name, false);
if (value != null) {
return VariableLine.of(export, name, value, getSource());
}
}
return null;
}

/**
* @param propertiesFilePath the {@link #getPropertiesFilePath() propertiesFilePath} of the child {@link EnvironmentVariables}.
* @param type the {@link #getType() type}.
Expand Down Expand Up @@ -326,7 +323,7 @@ public String inverseResolve(String string, Object src, VariableSyntax syntax) {
@Override
public String toString() {

return getSource();
return getSource().toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import com.devonfw.tools.ide.context.IdeContext;
Expand Down Expand Up @@ -126,9 +127,9 @@ default EnvironmentVariables getByType(EnvironmentVariablesType type) {
Path getPropertiesFilePath();

/**
* @return the source identifier describing this {@link EnvironmentVariables} for debugging.
* @return the {@link VariableSource} of this {@link EnvironmentVariables}.
*/
String getSource();
VariableSource getSource();

/**
* @return the parent {@link EnvironmentVariables} to inherit from or {@code null} if this is the {@link EnvironmentVariablesType#SYSTEM root}
Expand Down Expand Up @@ -180,13 +181,13 @@ default EnvironmentVariables findVariable(String name) {
/**
* @return the {@link Collection} of the {@link VariableLine}s defined by this {@link EnvironmentVariables} including inheritance.
*/
Collection<VariableLine> collectVariables();
List<VariableLine> collectVariables();

/**
* @return the {@link Collection} of the {@link VariableLine#isExport() exported} {@link VariableLine}s defined by this {@link EnvironmentVariables} including
* inheritance.
*/
Collection<VariableLine> collectExportedVariables();
List<VariableLine> collectExportedVariables();

/**
* @param string the {@link String} that potentially contains variables in {@link VariableSyntax#CURLY} ("${«variable«}"). Those will be resolved by this
Expand Down
Loading

0 comments on commit 8513f9f

Please sign in to comment.