Add fedora local resolver

- Fix quoting of arguments to mvn scripts
- Add javadoc subpackage
- Make jars versionless and remove unneeded clean section
This commit is contained in:
Stanislav Ochotnicky 2010-12-21 15:25:37 +01:00
parent 91ffb10ecc
commit 1ae9fb1553
6 changed files with 490 additions and 17 deletions

View File

@ -0,0 +1,133 @@
From efb78912935d04507ce36951686608d33a3b3647 Mon Sep 17 00:00:00 2001
From: Stanislav Ochotnicky <sochotnicky@redhat.com>
Date: Tue, 2 Nov 2010 14:47:05 +0100
Subject: [PATCH 3/3] Use custom resolver
---
.../org/apache/maven/artifact/ArtifactUtils.java | 8 ++++++--
.../main/java/org/apache/maven/DefaultMaven.java | 6 ++++++
.../apache/maven/plugin/MavenPluginValidator.java | 3 ++-
.../internal/DefaultPluginVersionResolver.java | 7 +++++++
.../model/validation/DefaultModelValidator.java | 13 ++++++++++---
5 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
index 1f37d4f..04bc346 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
@@ -99,12 +99,16 @@ public final class ArtifactUtils
{
throw new NullPointerException( "artifactId is null" );
}
- if ( version == null )
+ if ( version == null && System.getProperty("maven.jpp.mode") == null )
{
throw new NullPointerException( "version is null" );
}
- return groupId + ":" + artifactId + ":" + version;
+ if( System.getProperty("maven.jpp.mode") == null ) {
+ return groupId + ":" + artifactId + ":" + version;
+ } else {
+ return versionlessKey(groupId, artifactId);
+ }
}
public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index e892ee9..b0bfea6 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -55,6 +55,7 @@ import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.project.ProjectSorter;
+import org.apache.maven.artifact.resolver.JavadirWorkspaceReader;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
import org.apache.maven.settings.Mirror;
@@ -361,6 +362,11 @@ public class DefaultMaven
session.setWorkspaceReader( workspaceRepository );
}
+ if ( System.getProperty("maven.jpp.mode") != null)
+ {
+ session.setWorkspaceReader(new JavadirWorkspaceReader());
+ }
+
DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
decrypt.setProxies( request.getProxies() );
decrypt.setServers( request.getServers() );
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
index 009635b..91ad68e 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginValidator.java
@@ -60,7 +60,8 @@ public class MavenPluginValidator
errors.add( "Plugin's descriptor contains the wrong artifact ID: " + pluginDescriptor.getArtifactId() );
}
- if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() ) )
+ if ( !pluginArtifact.getBaseVersion().equals( pluginDescriptor.getVersion() )
+ && System.getProperty("maven.jpp.mode") == null)
{
errors.add( "Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion() );
}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
index fb074fb..9583d05 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java
@@ -75,6 +75,13 @@ public class DefaultPluginVersionResolver
throws PluginVersionResolutionException
{
logger.debug( "Resolving plugin version for " + request.getGroupId() + ":" + request.getArtifactId() );
+ if (System.getProperty("maven.jpp.mode") != null) {
+ DefaultPluginVersionResult result = new DefaultPluginVersionResult("latest");
+ result.setRepository(request.getRepositorySession().getWorkspaceReader().getRepository());
+ logger.debug( "Resolved plugin version for " + request.getGroupId() + ":" + request.getArtifactId()
+ + " to latest from repository " + result.getRepository());
+ return result;
+ }
PluginVersionResult result = resolveFromProject( request );
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 033211a..1c09272 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
@@ -405,7 +405,10 @@ public class DefaultModelValidator
if ( !management )
{
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null)
+ d.setVersion("latest");
+ else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
/*
* TODO: Extensions like Flex Mojos use custom scopes like "merged", "internal", "external", etc.
@@ -433,7 +436,10 @@ public class DefaultModelValidator
{
validateEffectiveDependency( problems, d, false, prefix, request );
- validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
+ if(System.getProperty("maven.jpp.mode") != null && d.getVersion() == null)
+ d.setVersion("latest");
+ else
+ validateVersion( prefix + "version", problems, errOn30, d.getVersion(), d.getManagementKey(), d );
validateEnum( prefix + "scope", problems, errOn30, d.getScope(), d.getManagementKey(), d, "compile",
"runtime", "system" );
@@ -452,7 +458,8 @@ public class DefaultModelValidator
{
validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, d.getType(), d.getManagementKey(), d );
- validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
+ if(System.getProperty("maven.jpp.mode") == null)
+ validateStringNotEmpty( prefix + "version", problems, Severity.ERROR, d.getVersion(), d.getManagementKey(),
d );
}
--
1.7.3.2

View File

@ -0,0 +1,95 @@
package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.repository.MavenJPackageDepmap;
import java.io.File;
import java.util.List;
import java.util.LinkedList;
import java.util.Hashtable;
import org.sonatype.aether.repository.WorkspaceReader;
import org.sonatype.aether.repository.WorkspaceRepository;
import org.sonatype.aether.artifact.Artifact;
public class JavadirWorkspaceReader
implements WorkspaceReader
{
private WorkspaceRepository workspaceRepository;
private static final char GROUP_SEPARATOR = '.';
private static final char PATH_SEPARATOR = '/';
public JavadirWorkspaceReader() {
workspaceRepository = new WorkspaceRepository("javadir-workspace");
}
public WorkspaceRepository getRepository() {
return workspaceRepository;
}
public File findArtifact( Artifact artifact ) {
MavenJPackageDepmap.debug("=============JAVADIRREADER-FIND_ARTIFACT: " + artifact.getArtifactId());
StringBuffer path = new StringBuffer();
String artifactId = artifact.getArtifactId();
String groupId = artifact.getGroupId();
String version = artifact.getVersion();
MavenJPackageDepmap.debug("Wanted GROUPID=" + groupId);
MavenJPackageDepmap.debug("Wanted ARTIFACTID=" + artifactId);
if (!groupId.startsWith("JPP")) {
MavenJPackageDepmap map = MavenJPackageDepmap.getInstance();
Hashtable<String,String> newInfo = map.getMappedInfo(groupId, artifactId, version);
groupId = (String) newInfo.get("group");
artifactId = (String) newInfo.get("artifact");
}
MavenJPackageDepmap.debug("Resolved GROUPID=" + groupId);
MavenJPackageDepmap.debug("Resolved ARTIFACTID=" + artifactId);
if (artifact.getExtension().equals("pom")) {
path = getPOMPath(groupId, artifactId);
} else if (artifact.getExtension().equals("signature")) {
path.append("/usr/share/maven/repository/");
path.append( groupId ).append( '/' );
path.append( artifactId ).append( ".signature" );
} else {
path.append("/usr/share/maven/repository/");
path.append( groupId ).append( '/' );
path.append( artifactId ).append( ".jar" );
}
MavenJPackageDepmap.debug("Returning " + path.toString());
return new File(path.toString());
}
public List<String> findVersions( Artifact artifact ) {
List<String> ret = new LinkedList<String>();
ret.add("latest");
return ret;
}
private StringBuffer getPOMPath(String groupId, String artifactId) {
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);
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());
//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.insert(0, "/usr/share/maven2/repository/");
return path;
}
}

213
MavenJPackageDepmap.java Normal file
View File

@ -0,0 +1,213 @@
package org.apache.maven.artifact.repository;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import org.w3c.dom.*;
public class MavenJPackageDepmap {
private static class ArtifactDefinition {
String groupId = null;
String artifactId = null;
String version = null;
}
private static MavenJPackageDepmap instance;
private static Hashtable<String, String> jppArtifactMap;
private MavenJPackageDepmap() {
jppArtifactMap = new Hashtable<String,String>();
buildJppArtifactMap();
}
public static MavenJPackageDepmap getInstance() {
if (instance == null) {
instance = new MavenJPackageDepmap();
}
return instance;
}
public Hashtable<String, String> getMappedInfo(Hashtable<String, String> mavenDep) {
return getMappedInfo((String) mavenDep.get("group"),
(String) mavenDep.get("artifact"),
(String) mavenDep.get("version"));
}
public Hashtable<String, String> getMappedInfo(String groupId, String artifactId, String version) {
Hashtable<String, String> jppDep;
String idToCheck, jppCombination;
if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) {
idToCheck = groupId+","+artifactId+","+version;
} else {
idToCheck = groupId+","+artifactId;
}
jppCombination = (String) jppArtifactMap.get(idToCheck);
//System.err.println("*** " + groupId+","+artifactId+","+version + " => " + jppCombination);
jppDep = new Hashtable<String, String>();
if (jppCombination != null && jppCombination != "") {
StringTokenizer st = new StringTokenizer(jppCombination, ",");
jppDep.put("group", st.nextToken());
jppDep.put("artifact",st.nextToken());
jppDep.put("version",st.nextToken());
} else {
jppDep.put("group", groupId);
jppDep.put("artifact", artifactId);
jppDep.put("version", version);
}
return jppDep;
}
/**
* Returns whether or not the given dependency should be dropped.
*/
public boolean shouldEliminate(String groupId, String artifactId, String version) {
String idToCheck;
if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) {
idToCheck = groupId+","+artifactId+","+version;
} else {
idToCheck = groupId+","+artifactId;
}
return jppArtifactMap.get(idToCheck) != null && jppArtifactMap.get(idToCheck).equals("");
}
private static void buildJppArtifactMap() {
if (System.getProperty("maven.ignore.versions") != null || System.getProperty("maven.jpp.mode") != null) {
debug("Processing file: /usr/share/java-utils/xml/maven2-versionless-depmap.xml");
processDepmapFile("/etc/maven/maven2-versionless-depmap.xml");
}
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);
if (customFileName != null) {
debug("Processing file: " + customFileName);
processDepmapFile(customFileName);
}
}
private static void processDepmapFile(String fileName) {
Document mapDocument;
debug("Loading depmap file: " + fileName);
try {
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setNamespaceAware(true);
DocumentBuilder builder = fact.newDocumentBuilder();
mapDocument = builder.parse(fileName);
} catch (FileNotFoundException fnfe) {
System.err.println("ERROR: Unable to find map file: " + fileName);
fnfe.printStackTrace();
return;
} catch (IOException ioe) {
System.err.println("ERROR: I/O exception occured when opening map file");
ioe.printStackTrace();
return;
} catch (ParserConfigurationException pce) {
System.err.println("ERROR: Parsing of depmap file failed - configuration");
pce.printStackTrace();
return;
} catch (SAXException se) {
System.err.println("ERROR: Parsing of depmap file failed");
se.printStackTrace();
return;
}
NodeList depNodes = (NodeList) mapDocument.getElementsByTagName("dependency");
for (int i = 0; i < depNodes.getLength(); i++) {
Element depNode = (Element) depNodes.item(i);
NodeList mavenNodeList = (NodeList) depNode.getElementsByTagName("maven");
if (mavenNodeList.getLength() != 1) {
debug("Number of maven sub-elements is not 1. Bailing from depmap generation");
debug("Maven node: " + depNode.getTextContent());
return;
}
ArtifactDefinition mavenAD = getArtifactDefinition((Element) mavenNodeList.item(0));
ArtifactDefinition jppAD = null;
NodeList jppNodeList = (NodeList) depNode.getElementsByTagName("jpp");
if (jppNodeList.getLength() == 1) {
jppAD = getArtifactDefinition((Element) jppNodeList.item(0));
if (System.getProperty("maven.ignore.versions") == null && System.getProperty("maven.jpp.mode") == null) {
debug("*** Adding: " + mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version + " => "
+ jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map...");
jppArtifactMap.put(mavenAD.groupId + "," + mavenAD.artifactId + "," + mavenAD.version,
jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version);
} else {
debug("*** Adding: " + mavenAD.groupId+"," + mavenAD.artifactId + " => "
+ jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version + " to map...");
jppArtifactMap.put(mavenAD.groupId+","+mavenAD.artifactId,
jppAD.groupId + "," + jppAD.artifactId + "," + jppAD.version);
}
} else {
debug("Number of jpp sub-elements is not 1. Dropping dependency");
debug("*** Adding: " + mavenAD.groupId+","+mavenAD.artifactId+"," + " => " + "JPP/maven2,empty-dep,"+mavenAD.version + " to map...");
jppArtifactMap.put(mavenAD.groupId+","+mavenAD.artifactId, "JPP/maven2,empty-dep,"+mavenAD.version);
}
}
}
private static ArtifactDefinition getArtifactDefinition(Element element) {
ArtifactDefinition ad = new ArtifactDefinition();
NodeList nodes = element.getElementsByTagName("groupId");
if (nodes.getLength() != 1) {
debug("groupId definition not found in depmap");
return null;
}
ad.groupId = nodes.item(0).getTextContent();
nodes = element.getElementsByTagName("artifactId");
if (nodes.getLength() != 1) {
debug("artifactId definition not found in depmap");
return null;
}
ad.artifactId = nodes.item(0).getTextContent();
nodes = element.getElementsByTagName("version");
if (nodes.getLength() != 1) {
ad.version = "DUMMY_VER";
} else {
ad.version = nodes.item(0).getTextContent();
}
return ad;
}
public static void debug(String msg) {
if (System.getProperty("maven.jpp.debug") != null)
System.err.println(msg);
}
}

