Skip to content

Commit

Permalink
Paths must be relative to ${project.basedir}.
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-petricca committed Aug 9, 2024
1 parent 0ef954b commit ecf0b81
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<groupId>io.github.antonio-petricca</groupId>
<artifactId>filemerger-maven-plugin</artifactId>
<version>1.4.7</version>
<version>1.5.0</version>

<packaging>maven-plugin</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.antoniopetricca.maven.plugins.filemerger.configuration.*;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -40,10 +39,10 @@ public class MavenFileMergerMojo extends AbstractMojo {
protected DefaultMavenReaderFilter defaultMavenReaderFilter;

@Parameter(defaultValue = "${project}", readonly = true)
MavenProject mavenProject;
private MavenProject mavenProject;

@Parameter(defaultValue = "${session}", readonly = true)
MavenSession mavenSession;
private MavenSession mavenSession;

@Parameter(required = false)
private PropertiesSet[] propertiesSets;
Expand All @@ -57,7 +56,7 @@ public class MavenFileMergerMojo extends AbstractMojo {
@Parameter(required = true)
private TargetFile[] targetFiles;

String convertReaderToString(Reader reader) throws IOException {
private String convertReaderToString(Reader reader) throws IOException {
StringWriter writer = new StringWriter();
char[] buffer = new char[8192];

Expand Down Expand Up @@ -192,7 +191,7 @@ private String getIndentation(TargetFile targetFileConfiguration) {
return indentationString;
}

private Properties getPropertiesConfiguration(String setId)
private Properties getPropertiesConfiguration(String setId, String projectBaseDir)
throws IOException, MojoExecutionException, MavenFilteringException
{
Optional<PropertiesSet> propertiesSetConfiguration =
Expand Down Expand Up @@ -223,6 +222,7 @@ private Properties getPropertiesConfiguration(String setId)

if (propertiesSet.hasPropertyFiles()) {
String[] propertyFilePatterns = scanForFiles(
projectBaseDir,
propertiesSet.getPropertyFilePatterns()
);

Expand Down Expand Up @@ -401,7 +401,8 @@ private void mergeTargetFile(
private void mergeTargetFile(
TargetFile targetFileConfiguration,
Properties properties,
SourceFile[] sourceFilesConfiguration
SourceFile[] sourceFilesConfiguration,
String projectBaseDir
)
throws IOException, MavenFilteringException, MojoExecutionException
{
Expand All @@ -417,7 +418,7 @@ private void mergeTargetFile(
Charset targetCharset = getCharset(targetFileConfiguration);
String targetFolderName = targetFileConfiguration.getTargetFolder();
File targetFolder = new File(targetFolderName);
String[] resolvedTemplateFiles = scanForFiles(templateFilePatterns);
String[] resolvedTemplateFiles = scanForFiles(projectBaseDir, templateFilePatterns);

if ((null == templateFilePatterns) || (0 == templateFilePatterns.length)) {
log.warn("No template files found.");
Expand Down Expand Up @@ -450,10 +451,10 @@ private void mergeTargetFile(
setProperties(propertiesBackup, true);
}

private String[] scanForFiles(String[] filePatterns) {
private String[] scanForFiles(String projectBaseDir, String[] filePatterns) {
DirectoryScanner directoryScanner = new DirectoryScanner();

directoryScanner.setBasedir(".");
directoryScanner.setBasedir(projectBaseDir);
directoryScanner.setCaseSensitive(true);
directoryScanner.setFollowSymlinks(false);
directoryScanner.setIncludes(filePatterns);
Expand Down Expand Up @@ -487,15 +488,22 @@ public void execute()
return;
}

log.info("Merging...");
String projectBaseDir = mavenProject
.getBasedir()
.getAbsolutePath();

log.info(String.format(
"Merging from project base dir \"%s\"...",
projectBaseDir
));

for (TargetFile targetFile : targetFiles) {
try {
Properties properties = null;
String propertiesSet = targetFile.getPropertiesSet();

if ((null != propertiesSet) && !propertiesSet.isEmpty()) {
properties = getPropertiesConfiguration(propertiesSet);
properties = getPropertiesConfiguration(propertiesSet, projectBaseDir);
}

SourceFile[] sourceFiles = null;
Expand All @@ -505,7 +513,7 @@ public void execute()
sourceFiles = getSourceFilesConfiguration(sourceFilesSet);
}

mergeTargetFile(targetFile, properties, sourceFiles);
mergeTargetFile(targetFile, properties, sourceFiles, projectBaseDir);
} catch(IOException | MavenFilteringException exception) {
throw new MojoExecutionException(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public void validate()
}
}

}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>io.github.antonio-petricca</groupId>
<artifactId>filemerger-maven-plugin-pom</artifactId>
<version>1.4.7</version>
<version>1.5.0</version>

<packaging>pom</packaging>

Expand Down
4 changes: 3 additions & 1 deletion tester/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>io.github.antonio-petricca</groupId>
<artifactId>filemerger-maven-plugin-tester</artifactId>
<version>1.4.7</version>
<version>1.5.0</version>

<packaging>jar</packaging>

Expand All @@ -31,6 +31,8 @@
<goal>file-merge</goal>
</goals>
<configuration>
<!-- Paths must be relative to ${project.basedir} -->

<skip>false</skip>

<propertiesSets>
Expand Down

0 comments on commit ecf0b81

Please sign in to comment.