Skip to content
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
17 changes: 15 additions & 2 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>4.5.3.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -50,9 +60,12 @@
<mainClass>org.jboss.set.mavendependencyupdater.cli.Cli</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptors>
<descriptor>src/assembly/jar.xml</descriptor>
</descriptors>
<!--<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</descriptorRefs>-->
<appendAssemblyId>false</appendAssemblyId>
<finalName>${artifactName}-${project.version}</finalName>
</configuration>
Expand Down
28 changes: 28 additions & 0 deletions cli/src/assembly/jar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>customized-jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<containerDescriptorHandlers>
<containerDescriptorHandler>
<handlerName>metaInf-services</handlerName>
</containerDescriptorHandler>
<containerDescriptorHandler>
<handlerName>metaInf-spring</handlerName>
</containerDescriptorHandler>
<containerDescriptorHandler>
<handlerName>plexus</handlerName>
</containerDescriptorHandler>
</containerDescriptorHandlers>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jboss.set.mavendependencyupdater.AvailableVersionsResolver;
import org.jboss.set.mavendependencyupdater.DefaultAvailableVersionsResolver;
import org.jboss.set.mavendependencyupdater.DependencyEvaluator;
import org.jboss.set.mavendependencyupdater.core.processingstrategies.HtmlReportProcessingStrategy;
import org.jboss.set.mavendependencyupdater.core.processingstrategies.ModifyLocallyProcessingStrategy;
import org.jboss.set.mavendependencyupdater.core.processingstrategies.SeparatePRsProcessingStrategy;
import org.jboss.set.mavendependencyupdater.core.processingstrategies.TextReportProcessingStrategy;
Expand All @@ -33,9 +34,11 @@ public class Cli {
private static final String PERFORM_UPGRADES = "perform-upgrades";
private static final String GENERATE_PRS = "generate-prs";
private static final String GENERATE_REPORT = "generate-report";
private static final String GENERATE_HTML_REPORT = "generate-html-report";
private static final String GENERATE_CONFIG = "generate-config";
private static final String CHECK_CONFIG = "check-config";
private static final String[] COMMANDS = {PERFORM_UPGRADES, GENERATE_PRS, GENERATE_REPORT, GENERATE_CONFIG, CHECK_CONFIG};
private static final String[] COMMANDS = {PERFORM_UPGRADES, GENERATE_PRS, GENERATE_REPORT, GENERATE_HTML_REPORT,
GENERATE_CONFIG, CHECK_CONFIG};

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

Expand Down Expand Up @@ -137,6 +140,15 @@ private int run(String[] args) throws Exception {
strategy = new TextReportProcessingStrategy(configuration, pomFile, System.out);
}
success = performAlignment(strategy);
} else if (GENERATE_HTML_REPORT.equals(arguments[0])) {
configuration = new Configuration(configurationFile);
UpgradeProcessingStrategy strategy;
if (cmd.hasOption('o')) {
strategy = new HtmlReportProcessingStrategy(configuration, pomFile, cmd.getOptionValue('o'));
} else {
strategy = new HtmlReportProcessingStrategy(configuration, pomFile, System.out);
}
success = performAlignment(strategy);
} else if (GENERATE_CONFIG.equals(arguments[0])) {
new ConfigurationGenerator().generateDefautlConfig(configurationFile, rootProjectDependencies);
success = true;
Expand Down
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>git-manipulator</artifactId>
</dependency>

<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package org.jboss.set.mavendependencyupdater.core.processingstrategies;

import org.jboss.set.mavendependencyupdater.DependencyEvaluator.ComponentUpgrade;
import org.jboss.set.mavendependencyupdater.configuration.Configuration;

import java.io.File;
import java.io.PrintStream;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static j2html.TagCreator.a;
import static j2html.TagCreator.caption;
import static j2html.TagCreator.div;
import static j2html.TagCreator.each;
import static j2html.TagCreator.h2;
import static j2html.TagCreator.li;
import static j2html.TagCreator.p;
import static j2html.TagCreator.span;
import static j2html.TagCreator.table;
import static j2html.TagCreator.td;
import static j2html.TagCreator.text;
import static j2html.TagCreator.th;
import static j2html.TagCreator.thead;
import static j2html.TagCreator.tr;
import static j2html.TagCreator.ul;

/**
* Prints upgradable dependencies report to stdout or to given file.
* <p>
* Non thread safe.
*/
public class HtmlReportProcessingStrategy extends TextReportProcessingStrategy {

private static final String BASIC_STYLES = "font-family: Verdana,sans-serif;" +
"font-size: 10pt;";
private static final String TABLE_STYLES = "margin: 2em 0;" +
"border-collapse: collapse;";
private static final String CAPTION_STYLES = "text-align: left;" +
"font-weight: bold;";
private static final String TH_TD_STYLES = "border-bottom: 1px solid #ddd;" +
"padding: 10px;" +
"text-align: left;";
private static final String GAV_STYLES = "font-family: \"Courier New\";";
private static final String UL_STYLES = "list-style-type: circle;";
private static final String LI_STYLES = "margin: 7px 0;";
private static final String REPO_LABEL_STYLES = "border-radius: 5px;" +
"padding: 3px;";
private static final String FOOTER_STYLES = "color: #999;";

private static final String BG_NEW = "background-color: #fffeec;";

private static final String BG1 = "background-color: #a8df65;";
private static final String BG2 = "background-color: #edf492;";
private static final String BG3 = "background-color: #efb960;";
private static final String BG4 = "background-color: #ee91bc;";

private static final String[] BACKGROUNDS = {BG1, BG2, BG3, BG4};

private List<String> repositoryKeys;

public HtmlReportProcessingStrategy(Configuration configuration, File pomFile, PrintStream printStream) {
super(configuration, pomFile, printStream);
initRepositoryKeys();
}

public HtmlReportProcessingStrategy(Configuration configuration, File pomFile, String outputFileName) {
super(configuration, pomFile, outputFileName);
initRepositoryKeys();
}

@Override
public boolean process(List<ComponentUpgrade> upgrades) {
try {
if (upgrades.size() == 0) {
LOG.info("No components to upgrade.");
return true;
}
initOutputStream();

List<ComponentUpgrade> sortedUpgrades =
upgrades.stream().sorted(new ComponentUpgradeComparator())
.collect(Collectors.toList());

String html = div().withStyle(BASIC_STYLES).with(
h2("Component Upgrade Report"),
p("Following repositories were searched:"),
ul().withStyle(UL_STYLES).with(
each(configuration.getRepositories().entrySet(),
entry -> li().withStyle(LI_STYLES).with(
span(entry.getKey())
.withStyle(REPO_LABEL_STYLES + repositoryColor(entry.getKey())),
text(" " + entry.getValue())
))
),
table().withStyle(BASIC_STYLES + TABLE_STYLES).with(
caption("Possible Component Upgrades").withStyle(CAPTION_STYLES),
thead(tr().with(
th("GAV").withStyle(TH_TD_STYLES),
th("New Version").withStyle(TH_TD_STYLES),
th("Repository").withStyle(TH_TD_STYLES),
th("Since").withStyle(TH_TD_STYLES)
)),
each(sortedUpgrades, upgrade -> {
boolean isNew = upgrade.getFirstSeen() == null;
return tr().with(
td(upgrade.getArtifact().getGroupId()
+ ":" + upgrade.getArtifact().getArtifactId()
+ ":" + upgrade.getArtifact().getVersionString())
.withStyle(TH_TD_STYLES + GAV_STYLES + (isNew ? BG_NEW : "")),
td(upgrade.getNewVersion())
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : "")),
td(span(upgrade.getRepository())
.withStyle(REPO_LABEL_STYLES + repositoryColor(upgrade.getRepository())))
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : "")),
td(upgrade.getFirstSeen() == null ? "new" : upgrade.getFirstSeen().format(DATE_FORMATTER))
.withStyle(TH_TD_STYLES + (isNew ? BG_NEW : ""))
);
}),
tr(td(sortedUpgrades.size() + " items").withStyle(TH_TD_STYLES).attr("colspan", "4"))),
p("Generated on " + DATE_FORMATTER.format(ZonedDateTime.now())),
p().withStyle(FOOTER_STYLES).with(
text("Report generated by "),
a("Maven Dependency Updater")
.withHref(PROJECT_URL)
.withStyle(FOOTER_STYLES)
)
).render();
outputStream.println(html);
return true;
} catch (Exception e) {
throw new RuntimeException("Report generation failed", e);
} finally {
if (outputStream != null && outputStream != System.out) {
outputStream.close();
}
}
}

private void initRepositoryKeys() {
repositoryKeys = new ArrayList<>(configuration.getRepositories().keySet());
}

private String repositoryColor(String key) {
int idx = repositoryKeys.indexOf(key);
return BACKGROUNDS[idx % BACKGROUNDS.length];
}

}
Loading