Skip to content

Commit

Permalink
Merge pull request #14 from Bernardo-MG/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Bernardo-MG committed Nov 29, 2022
2 parents c492798 + 5295377 commit 94f218f
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 131 deletions.
51 changes: 18 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?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">
<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">

<modelVersion>4.0.0</modelVersion>

Expand All @@ -11,7 +10,7 @@
<parent>
<groupId>com.bernardomg.maven</groupId>
<artifactId>base-pom</artifactId>
<version>1.5.1</version>
<version>1.5.3</version>
</parent>

<!-- ********************************************** -->
Expand All @@ -20,7 +19,7 @@

<groupId>com.bernardomg.velocity</groupId>
<artifactId>velocity-config-tool</artifactId>
<version>1.2.5</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>Velocity config tool</name>
Expand Down Expand Up @@ -188,18 +187,18 @@
<!-- ============================================== -->
<!-- =========== DEPENDENCIES VERSIONS ============ -->
<!-- ============================================== -->
<commons.beanUtils.version>1.9.3</commons.beanUtils.version>
<commons.collections.version>3.2.2</commons.collections.version>
<commons.beanUtils.version>1.9.4</commons.beanUtils.version>
<commons.lang3.version>3.11</commons.lang3.version>
<commons.logging.version>1.2</commons.logging.version>
<doxia.decoration.version>1.9.2</doxia.decoration.version>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<mockito.version>4.6.1</mockito.version>
<doxia.decoration.version>1.11.1</doxia.decoration.version>
<junit.jupiter.version>5.9.1</junit.jupiter.version>
<mockito.version>4.9.0</mockito.version>
<plexus.version>3.3.0</plexus.version>
<velocity.tools.version>2.0</velocity.tools.version>
<velocity.tools.version>3.1</velocity.tools.version>
<!-- ============================================== -->
<!-- ================= MAVEN SITE ================= -->
<!-- ============================================== -->
<site.skin.version>2.2.6</site.skin.version>
<site.skin.version>2.2.9</site.skin.version>
<mavenURL>http://mvnrepository.com/artifact/com.bernardomg.velocity/velocity-config-tool</mavenURL>
</properties>

Expand Down Expand Up @@ -235,23 +234,9 @@
</dependency>
<dependency>
<!-- Velocity Tools -->
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>${velocity.tools.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>struts-taglib</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.struts</groupId>
<artifactId>struts-tiles</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- ============================================== -->
<!-- ============ ENFORCED DEPENDENCIES =========== -->
Expand All @@ -265,18 +250,18 @@
<artifactId>commons-beanutils</artifactId>
<version>${commons.beanUtils.version}</version>
</dependency>
<dependency>
<!-- Commons Collections -->
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons.collections.version}</version>
</dependency>
<dependency>
<!-- Commons Logging -->
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons.logging.version}</version>
</dependency>
<dependency>
<!-- Commons Lang 3 -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<!-- ============================================== -->
<!-- ======= TEST ENVIRONMENT DEPENDENCIES ======== -->
<!-- ============================================== -->
Expand Down
8 changes: 8 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,13 @@
Updated dependencies.
</action>
</release>
<release version="1.3.0" date="2022-11-29" description="Updated velocity">
<action dev="bmg" type="fix">
Updated velocity to the latest stable version to fix vulnerabilities.
</action>
<action dev="bmg" type="update">
Updated dependencies.
</action>
</release>
</body>
</document>
107 changes: 50 additions & 57 deletions src/main/java/com/bernardomg/velocity/tool/ConfigTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;

