Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-6649][WFCORE-6653] Deprecate --no-resol-local-cache and replace it with --… #5810

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.ObjectTypeAttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
Expand Down Expand Up @@ -63,16 +64,28 @@ abstract class AbstractInstMgrUpdateHandler extends InstMgrOperationStepHandler
.addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE)
.setMinSize(1)
.setRequired(false)
.setAlternatives(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE)
.setAlternatives(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE, InstMgrConstants.USE_DEFAULT_LOCAL_CACHE)
.build();

/**
* @deprecated Use USE_DEFAULT_LOCAL_CACHE instead.
*/
@Deprecated(forRemoval = true)
protected static final AttributeDefinition NO_RESOLVE_LOCAL_CACHE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE, ModelType.BOOLEAN)
.setStorageRuntime()
.setRuntimeServiceNotRequired()
.setDefaultValue(ModelNode.FALSE)
.setRequired(false)
.setStorageRuntime()
.setAlternatives(InstMgrConstants.LOCAL_CACHE)
.setAlternatives(InstMgrConstants.LOCAL_CACHE, InstMgrConstants.USE_DEFAULT_LOCAL_CACHE)
.setDeprecated(ModelVersion.create(24))
.build();

protected static final AttributeDefinition USE_DEFAULT_LOCAL_CACHE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE, ModelType.BOOLEAN)
.setStorageRuntime()
.setRuntimeServiceNotRequired()
.setRequired(false)
.setStorageRuntime()
.setAlternatives(InstMgrConstants.LOCAL_CACHE, InstMgrConstants.NO_RESOLVE_LOCAL_CACHE)
.build();

