Skip to content

Commit ca7d178

Browse files
authored
Merge pull request #4 from TomasHofman/external-service
SET-218 Order component upgrades by age
2 parents 01a7377 + 772ffa7 commit ca7d178

File tree

26 files changed

+630
-56
lines changed

26 files changed

+630
-56
lines changed

cli/pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
<groupId>commons-cli</groupId>
2424
<artifactId>commons-cli</artifactId>
2525
</dependency>
26+
<dependency>
27+
<groupId>org.jboss.resteasy</groupId>
28+
<artifactId>resteasy-client</artifactId>
29+
<version>4.5.3.Final</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.fasterxml.jackson.core</groupId>
33+
<artifactId>jackson-databind</artifactId>
34+
<version>2.10.1</version>
35+
</dependency>
2636
</dependencies>
2737

2838
<build>
@@ -50,9 +60,12 @@
5060
<mainClass>org.jboss.set.mavendependencyupdater.cli.Cli</mainClass>
5161
</manifest>
5262
</archive>
53-
<descriptorRefs>
63+
<descriptors>
64+
<descriptor>src/assembly/jar.xml</descriptor>
65+
</descriptors>
66+
<!--<descriptorRefs>
5467
<descriptorRef>jar-with-dependencies</descriptorRef>
55-
</descriptorRefs>
68+
</descriptorRefs>-->
5669
<appendAssemblyId>false</appendAssemblyId>
5770
<finalName>${artifactName}-${project.version}</finalName>
5871
</configuration>

cli/src/assembly/jar.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
4+
<id>customized-jar-with-dependencies</id>
5+
<formats>
6+
<format>jar</format>
7+
</formats>
8+
<includeBaseDirectory>false</includeBaseDirectory>
9+
<dependencySets>
10+
<dependencySet>
11+
<outputDirectory>/</outputDirectory>
12+
<useProjectArtifact>true</useProjectArtifact>
13+
<unpack>true</unpack>
14+
<scope>runtime</scope>
15+
</dependencySet>
16+
</dependencySets>
17+
<containerDescriptorHandlers>
18+
<containerDescriptorHandler>
19+
<handlerName>metaInf-services</handlerName>
20+
</containerDescriptorHandler>
21+
<containerDescriptorHandler>
22+
<handlerName>metaInf-spring</handlerName>
23+
</containerDescriptorHandler>
24+
<containerDescriptorHandler>
25+
<handlerName>plexus</handlerName>
26+
</containerDescriptorHandler>
27+
</containerDescriptorHandlers>
28+
</assembly>

