Force source >= 1.5 and target >= source

This commit is contained in:
Mikolaj Izdebski 2012-11-22 14:50:49 +01:00
parent 5003b5412a
commit c10d2c0069
2 changed files with 110 additions and 1 deletions

View File

@ -0,0 +1,104 @@
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

View File

@ -2,7 +2,7 @@
Name: maven
Version: 3.0.4
Release: 25%{?dist}
Release: 26%{?dist}
Summary: Java project management and project comprehension tool
Group: Development/Tools
@ -41,6 +41,7 @@ Patch151: 0003-Use-utf-8-source-encoding.patch
# Patch2XX for non-upstreamable patches
Patch200: 0002-Use-custom-resolver.patch
Patch201: 0004-Fix-text-scope-skipping-with-maven.test.skip.patch
Patch202: 0001-Customize-compiler-plugin.patch
BuildArch: noarch
@ -151,6 +152,7 @@ BuildArch: noarch
%patch151 -p1
%patch200 -p1
%patch201 -p1
%patch202 -p1
%patch100 -p1
%patch101 -p1
@ -424,6 +426,9 @@ ln -sf `rpm --eval '%%{_jnidir}'` %{_datadir}/%{name}/repository-jni/JPP
%changelog
* Thu Nov 22 2012 Mikolaj Izdebski <mizdebsk@redhat.com> - 3.0.4-26
- Force source >= 1.5 and target >= source
* Mon Nov 19 2012 Mikolaj Izdebski <mizdebsk@redhat.com> - 3.0.4-25
- Fix license tag