View File

@ -7,4 +7,4 @@ fi
export M2_HOME=/usr/share/maven
echo $JAVA_HOME
export JAVA_HOME; $M2_HOME/bin/mvn $@
export JAVA_HOME; $M2_HOME/bin/mvn "$@"

10
maven-script-local Normal file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if [ -f /usr/share/java-utils/java-functions ] ; then
. /usr/share/java-utils/java-functions
set_jvm
set_javacmd
fi
export M2_HOME=/usr/share/maven
echo $JAVA_HOME
export JAVA_HOME; $M2_HOME/bin/mvn -Dmaven.jpp.mode "$@"

View File

@ -1,7 +1,7 @@
Name: maven
Version: 3.0
Release: 3%{?dist}
Release: 4%{?dist}
Summary: Java project management and project comprehension tool
Group: Development/Tools
@ -9,14 +9,22 @@ License: ASL 2.0 and MIT and BSD
URL: http://maven.apache.org/
Source0: http://www.apache.org/dyn/closer.cgi/maven/source/apache-%{name}-%{version}-src.tar.gz
# custom resolver java files
# source: git clone git://fedorapeople.org/~sochotni/maven-javadir-resolver/
Source100: JavadirWorkspaceReader.java
Source101: MavenJPackageDepmap.java
# 2xx for created non-buildable sources
Source200: %{name}-script
Source201: %{name}-script-local
# Patch1XX could be upstreamed probably
# Patch15X are already upstream
Patch150: 0001-Add-plexus-default-container-dep.patch
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
# Patch2XX for non-upstreamable patches
Patch200: 0003-Use-custom-resolver.patch
BuildArch: noarch
BuildRequires: maven2
@ -86,6 +94,11 @@ Requires: jpackage-utils
%prep
%setup -q -n apache-%{name}-%{version}
%patch150 -p1
%patch200 -p1
# get custom resolver in place
cp %{SOURCE100} maven-core/src/main/java/org/apache/maven/artifact/resolver
cp %{SOURCE101} maven-core/src/main/java/org/apache/maven/artifact/repository
# not really used during build, but a precaution
rm maven-ant-tasks-*.jar
@ -126,8 +139,6 @@ chmod -x apache-%{name}-%{version}/conf/settings.xml
%install
rm -rf $RPM_BUILD_ROOT
export M2_HOME=$(pwd)/m2home/apache-maven-%{version}
# maven2 directory in /usr/share/java
@ -182,7 +193,7 @@ install -dm 755 $RPM_BUILD_ROOT%{_datadir}/%{name}/lib
plexus/interpolation plexus/plexus-sec-dispatcher plexus/utils \
sisu/sisu-inject-bean sisu/sisu-inject-plexus maven-wagon/file \
maven-wagon/http-lightweight maven-wagon/http-shared maven-wagon/provider-api \
xbean/xbean-reflect xerces-j2 jdom
xbean/xbean-reflect xerces-j2 jdom xml-commons-apis
)
################
@ -218,6 +229,7 @@ install -dm 755 $RPM_BUILD_ROOT%{_bindir}
# Wrappers
cp -af %{SOURCE200} $RPM_BUILD_ROOT%{_bindir}/mvn3
cp -af %{SOURCE201} $RPM_BUILD_ROOT%{_bindir}/mvn3-local
###################
# Individual jars #
@ -230,10 +242,8 @@ for module in maven-aether-provider maven-artifact maven-compat \
maven-settings-builder;do
pushd $module
install -m 644 target/$module-%{version}.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/
ln -s $module-%version.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/$module.jar
ln -s %{_javadir}/%{name}/$module-%{version}.jar \
$RPM_BUILD_ROOT%{_datadir}/%{name}/lib/$module-%{version}.jar
install -m 644 target/$module-%{version}.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/$module.jar
ln -s %{_javadir}/%{name}/$module.jar $RPM_BUILD_ROOT%{_datadir}/%{name}/lib/$module.jar
install -m 644 pom.xml $RPM_BUILD_ROOT%{_datadir}/%{name}/poms/JPP.%{name}-$module.pom
%add_to_maven_depmap org.apache.maven $module %{version} JPP/%{name} $module
popd
@ -243,9 +253,10 @@ done
install -m 644 pom.xml $RPM_BUILD_ROOT%{_datadir}/%{name}/poms/JPP.%{name}-maven.pom
%add_to_maven_depmap org.apache.maven maven %{version} JPP/%{name} maven
# javadocs
install -d -m 755 $RPM_BUILD_ROOT%{_javadocdir}/%{name}
cp -pr target/site/apidocs/* $RPM_BUILD_ROOT%{_javadocdir}/%{name}
%clean
rm -rf $RPM_BUILD_ROOT
%post
%update_maven_depmap
@ -258,6 +269,7 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,-)
%doc LICENSE.txt NOTICE.txt README.txt
%attr(0755,root,root) %{_bindir}/mvn3
%attr(0755,root,root) %{_bindir}/mvn3-local
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/bin
%attr(0755,root,root) %{_datadir}/%{name}/bin/mvn
@ -273,9 +285,19 @@ rm -rf $RPM_BUILD_ROOT
%config %{_mavendepmapfragdir}/%{name}
%{_javadir}/%{name}
%files javadoc
%defattr(-,root,root,-)
%doc LICENSE.txt
%{_javadocdir}/%{name}
%changelog
* Tue Dec 21 2010 Stanislav Ochotnicky <sochotnicky@redhat.com> - 3.0-4
- Add fedora local resolver
- Fix quoting of arguments to mvn scripts
- Add javadoc subpackage
- Make jars versionless and remove unneeded clean section
* Wed Dec 1 2010 Stanislav Ochotnicky <sochotnicky@redhat.com> - 3.0-3
- Remove maven-ant-tasks jar in prep
- Make fragment file as %%config