From f5501c5008f4d8ff1357f2a14bbb6dff5e114836 Mon Sep 17 00:00:00 2001 From: Stanislav Ochotnicky Date: Thu, 10 Feb 2011 11:57:07 +0100 Subject: [PATCH] Added mvn-rpmbuild script to be used in spec files - mvn-local is now mixed mode (online with javadir priority) - Changed mvn.jpp to mvn.local --- 0002-Use-custom-resolver.patch | 34 ++++++++++++------------ JavadirWorkspaceReader.java | 6 ++--- MavenJPackageDepmap.java | 12 ++++----- maven-script-local | 37 +++----------------------- maven-script-rpmbuild | 47 ++++++++++++++++++++++++++++++++++ maven.spec | 10 +++++++- 6 files changed, 85 insertions(+), 61 deletions(-) create mode 100644 maven-script-rpmbuild diff --git a/0002-Use-custom-resolver.patch b/0002-Use-custom-resolver.patch index 10ab008..eec152c 100644 --- a/0002-Use-custom-resolver.patch +++ b/0002-Use-custom-resolver.patch @@ -35,7 +35,7 @@ index cae3735..2d11d64 100644 throws UnresolvableModelException { Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); -+ if ( System.getProperty("maven.jpp.mode") != null) { ++ if ( System.getProperty("maven.local.mode") != null) { + JavadirWorkspaceReader wReader = new JavadirWorkspaceReader(); + File pomFile = wReader.findArtifact(pomArtifact); + // if pom file does not exist continue resolving using different @@ -55,15 +55,15 @@ index 1f37d4f..d60dab8 100644 throw new NullPointerException( "artifactId is null" ); } - if ( version == null ) -+ // in jpp mode we ignore versions because these would only cause ++ // in local mode we ignore versions because these would only cause + // problems -+ if ( version == null && System.getProperty("maven.jpp.mode") == null ) ++ if ( version == null && System.getProperty("maven.local.mode") == null ) { throw new NullPointerException( "version is null" ); } - return groupId + ":" + artifactId + ":" + version; -+ if( System.getProperty("maven.jpp.mode") == null ) { ++ if( System.getProperty("maven.local.mode") == null ) { + return groupId + ":" + artifactId + ":" + version; + } else { + return versionlessKey(groupId, artifactId); @@ -88,7 +88,7 @@ index e892ee9..0222b01 100644 } + // Set our own workspace reader to resolve from /usr/share/java -+ if ( System.getProperty("maven.jpp.mode") != null) ++ if ( System.getProperty("maven.local.mode") != null) + { + session.setWorkspaceReader(new JavadirWorkspaceReader()); + } @@ -127,10 +127,10 @@ index 009635b..7d03748 100644 } - if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) ) -+ // ignore incorrect version in jpp mode (we can have different ++ // ignore incorrect version in local mode (we can have different + // versions in /usr/share/java + if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) -+ && System.getProperty("maven.jpp.mode") == null) ++ && System.getProperty("maven.local.mode") == null) { errors.add( "Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion() ); } @@ -142,8 +142,8 @@ index fb074fb..bf2e703 100644 throws PluginVersionResolutionException { logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() ); -+ if (System.getProperty("maven.jpp.mode") != null) { -+ // in jpp mode we always use "latest" as a resolved version ++ if (System.getProperty("maven.local.mode") != null) { ++ // in local mode we always use "latest" as a resolved version + // (we ignore it anyway) + DefaultPluginVersionResult result = new DefaultPluginVersionResult("latest"); + result.setRepository(request.getRepositorySession().getWorkspaceReader().getRepository()); @@ -170,7 +170,7 @@ index 403351a..2351620 100644 if ( pomFile == null ) { Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); -+ if ( System.getProperty("maven.jpp.mode") != null) { ++ if ( System.getProperty("maven.local.mode") != null) { + JavadirWorkspaceReader wReader = new JavadirWorkspaceReader(); + pomFile = wReader.findArtifact(pomArtifact); + // if pom file does not exist continue resolving using different resolvers @@ -193,7 +193,7 @@ index 066fbf3..a7cbf40 100644 + // Seems like plexus-container-default has some quirks that + // cause it to lose version. Needs more looking into and fix it + // properly -+ if (dependency.getVersion() == null && System.getProperty("maven.jpp.mode") != null) ++ if (dependency.getVersion() == null && System.getProperty("maven.local.mode") != null) + { + System.out.println("FIXING NULL VERSION:" + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion()); + dependency.setVersion("1.0.0"); @@ -210,8 +210,8 @@ index 033211a..eec6caf 100644 if ( !management ) { - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); -+ // in jpp mode set version to "latest" and validate -+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null) ++ // in local mode set version to "latest" and validate ++ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null) + d.setVersion("latest"); + else + validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); @@ -223,8 +223,8 @@ index 033211a..eec6caf 100644 validateEffectiveDependency( problems, d, false, prefix, request ); - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); -+ // in jpp mode set version to "latest" and validate -+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null) ++ // in local mode set version to "latest" and validate ++ if(System.getProperty("maven.local.mode") != null && d.getVersion() == null) + d.setVersion("latest"); + else + validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); @@ -236,8 +236,8 @@ index 033211a..eec6caf 100644 validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d ); - validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(), -+ // in jpp mode ignore missing version completely -+ if(System.getProperty("maven.jpp.mode") == null) ++ // in local mode ignore missing version completely ++ if(System.getProperty("maven.local.mode") == null) + validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(), d ); } diff --git a/JavadirWorkspaceReader.java b/JavadirWorkspaceReader.java index 81dc6b1..0fe02b7 100644 --- a/JavadirWorkspaceReader.java +++ b/JavadirWorkspaceReader.java @@ -85,18 +85,18 @@ public class JavadirWorkspaceReader StringBuffer path = new StringBuffer(); String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-" + artifactId + ".pom"; - path.append(System.getProperty("maven.jpp.pom.path", "JPP/maven2/poms")).append("/").append(fName); + path.append(System.getProperty("maven.local.pom.path", "JPP/maven2/poms")).append("/").append(fName); java.io.File f; // NOTE: We are returning default_poms/ as the path for this pom // even though it may not exist there. This may cause an error, // but that is fine because if the pom is not there, there is // a serious problem anyways.. - f = new java.io.File(System.getProperty("maven.jpp.default.repo", "/usr/share/maven2/repository") + "/" + path.toString()); + f = new java.io.File(System.getProperty("maven.local.default.repo", "/usr/share/maven2/repository") + "/" + path.toString()); //System.err.println("Checking path " + f.getAbsolutePath() + " for the pom"); if (!f.exists()) { path = new StringBuffer(); - path.append(System.getProperty("maven.jpp.default.pom.path", "JPP/maven2/default_poms")).append("/").append(fName); + path.append(System.getProperty("maven.local.default.pom.path", "JPP/maven2/default_poms")).append("/").append(fName); } path.insert(0, "/usr/share/maven2/repository/"); return path; diff --git a/MavenJPackageDepmap.java b/MavenJPackageDepmap.java index c65155a..8cd1651 100644 --- a/MavenJPackageDepmap.java +++ b/MavenJPackageDepmap.java @@ -51,7 +51,7 @@ public class MavenJPackageDepmap { Hashtable jppDep; String idToCheck, jppCombination; - if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) { + if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.local.mode") == null) { idToCheck = groupId+","+artifactId+","+version; } else { idToCheck = groupId+","+artifactId; @@ -86,7 +86,7 @@ public class MavenJPackageDepmap { public boolean shouldEliminate(String groupId, String artifactId, String version) { String idToCheck; - if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) { + if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.local.mode") == null) { idToCheck = groupId+","+artifactId+","+version; } else { idToCheck = groupId+","+artifactId; @@ -98,7 +98,7 @@ public class MavenJPackageDepmap { private static void buildJppArtifactMap() { - if (System.getProperty("maven.ignore.versions") != null || System.getProperty("maven.jpp.mode") != null) { + if (System.getProperty("maven.ignore.versions") != null || System.getProperty("maven.local.mode") != null) { debug("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml"); processDepmapFile("/etc/maven/maven2-versionless-depmap.xml"); } @@ -106,7 +106,7 @@ public class MavenJPackageDepmap { debug("Processing file: /usr/share/java-utils/xml/maven2-depmap.xml"); processDepmapFile("/etc/maven/maven2-depmap.xml"); - String customFileName = System.getProperty("maven.jpp.depmap.file", null); + String customFileName = System.getProperty("maven.local.depmap.file", null); if (customFileName != null) { debug("Processing file: " + customFileName); processDepmapFile(customFileName); @@ -158,7 +158,7 @@ public class MavenJPackageDepmap { if (jppNodeList.getLength() == 1) { jppAD = getArtifactDefinition((Element) jppNodeList.item(0)); - if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) { + if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.local.mode") == null) { debug("*** Adding: " + mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version + " => " + jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map..."); @@ -207,7 +207,7 @@ public class MavenJPackageDepmap { public static void debug(String msg) { - if (System.getProperty("maven.jpp.debug") != null) + if (System.getProperty("maven.local.debug") != null) System.err.println(msg); } } diff --git a/maven-script-local b/maven-script-local index bdbc22e..a5ebc59 100644 --- a/maven-script-local +++ b/maven-script-local @@ -5,43 +5,12 @@ if [ -f /usr/share/java-utils/java-functions ] ; then set_javacmd fi -function install_metadata() -{ - mkdir -p "$1" - tar xf /usr/share/maven/repo-metadata.tar.xz -C "$1" -} - - -# add maven.repo.local if it's not defined already -local_add="-Dmaven.repo.local=$(pwd)/.m2/" - -function process_args() -{ -while [ $# != 0 ]; do - flag="$1" - case "$flag" in - *) ind=`expr match "$flag" -Dmaven.repo.local=` - if [[ $ind != 0 ]];then - install_metadata "${flag/-Dmaven.repo.local=/}/" - local_add="" - fi - ;; - esac - shift -done -} - -process_args "$@" - -if [ -n "$local_add" ];then - install_metadata "${local_add/-Dmaven.repo.local=/}/" -fi - export M2_HOME=/usr/share/maven echo $JAVA_HOME export JAVA_HOME # can't put it on command line due to # http://jira.codehaus.org/browse/SUREFIRE-121 -export MAVEN_OPTS="-Dmaven.jpp.mode ${local_add}" +export MAVEN_OPTS="-Dmaven.local.mode ${local_add}" +echo "Running mvn in local mode. Please report bugs to http://bugzilla.redhat.com" -$M2_HOME/bin/mvn -o "$@" +$M2_HOME/bin/mvn "$@" diff --git a/maven-script-rpmbuild b/maven-script-rpmbuild new file mode 100644 index 0000000..3f3c1ae --- /dev/null +++ b/maven-script-rpmbuild @@ -0,0 +1,47 @@ +#!/bin/sh +if [ -f /usr/share/java-utils/java-functions ] ; then + . /usr/share/java-utils/java-functions + set_jvm + set_javacmd +fi + +function install_metadata() +{ + mkdir -p "$1" + tar xf /usr/share/maven/repo-metadata.tar.xz -C "$1" +} + + +# add maven.repo.local if it's not defined already +local_add="-Dmaven.repo.local=$(pwd)/.m2/" + +function process_args() +{ +while [ $# != 0 ]; do + flag="$1" + case "$flag" in + *) ind=`expr match "$flag" -Dmaven.repo.local=` + if [[ $ind != 0 ]];then + install_metadata "${flag/-Dmaven.repo.local=/}/" + local_add="" + fi + ;; + esac + shift +done +} + +process_args "$@" + +if [ -n "$local_add" ];then + install_metadata "${local_add/-Dmaven.repo.local=/}/" +fi + +export M2_HOME=/usr/share/maven +echo $JAVA_HOME +export JAVA_HOME +# can't put it on command line due to +# http://jira.codehaus.org/browse/SUREFIRE-121 +export MAVEN_OPTS="-Dmaven.local.mode ${local_add}" + +$M2_HOME/bin/mvn -o "$@" diff --git a/maven.spec b/maven.spec index c3f6a82..47faca6 100644 --- a/maven.spec +++ b/maven.spec @@ -1,7 +1,7 @@ Name: maven Version: 3.0.2 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Java project management and project comprehension tool Group: Development/Tools @@ -17,6 +17,7 @@ Source101: MavenJPackageDepmap.java # 2xx for created non-buildable sources Source200: %{name}-script Source201: %{name}-script-local +Source202: %{name}-script-rpmbuild # Other included files Source250: repo-metadata.tar.xz @@ -246,6 +247,7 @@ install -dm 755 $RPM_BUILD_ROOT%{_bindir} # Wrappers cp -af %{SOURCE200} $RPM_BUILD_ROOT%{_bindir}/mvn3 cp -af %{SOURCE201} $RPM_BUILD_ROOT%{_bindir}/mvn-local +cp -af %{SOURCE202} $RPM_BUILD_ROOT%{_bindir}/mvn-rpmbuild ################### # Individual jars # @@ -286,6 +288,7 @@ cp -pr target/site/apidocs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name} %doc LICENSE.txt NOTICE.txt README.txt %attr(0755,root,root) %{_bindir}/mvn3 %attr(0755,root,root) %{_bindir}/mvn-local +%attr(0755,root,root) %{_bindir}/mvn-rpmbuild %dir %{_datadir}/%{name} %dir %{_datadir}/%{name}/bin %attr(0755,root,root) %{_datadir}/%{name}/bin/mvn @@ -309,6 +312,11 @@ cp -pr target/site/apidocs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name} %changelog +* Thu Feb 10 2011 Stanislav Ochotnicky - 3.0.2-2 +- Added mvn-rpmbuild script to be used in spec files +- mvn-local is now mixed mode (online with javadir priority) +- Changed mvn.jpp to mvn.local + * Fri Jan 28 2011 Stanislav Ochotnicky - 3.0.2-1 - Update to latest version (3.0.2) - Ignore test failures temporarily