Skip to content

Commit

Permalink
Introduce a cli-support module. Advertise OS deployers first place
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Francois Denise committed Apr 16, 2024
1 parent ce41d98 commit 9a5fe7b
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 119 deletions.
63 changes: 63 additions & 0 deletions cli-support/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>wildfly-glow-parent</artifactId>
<groupId>org.wildfly.glow</groupId>
<version>1.0.1.Final-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>wildfly-glow-cli-support</artifactId>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer />
<transformer>
<mainClass>org.wildfly.glow.cli.GlowCLI</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<recompressZippedFiles>true</recompressZippedFiles>
<finalName>wildfly-glow-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}</outputDirectory>
<workDirectory>${project.build.directory}/assembly/work</workDirectory>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<location.checkstyle.xml>../checkstyle/checkstyle.xml</location.checkstyle.xml>
</properties>
</project>
41 changes: 41 additions & 0 deletions cli-support/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wildfly.glow</groupId>
<artifactId>wildfly-glow-parent</artifactId>
<version>1.0.1.Final-SNAPSHOT</version>
</parent>
<artifactId>wildfly-glow-cli-support</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<location.checkstyle.xml>../checkstyle/checkstyle.xml</location.checkstyle.xml>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-core</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-maven-resolver</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-openshift-deployment-api</artifactId>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.channel</groupId>
<artifactId>channel-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.commands;
package org.wildfly.glow.cli.support;

