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
This commit is contained in:
Stanislav Ochotnicky 2011-02-10 11:57:07 +01:00
parent 19154e4096
commit f5501c5008
6 changed files with 85 additions and 61 deletions

View File

@ -35,7 +35,7 @@ index cae3735..2d11d64 100644
throws UnresolvableModelException throws UnresolvableModelException
{ {
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); 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(); + JavadirWorkspaceReader wReader = new JavadirWorkspaceReader();
+ File pomFile = wReader.findArtifact(pomArtifact); + File pomFile = wReader.findArtifact(pomArtifact);
+ // if pom file does not exist continue resolving using different + // if pom file does not exist continue resolving using different
@ -55,15 +55,15 @@ index 1f37d4f..d60dab8 100644
throw new NullPointerException( "artifactId is null" ); throw new NullPointerException( "artifactId is null" );
} }
- if ( version == 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 + // 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" ); throw new NullPointerException( "version is null" );
} }
- return groupId + ":" + artifactId + ":" + version; - return groupId + ":" + artifactId + ":" + version;
+ if( System.getProperty("maven.jpp.mode") == null ) { + if( System.getProperty("maven.local.mode") == null ) {
+ return groupId + ":" + artifactId + ":" + version; + return groupId + ":" + artifactId + ":" + version;
+ } else { + } else {
+ return versionlessKey(groupId, artifactId); + return versionlessKey(groupId, artifactId);
@ -88,7 +88,7 @@ index e892ee9..0222b01 100644
} }
+ // Set our own workspace reader to resolve from /usr/share/java + // 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()); + session.setWorkspaceReader(new JavadirWorkspaceReader());
+ } + }
@ -127,10 +127,10 @@ index 009635b..7d03748 100644
} }
- if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) ) - 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 + // versions in /usr/share/java
+ if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) + 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() ); errors.add( "Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion() );
} }
@ -142,8 +142,8 @@ index fb074fb..bf2e703 100644
throws PluginVersionResolutionException throws PluginVersionResolutionException
{ {
logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() ); logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );
+ if (System.getProperty("maven.jpp.mode") != null) { + if (System.getProperty("maven.local.mode") != null) {
+ // in jpp mode we always use "latest" as a resolved version + // in local mode we always use "latest" as a resolved version
+ // (we ignore it anyway) + // (we ignore it anyway)
+ DefaultPluginVersionResult result = new DefaultPluginVersionResult("latest"); + DefaultPluginVersionResult result = new DefaultPluginVersionResult("latest");
+ result.setRepository(request.getRepositorySession().getWorkspaceReader().getRepository()); + result.setRepository(request.getRepositorySession().getWorkspaceReader().getRepository());
@ -170,7 +170,7 @@ index 403351a..2351620 100644
if ( pomFile == null ) if ( pomFile == null )
{ {
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version ); 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(); + JavadirWorkspaceReader wReader = new JavadirWorkspaceReader();
+ pomFile = wReader.findArtifact(pomArtifact); + pomFile = wReader.findArtifact(pomArtifact);
+ // if pom file does not exist continue resolving using different resolvers + // 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 + // Seems like plexus-container-default has some quirks that
+ // cause it to lose version. Needs more looking into and fix it + // cause it to lose version. Needs more looking into and fix it
+ // properly + // 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()); + System.out.println("FIXING NULL VERSION:" + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion());
+ dependency.setVersion("1.0.0"); + dependency.setVersion("1.0.0");
@ -210,8 +210,8 @@ index 033211a..eec6caf 100644
if ( !management ) if ( !management )
{ {
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ // in jpp mode set version to "latest" and validate + // in local mode set version to "latest" and validate
+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null) + if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
+ d.setVersion("latest"); + d.setVersion("latest");
+ else + else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); + validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
@ -223,8 +223,8 @@ index 033211a..eec6caf 100644
validateEffectiveDependency( problems, d, false, prefix, request ); validateEffectiveDependency( problems, d, false, prefix, request );
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); - validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ // in jpp mode set version to "latest" and validate + // in local mode set version to "latest" and validate
+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null) + if(System.getProperty("maven.local.mode") != null && d.getVersion() == null)
+ d.setVersion("latest"); + d.setVersion("latest");
+ else + else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d ); + 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 + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d );
- validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(), - validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
+ // in jpp mode ignore missing version completely + // in local mode ignore missing version completely
+ if(System.getProperty("maven.jpp.mode") == null) + if(System.getProperty("maven.local.mode") == null)
+ validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(), + validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
d ); d );
} }

View File