/**
* Utilities class to ease using custom Maven Site configuration values through
* Velocity.
* Utilities class to ease using custom Maven Site configuration values through Velocity.
* <p>
* The configuration values should be in the site.xml file, inside a {@code
* <skinConfig>}, itself inside the {@code <custom>} element, like this:
*
*
* <pre>
* {@code <project>
* <custom>
Expand All @@ -49,17 +48,15 @@
* </project>}
* </pre>
* <p>
* Any value stored there can be acquired through the use of the
* {@link #get(String) get} method. Note that thanks to Velocity inside a
* template any getter can be replaced by the field it returns, and this works
* with the {@code get} method too.
* Any value stored there can be acquired through the use of the {@link #get(String) get} method. Note that thanks to
* Velocity inside a template any getter can be replaced by the field it returns, and this works with the {@code get}
* method too.
* <p>
* This means that instead of using {@code $config.get("myproperty")}, the same
* value can be acquired with {@code $config.myproperty}.
* This means that instead of using {@code $config.get("myproperty")}, the same value can be acquired with
* {@code $config.myproperty}.
* <p>
* This tool is stateful, as it binds itself to the context and data of the page
* being rendered.
*
* This tool is stateful, as it binds itself to the context and data of the page being rendered.
*
* @author Bernardo Mart&iacute;nez Garrido
*/
@DefaultKey("config")
Expand All @@ -85,8 +82,8 @@ public final class ConfigTool extends SafeConfig {
/**
* Skin configuration node.
* <p>
* This contains the custom configuration for the skin, as set inside the
* site.xml file, inside the {@code <custom>} node.
* This contains the custom configuration for the skin, as set inside the site.xml file, inside the {@code <custom>}
* node.
*/
private Xpp3Dom skinConfig = new Xpp3Dom("");

Expand All @@ -105,14 +102,12 @@ public ConfigTool() {
/**
* Returns a configuration's node property.
* <p>
* This node will be acquired from the custom skin configuration inside the
* site.xml file. If there is no node with a matching name then the returned
* value will be {@code null}.
*
* This node will be acquired from the custom skin configuration inside the site.xml file. If there is no node with
* a matching name then the returned value will be {@code null}.
*
* @param property
* the property being acquired
* @return the value assigned to the property in the skin custom
* configuration
* @return the value assigned to the property in the skin custom configuration
*/
public final Xpp3Dom get(final String property) {
Objects.requireNonNull(property, "Received a null pointer as property");
Expand All @@ -125,9 +120,8 @@ public final Xpp3Dom get(final String property) {
* <p>
* This is a slugged version of the current file name.
* <p>
* With Velocity the value can be acquired by using the command
* {@code $config.fileId}.
*
* With Velocity the value can be acquired by using the command {@code $config.fileId}.
*
* @return the file identifier
*/
public final String getFileId() {
Expand All @@ -136,7 +130,7 @@ public final String getFileId() {

/**
* Returns the regular expression for multiple hyphens.
*
*
* @return the regular expression for multiple hyphens
*/
private final Pattern getMultipleHyphenPattern() {
Expand All @@ -145,7 +139,7 @@ private final Pattern getMultipleHyphenPattern() {

/**
* Returns the non-latin characters regular expression.
*
*
* @return the non-latin characters regular expression
*/
private final Pattern getNonLatinPattern() {
Expand All @@ -155,9 +149,9 @@ private final Pattern getNonLatinPattern() {
/**
* Returns the skin config node.
* <p>
* This contains the custom configuration for the skin, as set inside the
* site.xml file, inside the {@code <custom>} node.
*
* This contains the custom configuration for the skin, as set inside the site.xml file, inside the {@code <custom>}
* node.
*
* @return the skin config node
*/
private final Xpp3Dom getSkinConfig() {
Expand All @@ -166,7 +160,7 @@ private final Xpp3Dom getSkinConfig() {

/**
* Returns the regular expression for whitespaces.
*
*
* @return the regular expression for whitespaces
*/
private final Pattern getWhitespacePattern() {
Expand All @@ -177,18 +171,17 @@ private final Pattern getWhitespacePattern() {
* Loads the file identifier from the velocity tools context.
* <p>
* This is generated from the file's name.
*
*
* @param context
* the Velocity tools context
*/
private final void loadFileId(final ToolContext context) {
final Integer lastDot; // Location of the extension dot
final Object currentFileObj; // File's name as received
String currentFile; // File's name
final Integer lastDot; // Location of the extension dot
final Object currentFileObj; // File's name as received
String currentFile; // File's name

if (context.containsKey(ConfigToolConstants.CURRENT_FILE_NAME_KEY)) {
currentFileObj = context
.get(ConfigToolConstants.CURRENT_FILE_NAME_KEY);
currentFileObj = context.get(ConfigToolConstants.CURRENT_FILE_NAME_KEY);
if (currentFileObj == null) {
setFileId("");
} else {
Expand All @@ -209,16 +202,15 @@ private final void loadFileId(final ToolContext context) {
}

/**
* Processes the decoration model, acquiring the skin and page
* configuration.
* Processes the decoration model, acquiring the skin and page configuration.
* <p>
* The decoration model are the contents of the site.xml file.
*
*
* @param model
* decoration data
*/
private final void processDecoration(final DecorationModel model) {
final Object customObj; // Object for the <custom> node
final Object customObj; // Object for the <custom> node
final Xpp3Dom customNode; // <custom> node
final Xpp3Dom skinNode; // <skinConfig> node

Expand All @@ -242,7 +234,7 @@ private final void processDecoration(final DecorationModel model) {

/**
* Sets the identifier for the current file.
*
*
* @param id
* the identifier for the current file
*/
Expand All @@ -252,7 +244,7 @@ private final void setFileId(final String id) {

/**
* Sets the skin config node.
*
*
* @param config
* the skin config node.
*/
Expand All @@ -263,39 +255,40 @@ private final void setSkinConfig(final Xpp3Dom config) {
/**
* Returns a URL slug created from the received text.
* <p>
* A slug is a human-readable version of the text, where all the special
* characters have been removed, and spaces have been swapped by dashes.
* A slug is a human-readable version of the text, where all the special characters have been removed, and spaces
* have been swapped by dashes.
* <p>
* For example: <em>This, That & the Other! Various Outré
* Considerations</em> would become
* For example: <em>This, That & the Other! Various Outré Considerations</em> would become
* <em>this-that-the-other-various-outre-considerations</em>
* <p>
* Of course, this can be applied to any text, not just URLs, but it is
* usually used in the context of an URL.
*
* Of course, this can be applied to any text, not just URLs, but it is usually used in the context of an URL.
*
* @param text
* text to generate the slug from
* @return the slug of the given text
*/
private final String slug(final String text) {
final String separator; // Separator for swapping whitespaces
String corrected; // Modified string
String corrected; // Modified string

Objects.requireNonNull(text, "Received a null pointer as the text");

separator = "-";

corrected = text.replace('/', '-').replace('\\', '-').replace('.', '-')
.replace('_', '-');
corrected = text.replace('/', '-')
.replace('\\', '-')
.replace('.', '-')
.replace('_', '-');

// Removes multiple lines
corrected = getMultipleHyphenPattern().matcher(corrected)
.replaceAll(separator);
.replaceAll(separator);
// Removes white spaces
corrected = getWhitespacePattern().matcher(corrected)
.replaceAll(separator);
.replaceAll(separator);
// Removes non-latin characters
corrected = getNonLatinPattern().matcher(corrected).replaceAll("");
corrected = getNonLatinPattern().matcher(corrected)
.replaceAll("");

return corrected.toLowerCase();
}
Expand All @@ -305,9 +298,9 @@ private final String slug(final String text) {
*/
@Override
protected final void configure(final ValueParser values) {
final Object velocityContext; // Value from the parser
final ToolContext ctxt; // Casted context
final Object decorationObj; // Value of the decoration key
final Object velocityContext; // Value from the parser
final ToolContext ctxt; // Casted context
final Object decorationObj; // Value of the decoration key

Objects.requireNonNull(values, "Received a null pointer as values");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
/**
* Constants for the configuration tool.
* <p>
* The {@link #SKIN_KEY} field contains the name for the node containing the
* configuration. Changing this will change the configuration location.
* The {@link #SKIN_KEY} field contains the name for the node containing the configuration. Changing this will change
* the configuration location.
* <p>
* All the other constants should not be modified.
*
*
* @author Bernardo Mart&iacute;nez Garrido
*/
@DefaultKey("config")
Expand All @@ -57,12 +57,10 @@ public final class ConfigToolConstants {
/**
* Key for the skin configuration.
* <p>
* This is the name of the node inside the site.xml file where the skin's
* configuration is stored.
* This is the name of the node inside the site.xml file where the skin's configuration is stored.
* <p>
* It will be a node inside the custom node, with the project node at the
* root, like this:
*
* It will be a node inside the custom node, with the project node at the root, like this:
*
* <pre>
* {@code <project>
* <custom>
Expand Down

0 comments on commit 94f218f

Please sign in to comment.