-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a cli-support module. Advertise OS deployers first place
- Loading branch information
Jean Francois Denise
committed
Apr 16, 2024
1 parent
ce41d98
commit 9a5fe7b
Showing
21 changed files
with
404 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
cli-support/src/main/java/org/wildfly/glow/cli/support/CLIConfigurationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
cli-support/src/main/java/org/wildfly/glow/cli/support/Utils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.