Skip to content

Commit

Permalink
Extract more parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zbynek committed Sep 12, 2023
1 parent f734c65 commit ff3ebba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public int compare(StepDescriptor o1, StepDescriptor o2) {
private static final long serialVersionUID = 1L;
}

public void generateAscii(Map<String, Map<String, List<QuasiDescriptor>>> allSteps, HyperLocalPluginManager pluginManager) {
public void generateAscii(
Map<String, Map<String, List<QuasiDescriptor>>> allSteps, HyperLocalPluginManager pluginManager) {
File allAscii;
if (asciiDest != null) {
allAscii = new File(asciiDest);
Expand Down Expand Up @@ -267,8 +268,7 @@ public void generateAscii(Map<String, Map<String, List<QuasiDescriptor>>> allSte
PluginWrapper thePlugin = pluginManager.getPlugin(plugin);
String displayName = thePlugin == null ? "Jenkins Core" : thePlugin.getDisplayName();
boolean isDeprecated = deprecatedPlugins.has(plugin);
String whole9yards = toAsciiDoc.generatePluginHelp(plugin, displayName, byPlugin, isDeprecated,
true);
String whole9yards = toAsciiDoc.generatePluginHelp(plugin, displayName, byPlugin, isDeprecated, true);

try {
Paths.get(allAsciiPath, plugin).toFile().mkdirs();
Expand All @@ -279,12 +279,15 @@ public void generateAscii(Map<String, Map<String, List<QuasiDescriptor>>> allSte
// continue to next plugin
}
}
for (Map.Entry<String, StringBuilder> entry: toAsciiDoc.getExtractedParams().entrySet()) {
for (Map.Entry<String, StringBuilder> entry :
toAsciiDoc.getExtractedParams().entrySet()) {
String plugin = entry.getKey();
try {
Paths.get(allAsciiPath, plugin).toFile().mkdirs();
Files.writeString(
new File(allAsciiPath, entry.getKey() + "/params.adoc").toPath(), entry.getValue().toString(), StandardCharsets.UTF_8);
new File(allAsciiPath, entry.getKey() + "/params.adoc").toPath(),
entry.getValue().toString(),
StandardCharsets.UTF_8);
} catch (IOException ex) {
LOG.log(Level.SEVERE, "Error generating plugin params file for " + entry.getKey() + ". Skip.", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -23,7 +22,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.jenkinsci.infra.tools.HyperLocalPluginManager;
import org.jenkinsci.plugins.structs.SymbolLookup;
import org.jenkinsci.plugins.structs.describable.ArrayType;
Expand Down Expand Up @@ -71,11 +69,11 @@ public Map<String, StringBuilder> getExtractedParams() {
public ToAsciiDoc(HyperLocalPluginManager pluginManager) {
this.pluginManager = pluginManager;
this.map = new HashMap<>();
for (Map.Entry<String, String> entry: pluginManager.uberPlusClassLoader
.getByPlugin().entrySet()) {
ExtensionList<Descriptor> descriptors = ExtensionList.lookup(Descriptor.class);
for (Descriptor d: descriptors) {
if (d.getClass().getName() == entry.getKey()) {
for (Map.Entry<String, String> entry :
pluginManager.uberPlusClassLoader.getByPlugin().entrySet()) {
ExtensionList<Descriptor> descriptors = ExtensionList.lookup(Descriptor.class);
for (Descriptor d : descriptors) {
if (entry.getKey().equals(d.getClass().getName())) {
map.put(d.clazz.getName(), entry.getValue());
}
}
Expand Down Expand Up @@ -127,12 +125,18 @@ String describeType(ParameterType type, String prefix) throws Exception {
String help = generateHelp(entry.getValue(), true);
if (shouldExtract(heterogeneousObjectType.getType())) {
String pluginName = map.get(entry.getValue().getType().getName());
extractedParams.computeIfAbsent(pluginName, (foo) -> new StringBuilder())
.append(header(3)).append(symbol)
.append("\n\n").append(help).append("\n");
extractedParams
.computeIfAbsent(pluginName, (foo) -> new StringBuilder())
.append(header(3))
.append(symbol)
.append("\n\n")
.append(help)
.append("\n");
typeInfo.append("<li><a href=\"../")
.append(pluginName)
.append("/params#").append(symbol).append("\">")
.append("/params#")
.append(symbol)
.append("\">")
.append(symbol)
.append("</a></li>\n");
} else {
Expand Down Expand Up @@ -403,7 +407,7 @@ public String generatePluginHelp(
Map<String, List<QuasiDescriptor>> byPlugin,
boolean isDeprecated,
boolean genHeader) {
Main.isUnitTest = true;
setUnitTest();

// TODO: if condition
StringBuilder whole9yards = new StringBuilder();
Expand All @@ -427,9 +431,13 @@ public String generatePluginHelp(
return whole9yards.toString();
}

private static void setUnitTest() {
Main.isUnitTest = true;
}

public String generateDirectiveHelp(
String directiveName, Map<String, List<Descriptor>> descsByPlugin, boolean genHeader) {
Main.isUnitTest = true;
setUnitTest();
StringBuilder whole9yards = new StringBuilder();
if (genHeader) {
whole9yards.append(generateHeader(directiveName));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.pipeline_steps_doc_generator;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
Expand All @@ -16,7 +15,6 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import org.jenkinsci.infra.tools.HyperLocalPluginManager;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.junit.Test;
Expand All @@ -27,7 +25,8 @@ public class ToAsciidocTest {
public void testDescribeType() {
DescribableModel<DescribeMe> model = new DescribableModel<>(DescribeMe.class);
try {
String desc = new ToAsciiDoc(new HyperLocalPluginManager(true)).describeType(model.getParameter("s").getType(), "");
String desc = new ToAsciiDoc(new HyperLocalPluginManager(true))
.describeType(model.getParameter("s").getType(), "");
assertEquals(
"<li><b>Type:</b> <code>java.util.HashMap&lt;java.lang.String, java.lang.String&gt;</code></li>",
desc.trim());
Expand Down Expand Up @@ -79,8 +78,7 @@ private Path setupPluginDir(PipelineStepExtractor pes) throws IOException {
}

private void downloadPlugin(Path plugins, String id, String version) throws IOException {
URL website = new URL(
"https://updates.jenkins.io/download/plugins/" + id + "/" + version + "/" + id + ".hpi");
URL website = new URL("https://updates.jenkins.io/download/plugins/" + id + "/" + version + "/" + id + ".hpi");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
try (FileOutputStream fos =
new FileOutputStream(plugins.resolve(id + ".hpi").toFile())) {
Expand Down

0 comments on commit ff3ebba

Please sign in to comment.