cli/src/main/java/org/jboss/set/mavendependencyupdater/cli/Cli.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.jboss.set.mavendependencyupdater.AvailableVersionsResolver;
1414
import org.jboss.set.mavendependencyupdater.DefaultAvailableVersionsResolver;
1515
import org.jboss.set.mavendependencyupdater.DependencyEvaluator;
16+
import org.jboss.set.mavendependencyupdater.core.processingstrategies.HtmlReportProcessingStrategy;
1617
import org.jboss.set.mavendependencyupdater.core.processingstrategies.ModifyLocallyProcessingStrategy;
1718
import org.jboss.set.mavendependencyupdater.core.processingstrategies.SeparatePRsProcessingStrategy;
1819
import org.jboss.set.mavendependencyupdater.core.processingstrategies.TextReportProcessingStrategy;
@@ -33,9 +34,11 @@ public class Cli {
3334
private static final String PERFORM_UPGRADES = "perform-upgrades";
3435
private static final String GENERATE_PRS = "generate-prs";
3536
private static final String GENERATE_REPORT = "generate-report";
37+
private static final String GENERATE_HTML_REPORT = "generate-html-report";
3638
private static final String GENERATE_CONFIG = "generate-config";
3739
private static final String CHECK_CONFIG = "check-config";
38-
private static final String[] COMMANDS = {PERFORM_UPGRADES, GENERATE_PRS, GENERATE_REPORT, GENERATE_CONFIG, CHECK_CONFIG};
40+
private static final String[] COMMANDS = {PERFORM_UPGRADES, GENERATE_PRS, GENERATE_REPORT, GENERATE_HTML_REPORT,
41+
GENERATE_CONFIG, CHECK_CONFIG};
3942

4043
private static final String PREFIX_DOESNT_MATCH_MSG = "Dependency %s doesn't match prefix '%s'";
4144

@@ -137,6 +140,15 @@ private int run(String[] args) throws Exception {
137140
strategy = new TextReportProcessingStrategy(configuration, pomFile, System.out);
138141
}
139142
success = performAlignment(strategy);
143+
} else if (GENERATE_HTML_REPORT.equals(arguments[0])) {
144+
configuration = new Configuration(configurationFile);
145+
UpgradeProcessingStrategy strategy;
146+
if (cmd.hasOption('o')) {
147+
strategy = new HtmlReportProcessingStrategy(configuration, pomFile, cmd.getOptionValue('o'));
148+
} else {
149+
strategy = new HtmlReportProcessingStrategy(configuration, pomFile, System.out);
150+
}
151+
success = performAlignment(strategy);
140152
} else if (GENERATE_CONFIG.equals(arguments[0])) {
141153
new ConfigurationGenerator().generateDefautlConfig(configurationFile, rootProjectDependencies);
142154
success = true;

core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
<groupId>${project.groupId}</groupId>
3131
<artifactId>git-manipulator</artifactId>
3232
</dependency>
33+
34+
<dependency>
35+
<groupId>com.j2html</groupId>
36+
<artifactId>j2html</artifactId>
37+
</dependency>
3338
</dependencies>
3439
</project>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package org.jboss.set.mavendependencyupdater.core.processingstrategies;
2+
3+
import org.jboss.set.mavendependencyupdater.DependencyEvaluator.ComponentUpgrade;
4+
import org.jboss.set.mavendependencyupdater.configuration.Configuration;
5+
6+
import java.io.File;
7+
import java.io.PrintStream;
8+
import java.time.ZonedDateTime;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
import static j2html.TagCreator.a;
14+
import static j2html.TagCreator.caption;
15+
import static j2html.TagCreator.div;
16+
import static j2html.TagCreator.each;
17+
import static j2html.TagCreator.h2;
18+
import static j2html.TagCreator.li;
19+
import static j2html.TagCreator.p;
20+
import static j2html.TagCreator.span;
21+
import static j2html.TagCreator.table;
22+
import static j2html.TagCreator.td;
23+
import static j2html.TagCreator.text;
24+
import static j2html.TagCreator.th;
25+
import static j2html.TagCreator.thead;
26+
import static j2html.TagCreator.tr;
27+
import static j2html.TagCreator.ul;
28+
29+
/**
30+
* Prints upgradable dependencies report to stdout or to given file.
31+
* <p>
32+
* Non thread safe.
33+
*/
34+
public class HtmlReportProcessingStrategy extends TextReportProcessingStrategy {
35+
36+
private static final String BASIC_STYLES = "font-family: Verdana,sans-serif;" +
37+
"font-size: 10pt;";
38+
private static final String TABLE_STYLES = "margin: 2em 0;" +
39+
"border-collapse: collapse;";
40+
private static final String CAPTION_STYLES = "text-align: left;" +
41+
"font-weight: bold;";
42+
private static final String TH_TD_STYLES = "border-bottom: 1px solid #ddd;" +
43+
"padding: 10px;" +
44+
"text-align: left;";
45+
private static final String GAV_STYLES = "font-family: \"Courier New\";";
46+
private static final String UL_STYLES = "list-style-type: circle;";
47+
private static final String LI_STYLES = "margin: 7px 0;";
48+
private static final String REPO_LABEL_STYLES = "border-radius: 5px;" +
49+
"padding: 3px;";
50+
private static final String FOOTER_STYLES = "color: #999;";
51+
52+
private static final String BG_NEW = "background-color: #fffeec;";
53+
54+
private static final String BG1 = "background-color: #a8df65;";
55+
private static final String BG2 = "background-color: #edf492;";
56+
private static final String BG3 = "background-color: #efb960;";
57+
private static final String BG4 = "background-color: #ee91bc;";
58+
59+
private static final String[] BACKGROUNDS = {BG1, BG2, BG3, BG4};
60+
61+
private List<String> repositoryKeys;
62+
63+
public HtmlReportProcessingStrategy(Configuration configuration, File pomFile, PrintStream printStream) {
64+
super(configuration, pomFile, printStream);
65+
initRepositoryKeys();
66+
}
67+
68+
public HtmlReportProcessingStrategy(Configuration configuration, File pomFile, String outputFileName) {
69+
super(configuration, pomFile, outputFileName);
70+
initRepositoryKeys();
71+
}
72+
73+
@Override
74+
public boolean process(List<ComponentUpgrade> upgrades) {
75+
try {
76+
if (upgrades.size() == 0) {
77+
LOG.info("No components to upgrade.");
78+
return true;
79+
}
80+
initOutputStream();
81+
82+
List<ComponentUpgrade> sortedUpgrades =
83+
upgrades.stream().sorted(new ComponentUpgradeComparator())
84+
.collect(Collectors.toList());
85+
86+
String html = div().withStyle(BASIC_STYLES).with(
87+
h2("Component Upgrade Report"),
88+
p("Following repositories were searched:"),
89+
ul().withStyle(UL_STYLES).with(
90+
each(configuration.getRepositories().entrySet(),
91+
entry -> li().withStyle(LI_STYLES).with(
92+
span(entry.getKey())
93+
.withStyle(REPO_LABEL_STYLES + repositoryColor(entry.getKey())),
94+
text(" " + entry.getValue())
95+
))
96+
),
97+
table().withStyle(BASIC_STYLES + TABLE_STYLES).with(
98+
caption("Possible Component Upgrades").withStyle(CAPTION_STYLES),
99+
thead(tr().with(
100+
th("GAV").withStyle(TH_TD_STYLES),
101+
th("New Version").withStyle(TH_TD_STYLES),
102+
th("Repository").withStyle(TH_TD_STYLES),
103+
th("Since").withStyle(TH_TD_STYLES)
104+
)),
105+
each(sortedUpgrades, upgrade -> {
106+
boolean isNew = upgrade.getFirstSeen() == null;
107+
return tr().with(
108+
td(upgrade.getArtifact().getGroupId()
109+
+ ":" + upgrade.getArtifact().getArtifactId()
110+
+ ":" + upgrade.getArtifact().getVersionString())
111+
.withStyle(TH_TD_STYLES + GAV_STYLES + (isNew ? BG_NEW : "")),
112+
td(upgrade.getNewVersion())
113+
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : "")),
114+
td(span(upgrade.getRepository())
115+
.withStyle(REPO_LABEL_STYLES + repositoryColor(upgrade.getRepository())))
116+
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : "")),
117+
td(upgrade.getFirstSeen() == null ? "new" : upgrade.getFirstSeen().format(DATE_FORMATTER))
118+
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : ""))
119+
);
120+
}),
121+
tr(td(sortedUpgrades.size() + " items").withStyle(TH_TD_STYLES).attr("colspan", "4"))),
122+
p("Generated on " + DATE_FORMATTER.format(ZonedDateTime.now())),
123+
p().withStyle(FOOTER_STYLES).with(
124+
text("Report generated by "),
125+
a("Maven Dependency Updater")
126+
.withHref(PROJECT_URL)
127+
.withStyle(FOOTER_STYLES)
128+
)
129+
).render();
130+
outputStream.println(html);
131+
return true;
132+
} catch (Exception e) {
133+
throw new RuntimeException("Report generation failed", e);
134+
} finally {
135+
if (outputStream != null && outputStream != System.out) {
136+
outputStream.close();
137+
}
138+
}
139+
}
140+
141+
private void initRepositoryKeys() {
142+
repositoryKeys = new ArrayList<>(configuration.getRepositories().keySet());
143+
}
144+
145+
private String repositoryColor(String key) {
146+
int idx = repositoryKeys.indexOf(key);
147+
return BACKGROUNDS[idx % BACKGROUNDS.length];
148+
}
149+
150+
}

0 commit comments

Comments
 (0)