Skip to content

Commit

Permalink
#727: allow fallback to edition independent dependencies.json (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Nov 4, 2024
1 parent 881c978 commit 15910e5
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public abstract class AbstractIdeContext implements IdeContext {

private String workspaceName;

private Path urlsPath;
protected Path urlsPath;

private Path tempPath;

Expand All @@ -94,7 +94,7 @@ public abstract class AbstractIdeContext implements IdeContext {

private Path toolRepositoryPath;

private Path userHome;
protected Path userHome;

private Path userHomeIde;

Expand All @@ -110,19 +110,19 @@ public abstract class AbstractIdeContext implements IdeContext {

private final CommandletManager commandletManager;

private ToolRepository defaultToolRepository;
protected ToolRepository defaultToolRepository;

private CustomToolRepository customToolRepository;

private DirectoryMerger workspaceMerger;

private UrlMetadata urlMetadata;
protected UrlMetadata urlMetadata;

private Path defaultExecutionDirectory;
protected Path defaultExecutionDirectory;

private StepImpl currentStep;

private Boolean online;
protected Boolean online;

/**
* The constructor.
Expand Down Expand Up @@ -366,14 +366,6 @@ public ToolRepository getDefaultToolRepository() {
return this.defaultToolRepository;
}

/**
* @param defaultToolRepository the new value of {@link #getDefaultToolRepository()}.
*/
protected void setDefaultToolRepository(ToolRepository defaultToolRepository) {

this.defaultToolRepository = defaultToolRepository;
}

@Override
public CustomToolRepository getCustomToolRepository() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.url.model.UrlMetadata;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;
import com.devonfw.tools.ide.url.model.file.UrlDownloadFile;
import com.devonfw.tools.ide.url.model.file.UrlDownloadFileMetadata;
import com.devonfw.tools.ide.url.model.file.json.ToolDependencies;
import com.devonfw.tools.ide.url.model.file.json.ToolDependency;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.url.model.folder.UrlTool;
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
import com.devonfw.tools.ide.version.GenericVersionRange;
import com.devonfw.tools.ide.version.VersionIdentifier;
Expand Down Expand Up @@ -55,7 +57,15 @@ protected UrlDownloadFileMetadata getMetadata(String tool, String edition, Versi
@Override
public Collection<ToolDependency> findDependencies(String tool, String edition, VersionIdentifier version) {

UrlDependencyFile dependencyFile = this.context.getUrls().getEdition(tool, edition).getDependencyFile();
return dependencyFile.getDependencies().findDependencies(version, this.context);
UrlEdition urlEdition = this.context.getUrls().getEdition(tool, edition);
ToolDependencies dependencies = urlEdition.getDependencyFile().getDependencies();
if (dependencies == ToolDependencies.getEmpty()) {
UrlTool urlTool = urlEdition.getParent();
dependencies = urlTool.getDependencyFile().getDependencies();
}
if (dependencies != ToolDependencies.getEmpty()) {
this.context.trace("Found dependencies in {}", dependencies);
}
return dependencies.findDependencies(version, this.context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.io.FileAccess;
import com.devonfw.tools.ide.io.FileCopyMode;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.process.EnvironmentContext;
import com.devonfw.tools.ide.repo.ToolRepository;
import com.devonfw.tools.ide.step.Step;
Expand Down Expand Up @@ -118,8 +117,9 @@ public final boolean install(boolean silent, EnvironmentContext environmentConte
}

private boolean toolAlreadyInstalled(boolean silent, VersionIdentifier installedVersion, Step step) {
IdeLogLevel level = silent ? IdeLogLevel.DEBUG : IdeLogLevel.INFO;
this.context.level(level).log("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
if (!silent) {
this.context.info("Version {} of tool {} is already installed", installedVersion, getToolWithEdition());
}
postInstall(false);
step.success();
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.devonfw.tools.ide.url.model.file;

import com.devonfw.tools.ide.url.model.file.json.ToolDependencies;
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
import com.devonfw.tools.ide.url.model.folder.AbstractUrlToolOrEdition;

/**
* {@link UrlFile} for the "dependency.json" file.
*/
public class UrlDependencyFile extends AbstractUrlFile<UrlEdition> {
public class UrlDependencyFile extends AbstractUrlFile<AbstractUrlToolOrEdition<?, ?>> {

public static final String DEPENDENCY_JSON = "dependencies.json";

Expand All @@ -18,7 +18,7 @@ public class UrlDependencyFile extends AbstractUrlFile<UrlEdition> {
*
* @param parent the {@link #getParent() parent folder}.
*/
public UrlDependencyFile(UrlEdition parent) {
public UrlDependencyFile(AbstractUrlToolOrEdition<?, ?> parent) {

super(parent, DEPENDENCY_JSON);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public List<ToolDependency> findDependencies(VersionIdentifier version, IdeLogge
return Collections.emptyList();
}

@Override
public String toString() {

if (this == EMPTY) {
return "[empty]";
}
return this.path.toString();
}

/**
* @param file the {@link Path} to the JSON file to load.
* @return the loaded {@link ToolDependencies} or the {@link #getEmpty() empty instance} if given {@link Path} does not exist.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.devonfw.tools.ide.url.model.folder;

import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent;
import com.devonfw.tools.ide.url.model.UrlArtifactWithParent;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;

public abstract class AbstractUrlToolOrEdition<P extends AbstractUrlFolder<?>, C extends UrlArtifactWithParent<?>> extends AbstractUrlFolderWithParent<P, C> {

private UrlDependencyFile dependencyFile;

/**
* The constructor.
*
* @param parent the {@link #getParent() parent folder}.
* @param name the {@link #getName() filename}.
*/
public AbstractUrlToolOrEdition(P parent, String name) {

super(parent, name);
}


/**
* @return the {@link UrlDependencyFile} of this {@link UrlEdition}. Will be lazily initialized on the first call of this method. If the file exists, it will
* be loaded, otherwise it will be empty and only created on save if data was added.
*/
public UrlDependencyFile getDependencyFile() {

if (this.dependencyFile == null) {
this.dependencyFile = new UrlDependencyFile(this);
this.dependencyFile.load(false);
}
return dependencyFile;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.devonfw.tools.ide.url.model.folder;

import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent;
import com.devonfw.tools.ide.url.model.file.UrlDependencyFile;
import com.devonfw.tools.ide.url.model.file.UrlSecurityFile;

/**
* An {@link UrlFolder} representing the actual edition of a {@link UrlTool}. The default edition may have the same {@link #getName() name} as the
* {@link UrlTool} itself. However, tools like "intellij" may have editions like "community" or "ultimate".
*/
public class UrlEdition extends AbstractUrlFolderWithParent<UrlTool, UrlVersion> {
public class UrlEdition extends AbstractUrlToolOrEdition<UrlTool, UrlVersion> {

private UrlSecurityFile securityFile;

private UrlDependencyFile dependencyFile;

/**
* The constructor.
*
Expand Down Expand Up @@ -49,19 +45,6 @@ public UrlSecurityFile getSecurityFile() {
return this.securityFile;
}

/**
* @return the {@link UrlDependencyFile} of this {@link UrlEdition}. Will be lazily initialized on the first call of this method. If the file exists, it will
* be loaded, otherwise it will be empty and only created on save if data was added.
*/
public UrlDependencyFile getDependencyFile() {

if (this.dependencyFile == null) {
this.dependencyFile = new UrlDependencyFile(this);
this.dependencyFile.load(false);
}
return dependencyFile;
}

@Override
public void save() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.devonfw.tools.ide.url.model.folder;

import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent;

/**
* An {@link UrlFolder} representing the actual software tool like "docker" or "vscode".
*/
public class UrlTool extends AbstractUrlFolderWithParent<UrlRepository, UrlEdition> {
public class UrlTool extends AbstractUrlToolOrEdition<UrlRepository, UrlEdition> {

/**
* The constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.repo.ToolRepository;
import com.devonfw.tools.ide.url.model.UrlMetadata;
import com.devonfw.tools.ide.variable.IdeVariables;

/**
Expand All @@ -31,10 +32,6 @@ public class AbstractIdeTestContext extends AbstractIdeContext {

private SystemInfo systemInfo;

private Path dummyUserHome;

private Boolean online;

private ProcessContext mockContext;

/**
Expand All @@ -58,6 +55,22 @@ public boolean isTest() {
return true;
}

/**
* @return {@code true} if mutable, {@code false} otherwise.
* @see IdeTestContextMock
*/
protected boolean isMutable() {

return true;
}

private void requireMutable() {

if (!isMutable()) {
throw new IllegalStateException(getClass().getSimpleName() + " is immutable!");
}
}

@Override
protected String readLine() {

Expand All @@ -68,6 +81,7 @@ protected String readLine() {
}

public void setAnswers(String... answers) {
requireMutable();
this.answers = answers;
this.answerIndex = 0;
}
Expand Down Expand Up @@ -114,20 +128,12 @@ protected SystemPath computeSystemPath() {
return new SystemPath(this, envPath);
}

@Override
public boolean isOnline() {

if (this.online != null) {
return this.online.booleanValue();
}
return super.isOnline();
}

/**
* @param online the mocked {@link #isOnline()} result.
*/
public void setOnline(Boolean online) {

requireMutable();
this.online = online;
}

Expand All @@ -145,6 +151,7 @@ public ProcessContext newProcess() {
*/
public void setProcessContext(ProcessContext mockContext) {

requireMutable();
this.mockContext = mockContext;
}

Expand All @@ -160,6 +167,7 @@ public SystemInfo getSystemInfo() {
*/
public void setSystemInfo(SystemInfo systemInfo) {

requireMutable();
this.systemInfo = systemInfo;
}

Expand All @@ -168,25 +176,24 @@ public void setSystemInfo(SystemInfo systemInfo) {
*/
public void setUserHome(Path dummyUserHome) {

this.dummyUserHome = dummyUserHome;
requireMutable();
this.userHome = dummyUserHome;
}

/**
* @return a dummy UserHome path to avoid global path access in a commandlet test. The defined {@link #dummyUserHome} will be returned if it is not
* {@code null}, else see implementation {@link #AbstractIdeContext}.
* @param urlsPath the mocked {@link #getUrlsPath() urls path}.
*/
@Override
public Path getUserHome() {
public void setUrlsPath(Path urlsPath) {

if (this.dummyUserHome != null) {
return this.dummyUserHome;
}
return super.getUserHome();
this.urlsPath = urlsPath;
this.urlMetadata = new UrlMetadata(this);
}

@Override
/**
* @param defaultToolRepository the new value of {@link #getDefaultToolRepository()}.
*/
public void setDefaultToolRepository(ToolRepository defaultToolRepository) {

super.setDefaultToolRepository(defaultToolRepository);
this.defaultToolRepository = defaultToolRepository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
*/
public class IdeSlf4jContext extends AbstractIdeTestContext {

private static final Path PATH_MOCK = Path.of("/");

/**
* The constructor.
*/
public IdeSlf4jContext() {
this(PATH_MOCK);
}

/**
* The constructor.
*
Expand Down
Loading

0 comments on commit 15910e5

Please sign in to comment.