[MRM-346]: Show Artifact results in error 500.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@539619 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-05-18 22:35:12 +00:00
parent c870196fff
commit 3dce54c7fb
16 changed files with 163 additions and 425 deletions

View File

@ -38,6 +38,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelReader;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -130,6 +131,9 @@ public class ProjectModelToDatabaseConsumer
try
{
ArchivaProjectModel model = project400Reader.read( artifactFile );
model.setOrigin( "filesystem" );
dao.getProjectModelDAO().saveProjectModel( model );
}
catch ( ProjectModelException e )

View File

@ -62,7 +62,7 @@ public class ArchivaModelCloner
cloned.setOrganization( clone( model.getOrganization() ) );
cloned.setScm( clone( model.getScm() ) );
cloned.setRepositories( cloneRepositories( model.getRepositories() ) );
cloned.setDependencyTree( clone( model.getDependencyTree() ) );
cloned.setDependencies( cloneDependencies( model.getDependencies() ) );
cloned.setPlugins( clonePlugins( model.getPlugins() ) );
cloned.setReports( cloneReports( model.getReports() ) );
cloned.setDependencyManagement( cloneDependencies( model.getDependencyManagement() ) );
@ -130,37 +130,6 @@ public class ArchivaModelCloner
return cloned;
}
public static DependencyEdge clone( DependencyEdge edge )
{
if ( edge == null )
{
return null;
}
DependencyEdge cloned = new DependencyEdge();
cloned.setFromDependency( clone( edge.getFromDependency() ) );
cloned.setToDependency( clone( edge.getToDependency() ) );
cloned.setType( edge.getType() );
return cloned;
}
public static DependencyTree clone( DependencyTree dependencyTree )
{
if ( dependencyTree == null )
{
return null;
}
DependencyTree cloned = new DependencyTree();
cloned.setDependencyNodes( cloneDependencies( dependencyTree.getDependencyNodes() ) );
cloned.setDependencyEdges( cloneDependencyEdges( dependencyTree.getDependencyEdges() ) );
return cloned;
}
public static IssueManagement clone( IssueManagement issueManagement )
{
if ( issueManagement == null )
@ -323,32 +292,6 @@ public class ArchivaModelCloner
return ret;
}
public static List cloneDependencyEdges( List dependencyEdges )
{
if ( dependencyEdges == null )
{
return null;
}
List ret = new ArrayList();
Iterator it = dependencyEdges.iterator();
while ( it.hasNext() )
{
DependencyEdge edge = (DependencyEdge) it.next();
if ( edge == null )
{
// Skip empty edge.
continue;
}
ret.add( clone( edge ) );
}
return ret;
}
public static List cloneExclusions( List exclusions )
{
if ( exclusions == null )

View File

@ -998,7 +998,7 @@
<name>whenIndexed</name>
<identifier>false</identifier>
<version>1.0.0+</version>
<required>true</required>
<required>false</required>
<type>Date</type>
<description>
The timestamp when this model was indexed.
@ -1080,14 +1080,15 @@
</association>
</field>
<field>
<name>dependencyTree</name>
<name>dependencies</name>
<version>1.0.0+</version>
<description><![CDATA[
This element describes all of the dependencies associated with a
project.
]]></description>
<association>
<type>DependencyTree</type>
<type>Dependency</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
@ -1442,129 +1443,6 @@
</fields>
</class>
<class stash.storable="true"
jpox.table="DEPENDENCY_TREE">
<name>DependencyTree</name>
<description>The Dependency Tree</description>
<version>1.0.0+</version>
<fields>
<field>
<name>dependencyNodes</name>
<version>1.0.0+</version>
<description>The nodes for this dependency tree.</description>
<association>
<type>Dependency</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>dependencyEdges</name>
<version>1.0.0+</version>
<description>The edges for this dependency tree.</description>
<association>
<type>DependencyEdge</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
/**
* True if the dependency tree is empty.
*
* @return true if the dependency tree is empty.
*/
public boolean isEmpty()
{
if ( this.dependencyNodes == null )
{
return true;
}
return this.dependencyNodes.isEmpty();
}
public void addDependencyEdge( Dependency fromNode, Dependency toNode )
{
if ( this.dependencyNodes == null )
{
this.dependencyNodes = new java.util.ArrayList();
}
if ( this.dependencyEdges == null )
{
this.dependencyEdges = new java.util.ArrayList();
}
java.util.Iterator it;
DependencyEdge edge = new DependencyEdge();
edge.setFromDependency( toArtifactReference( fromNode ) );
edge.setToDependency( toArtifactReference( toNode ) );
String key = DependencyEdge.toKey( edge );
// Test for existance of previous edge.
it = this.dependencyEdges.iterator();
while ( it.hasNext() )
{
DependencyEdge existingEdge = (DependencyEdge) it.next();
String existingKey = DependencyEdge.toKey( existingEdge );
if ( key.equals( existingKey ) )
{
// Key already exists.
// Update type and return.
existingEdge.setType( edge.getType() );
return;
}
}
// Test for existance of fromNode or toNode and add if not present.
String fromKey = Dependency.toVersionlessKey( fromNode );
String toKey = Dependency.toVersionlessKey( toNode );
// Generate list of keys
java.util.List existingKeys = new java.util.ArrayList();
it = this.dependencyNodes.iterator();
while ( it.hasNext() )
{
Dependency existingDep = (Dependency) it.next();
String existingKey = Dependency.toVersionlessKey( existingDep );
existingKeys.add( existingKey );
}
// Now add nodes that are not present.
if ( !existingKeys.contains( fromKey ) )
{
this.dependencyNodes.add( fromNode );
}
if ( !existingKeys.contains( toKey ) )
{
this.dependencyNodes.add( toNode );
}
}
public static ArtifactReference toArtifactReference( Dependency dependency )
{
ArtifactReference ref = new ArtifactReference();
ref.setGroupId( dependency.getGroupId() );
ref.setArtifactId( dependency.getArtifactId() );
ref.setVersion( dependency.getVersion() );
ref.setClassifier( dependency.getClassifier() );
ref.setType( dependency.getType() );
return ref;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class stash.storable="true"
jpox.table="DEPENDENCY">
<name>Dependency</name>
@ -1602,6 +1480,7 @@
<version>1.0.0+</version>
<type>String</type>
<required>false</required>
<defaultValue></defaultValue>
<description><![CDATA[
The classifier of the dependency. This allows distinguishing two artifacts that belong to the same POM but
were built differently, and is appended to the filename after the version. For example,
@ -1737,85 +1616,6 @@
</codeSegments>
</class>
<class stash.storable="true"
jpox.table="DEPENDENCY_EDGE">
<name>DependencyEdge</name>
<version>1.0.0+</version>
<fields>
<field>
<name>fromDependency</name>
<version>1.0.0+</version>
<required>true</required>
<description>The dependency reference for the 'from' node</description>
<association>
<type>ArtifactReference</type>
</association>
</field>
<field>
<name>toDependency</name>
<version>1.0.0+</version>
<required>true</required>
<description>The dependency reference for the 'to' node</description>
<association>
<type>ArtifactReference</type>
</association>
</field>
<field jpox.column="EDGE_TYPE">
<name>type</name>
<version>1.0.0+</version>
<required>true</required>
<description><![CDATA[
<p>
The type of edge you have.
</p>
<dl>
<dt><code>runtime</code></dt>
<dd>A dependency node that is required for runtime of the project</dd>
<dt><code>test</code></dt>
<dd>A dependency node that is used by the project for testing purposes.</dd>
<dt><code>build</code></dt>
<dd>A dependency node that is used in the build/extension capacity.</dd>
<dt><code>plugin</code></dt>
<dd>A dependency node that is used as, or by a, declared plugin in this project.
This includes the plugin itself, and any defined plugins/plugin/dependencies/dependency references.
</dd>
<dt><code>report</code></dt>
<dd>A dependency node that is used as, or by a, declared report in this project.
This includes the report itself, and any defined reporting/plugins/plugin/dependencies/dependency references.</dd>
</dl>
]]></description>
<type>String</type>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>1.0.0+</version>
<code><![CDATA[
public static String toKey( DependencyEdge edge )
{
StringBuffer key = new StringBuffer();
key.append( ArtifactReference.toVersionlessKey( edge.getFromDependency() ) );
key.append( "->" );
key.append( ArtifactReference.toVersionlessKey( edge.getToDependency() ) );
return key.toString();
}
public String toString()
{
return DependencyEdge.toKey( this );
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class stash.storable="true"
jpox.table="EXCLUSIONS">
<name>Exclusion</name>

View File

@ -25,8 +25,6 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.CiManagement;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.DependencyEdge;
import org.apache.maven.archiva.model.DependencyTree;
import org.apache.maven.archiva.model.Exclusion;
import org.apache.maven.archiva.model.Individual;
import org.apache.maven.archiva.model.IssueManagement;
@ -94,7 +92,7 @@ public class ProjectModelMerge
merged.setOrganization( merge( mainProject.getOrganization(), parentProject.getOrganization() ) );
merged.setScm( merge( mainProject.getScm(), parentProject.getScm() ) );
merged.setRepositories( mergeRepositories( mainProject.getRepositories(), parentProject.getRepositories() ) );
merged.setDependencyTree( merge( mainProject.getDependencyTree(), parentProject.getDependencyTree() ) );
merged.setDependencies( mergeDependencies( mainProject.getDependencies(), parentProject.getDependencies() ) );
merged.setDependencyManagement( mergeDependencyManagement( mainProject.getDependencyManagement(), parentProject
.getDependencyManagement() ) );
merged.setPlugins( mergePlugins( mainProject.getPlugins(), parentProject.getPlugins() ) );
@ -181,21 +179,6 @@ public class ProjectModelMerge
return ret;
}
private static Map createEdgeMap( List dependencyEdges )
{
Map ret = new HashMap();
Iterator it = dependencyEdges.iterator();
while ( it.hasNext() )
{
DependencyEdge edge = (DependencyEdge) it.next();
String key = toKey( edge );
ret.put( key, edge );
}
return ret;
}
private static boolean empty( String val )
{
if ( val == null )
@ -233,28 +216,6 @@ public class ProjectModelMerge
return merged;
}
private static DependencyTree merge( DependencyTree mainDependencyTree, DependencyTree parentDependencyTree )
{
if ( parentDependencyTree == null )
{
return mainDependencyTree;
}
if ( mainDependencyTree == null )
{
return ArchivaModelCloner.clone( parentDependencyTree );
}
DependencyTree merged = ArchivaModelCloner.clone( mainDependencyTree );
merged.setDependencyNodes( mergeDependencies( mainDependencyTree.getDependencyNodes(), parentDependencyTree
.getDependencyNodes() ) );
merged.setDependencyEdges( mergeDependencyEdges( mainDependencyTree.getDependencyEdges(), parentDependencyTree
.getDependencyEdges() ) );
return merged;
}
private static CiManagement merge( CiManagement mainCim, CiManagement parentCim )
{
if ( parentCim == null )
@ -675,45 +636,6 @@ public class ProjectModelMerge
return merged;
}
private static List mergeDependencyEdges( List mainDependencyEdges, List parentDependencyEdges )
{
if ( parentDependencyEdges == null )
{
return mainDependencyEdges;
}
if ( mainDependencyEdges == null )
{
return ArchivaModelCloner.cloneDependencyEdges( parentDependencyEdges );
}
List merged = new ArrayList();
Map mainEdgesMap = createEdgeMap( mainDependencyEdges );
Map parentEdgesMap = createEdgeMap( parentDependencyEdges );
Iterator it = mainEdgesMap.entrySet().iterator();
while ( it.hasNext() )
{
Map.Entry entry = (Entry) it.next();
String key = (String) entry.getKey();
DependencyEdge mainEdge = (DependencyEdge) entry.getValue();
DependencyEdge parentEdge = (DependencyEdge) parentEdgesMap.get( key );
if ( parentEdge == null )
{
merged.add( mainEdge );
}
else
{
// Not merging. Local wins.
merged.add( parentEdge );
}
}
return merged;
}
private static String toVersionlessArtifactKey( ArtifactReference artifactReference )
{
StringBuffer key = new StringBuffer();
@ -735,15 +657,4 @@ public class ProjectModelMerge
return key.toString();
}
private static String toKey( DependencyEdge edge )
{
StringBuffer key = new StringBuffer();
key.append( toVersionlessArtifactKey( edge.getFromDependency() ) );
key.append( "->" );
key.append( toVersionlessArtifactKey( edge.getToDependency() ) );
return key.toString();
}
}

View File

@ -118,20 +118,20 @@ public class EffectiveProjectModelFilter implements ProjectModelFilter
private void applyDependencyManagement( ArchivaProjectModel pom )
{
if ( ( pom.getDependencyManagement() == null ) || ( pom.getDependencyTree() == null ) )
if ( ( pom.getDependencyManagement() == null ) || ( pom.getDependencies() == null ) )
{
// Nothing to do. All done!
return;
}
if ( pom.getDependencyManagement().isEmpty() || pom.getDependencyTree().isEmpty() )
if ( pom.getDependencyManagement().isEmpty() || pom.getDependencies().isEmpty() )
{
// Nothing to do. All done!
return;
}
Map managedDependencies = createDependencyMap( pom.getDependencyManagement() );
Iterator it = pom.getDependencyTree().getDependencyNodes().iterator();
Iterator it = pom.getDependencies().iterator();
while ( it.hasNext() )
{
Dependency dep = (Dependency) it.next();

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.repository.project.filters;
* under the License.
*/
import org.apache.commons.collections.CollectionUtils;
import org.apache.maven.archiva.model.ArchivaModelCloner;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency;
@ -73,9 +74,9 @@ public class ProjectModelExpressionFilter
ret.setVersion( evaluator.expand( ret.getVersion() ) );
ret.setGroupId( evaluator.expand( ret.getGroupId() ) );
if ( ( ret.getDependencyTree() != null ) && !ret.getDependencyTree().isEmpty() )
if ( CollectionUtils.isNotEmpty( ret.getDependencies() ) )
{
evaluateExpressionsInDependencyList( evaluator, ret.getDependencyTree().getDependencyNodes() );
evaluateExpressionsInDependencyList( evaluator, ret.getDependencies() );
}
evaluateExpressionsInDependencyList( evaluator, ret.getDependencyManagement() );

View File

@ -25,7 +25,6 @@ import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.CiManagement;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.DependencyScope;
import org.apache.maven.archiva.model.DependencyTree;
import org.apache.maven.archiva.model.Exclusion;
import org.apache.maven.archiva.model.Individual;
import org.apache.maven.archiva.model.IssueManagement;
@ -100,7 +99,7 @@ public class ProjectModel400Reader
model.setScm( getSCM( xml ) );
model.setRepositories( getRepositories( xml ) );
model.setDependencyTree( getDependencyTree( xml ) );
model.setDependencies( getDependencies( xml ) );
model.setDependencyManagement( getDependencyManagement( xml ) );
model.setPlugins( getPlugins( xml ) );
model.setReports( getReports( xml ) );
@ -142,20 +141,10 @@ public class ProjectModel400Reader
return null;
}
private DependencyTree getDependencyTree( XMLReader xml )
private List getDependencies( XMLReader xml )
throws XMLException
{
DependencyTree tree = new DependencyTree();
List dependencies = getDependencyList( xml, new String[] { "dependencies" } );
Iterator it = dependencies.iterator();
while ( it.hasNext() )
{
Dependency dependency = (Dependency) it.next();
tree.addDependencyNode( dependency );
}
return tree;
return getDependencyList( xml, new String[] { "dependencies" } );
}
private List getDependencyList( XMLReader xml, String parts[] )
@ -187,7 +176,7 @@ public class ProjectModel400Reader
dependency.setArtifactId( elemDependency.elementTextTrim( "artifactId" ) );
dependency.setVersion( elemDependency.elementTextTrim( "version" ) );
dependency.setClassifier( elemDependency.elementTextTrim( "classifier" ) );
dependency.setClassifier( StringUtils.defaultString( elemDependency.elementTextTrim( "classifier" ) ) );
dependency.setType( StringUtils.defaultIfEmpty( elemDependency.elementTextTrim( "type" ), "jar" ) );
dependency.setScope( StringUtils.defaultIfEmpty( elemDependency.elementTextTrim( "scope" ), "compile" ) );
// Not for v4.0.0 -> dependency.setUrl( elemDependency.elementTextTrim("url") );

View File

@ -22,7 +22,6 @@ package org.apache.maven.archiva.repository.project.filters;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.ArchivaRepository;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.DependencyTree;
import org.apache.maven.archiva.model.Individual;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
@ -100,30 +99,28 @@ public class EffectiveProjectModelFilterTest
assertEquals( "Equivalent Models", expectedModel, effectiveModel );
assertContainsSameIndividuals( "Individuals", expectedModel.getIndividuals(), effectiveModel.getIndividuals() );
dumpDependencyList( "Expected", expectedModel.getDependencyTree() );
dumpDependencyList( "Effective", effectiveModel.getDependencyTree() );
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencyTree().getDependencyNodes(),
effectiveModel.getDependencyTree().getDependencyNodes() );
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
.getDependencyManagement() );
dumpDependencyList( "Expected", expectedModel.getDependencies() );
dumpDependencyList( "Effective", effectiveModel.getDependencies() );
assertContainsSameDependencies( "Dependencies", expectedModel.getDependencies(),
effectiveModel.getDependencies() );
assertContainsSameDependencies( "DependencyManagement", expectedModel.getDependencyManagement(),
effectiveModel.getDependencyManagement() );
}
private void dumpDependencyList( String type, DependencyTree tree )
private void dumpDependencyList( String type, List deps )
{
if ( tree == null )
if ( deps == null )
{
System.out.println( " Tree [" + type + "] is null." );
System.out.println( " Dependencies [" + type + "] is null." );
return;
}
if ( tree.getDependencyNodes() == null )
if ( deps.isEmpty() )
{
System.out.println( " Tree [" + type + "] dependency list (nodes) is null." );
System.out.println( " Dependencies [" + type + "] dependency list is empty." );
return;
}
List deps = tree.getDependencyNodes();
System.out.println( ".\\ [" + type + "] Dependency List (size:" + deps.size() + ") \\.________________" );
Iterator it = deps.iterator();
while ( it.hasNext() )

View File

@ -21,11 +21,12 @@ package org.apache.maven.archiva.repository.project.filters;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.DependencyTree;
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
import org.codehaus.plexus.PlexusTestCase;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* ProjectModelExpressionExpanderTest
@ -49,13 +50,13 @@ public class ProjectModelExpressionExpanderTest
model.setArtifactId( "archiva-test-project" );
model.setVersion( "1.0-SNAPSHOT" );
DependencyTree depTree = new DependencyTree();
List deps = new ArrayList();
depTree.addDependencyEdge( model.asDependency(), createDependency( "org.apache.maven.archiva", "archiva-model", "${archiva.version}" ) );
depTree.addDependencyEdge( model.asDependency(), createDependency( "org.apache.maven.archiva", "archiva-common", "${archiva.version}" ) );
depTree.addDependencyEdge( model.asDependency(), createDependency( "org.apache.maven.archiva", "archiva-indexer", "${archiva.version}" ) );
deps.add( createDependency( "org.apache.maven.archiva", "archiva-model", "${archiva.version}" ) );
deps.add( createDependency( "org.apache.maven.archiva", "archiva-common", "${archiva.version}" ) );
deps.add( createDependency( "org.apache.maven.archiva", "archiva-indexer", "${archiva.version}" ) );
model.setDependencyTree( depTree );
model.setDependencies( deps );
model.addProperty( "archiva.version", "1.0-SNAPSHOT" );
@ -67,11 +68,10 @@ public class ProjectModelExpressionExpanderTest
assertEquals( "Group ID", "org.apache.maven.archiva", model.getGroupId() );
assertEquals( "Artifact ID", "archiva-test-project", model.getArtifactId() );
assertEquals( "Version", "1.0-SNAPSHOT", model.getVersion() );
assertNotNull( "DependencyTree", model.getDependencyTree() );
assertNotNull( "DependencyTree.dependencies", model.getDependencyTree().getDependencyNodes() );
assertEquals( "Dependencies Size", 4, model.getDependencyTree().getDependencyNodes().size() );
assertNotNull( "Dependencies", model.getDependencies() );
assertEquals( "Dependencies Size", 3, model.getDependencies().size() );
Iterator it = model.getDependencyTree().getDependencyNodes().iterator();
Iterator it = model.getDependencies().iterator();
while ( it.hasNext() )
{
Dependency dep = (Dependency) it.next();

View File

@ -23,7 +23,6 @@ import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelReader;
import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
@ -63,9 +62,8 @@ public class ProjectModel400ReaderTest
assertEquals( "Parent Artifact ID", "maven-shared-components", parentRef.getArtifactId() );
assertEquals( "Parent Version", "4", parentRef.getVersion() );
assertNotNull( "DependencyTree", project.getDependencyTree() );
assertNotNull( "DependencyTree.dependencies", project.getDependencyTree().getDependencyNodes() );
assertEquals( "Dependencies.size", 3, project.getDependencyTree().getDependencyNodes().size() );
assertNotNull( "Dependencies", project.getDependencies() );
assertEquals( "Dependencies.size", 3, project.getDependencies().size() );
}
public void testLoadWithNamespace()
@ -93,8 +91,7 @@ public class ProjectModel400ReaderTest
assertEquals( "Parent Artifact ID", "archiva-base", parentRef.getArtifactId() );
assertEquals( "Parent Version", "1.0-SNAPSHOT", parentRef.getVersion() );
assertNotNull( "DependencyTree", project.getDependencyTree() );
assertNotNull( "DependencyTree.dependencies", project.getDependencyTree().getDependencyNodes() );
assertEquals( "Dependencies.size", 6, project.getDependencyTree().getDependencyNodes().size() );
assertNotNull( "Dependencies", project.getDependencies() );
assertEquals( "Dependencies.size", 6, project.getDependencies().size() );
}
}

View File

@ -19,7 +19,6 @@ package org.apache.maven.archiva.database.constraints;
* under the License.
*/
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.maven.archiva.database.Constraint;
/**
@ -36,9 +35,9 @@ public class ArtifactsRelatedConstraint
public ArtifactsRelatedConstraint( String groupId, String artifactId, String version )
{
whereClause = "groupId == '" + StringEscapeUtils.escapeSql( groupId ) + "' AND artifactId == '"
+ StringEscapeUtils.escapeSql( artifactId ) + "' AND version == '" + StringEscapeUtils.escapeSql( version )
+ "'";
whereClause = "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) && version.equals(selectedVersion)";
declParams = new String[] { "String selectedGroupId", "String selectedArtifactId", "String selectedVersion" };
params = new Object[] { groupId, artifactId, version };
}
public String getSortColumn()

View File

@ -310,11 +310,7 @@ public class JdoAccess
if ( constraint.getDeclaredImports() != null )
{
for ( int i = 0; i < constraint.getDeclaredImports().length; i++ )
{
String qimport = constraint.getDeclaredImports()[i];
query.declareImports( qimport );
}
query.declareImports( StringUtils.join( constraint.getDeclaredImports(), ", " ) );
}
if ( constraint.getDeclaredParameters() != null )
@ -332,11 +328,7 @@ public class JdoAccess
+ "> parameter objects to use. This should be equal." );
}
for ( int i = 0; i < constraint.getDeclaredParameters().length; i++ )
{
String declaredParam = constraint.getDeclaredParameters()[i];
query.declareParameters( declaredParam );
}
query.declareParameters( StringUtils.join( constraint.getDeclaredParameters(), ", " ) );
return processParameterizedQuery( query, constraint.getParameters() );
}

View File

@ -0,0 +1,91 @@
package org.apache.maven.archiva.database.constraints;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import java.util.Calendar;
import java.util.List;
/**
* ArtifactsRelatedConstraintTest
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
* @version $Id$
*/
public class ArtifactsRelatedConstraintTest
extends AbstractArchivaDatabaseTestCase
{
private static final String TEST_GROUPID = "org.apache.maven.archiva.test";
private ArtifactDAO artifactDao;
protected void setUp()
throws Exception
{
super.setUp();
ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
artifactDao = dao.getArtifactDAO();
}
public ArchivaArtifact createArtifact( String artifactId, String version, String classifier, String type )
{
ArchivaArtifact artifact = artifactDao.createArtifact( TEST_GROUPID, artifactId, version,
classifier, type );
Calendar cal = Calendar.getInstance();
artifact.getModel().setLastModified( cal.getTime() );
artifact.getModel().setRepositoryId( "testable_repo" );
return artifact;
}
public void testConstraint()
throws Exception
{
// Setup artifacts in fresh DB.
artifactDao.saveArtifact( createArtifact( "test-one", "1.0", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-one", "1.0", "", "pom" ) );
artifactDao.saveArtifact( createArtifact( "test-one", "1.0", "javadoc", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-one", "1.0", "sources", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-one", "1.1", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-one", "1.2", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-two", "1.0", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-two", "2.0", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-two", "2.1", "", "jar" ) );
artifactDao.saveArtifact( createArtifact( "test-two", "3.0", "", "jar" ) );
assertConstraint( 4, new ArtifactsRelatedConstraint( TEST_GROUPID, "test-one", "1.0" ) );
assertConstraint( 1, new ArtifactsRelatedConstraint( TEST_GROUPID, "test-one", "1.1" ) );
}
private void assertConstraint( int expectedHits, Constraint constraint )
throws Exception
{
List results = artifactDao.queryArtifacts( constraint );
assertNotNull( "Related Artifacts: Not Null", results );
assertEquals( "Related Artifacts: Results.size", expectedHits, results.size() );
}
}

View File

@ -87,7 +87,9 @@ public class DownloadArtifact
this.res = (HttpServletResponse) pageContext.getResponse();
try
{
dao = (ArchivaDAO) PlexusTagUtil.lookup( pageContext, ArchivaDAO.ROLE );
dao = (ArchivaDAO) PlexusTagUtil.lookup( pageContext, ArchivaDAO.ROLE, "jdo" );
layoutFactory = (BidirectionalRepositoryLayoutFactory) PlexusTagUtil
.lookup( pageContext, BidirectionalRepositoryLayoutFactory.class );
}
catch ( ComponentLookupException e )
{

View File

@ -34,12 +34,24 @@ import javax.servlet.jsp.PageContext;
*/
public class PlexusTagUtil
{
public static Object lookup( PageContext pageContext, Class clazz )
throws ComponentLookupException
{
return getContainer( pageContext ).lookup( clazz );
}
public static Object lookup( PageContext pageContext, String role )
throws ComponentLookupException
{
return getContainer( pageContext ).lookup( role );
}
public static Object lookup( PageContext pageContext, Class clazz, String hint )
throws ComponentLookupException
{
return getContainer( pageContext ).lookup( clazz, hint );
}
public static Object lookup( PageContext pageContext, String role, String hint )
throws ComponentLookupException
{

View File

@ -70,16 +70,16 @@
</td>
</tr>
--%>
<c:if test="${model.parent != null}">
<c:if test="${model.parentProject != null}">
<tr>
<th>Parent</th>
<td>
${model.parent.groupId} ${model.parent.artifactId} ${model.parent.version}
${model.parentProject.groupId} ${model.parentProject.artifactId} ${model.parentProject.version}
<c:set var="url">
<ww:url action="showArtifact" namespace="/">
<ww:param name="groupId" value="%{'${model.parent.groupId}'}"/>
<ww:param name="artifactId" value="%{'${model.parent.artifactId}'}"/>
<ww:param name="version" value="%{'${model.parent.version}'}"/>
<ww:param name="groupId" value="%{'${model.parentProject.groupId}'}"/>
<ww:param name="artifactId" value="%{'${model.parentProject.artifactId}'}"/>
<ww:param name="version" value="%{'${model.parentProject.version}'}"/>
</ww:url>
</c:set>
(<a href="${url}">View</a>)