|
27 | 27 | import java.net.URL; |
28 | 28 | import java.util.ArrayList; |
29 | 29 | import java.util.Arrays; |
| 30 | +import java.util.Collections; |
30 | 31 | import java.util.LinkedHashSet; |
31 | 32 | import java.util.LinkedList; |
32 | 33 | import java.util.List; |
|
37 | 38 | import org.apache.maven.artifact.Artifact; |
38 | 39 | import org.apache.maven.artifact.handler.ArtifactHandler; |
39 | 40 | import org.apache.maven.artifact.manager.WagonManager; |
| 41 | +import org.apache.maven.execution.MavenSession; |
40 | 42 | import org.apache.maven.model.Build; |
41 | 43 | import org.apache.maven.model.Plugin; |
42 | 44 | import org.apache.maven.model.Resource; |
|
66 | 68 | import org.apache.maven.settings.MavenSettingsBuilder; |
67 | 69 | import org.apache.maven.settings.Proxy; |
68 | 70 | 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; |
69 | 74 | import org.apache.maven.wagon.Wagon; |
70 | 75 | import org.apache.maven.wagon.WagonException; |
71 | 76 | import org.apache.maven.wagon.observers.Debug; |
|
95 | 100 | * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a> |
96 | 101 | * @version $Id$ |
97 | 102 | */ |
98 | | -@Mojo( name = "eclipse" ) |
| 103 | +@Mojo( name = "eclipse", requiresProject = true ) |
99 | 104 | @Execute( phase = LifecyclePhase.GENERATE_RESOURCES ) |
100 | 105 | public class EclipsePlugin |
101 | 106 | extends AbstractIdeSupportMojo |
@@ -647,6 +652,11 @@ public class EclipsePlugin |
647 | 652 | @Parameter( property = "eclipse.jeeversion" ) |
648 | 653 | protected String jeeversion; |
649 | 654 |
|
| 655 | + @Component( role = MavenResourcesFiltering.class, hint = "default" ) |
| 656 | + protected MavenResourcesFiltering mavenResourcesFiltering; |
| 657 | + @Parameter( defaultValue = "${session}" ) |
| 658 | + private MavenSession mavenSession; |
| 659 | + |
650 | 660 | protected final boolean isJavaProject() |
651 | 661 | { |
652 | 662 | return isJavaProject; |
@@ -1337,6 +1347,51 @@ private void writeAdditionalConfig() |
1337 | 1347 | throw new MojoExecutionException( Messages.getString( "EclipsePlugin.settingsxmlfailure", |
1338 | 1348 | e.getMessage() ) ); |
1339 | 1349 | } |
| 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 | + |
1340 | 1395 | } |
1341 | 1396 | } |
1342 | 1397 | } |
|
0 commit comments