@ -85,18 +85,18 @@ public class JavadirWorkspaceReader
StringBuffer path = new StringBuffer(); StringBuffer path = new StringBuffer();
String fName = groupId.replace(PATH_SEPARATOR, GROUP_SEPARATOR) + "-" + artifactId + ".pom"; 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; java.io.File f;
// NOTE: We are returning default_poms/ as the path for this pom // NOTE: We are returning default_poms/ as the path for this pom
// even though it may not exist there. This may cause an error, // 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 // but that is fine because if the pom is not there, there is
// a serious problem anyways.. // 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"); //System.err.println("Checking path " + f.getAbsolutePath() + " for the pom");
if (!f.exists()) { if (!f.exists()) {
path = new StringBuffer(); 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/"); path.insert(0, "/usr/share/maven2/repository/");
return path; return path;

View File

@ -51,7 +51,7 @@ public class MavenJPackageDepmap {
Hashtable<String, String> jppDep; Hashtable<String, String> jppDep;
String idToCheck, jppCombination; 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; idToCheck = groupId+","+artifactId+","+version;
} else { } else {
idToCheck = groupId+","+artifactId; idToCheck = groupId+","+artifactId;
@ -86,7 +86,7 @@ public class MavenJPackageDepmap {
public boolean shouldEliminate(String groupId, String artifactId, String version) { public boolean shouldEliminate(String groupId, String artifactId, String version) {
String idToCheck; 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; idToCheck = groupId+","+artifactId+","+version;
} else { } else {
idToCheck = groupId+","+artifactId; idToCheck = groupId+","+artifactId;
@ -98,7 +98,7 @@ public class MavenJPackageDepmap {
private static void buildJppArtifactMap() { 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"); debug("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml");
processDepmapFile("/etc/maven/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"); debug("Processing file: /usr/share/java-utils/xml/maven2-depmap.xml");
processDepmapFile("/etc/maven/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) { if (customFileName != null) {
debug("Processing file: " + customFileName); debug("Processing file: " + customFileName);
processDepmapFile(customFileName); processDepmapFile(customFileName);
@ -158,7 +158,7 @@ public class MavenJPackageDepmap {
if (jppNodeList.getLength() == 1) { if (jppNodeList.getLength() == 1) {
jppAD = getArtifactDefinition((Element) jppNodeList.item(0)); 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 + " => " debug("*** Adding: " + mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version + " => "
+ jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map..."); + jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map...");
@ -207,7 +207,7 @@ public class MavenJPackageDepmap {
public static void debug(String msg) { public static void debug(String msg) {
if (System.getProperty("maven.jpp.debug") != null) if (System.getProperty("maven.local.debug") != null)
System.err.println(msg); System.err.println(msg);
} }
} }

View File

@ -5,43 +5,12 @@ if [ -f /usr/share/java-utils/java-functions ] ; then
set_javacmd set_javacmd
fi 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 export M2_HOME=/usr/share/maven
echo $JAVA_HOME echo $JAVA_HOME
export JAVA_HOME export JAVA_HOME
# can't put it on command line due to # can't put it on command line due to
# http://jira.codehaus.org/browse/SUREFIRE-121 # 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 "$@"

47
maven-script-rpmbuild Normal file
View File

@ -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 "$@"

View File

@ -1,7 +1,7 @@
Name: maven Name: maven
Version: 3.0.2 Version: 3.0.2
Release: 1%{?dist} Release: 2%{?dist}
Summary: Java project management and project comprehension tool Summary: Java project management and project comprehension tool
Group: Development/Tools Group: Development/Tools
@ -17,6 +17,7 @@ Source101: MavenJPackageDepmap.java
# 2xx for created non-buildable sources # 2xx for created non-buildable sources
Source200: %{name}-script Source200: %{name}-script
Source201: %{name}-script-local Source201: %{name}-script-local
Source202: %{name}-script-rpmbuild
# Other included files # Other included files
Source250: repo-metadata.tar.xz Source250: repo-metadata.tar.xz
@ -246,6 +247,7 @@ install -dm 755 $RPM_BUILD_ROOT%{_bindir}
# Wrappers # Wrappers
cp -af %{SOURCE200} $RPM_BUILD_ROOT%{_bindir}/mvn3 cp -af %{SOURCE200} $RPM_BUILD_ROOT%{_bindir}/mvn3
cp -af %{SOURCE201} $RPM_BUILD_ROOT%{_bindir}/mvn-local cp -af %{SOURCE201} $RPM_BUILD_ROOT%{_bindir}/mvn-local
cp -af %{SOURCE202} $RPM_BUILD_ROOT%{_bindir}/mvn-rpmbuild
################### ###################
# Individual jars # # Individual jars #
@ -286,6 +288,7 @@ cp -pr target/site/apidocs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}
%doc LICENSE.txt NOTICE.txt README.txt %doc LICENSE.txt NOTICE.txt README.txt
%attr(0755,root,root) %{_bindir}/mvn3 %attr(0755,root,root) %{_bindir}/mvn3
%attr(0755,root,root) %{_bindir}/mvn-local %attr(0755,root,root) %{_bindir}/mvn-local
%attr(0755,root,root) %{_bindir}/mvn-rpmbuild
%dir %{_datadir}/%{name} %dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/bin %dir %{_datadir}/%{name}/bin
%attr(0755,root,root) %{_datadir}/%{name}/bin/mvn %attr(0755,root,root) %{_datadir}/%{name}/bin/mvn
@ -309,6 +312,11 @@ cp -pr target/site/apidocs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}
%changelog %changelog
* Thu Feb 10 2011 Stanislav Ochotnicky <sochotnicky@redhat.com> - 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 <sochotnicky@redhat.com> - 3.0.2-1 * Fri Jan 28 2011 Stanislav Ochotnicky <sochotnicky@redhat.com> - 3.0.2-1
- Update to latest version (3.0.2) - Update to latest version (3.0.2)
- Ignore test failures temporarily - Ignore test failures temporarily