maven/0001-Customize-compiler-plugin.patch
2012-11-22 15:38:55 +01:00

105 lines
3.6 KiB
Diff

From c7d89b31e7764c514138135f91b2e290d410ebc7 Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Thu, 22 Nov 2012 15:28:28 +0100
Subject: [PATCH] Customize compiler plugin
In local mode require source to be >= 1.5 and target >= source.
---
.../model/validation/DefaultModelValidator.java | 68 ++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
index 6c76173..bc0b836 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
@@ -19,6 +19,10 @@ package org.apache.maven.model.validation;
* under the License.
*/
+import java.math.BigDecimal;
+import java.util.LinkedList;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
@@ -342,6 +346,8 @@ public class DefaultModelValidator
"distributionManagement.snapshotRepository", request );
}
}
+
+ customizeModel( model );
}
private void validateRawDependencies( ModelProblemCollector problems, List<Dependency> dependencies, String prefix,
@@ -924,4 +930,66 @@ public class DefaultModelValidator
}
}
+ private void customizeModel( Model model )
+ {
+ // Enable model customizations only in local mode
+ if ( System.getProperty( "maven.local.mode" ) == null )
+ return;
+
+ Build build = model.getBuild();
+ if ( build == null )
+ return;
+
+ List<Plugin> plugins = build.getPlugins();
+ if ( plugins == null )
+ return;
+
+ for ( Plugin plugin : plugins )
+ {
+ String groupId = plugin.getGroupId();
+ String artifactId = plugin.getArtifactId();
+
+ if ( groupId.equals( "org.apache.maven.plugins" ) && artifactId.equals( "maven-compiler-plugin" ) )
+ customizeCompilerPlugin( plugin );
+ }
+ }
+
+ private void customizeCompilerPlugin( Plugin plugin )
+ {
+ List<Object> configurations = new LinkedList<Object>();
+ configurations.add( plugin.getConfiguration() );
+
+ List<PluginExecution> executions = plugin.getExecutions();
+ for ( PluginExecution exec : executions )
+ configurations.add( exec.getConfiguration() );
+
+ for ( Object configObj : configurations )
+ {
+ try
+ {
+ Xpp3Dom config = (Xpp3Dom) configObj;
+ BigDecimal source = new BigDecimal( config.getChild( "source" ).getValue() );
+ BigDecimal target = new BigDecimal( config.getChild( "target" ).getValue() );
+
+ // Source must be at least 1.5
+ BigDecimal minSource = new BigDecimal( "1.5" );
+ if ( source.compareTo( minSource ) < 0 )
+ source = minSource;
+
+ // Target must not be less than source
+ if ( target.compareTo( source ) < 0 )
+ target = source;
+
+ config.getChild( "source" ).setValue( source.toString() );
+ config.getChild( "target" ).setValue( target.toString() );
+ }
+ catch ( NullPointerException e )
+ {
+ }
+ catch ( NumberFormatException e )
+ {
+ }
+ }
+ }
+
}
--
1.7.11.7