Skip to content

Commit 528ae01

Browse files
committed
Merge branch 'feature/config-file-filtering' into develop
2 parents 40ba069 + 72a1ad3 commit 528ae01

5 files changed

Lines changed: 99 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ npm-debug.log
2727
*.sublime-*
2828
*nbactions*.xml
2929
.temp/
30+
31+
pom-test.xml

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ In our wcm.io and other Maven-based projects we usually use both m2e Integration
1111

1212
So we maintain a fork of the original plugin here and publish it under Apache 2.0 license within the wcm.io DevOps project.
1313

14-
This fork includes the patch from [MECLIPSE-641](https://issues.apache.org/jira/browse/MECLIPSE-641) which was never applied to the original code base, but is important for generating the eclipse project settings.
14+
Changes since the original Maven Eclipse Plugin 2.10:
15+
16+
* Patch from [MECLIPSE-641](https://issues.apache.org/jira/browse/MECLIPSE-641) which was never applied to the original code base, but is important for generating the eclipse project settings (since 3.0.0)
17+
* Add support for `filtering` property on additionalConfig files (since 3.1.0)
1518

1619
To use this in your projects update all your POMs to use
1720

1821
```xml
1922
<plugin>
2023
<groupId>io.wcm.devops.maven.plugins</groupId>
2124
<artifactId>eclipse-maven-plugin</artifactId>
22-
<version>3.0.0</version>
25+
<version>3.1.0</version>
2326
</plugin>
2427
```
2528

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ under the License.
139139
<artifactId>wagon-provider-api</artifactId>
140140
<version>2.1</version>
141141
</dependency>
142+
<dependency>
143+
<groupId>org.apache.maven.shared</groupId>
144+
<artifactId>maven-filtering</artifactId>
145+
<version>3.1.1</version>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.codehaus.plexus</groupId>
149+
<artifactId>plexus-interpolation</artifactId>
150+
<version>1.25</version>
151+
</dependency>
142152
<dependency>
143153
<groupId>commons-io</groupId>
144154
<artifactId>commons-io</artifactId>
@@ -320,6 +330,7 @@ under the License.
320330
<excludes combine.children="append">
321331
<exclude>README-testing.txt</exclude>
322332
<exclude>README.md</exclude>
333+
<exclude>infinitest.filters</exclude>
323334

324335
<!--
325336
These files contain several files for eclipse

src/main/java/org/apache/maven/plugin/eclipse/EclipseConfigFile.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class EclipseConfigFile
5252
* @since 2.5
5353
*/
5454
private URL url;
55+
56+
private boolean filtering;
5557

5658
/**
5759
* Getter for <code>content</code>.
@@ -132,4 +134,27 @@ public void setURL( URL url )
132134
{
133135
this.url = url;
134136
}
137+
138+
/**
139+
* Filter resource (replace placeholders)
140+
* @return if true resources is filtered
141+
*
142+
* @since 3.1.0
143+
*/
144+
public boolean isFiltering()
145+
{
146+
return filtering;
147+
}
148+
149+
/**
150+
* Filter resource (replace placeholders)
151+
* @param filtering if true resources is filtered
152+
*
153+
* @since 3.1.0
154+
*/
155+
public void setFiltering( boolean filtering )
156+
{
157+
this.filtering = filtering;
158+
}
159+
135160
}

src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.URL;
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
30+
import java.util.Collections;
3031
import java.util.LinkedHashSet;
3132
import java.util.LinkedList;
3233
import java.util.List;
@@ -37,6 +38,7 @@
3738
import org.apache.maven.artifact.Artifact;
3839
import org.apache.maven.artifact.handler.ArtifactHandler;
3940
import org.apache.maven.artifact.manager.WagonManager;
41+
import org.apache.maven.execution.MavenSession;
4042
import org.apache.maven.model.Build;
4143
import org.apache.maven.model.Plugin;
4244
import org.apache.maven.model.Resource;
@@ -66,6 +68,9 @@
6668
import org.apache.maven.settings.MavenSettingsBuilder;
6769
import org.apache.maven.settings.Proxy;
6870
import org.apache.maven.settings.Settings;
71+
import org.apache.maven.shared.filtering.MavenFilteringException;
72+
import org.apache.maven.shared.filtering.MavenResourcesExecution;
73+
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
6974
import org.apache.maven.wagon.Wagon;
7075
import org.apache.maven.wagon.WagonException;
7176
import org.apache.maven.wagon.observers.Debug;
@@ -95,7 +100,7 @@
95100
* @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
96101
* @version $Id$
97102
*/
98-
@Mojo( name = "eclipse" )
103+
@Mojo( name = "eclipse", requiresProject = true )
99104
@Execute( phase = LifecyclePhase.GENERATE_RESOURCES )
100105
public class EclipsePlugin
101106
extends AbstractIdeSupportMojo
@@ -647,6 +652,11 @@ public class EclipsePlugin
647652
@Parameter( property = "eclipse.jeeversion" )
648653
protected String jeeversion;
649654

655+
@Component( role = MavenResourcesFiltering.class, hint = "default" )
656+
protected MavenResourcesFiltering mavenResourcesFiltering;
657+
@Parameter( defaultValue = "${session}" )
658+
private MavenSession mavenSession;
659+
650660
protected final boolean isJavaProject()
651661
{
652662
return isJavaProject;
@@ -1337,6 +1347,51 @@ private void writeAdditionalConfig()
13371347
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.settingsxmlfailure",
13381348
e.getMessage() ) );
13391349
}
1350+
1351+
// if configured apply resource filtering on the copied resource
1352+
if ( projectRelativeFile.exists() && projectRelativeFile.isFile() && file.isFiltering() )
1353+
{
1354+
String encoding = IdeUtils.getCompilerSourceEncoding( project );
1355+
1356+
File outputDir = new File( projectRelativeFile.getParent() + "/_filtered" );
1357+
outputDir.mkdirs();
1358+
1359+
Resource dummyResource = new Resource();
1360+
dummyResource.setDirectory( projectRelativeFile.getParent() );
1361+
dummyResource.setIncludes( Arrays.asList( projectRelativeFile.getName() ) );
1362+
dummyResource.setFiltering( true );
1363+
MavenResourcesExecution exec = new MavenResourcesExecution(
1364+
Arrays.asList( dummyResource ),
1365+
outputDir,
1366+
project,
1367+
encoding,
1368+
Collections.<String>emptyList(),
1369+
Collections.<String>emptyList(),
1370+
mavenSession );
1371+
try
1372+
{
1373+
mavenResourcesFiltering.filterResources( exec );
1374+
}
1375+
catch ( MavenFilteringException ex )
1376+
{
1377+
throw new MojoExecutionException( "Error filtering resource: "
1378+
+ projectRelativeFile.getPath(), ex );
1379+
}
1380+
1381+
File filteredFile = new File( outputDir, projectRelativeFile.getName() );
1382+
projectRelativeFile.delete();
1383+
try
1384+
{
1385+
org.apache.commons.io.FileUtils.moveFile( filteredFile, projectRelativeFile );
1386+
}
1387+
catch ( IOException ex )
1388+
{
1389+
throw new MojoExecutionException( "Error moving " + filteredFile.getPath() + " to "
1390+
+ projectRelativeFile.getPath(), ex );
1391+
}
1392+
outputDir.delete();
1393+
}
1394+
13401395
}
13411396
}
13421397
}

0 commit comments

Comments
 (0)