Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	pom.xml
  • Loading branch information
agabrys committed Jan 11, 2017
2 parents ac6eb63 + 0fe37aa commit 29342af
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 36 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Directory Content Maven Plugin Changelog

## 1.1.0
Features:
* Added the [copyFile](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/copyFile-mojo.html) goal

Bugs:
* Corrected the condition of the skip copying for the [copy](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/copy-mojo.html) goal

[See documentation](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/)

## 1.0.2
Dependencies:
* Upgraded [Maven Plugin Utils](http://maven-plugin-utils.projects.gabrys.biz/) from [1.3.0](http://maven-plugin-utils.projects.gabrys.biz/1.3.0/) to [1.4.0](http://maven-plugin-utils.projects.gabrys.biz/1.4.0/)
Expand Down
38 changes: 38 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
properties([[
$class: 'BuildDiscarderProperty',
strategy: [
$class: 'LogRotator',
artifactDaysToKeepStr: '-1',
artifactNumToKeepStr: '10',
daysToKeepStr: '-1',
numToKeepStr: '10'
]
]])

node {
timestamps {
stage('Pre Build Cleanup') {
step($class: 'WsCleanup')
}
stage('Checkout') {
checkout scm
}

withMaven(maven: 'MVN-3', jdk: 'JDK-8', mavenLocalRepo: '.repository') {
stage('Build') {
sh 'mvn -e install site -DskipTests'
}
stage('Test') {
sh 'mvn -e test'
junit 'target/surefire-reports/TEST-*.xml'
}
}

stage('Archive') {
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
stage('Post Build Cleanup') {
step($class: 'WsCleanup')
}
}
}
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
Provides a collection of tools for working with directories.

# Goals Overview
* [directory-content:copy](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/copy-mojo.html) - copies files to directory
* [directory-content:transformList](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/transformList-mojo.html) - transforms files list to a document using [XSLT](http://www.w3.org/TR/xslt) technology
* [directory-content:transformMetadata](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/transformMetadata-mojo.html) - transforms files metadata to documents using [XSLT](http://www.w3.org/TR/xslt) technology
* [directory-content:copy](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/copy-mojo.html) - copies files to directory
* [directory-content:copyFile](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/copyFile-mojo.html) - copies file from source to output directory (allow to change name)
* [directory-content:transformList](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/transformList-mojo.html) - transforms files list to a document using [XSLT](http://www.w3.org/TR/xslt) technology
* [directory-content:transformMetadata](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/transformMetadata-mojo.html) - transforms files metadata to documents using [XSLT](http://www.w3.org/TR/xslt) technology

# Requirements
The plugin to run requires:
* Java 5.0 or higher
* Maven 2.0.11 or higher

# Usage
General instructions on how to use the Directory Content Maven Plugin can be found on the [usage](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/usage.html) page. Some more specific use cases are described in the examples given below. Last but not least, users occasionally contribute additional examples, tips or errata to the plugin's [wiki](https://github.com/gabrysbiz/directory-content-maven-plugin/wiki) page.
General instructions on how to use the Directory Content Maven Plugin can be found on the [usage](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/usage.html) page. Some more specific use cases are described in the examples given below. Last but not least, users occasionally contribute additional examples, tips or errata to the plugin's [wiki](https://github.com/gabrysbiz/directory-content-maven-plugin/wiki) page.

In case you still have questions regarding the plugin's usage, please have a look at the [FAQ](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/faq.html).
In case you still have questions regarding the plugin's usage, please have a look at the [FAQ](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/faq.html).

If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in the [issue tracker](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/issue-tracking.html). When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from the [source repository](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/source-repository.html) and will find supplementary information in the [guide to helping with Maven](http://maven.apache.org/guides/development/guide-helping.html).
If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in the [issue tracker](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/issue-tracking.html). When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from the [source repository](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/source-repository.html) and will find supplementary information in the [guide to helping with Maven](http://maven.apache.org/guides/development/guide-helping.html).

# Examples
To provide you with better understanding of some usages of the Directory Content Maven Plugin, you can take a look into the following examples:
* [Using include/exclude patterns](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/examples/patterns.html)
* [Copies files from source to output directory](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/examples/copy.html)
* [Transform files list to file with JavaScript imports](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/examples/transform-list.html)
* [Transform files metadata to download files](http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/examples/transform-metadata.html)
* [Using include/exclude patterns](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/examples/patterns.html)
* [Copies files from source to output directory](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/examples/copy.html)
* [Copies file to output directory with a new name](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/examples/copyFile.html)
* [Transform files list to file with JavaScript imports](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/examples/transform-list.html)
* [Transform files metadata to download files](http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/examples/transform-metadata.html)

You can also fetch example projects from [GitHub](https://github.com/gabrysbiz/directory-content-maven-plugin-examples).
22 changes: 12 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

<groupId>biz.gabrys.maven.plugins</groupId>
<artifactId>directory-content-maven-plugin</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
<packaging>maven-plugin</packaging>
<name>Directory Content Maven Plugin</name>
<description>Provides a collection of tools for working with directories.</description>
<url>http://directory-content-maven-plugin.projects.gabrys.biz/1.0.2/</url>
<url>http://directory-content-maven-plugin.projects.gabrys.biz/1.1.0/</url>

<inceptionYear>2015</inceptionYear>
<organization>
Expand Down Expand Up @@ -62,7 +62,7 @@
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>

Expand All @@ -80,7 +80,8 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<!-- latest compatible with JDK 1.5 -->
<version>3.4</version>
<scope>provided</scope>
</dependency>

Expand All @@ -106,16 +107,17 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<!-- latest compatible with JDK 1.5 -->
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype's SNAPSHOT repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
Expand Down Expand Up @@ -169,11 +171,11 @@
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.5.1</version>
<version>3.6</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
Expand Down Expand Up @@ -203,7 +205,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<version>0.7.8</version>
<configuration>
<rules>
<rule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import biz.gabrys.maven.plugin.util.parameter.sanitizer.SimpleSanitizer;

/**
* Parent class for all plugin goals.
* Parent class for plugin goals which process multiple files.
* @since 1.0
*/
abstract class AbstractPluginMojo extends AbstractMojo {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Directory Content Maven Plugin
* http://directory-content-maven-plugin.projects.gabrys.biz/
*
* Copyright (c) 2015 Adam Gabryś
*
* This file is licensed under the BSD 3-Clause (the "License").
* You may not use this file except in compliance with the License.
* You may obtain:
* - a copy of the License at project page
* - a template of the License at https://opensource.org/licenses/BSD-3-Clause
*/
package biz.gabrys.maven.plugins.directory.content;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import biz.gabrys.maven.plugin.util.parameter.ParametersLogBuilder;
import biz.gabrys.maven.plugin.util.parameter.sanitizer.SimpleSanitizer;

/**
* Copies file from source to output directory (allow to change name).
* @since 1.1.0
*/
@Mojo(name = "copyFile", defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true)
public class CopyFileMojo extends AbstractMojo {

/**
* Defines whether to skip the plugin execution.
* @since 1.1.0
*/
@Parameter(property = "directory.content.skip", defaultValue = "false")
protected boolean skip;

/**
* Forces to always copy file. By default file is only copied when modified or the destination file does not exist.
* @since 1.1.0
*/
@Parameter(property = "directory.content.force", defaultValue = "false")
protected boolean force;

/**
* The directory with source file.
* @since 1.1.0
*/
@Parameter(property = "directory.content.sourceDirectory", defaultValue = "${basedir}")
protected File sourceDirectory;

/**
* The source file path which will be copied (examples: <code>filename.ext</code>,
* <code>directory/filename.ext</code>).
* @since 1.1.0
*/
@Parameter(property = "directory.content.sourceFilePath", required = true)
protected String sourceFilePath;

/**
* The destination directory for copied file.
* @since 1.1.0
*/
@Parameter(property = "directory.content.outputDirectory", defaultValue = "${project.build.directory}")
protected File outputDirectory;

/**
* The destination file path (examples: <code>filename.ext</code>, <code>directory/filename.ext</code>).<br>
* <b>Default value is</b>: the same as <a href="#sourceFilePath">source file path</a>.
* @since 1.1.0
*/
@Parameter(property = "directory.content.outputFilePath")
protected String outputFilePath;

private void logParameters() {
if (!getLog().isDebugEnabled()) {
return;
}

final ParametersLogBuilder logger = new ParametersLogBuilder(getLog());
logger.append("skip", skip);
logger.append("force", force);
logger.append("sourceDirectory", sourceDirectory);
logger.append("sourceFilePath", sourceFilePath);
logger.append("outputDirectory", outputDirectory);
logger.append("outputFilePath", outputFilePath, new SimpleSanitizer(isOutputFilePathValid(), sourceFilePath));
logger.debug();
}

private void calculateParameters() {
if (!isOutputFilePathValid()) {
outputFilePath = sourceFilePath;
}
}

private boolean isOutputFilePathValid() {
return outputFilePath != null && outputFilePath.length() > 0;
}

public void execute() throws MojoFailureException {
logParameters();
if (skip) {
getLog().info("Skipping job execution");
return;
}
validateParameters();
calculateParameters();
final File sourceFile = new File(sourceDirectory, sourceFilePath);
final File outputFile = new File(outputDirectory, outputFilePath);
if (shouldCopyFile(sourceFile, outputFile)) {
copyFile(sourceFile, outputFile);
}
}

private void validateParameters() throws MojoFailureException {
if (!sourceDirectory.exists()) {
throw new MojoFailureException("Source directory does not exist: " + sourceDirectory.getAbsolutePath());
}
final File file = new File(sourceDirectory, sourceFilePath);
if (!file.exists()) {
throw new MojoFailureException("Source file does not exist: " + file.getAbsolutePath());
}
}

private boolean shouldCopyFile(final File sourceFile, final File outputFile) {
if (!force && outputFile.exists() && sourceFile.lastModified() <= outputFile.lastModified()) {
getLog().info(String.format("Skips copy file, because source (%s) is older than destination file (%s)",
sourceFile.getAbsolutePath(), outputFile.getAbsolutePath()));
return false;
}
return true;
}

private void copyFile(final File sourceFile, final File outputFile) throws MojoFailureException {
getLog().info(String.format("Copying %s to %s", sourceFile.getAbsolutePath(), outputFile.getAbsolutePath()));
try {
FileUtils.copyFile(sourceFile, outputFile);
} catch (final IOException e) {
final String message = String.format("Cannot copy %s to %s", sourceFile.getAbsolutePath(), outputFile.getAbsolutePath());
throw new MojoFailureException(message, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ protected void fillParameters(final ParametersLogBuilder logger) {
protected void execute(final Collection<File> files) throws MojoFailureException {
getLog().info(String.format("Coping %s file%s...", files.size(), files.size() != 1 ? "s" : ""));

for (final File file : files) {
copy(file, getDestination(file));
for (final File sourceFile : files) {
final File outputFile = getDestination(sourceFile);
if (shouldCopyFile(sourceFile, outputFile)) {
copyFile(sourceFile, outputFile);
}
}
}

Expand All @@ -57,21 +60,25 @@ private File getDestination(final File file) {
return new File(outputDirectory.getAbsolutePath() + File.separator + path);
}

private void copy(final File source, final File destination) throws MojoFailureException {
if (!force && destination.exists() && source.lastModified() < destination.lastModified()) {
private boolean shouldCopyFile(final File sourceFile, final File outputFile) {
if (!force && outputFile.exists() && sourceFile.lastModified() <= outputFile.lastModified()) {
if (verbose) {
getLog().info("Skips copy file, because source is older than destination file: " + destination.getAbsolutePath());
getLog().info(String.format("Skips copy file, because source (%s) is older than destination file (%s)",
sourceFile.getAbsolutePath(), outputFile.getAbsolutePath()));
}
return;
return false;
}
return true;
}

private void copyFile(final File sourceFile, final File outputFile) throws MojoFailureException {
if (verbose) {
getLog().info(String.format("Copying %s to %s", source.getAbsolutePath(), destination.getAbsolutePath()));
getLog().info(String.format("Copying %s to %s", sourceFile.getAbsolutePath(), outputFile.getAbsolutePath()));
}
try {
FileUtils.copyFile(source, destination);
FileUtils.copyFile(sourceFile, outputFile);
} catch (final IOException e) {
final String message = String.format("Cannot copy %s to %s", source.getAbsolutePath(), destination.getAbsolutePath());
final String message = String.format("Cannot copy %s to %s", sourceFile.getAbsolutePath(), outputFile.getAbsolutePath());
throw new MojoFailureException(message, e);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/site/site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.5</version>
<version>1.6</version>
</skin>
<custom>
<fluidoSkin>
Expand All @@ -37,6 +37,7 @@
<item name="Examples" collapse="true" href="examples.html">
<item name="Using include/exclude patterns" href="examples/patterns.html" />
<item name="Copies files" href="examples/copy.html" />
<item name="Copies file with a new name" href="examples/copyFile.html" />
<item name="Transform files list" href="examples/transform-list.html" />
<item name="Transform files metadata" href="examples/transform-metadata.html" />
</item>
Expand Down
Loading

0 comments on commit 29342af

Please sign in to comment.