AbstractInstMgrUpdateHandler(InstMgrService imService, InstallationManagerFactory imf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public interface InstMgrConstants {
String MAVEN_REPO_FILE = "maven-repo-file";
String MAVEN_REPO_FILES = "maven-repo-files";
String NO_RESOLVE_LOCAL_CACHE = "no-resolve-local-cache";
String USE_DEFAULT_LOCAL_CACHE = "use-default-local-cache";
String OFFLINE = "offline";
String REPOSITORIES = "repositories";
String REPOSITORY = "repository";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class InstMgrListUpdatesHandler extends AbstractInstMgrUpdateHandler {
.addParameter(REPOSITORIES)
.addParameter(LOCAL_CACHE)
.addParameter(NO_RESOLVE_LOCAL_CACHE)
.addParameter(USE_DEFAULT_LOCAL_CACHE)
.addParameter(MAVEN_REPO_FILES)
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
.setRuntimeOnly()
Expand All @@ -72,12 +73,21 @@ public InstMgrListUpdatesHandler(InstMgrService imService, InstallationManagerFa
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false);
final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull();
final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false);
final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null;
final List<ModelNode> mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty();
final List<ModelNode> repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty();

if (pathLocalRepo != null && noResolveLocalCache) {
if (noResolveLocalCache != null && useDefaultLocalCache !=null) {
throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && noResolveLocalCache !=null && noResolveLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache();
}

Expand All @@ -91,7 +101,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
context.acquireControllerLock();
try {
final Path homeDir = imService.getHomeDir();
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline);
boolean noResolveLocalCacheResult = noResolveLocalCache != null
? noResolveLocalCache
: useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null);
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline);
final InstallationManager im = imf.create(homeDir, mavenOptions);
final Path listUpdatesWorkDir = imService.createTempDir("list-updates-");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected Path getUploadedMvnRepoRoot(Path source) throws Exception, ZipExceptio
List<Path> entries = content
.filter(e -> e.toFile().isDirectory() && e.getFileName().toString().equals(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES))
.collect(Collectors.toList());
if (entries.isEmpty() || entries.size() != 1) {
if (entries.size() != 1) {
throw InstMgrLogger.ROOT_LOGGER.invalidZipEntry(InstMgrConstants.MAVEN_REPO_DIR_NAME_IN_ZIP_FILES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ public class InstMgrPrepareRevertHandler extends AbstractInstMgrUpdateHandler {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false);
final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull();
final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false);
final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null;
final List<ModelNode> mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty();
final List<ModelNode> repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty();
final String revision = REVISION.resolveModelAttribute(context, operation).asString();

if (pathLocalRepo != null && noResolveLocalCache) {
if (noResolveLocalCache != null && useDefaultLocalCache !=null) {
throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && noResolveLocalCache != null && noResolveLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache();
}

Expand All @@ -106,7 +115,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
imService.beginCandidateServer();
addCompleteStep(context, imService, null);
final Path homeDir = imService.getHomeDir();
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline);
boolean noResolveLocalCacheResult = noResolveLocalCache != null
? noResolveLocalCache
: useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null);
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline);
final InstallationManager im = imf.create(homeDir, mavenOptions);

final List<Repository> repositories = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class InstMgrPrepareUpdateHandler extends AbstractInstMgrUpdateHandler {
.addParameter(REPOSITORIES)
.addParameter(LOCAL_CACHE)
.addParameter(NO_RESOLVE_LOCAL_CACHE)
.addParameter(USE_DEFAULT_LOCAL_CACHE)
.addParameter(MAVEN_REPO_FILES)
.addParameter(LIST_UPDATES_WORK_DIR)
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY)
Expand All @@ -83,13 +84,22 @@ public class InstMgrPrepareUpdateHandler extends AbstractInstMgrUpdateHandler {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final boolean offline = OFFLINE.resolveModelAttribute(context, operation).asBoolean(false);
final String pathLocalRepo = LOCAL_CACHE.resolveModelAttribute(context, operation).asStringOrNull();
final boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBoolean(false);
final Boolean noResolveLocalCache = NO_RESOLVE_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Boolean useDefaultLocalCache = USE_DEFAULT_LOCAL_CACHE.resolveModelAttribute(context, operation).asBooleanOrNull();
final Path localRepository = pathLocalRepo != null ? Path.of(pathLocalRepo) : null;
final List<ModelNode> mavenRepoFileIndexes = MAVEN_REPO_FILES.resolveModelAttribute(context, operation).asListOrEmpty();
final List<ModelNode> repositoriesMn = REPOSITORIES.resolveModelAttribute(context, operation).asListOrEmpty();
final String listUpdatesWorkDir = LIST_UPDATES_WORK_DIR.resolveModelAttribute(context, operation).asStringOrNull();

if (pathLocalRepo != null && noResolveLocalCache) {
if (noResolveLocalCache != null && useDefaultLocalCache != null) {
throw InstMgrLogger.ROOT_LOGGER.noResolveLocalCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && useDefaultLocalCache != null && useDefaultLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithUseDefaultLocalCache();
}

if (pathLocalRepo != null && noResolveLocalCache!= null && noResolveLocalCache) {
throw InstMgrLogger.ROOT_LOGGER.localCacheWithNoResolveLocalCache();
}

Expand All @@ -114,7 +124,11 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
addCompleteStep(context, imService, null);

final Path homeDir = imService.getHomeDir();
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCache, offline);

boolean noResolveLocalCacheResult = noResolveLocalCache != null
? noResolveLocalCache
: useDefaultLocalCache == null ? localRepository == null : (!useDefaultLocalCache && localRepository == null);
final MavenOptions mavenOptions = new MavenOptions(localRepository, noResolveLocalCacheResult, offline);
final InstallationManager im = imf.create(homeDir, mavenOptions);

final List<Repository> repositories = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
import static org.wildfly.core.instmgr.cli.UpdateCommand.CONFIRM_OPTION;
import static org.wildfly.core.instmgr.cli.UpdateCommand.DRY_RUN_OPTION;
import static org.wildfly.core.instmgr.cli.UpdateCommand.NO_RESOLVE_LOCAL_CACHE_OPTION;
import static org.wildfly.core.instmgr.cli.UpdateCommand.USE_DEFAULT_LOCAL_CACHE_OPTION;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -45,6 +47,8 @@
@CommandDefinition(name = "abstract-inst-mgr-cmd", description = "", activator = InstMgrActivator.class)
public abstract class AbstractInstMgrCommand implements Command<CLICommandInvocation> {
static final PathElement CORE_SERVICE_INSTALLER = PathElement.pathElement(CORE_SERVICE, InstMgrGroupCommand.COMMAND_NAME);
static final String NO_RESOLVE_LOCAL_CACHE_OPTION= "no-resolve-local-cache";
static final String USE_DEFAULT_LOCAL_CACHE_OPTION = "use-default-local-cache";

@Option(name = "host", completer = AbstractInstMgrCommand.HostsCompleter.class, activator = AbstractInstMgrCommand.HostsActivator.class)
protected String host;
Expand Down Expand Up @@ -121,6 +125,18 @@ public ConfirmActivator() {
}
}

public static class UseDefaultLocalCacheActivator extends AbstractRejectOptionActivator {
public UseDefaultLocalCacheActivator() {
super(NO_RESOLVE_LOCAL_CACHE_OPTION);
}
}

public static class NoResolveLocalCacheActivator extends AbstractRejectOptionActivator {
public NoResolveLocalCacheActivator() {
super(USE_DEFAULT_LOCAL_CACHE_OPTION);
}
}

public static class HostsCompleter implements OptionCompleter<CLICompleterInvocation> {
@Override
public void complete(CLICompleterInvocation completerInvocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class ListUpdatesAction extends AbstractInstMgrCommand {
private final List<File> mavenRepoFiles;
private final List<String> repositories;
private final Path localCache;
private final boolean noResolveLocalCache;
private final Boolean noResolveLocalCache;
private final Boolean useDefaultLocalCache;
private final boolean offline;
private final ModelNode headers;

Expand All @@ -35,6 +36,7 @@ public ListUpdatesAction(Builder builder) {
this.noResolveLocalCache = builder.noResolveLocalCache;
this.offline = builder.offline;
this.headers = builder.headers;
this.useDefaultLocalCache = builder.useDefaultLocalCache;
}

@Override
Expand All @@ -59,7 +61,14 @@ protected Operation buildOperation() throws CommandException {
op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.normalize().toAbsolutePath().toString());
}

op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache);
if (useDefaultLocalCache != null) {
op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(useDefaultLocalCache);
}

if (noResolveLocalCache != null) {
op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache);
}

op.get(InstMgrConstants.OFFLINE).set(offline);

if (this.headers != null && headers.isDefined()) {
Expand All @@ -76,12 +85,12 @@ public static class Builder {
private List<String> repositories;
private Path localCache;

private boolean noResolveLocalCache;
private Boolean noResolveLocalCache;
private Boolean useDefaultLocalCache;

public Builder() {
this.repositories = new ArrayList<>();
this.offline = false;
this.noResolveLocalCache = false;
this.mavenRepoFiles = new ArrayList<>();
}

Expand All @@ -94,7 +103,7 @@ public Builder setMavenRepoFiles(List<File> mavenRepoFiles) {

public Builder setRepositories(List<String> repositories) {
if (repositories != null) {
this.repositories = new ArrayList<>(repositories);
this.repositories.addAll(repositories);
}
return this;
}
Expand All @@ -106,11 +115,16 @@ public Builder setLocalCache(File localCache) {
return this;
}

public Builder setNoResolveLocalCache(boolean noResolveLocalCache) {
public Builder setNoResolveLocalCache(Boolean noResolveLocalCache) {
this.noResolveLocalCache = noResolveLocalCache;
return this;
}

public Builder setUseDefaultLocalCache(Boolean useDefaultLocalCache) {
this.useDefaultLocalCache = useDefaultLocalCache;
return this;
}

public Builder setOffline(boolean offline) {
this.offline = offline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class PrepareUpdateAction extends AbstractInstMgrCommand {
private final List<File> mavenRepoFiles;
private final List<String> repositories;
private final Path localCache;
private final boolean noResolveLocalCache;
private final Boolean noResolveLocalCache;
private final Boolean useDefaultLocalCache;

private final Path listUpdatesWorkDir;

Expand All @@ -38,6 +39,7 @@ public PrepareUpdateAction(Builder builder) {
this.repositories = builder.repositories;
this.localCache = builder.localCache;
this.noResolveLocalCache = builder.noResolveLocalCache;
this.useDefaultLocalCache = builder.useDefaultLocalCache;
this.listUpdatesWorkDir = builder.listUpdatesWorkDir;
this.offline = builder.offline;
this.headers = builder.headers;
Expand Down Expand Up @@ -65,7 +67,14 @@ protected Operation buildOperation() throws CommandException {
op.get(InstMgrConstants.LOCAL_CACHE).set(localCache.normalize().toAbsolutePath().toString());
}

op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache);
if (noResolveLocalCache != null) {
op.get(InstMgrConstants.NO_RESOLVE_LOCAL_CACHE).set(noResolveLocalCache);
}

if (useDefaultLocalCache != null) {
op.get(InstMgrConstants.USE_DEFAULT_LOCAL_CACHE).set(useDefaultLocalCache);
}

op.get(InstMgrConstants.OFFLINE).set(offline);

if (listUpdatesWorkDir != null) {
Expand All @@ -86,13 +95,12 @@ public static class Builder {
private List<String> repositories;
private Path localCache;

private boolean noResolveLocalCache;
private Boolean noResolveLocalCache;
private Boolean useDefaultLocalCache;
private Path listUpdatesWorkDir;

public Builder() {
this.repositories = new ArrayList<>();
this.offline = false;
this.noResolveLocalCache = false;
this.mavenRepoFiles = new ArrayList<>();
}

Expand All @@ -103,7 +111,7 @@ public Builder setMavenRepoFiles(Set<File> mavenRepoFiles) {

public Builder setRepositories(List<String> repositories) {
if (repositories != null) {
this.repositories = new ArrayList<>(repositories);
this.repositories.addAll(repositories);
}
return this;
}
Expand All @@ -115,11 +123,16 @@ public Builder setLocalCache(File localCache) {
return this;
}

public Builder setNoResolveLocalCache(boolean noResolveLocalCache) {
public Builder setNoResolveLocalCache(Boolean noResolveLocalCache) {
this.noResolveLocalCache = noResolveLocalCache;
return this;
}

public Builder setUseDefaultLocalCache(Boolean useDefaultLocalCache) {
this.useDefaultLocalCache = useDefaultLocalCache;
return this;
}

public Builder setOffline(boolean offline) {
this.offline = offline;
return this;
Expand Down
Loading