import java.io.PrintWriter;
import java.util.concurrent.Callable;
Expand All @@ -39,10 +39,10 @@ public abstract class AbstractCommand implements Callable<Integer> {
@CommandLine.Option(
names = {Constants.VERBOSE_OPTION_SHORT, Constants.VERBOSE_OPTION}
)
boolean verbose;
protected boolean verbose;

@CommandLine.Spec
CommandLine.Model.CommandSpec spec;
protected CommandLine.Model.CommandSpec spec;

private PrintWriter stdout;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.support;

import java.util.Collections;
import java.util.Set;
import org.wildfly.glow.ConfigurationResolver;
import org.wildfly.glow.Env;
import org.wildfly.glow.Layer;
import org.wildfly.glow.deployment.openshift.api.OpenShiftSupport;

/**
*
* @author jdenise
*/
public class CLIConfigurationResolver implements ConfigurationResolver {

private final Set<String> disabledDeployers;
private final boolean isOpenShift;
public CLIConfigurationResolver() {
this(true, null);
}
public CLIConfigurationResolver(boolean isOpenShift,
Set<String> disabledDeployers) {
this.disabledDeployers = disabledDeployers == null ? Collections.emptySet() : disabledDeployers;
this.isOpenShift = isOpenShift;
}

@Override
public ResolvedEnvs getResolvedEnvs(Layer layer, Set<Env> input) throws Exception {
if (isOpenShift) {
return OpenShiftSupport.getResolvedEnvs(layer, input, disabledDeployers);
}
return null;
}

@Override
public String getPossibleDeployer(Set<Layer> layers) throws Exception {
return OpenShiftSupport.getPossibleDeployer(layers, disabledDeployers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.commands;
package org.wildfly.glow.cli.support;

import picocli.AutoComplete;
import picocli.CommandLine;
Expand All @@ -36,9 +36,13 @@ public class CompletionCommand implements Runnable {
@CommandLine.Spec
CommandLine.Model.CommandSpec spec;

private final String script;
public CompletionCommand(String script) {
this.script = script;
}
@Override
public void run() {
String script = AutoComplete.bash(Constants.WILDFLY_GLOW, spec.root().commandLine());
String script = AutoComplete.bash(this.script, spec.root().commandLine());
spec.commandLine().getOut().print(script);
spec.commandLine().getOut().print('\n');
spec.commandLine().getOut().flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.commands;
package org.wildfly.glow.cli.support;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
* limitations under the License.
*/

package org.wildfly.glow.cli;
package org.wildfly.glow.cli.support;

import java.lang.reflect.InvocationTargetException;
import org.wildfly.glow.cli.commands.AbstractCommand;
import picocli.CommandLine;


Expand Down
103 changes: 103 additions & 0 deletions cli-support/src/main/java/org/wildfly/glow/cli/support/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wildfly.glow.cli.support;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.jboss.galleon.api.config.GalleonProvisioningConfig;
import org.jboss.galleon.universe.FeaturePackLocation;
import org.wildfly.glow.AddOn;
import org.wildfly.glow.Layer;
import org.wildfly.glow.LayerMapping;
import org.wildfly.glow.ProvisioningUtils;
import org.wildfly.glow.maven.MavenResolver;

/**
*
* @author jdenise
*/
public class Utils {

public static void showAddOns(AbstractCommand cmd, String context, Path provisioningXml, boolean isLatest,
String serverVersion, boolean isPreview, Path channelsFile) throws Exception {
CLIConfigurationResolver resolver = new CLIConfigurationResolver();
ProvisioningUtils.ProvisioningConsumer consumer = new ProvisioningUtils.ProvisioningConsumer() {
@Override
public void consume(GalleonProvisioningConfig provisioning, Map<String, Layer> all,
LayerMapping mapping, Map<FeaturePackLocation.FPID, Set<FeaturePackLocation.ProducerSpec>> fpDependencies) throws Exception {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, Set<AddOn>> entry : mapping.getAddOnFamilyMembers().entrySet()) {
builder.append("* @|bold ").append(entry.getKey()).append("|@ add-ons:%n");
for (AddOn member : mapping.getAddOnFamilyMembers().get(entry.getKey())) {
if (!member.getName().endsWith(":default")) {
String deployer = resolver.getPossibleDeployer(member.getLayers());
builder.append(" - ").append(member.getName()).append((deployer == null ? "" : " @|bold (supported by " + deployer + " deployer)|@")).append(member.getDescription() == null ? "" : ": " + member.getDescription()).append("%n");
}
}
}
cmd.print(builder.toString());
cmd.print("@|bold Add-ons can be set using the|@ @|fg(yellow) %s=<list of add-ons>|@ @|bold option of the|@ @|fg(yellow) %s|@ @|bold command|@", Constants.ADD_ONS_OPTION, Constants.SCAN_COMMAND);

}

};
ProvisioningUtils.traverseProvisioning(consumer, context, provisioningXml, isLatest, serverVersion,
isPreview, MavenResolver.buildMavenResolver(channelsFile));
}

public static void setSystemProperties(Set<String> systemProperties) throws Exception {
if (!systemProperties.isEmpty()) {
for (String p : systemProperties) {
if (p.startsWith("-D")) {
int i = p.indexOf("=");
String propName;
String value = "";
if (i > 0) {
propName = p.substring(2, i);
value = p.substring(i + 1);
} else {
propName = p.substring(2);
}
System.setProperty(propName, value);
} else {
throw new Exception("Invalid system property " + p + ". A property must start with -D");
}
}
}
}

public static Map<String, String> handleOpenShiftEnvFile(Path envFile) throws Exception {
Map<String, String> extraEnv = new HashMap<>();
if (!Files.exists(envFile)) {
throw new Exception(envFile + " file doesn't exist");
}
for (String l : Files.readAllLines(envFile)) {
l = l.trim();
if (!l.isEmpty() && !l.startsWith("#")) {
int i = l.indexOf("=");
if (i < 0 || i == l.length() - 1) {
throw new Exception("Invalid environment variable " + l + " in " + envFile);
}
extraEnv.put(l.substring(0, i), l.substring(i + 1));
}
}
return extraEnv;
}
}
4 changes: 4 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-maven-resolver</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-glow-cli-support</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.galleon</groupId>
<artifactId>galleon-api</artifactId>
Expand Down
8 changes: 5 additions & 3 deletions cli/src/main/java/org/wildfly/glow/cli/GlowCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*/
package org.wildfly.glow.cli;

import org.wildfly.glow.cli.support.ExecutionExceptionHandler;
import java.util.Arrays;
import org.wildfly.glow.cli.commands.AbstractCommand;
import org.wildfly.glow.cli.commands.CompletionCommand;
import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.CompletionCommand;
import org.wildfly.glow.cli.support.Constants;
import org.wildfly.glow.cli.commands.GoOfflineCommand;
import org.wildfly.glow.cli.commands.ShowConfigurationCommand;
import org.wildfly.glow.cli.commands.MainCommand;
Expand All @@ -43,7 +45,7 @@ public static void main(String[] args) throws Exception {
commandLine.addSubcommand(new ShowServerVersionsCommand());
commandLine.addSubcommand(new ShowConfigurationCommand());
commandLine.addSubcommand(new GoOfflineCommand());
commandLine.addSubcommand(new CompletionCommand());
commandLine.addSubcommand(new CompletionCommand(Constants.WILDFLY_GLOW));
commandLine.setUsageHelpAutoWidth(true);
final boolean isVerbose = Arrays.stream(args).anyMatch(s -> s.equals("-vv") || s.equals("--verbose"));
commandLine.setExecutionExceptionHandler(new ExecutionExceptionHandler(isVerbose, command));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.wildfly.glow.cli.commands;

import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.Constants;
import java.nio.file.Path;
import java.util.Optional;
import org.wildfly.glow.Arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.wildfly.glow.cli.commands;

import org.wildfly.glow.cli.support.AbstractCommand;
import org.wildfly.glow.cli.support.Constants;
import java.util.ResourceBundle;
import org.wildfly.glow.Version;

Expand Down
Loading

0 comments on commit 9a5fe7b

Please sign in to comment.