You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/28 01:12:32 UTC
svn commit: r769199 [5/19] - in /maven/mercury/trunk:
mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/
mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/
mercury-core/src/main/java/org/apache/maven/mercury/artifact/ ...
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/HelpingSatSolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/HelpingSatSolver.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/HelpingSatSolver.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/HelpingSatSolver.java Mon Apr 27 23:12:25 2009
@@ -18,39 +18,6 @@
*/
package org.apache.maven.mercury.metadata.sat;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.maven.mercury.artifact.ArtifactMetadata;
-import org.apache.maven.mercury.artifact.MetadataTreeNode;
-import org.apache.maven.mercury.event.EventManager;
-import org.apache.maven.mercury.event.EventTypeEnum;
-import org.apache.maven.mercury.event.GenericEvent;
-import org.apache.maven.mercury.event.MercuryEventListener;
-import org.apache.maven.mercury.logging.IMercuryLogger;
-import org.apache.maven.mercury.logging.MercuryLoggerManager;
-import org.apache.maven.mercury.metadata.MetadataTreeNodeGAComparator;
-import org.apache.maven.mercury.metadata.MetadataTreeNodeGAVComparator;
-import org.codehaus.plexus.lang.DefaultLanguage;
-import org.codehaus.plexus.lang.Language;
-import org.sat4j.core.Vec;
-import org.sat4j.core.VecInt;
-import org.sat4j.pb.IPBSolver;
-import org.sat4j.pb.ObjectiveFunction;
-import org.sat4j.pb.SolverFactory;
-import org.sat4j.specs.ContradictionException;
-import org.sat4j.specs.IConstr;
-import org.sat4j.specs.IVec;
-import org.sat4j.specs.IVecInt;
-import org.sat4j.specs.TimeoutException;
-
/**
* Default SAT4J implementation.
*
@@ -58,594 +25,597 @@
* @version $Id$
*/
public class HelpingSatSolver
-{}
-//implements SatSolver
-//{
-// private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( HelpingSatSolver.class );
-// private static final Language LANG = new DefaultLanguage( HelpingSatSolver.class );
+{
+}
+// implements SatSolver
+// {
+// private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( HelpingSatSolver.class );
+// private static final Language LANG = new DefaultLanguage( HelpingSatSolver.class );
//
-// private DependencyHelper<MetadataTreeNode,String> _helper = new DependencyHelper<MetadataTreeNode,String>( SolverFactory.newEclipseP2() );
-// protected MetadataTreeNode _root;
+// private DependencyHelper<MetadataTreeNode,String> _helper = new DependencyHelper<MetadataTreeNode,String>(
+// SolverFactory.newEclipseP2() );
+// protected MetadataTreeNode _root;
//
-// protected EventManager _eventManager;
+// protected EventManager _eventManager;
//
-// protected static final Comparator<MetadataTreeNode> gaComparator = new MetadataTreeNodeGAComparator();
-// //-----------------------------------------------------------------------
-// public static SatSolver create( MetadataTreeNode tree )
-// throws SatException
-// {
-// return new HelpingSatSolver( tree );
-// }
-// //-----------------------------------------------------------------------
-// public static SatSolver create( MetadataTreeNode tree, EventManager eventManager )
-// throws SatException
-// {
-// return new HelpingSatSolver( tree, eventManager );
-// }
-// //-----------------------------------------------------------------------
-// public HelpingSatSolver( MetadataTreeNode tree, EventManager eventManager )
-// throws SatException
-// {
-// this._eventManager = eventManager;
-// GenericEvent event = null;
-//
-// if( tree == null)
-// throw new SatException( LANG.getMessage( "null.tree.arg" ) );
-//
-// try
-// {
-// if( _eventManager != null )
-// event = new GenericEvent( EventTypeEnum.satSolver, EVENT_CREATE_SOLVER, tree.toString() );
+// protected static final Comparator<MetadataTreeNode> gaComparator = new MetadataTreeNodeGAComparator();
+// //-----------------------------------------------------------------------
+// public static SatSolver create( MetadataTreeNode tree )
+// throws SatException
+// {
+// return new HelpingSatSolver( tree );
+// }
+// //-----------------------------------------------------------------------
+// public static SatSolver create( MetadataTreeNode tree, EventManager eventManager )
+// throws SatException
+// {
+// return new HelpingSatSolver( tree, eventManager );
+// }
+// //-----------------------------------------------------------------------
+// public HelpingSatSolver( MetadataTreeNode tree, EventManager eventManager )
+// throws SatException
+// {
+// this._eventManager = eventManager;
+// GenericEvent event = null;
+//
+// if( tree == null)
+// throw new SatException( LANG.getMessage( "null.tree.arg" ) );
+//
+// try
+// {
+// if( _eventManager != null )
+// event = new GenericEvent( EventTypeEnum.satSolver, EVENT_CREATE_SOLVER, tree.toString() );
//
-// if( tree.getId() == 0 )
-// MetadataTreeNode.reNumber( tree, 1 );
+// if( tree.getId() == 0 )
+// MetadataTreeNode.reNumber( tree, 1 );
//
-// int nNodes = tree.countDistinctNodes();
+// int nNodes = tree.countDistinctNodes();
//
-// LOG.debug( "SatContext: # of variables: "+nNodes );
+// LOG.debug( "SatContext: # of variables: "+nNodes );
//
-// _root = tree;
+// _root = tree;
//
-// try
-// {
-// addNode( tree );
-// }
-// catch (ContradictionException e)
-// {
-// throw new SatException(e);
-// }
-// }
-// finally
-// {
-// if( _eventManager != null )
-// {
-// event.stop();
-// _eventManager.fireEvent( event );
-// }
-// }
-// }
-// //-----------------------------------------------------------------------
-// public HelpingSatSolver( MetadataTreeNode tree )
-// throws SatException
-// {
-// this( tree, null );
-// }
-// //-----------------------------------------------------------------------
-// public final void applyPolicies( List<Comparator<MetadataTreeNode>> comparators )
-// throws SatException
-// {
-// if( comparators == null || comparators.size() < 1 )
-// return;
-//
-// if( _root == null )
-// throw new SatException( "cannot apply policies to a null tree" );
-//
-// // TODO og: assumption - around 128 GA's per tree. If more - map reallocates - slow down.
-// // TODO og: MERCURY-40
-// Map<String, List<MetadataTreeNode>> buckets = new LinkedHashMap<String, List<MetadataTreeNode>>(128);
-// fillBuckets( buckets, _root );
-// sortBuckets( buckets, comparators );
-// useBuckets( buckets );
-// }
-// //-----------------------------------------------------------------------
-// private void useBuckets( Map<String, List<MetadataTreeNode>> buckets )
-// throws SatException
-// {
-// if( buckets == null || buckets.size() < 1 )
-// return;
-//
-// IVecInt vars = new VecInt( 128 );
-// IVec<BigInteger> coeffs = new Vec<BigInteger>( 128 );
-//
-// int count = 0;
-//
-// for( String key : buckets.keySet() )
-// {
-// List<MetadataTreeNode> bucket = buckets.get( key );
+// try
+// {
+// addNode( tree );
+// }
+// catch (ContradictionException e)
+// {
+// throw new SatException(e);
+// }
+// }
+// finally
+// {
+// if( _eventManager != null )
+// {
+// event.stop();
+// _eventManager.fireEvent( event );
+// }
+// }
+// }
+// //-----------------------------------------------------------------------
+// public HelpingSatSolver( MetadataTreeNode tree )
+// throws SatException
+// {
+// this( tree, null );
+// }
+// //-----------------------------------------------------------------------
+// public final void applyPolicies( List<Comparator<MetadataTreeNode>> comparators )
+// throws SatException
+// {
+// if( comparators == null || comparators.size() < 1 )
+// return;
+//
+// if( _root == null )
+// throw new SatException( "cannot apply policies to a null tree" );
+//
+// // TODO og: assumption - around 128 GA's per tree. If more - map reallocates - slow down.
+// // TODO og: MERCURY-40
+// Map<String, List<MetadataTreeNode>> buckets = new LinkedHashMap<String, List<MetadataTreeNode>>(128);
+// fillBuckets( buckets, _root );
+// sortBuckets( buckets, comparators );
+// useBuckets( buckets );
+// }
+// //-----------------------------------------------------------------------
+// private void useBuckets( Map<String, List<MetadataTreeNode>> buckets )
+// throws SatException
+// {
+// if( buckets == null || buckets.size() < 1 )
+// return;
+//
+// IVecInt vars = new VecInt( 128 );
+// IVec<BigInteger> coeffs = new Vec<BigInteger>( 128 );
+//
+// int count = 0;
+//
+// for( String key : buckets.keySet() )
+// {
+// List<MetadataTreeNode> bucket = buckets.get( key );
//
-//// oleg: ? this is needed if optimization is "maximize"
-//// Collections.reverse( bucket );
+// // oleg: ? this is needed if optimization is "maximize"
+// // Collections.reverse( bucket );
//
-// int bucketSize = bucket.size();
+// int bucketSize = bucket.size();
//
-// boolean bigBucket = bucketSize > 1;
+// boolean bigBucket = bucketSize > 1;
//
-//if( LOG.isDebugEnabled() )
-// LOG.debug( "\n\nBucket "+key );
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "\n\nBucket "+key );
//
-// IVecInt bucketVars = new VecInt( bucketSize );
+// IVecInt bucketVars = new VecInt( bucketSize );
//
-// for( int i=0; i<bucketSize; i++ )
-// {
-// MetadataTreeNode n = bucket.get(i);
+// for( int i=0; i<bucketSize; i++ )
+// {
+// MetadataTreeNode n = bucket.get(i);
//
-//if( LOG.isDebugEnabled() )
-// LOG.debug( n.toString() );
+// if( LOG.isDebugEnabled() )
+// LOG.debug( n.toString() );
//
-// SatVar var = _context.findOrAdd(n);
-// int varLiteral = var.getLiteral();
+// SatVar var = _context.findOrAdd(n);
+// int varLiteral = var.getLiteral();
//
-// bucketVars.push( varLiteral );
+// bucketVars.push( varLiteral );
//
-// if( bigBucket )
-// {
-// vars.push( varLiteral );
+// if( bigBucket )
+// {
+// vars.push( varLiteral );
//
-// long cf = (long)Math.pow( 2, count++ );
+// long cf = (long)Math.pow( 2, count++ );
//
-// coeffs.push( BigInteger.valueOf( cf ) );
+// coeffs.push( BigInteger.valueOf( cf ) );
//
-//if( LOG.isDebugEnabled() )
-// LOG.debug( " "+cf+" x"+var.getLiteral() );
-// }
-//
-// }
-//
-// try
-// {
-// if( bucketVars != null && !bucketVars.isEmpty() )
-// {
-// _solver.addAtMost( bucketVars, 1 );
-// _solver.addAtLeast( bucketVars, 1 );
-// }
-// }
-// catch( ContradictionException e )
-// {
-// throw new SatException(e);
-// }
-//
-//if( LOG.isDebugEnabled() )
-// LOG.debug( "\n" );
-// }
-//
-// if( vars.isEmpty() )
-// return;
-//
-// _solver.setObjectiveFunction( new ObjectiveFunction( vars, coeffs ) );
-// }
-// //-----------------------------------------------------------------------
-// protected static final void sortBuckets(
-// Map<String, List<MetadataTreeNode>> buckets
-// , List<Comparator<MetadataTreeNode>> comparators
-// )
-// {
-// Comparator<MetadataTreeNode> lastComparator;
-// for( List<MetadataTreeNode> bucket : buckets.values() )
-// {
-// lastComparator = gaComparator;
-// for( Comparator<MetadataTreeNode> comparator : comparators )
-// {
-// sortBucket( bucket, comparator, lastComparator );
-// lastComparator = comparator;
-// }
-// // due to the nature of Comparator need to reverse the result
-// // as the best fit is now last
-// Collections.reverse( bucket );
-//
-// // the best fit now first, and we don't need duplicate GAVs
-// removeDuplicateGAVs( bucket );
-//
-// }
-// }
-// //-----------------------------------------------------------------------
-// // remove duplicates, preserving the order. The first one is the most fit,
-// // so need to delete from tail
-// protected static final void removeDuplicateGAVs( List<MetadataTreeNode> bucket )
-// {
-// if( bucket == null || bucket.size() < 2 )
-// return;
-//
-// Comparator<MetadataTreeNode> gav = new MetadataTreeNodeGAVComparator();
-//
-// int len = bucket.size();
-// int [] dups = new int[ len-1 ];
-// int cnt = 0;
-//
-// for( int i=1; i<len; i++ )
-// {
-// MetadataTreeNode ti = bucket.get(i);
-//
-// for( int j=0; j<i; j++ )
-// if( gav.compare( ti, bucket.get(j) ) == 0 )
-// {
-// dups[cnt++] = i;
-// break;
-// }
-// }
-//
-// if( cnt > 0 )
-// for( int i=0; i<cnt; i++ )
-// bucket.remove( dups[cnt-i-1] );
-// }
-// //-----------------------------------------------------------------------
-// /**
-// * reorders the bucket's lastComparator equal subsets with comparator.
-// */
-// protected static final void sortBucket(
-// List<MetadataTreeNode> bucket
-// , Comparator<MetadataTreeNode> comparator
-// , Comparator<MetadataTreeNode> lastComparator
-// )
-// {
-// if( bucket == null || bucket.size() < 2 )
-// return;
-//
-// int bLen = bucket.size();
-// MetadataTreeNode [] temp = bucket.toArray( new MetadataTreeNode[ bLen ] );
-//
-// int wStart = -1;
-// int wLen = 0;
-// MetadataTreeNode [] work = new MetadataTreeNode[ bLen ];
-//
-// MetadataTreeNode lastNode = null;
-// for( int i=0; i<bLen; i++ )
-// {
-// MetadataTreeNode n = temp[i];
-//
-// if( lastNode == null )
-// {
-// lastNode = n;
-// continue;
-// }
-//
-// if( lastComparator.compare(lastNode, n) == 0 )
-// {
-// if( wLen == 0 )
-// {
-// work[ wLen++ ] = lastNode;
-// wStart = i-1;
-// }
+// if( LOG.isDebugEnabled() )
+// LOG.debug( " "+cf+" x"+var.getLiteral() );
+// }
+//
+// }
+//
+// try
+// {
+// if( bucketVars != null && !bucketVars.isEmpty() )
+// {
+// _solver.addAtMost( bucketVars, 1 );
+// _solver.addAtLeast( bucketVars, 1 );
+// }
+// }
+// catch( ContradictionException e )
+// {
+// throw new SatException(e);
+// }
+//
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "\n" );
+// }
+//
+// if( vars.isEmpty() )
+// return;
+//
+// _solver.setObjectiveFunction( new ObjectiveFunction( vars, coeffs ) );
+// }
+// //-----------------------------------------------------------------------
+// protected static final void sortBuckets(
+// Map<String, List<MetadataTreeNode>> buckets
+// , List<Comparator<MetadataTreeNode>> comparators
+// )
+// {
+// Comparator<MetadataTreeNode> lastComparator;
+// for( List<MetadataTreeNode> bucket : buckets.values() )
+// {
+// lastComparator = gaComparator;
+// for( Comparator<MetadataTreeNode> comparator : comparators )
+// {
+// sortBucket( bucket, comparator, lastComparator );
+// lastComparator = comparator;
+// }
+// // due to the nature of Comparator need to reverse the result
+// // as the best fit is now last
+// Collections.reverse( bucket );
+//
+// // the best fit now first, and we don't need duplicate GAVs
+// removeDuplicateGAVs( bucket );
+//
+// }
+// }
+// //-----------------------------------------------------------------------
+// // remove duplicates, preserving the order. The first one is the most fit,
+// // so need to delete from tail
+// protected static final void removeDuplicateGAVs( List<MetadataTreeNode> bucket )
+// {
+// if( bucket == null || bucket.size() < 2 )
+// return;
+//
+// Comparator<MetadataTreeNode> gav = new MetadataTreeNodeGAVComparator();
+//
+// int len = bucket.size();
+// int [] dups = new int[ len-1 ];
+// int cnt = 0;
+//
+// for( int i=1; i<len; i++ )
+// {
+// MetadataTreeNode ti = bucket.get(i);
+//
+// for( int j=0; j<i; j++ )
+// if( gav.compare( ti, bucket.get(j) ) == 0 )
+// {
+// dups[cnt++] = i;
+// break;
+// }
+// }
+//
+// if( cnt > 0 )
+// for( int i=0; i<cnt; i++ )
+// bucket.remove( dups[cnt-i-1] );
+// }
+// //-----------------------------------------------------------------------
+// /**
+// * reorders the bucket's lastComparator equal subsets with comparator.
+// */
+// protected static final void sortBucket(
+// List<MetadataTreeNode> bucket
+// , Comparator<MetadataTreeNode> comparator
+// , Comparator<MetadataTreeNode> lastComparator
+// )
+// {
+// if( bucket == null || bucket.size() < 2 )
+// return;
+//
+// int bLen = bucket.size();
+// MetadataTreeNode [] temp = bucket.toArray( new MetadataTreeNode[ bLen ] );
+//
+// int wStart = -1;
+// int wLen = 0;
+// MetadataTreeNode [] work = new MetadataTreeNode[ bLen ];
+//
+// MetadataTreeNode lastNode = null;
+// for( int i=0; i<bLen; i++ )
+// {
+// MetadataTreeNode n = temp[i];
+//
+// if( lastNode == null )
+// {
+// lastNode = n;
+// continue;
+// }
+//
+// if( lastComparator.compare(lastNode, n) == 0 )
+// {
+// if( wLen == 0 )
+// {
+// work[ wLen++ ] = lastNode;
+// wStart = i-1;
+// }
//
-// work[ wLen++ ] = n;
+// work[ wLen++ ] = n;
//
-// lastNode = n;
+// lastNode = n;
//
-// if( i < (bLen-1) )
-// continue;
-// }
-//
-// if( wLen > 0 ) // eq list formed
-// {
-// reorder( work, wLen, comparator );
-// for( int j=0; j<wLen; j++ )
-// temp[ wStart+j ] = work[ j ];
-// wLen = 0;
-// wStart = -1;
-// }
-//
-// lastNode = n;
-// }
-//
-// bucket.clear();
-// for( int i=0; i<bLen; i++ )
-// bucket.add( temp[ i ] );
-// }
-// //-----------------------------------------------------------------------
-// private static final void reorder(
-// MetadataTreeNode[] work
-// , int wLen
-// , Comparator<MetadataTreeNode> comparator
-// )
-// {
-// MetadataTreeNode[] temp = new MetadataTreeNode[ wLen ];
-//
-// for( int i=0; i< wLen; i++ )
-// temp[i] = work[i];
-//
-// Arrays.sort( temp, comparator );
-//
-// for( int i=0; i<wLen; i++ )
-// work[i] = temp[i];
-//
-// }
-// //-----------------------------------------------------------------------
-// protected static final void fillBuckets(
-// Map<String, List<MetadataTreeNode>> buckets
-// , MetadataTreeNode node
-// )
-// {
-// String ga = node.getMd().getGA();
-// List<MetadataTreeNode> bucket = buckets.get(ga);
-// if( bucket == null )
-// {
-// // TODO og: assumption - around 32 GAVs per GA
-// bucket = new ArrayList<MetadataTreeNode>( 32 );
-// buckets.put( ga, bucket );
-// }
-//
-// bucket.add( node );
-//
-// if( ! node.hasChildren() )
-// return;
-//
-// for( MetadataTreeNode kid : node.getChildren() )
-// {
-// fillBuckets( buckets, kid );
-// }
-// }
-// //-----------------------------------------------------------------------
-// private final void addPB( IVecInt lits, IVec<BigInteger> coeff, boolean ge, BigInteger cardinality )
-// throws ContradictionException
-// {
-// _solver.addPseudoBoolean( lits, coeff, ge, cardinality );
-//
-//if( LOG.isDebugEnabled() )
-// LOG.debug("PB: ");
-//
-// for( int i=0; i<lits.size(); i++ )
-// {
-// int co = Integer.parseInt( ""+coeff.get(i) );
-// String sign = co < 0 ? "-" : "+";
-// int val = Math.abs(co);
-// String space = val == 1 ? "" : " ";
-//
-//if( LOG.isDebugEnabled() )
-// LOG.debug( " " + sign + (val==1?"":val) + space + "x"+lits.get(i) );
-// }
-//if( LOG.isDebugEnabled() )
-// LOG.debug(( ge ? " >= " : " < ")+" "+cardinality );
-// }
-// //-----------------------------------------------------------------------
-// private final Map<ArtifactMetadata, List<MetadataTreeNode>> processChildren(
-// List<ArtifactMetadata> queries
-// , List<MetadataTreeNode> children
-// )
-// throws SatException
-// {
-// if( queries == null || queries.size() < 1 )
-// return null;
-//
-// if( children == null || children.size() < 1 )
-// throw new SatException("there are queries, but not results. Queries: "+queries);
-//
-// // TODO og: MERCURY-40
-// Map<ArtifactMetadata, List<MetadataTreeNode>> res = new LinkedHashMap<ArtifactMetadata, List<MetadataTreeNode>>( queries.size() );
-//
-// for( ArtifactMetadata q : queries )
-// {
-// List<MetadataTreeNode> bucket = new ArrayList<MetadataTreeNode>(4);
-// String queryGA = q.getGA();
-//
-// for( MetadataTreeNode tn : children )
-// {
-// if( tn.getMd() == null )
-// throw new SatException("resulting tree node without metadata for query "+q );
+// if( i < (bLen-1) )
+// continue;
+// }
+//
+// if( wLen > 0 ) // eq list formed
+// {
+// reorder( work, wLen, comparator );
+// for( int j=0; j<wLen; j++ )
+// temp[ wStart+j ] = work[ j ];
+// wLen = 0;
+// wStart = -1;
+// }
+//
+// lastNode = n;
+// }
+//
+// bucket.clear();
+// for( int i=0; i<bLen; i++ )
+// bucket.add( temp[ i ] );
+// }
+// //-----------------------------------------------------------------------
+// private static final void reorder(
+// MetadataTreeNode[] work
+// , int wLen
+// , Comparator<MetadataTreeNode> comparator
+// )
+// {
+// MetadataTreeNode[] temp = new MetadataTreeNode[ wLen ];
+//
+// for( int i=0; i< wLen; i++ )
+// temp[i] = work[i];
+//
+// Arrays.sort( temp, comparator );
+//
+// for( int i=0; i<wLen; i++ )
+// work[i] = temp[i];
+//
+// }
+// //-----------------------------------------------------------------------
+// protected static final void fillBuckets(
+// Map<String, List<MetadataTreeNode>> buckets
+// , MetadataTreeNode node
+// )
+// {
+// String ga = node.getMd().getGA();
+// List<MetadataTreeNode> bucket = buckets.get(ga);
+// if( bucket == null )
+// {
+// // TODO og: assumption - around 32 GAVs per GA
+// bucket = new ArrayList<MetadataTreeNode>( 32 );
+// buckets.put( ga, bucket );
+// }
+//
+// bucket.add( node );
+//
+// if( ! node.hasChildren() )
+// return;
+//
+// for( MetadataTreeNode kid : node.getChildren() )
+// {
+// fillBuckets( buckets, kid );
+// }
+// }
+// //-----------------------------------------------------------------------
+// private final void addPB( IVecInt lits, IVec<BigInteger> coeff, boolean ge, BigInteger cardinality )
+// throws ContradictionException
+// {
+// _solver.addPseudoBoolean( lits, coeff, ge, cardinality );
+//
+// if( LOG.isDebugEnabled() )
+// LOG.debug("PB: ");
+//
+// for( int i=0; i<lits.size(); i++ )
+// {
+// int co = Integer.parseInt( ""+coeff.get(i) );
+// String sign = co < 0 ? "-" : "+";
+// int val = Math.abs(co);
+// String space = val == 1 ? "" : " ";
+//
+// if( LOG.isDebugEnabled() )
+// LOG.debug( " " + sign + (val==1?"":val) + space + "x"+lits.get(i) );
+// }
+// if( LOG.isDebugEnabled() )
+// LOG.debug(( ge ? " >= " : " < ")+" "+cardinality );
+// }
+// //-----------------------------------------------------------------------
+// private final Map<ArtifactMetadata, List<MetadataTreeNode>> processChildren(
+// List<ArtifactMetadata> queries
+// , List<MetadataTreeNode> children
+// )
+// throws SatException
+// {
+// if( queries == null || queries.size() < 1 )
+// return null;
+//
+// if( children == null || children.size() < 1 )
+// throw new SatException("there are queries, but not results. Queries: "+queries);
+//
+// // TODO og: MERCURY-40
+// Map<ArtifactMetadata, List<MetadataTreeNode>> res = new LinkedHashMap<ArtifactMetadata, List<MetadataTreeNode>>(
+// queries.size() );
+//
+// for( ArtifactMetadata q : queries )
+// {
+// List<MetadataTreeNode> bucket = new ArrayList<MetadataTreeNode>(4);
+// String queryGA = q.getGA();
+//
+// for( MetadataTreeNode tn : children )
+// {
+// if( tn.getMd() == null )
+// throw new SatException("resulting tree node without metadata for query "+q );
//
-// if( queryGA.equals( tn.getMd().getGA()) )
-// {
-// bucket.add(tn);
-// }
-// }
-//
-// if( bucket.size() < 1 )
-// throw new SatException("No children for query "+queryGA );
-//
-// res.put( q, bucket );
-// }
-//
-// return res;
-// }
-// //-----------------------------------------------------------------------
-// private final void addNode( MetadataTreeNode node )
-// throws ContradictionException, SatException
-// {
-// if( node == null )
-// return;
-//
-// if( node.getMd() == null )
-// throw new SatException("found a node without metadata");
-//
-// // this one is a must :)
-// if( node.getParent() == null )
-// _helper.setTrue( node, node.getName() );
-//
-// if( ! node.hasChildren() )
-// return;
-//
-// Map<ArtifactMetadata,List<MetadataTreeNode>> kids = processChildren( node.getQueries(), node.getChildren() );
-//
-// // leaf node in this scope
-// if( kids == null )
-// return;
-//
-// for( Map.Entry<ArtifactMetadata,List<MetadataTreeNode>> kid : kids.entrySet() )
-// {
-// ArtifactMetadata query = kid.getKey();
-//
-// List<MetadataTreeNode> range = kid.getValue();
-//
-// if( range.size() > 1 )
-// {
-// addRange( nodeLit.getLiteral(), range, query.isOptional() );
-// for( MetadataTreeNode tn : range )
-// {
-// addNode( tn );
-// }
-// }
-// else
-// {
-// MetadataTreeNode child = range.get(0);
-// SatVar kidLit = _context.findOrAdd( child );
+// if( queryGA.equals( tn.getMd().getGA()) )
+// {
+// bucket.add(tn);
+// }
+// }
+//
+// if( bucket.size() < 1 )
+// throw new SatException("No children for query "+queryGA );
+//
+// res.put( q, bucket );
+// }
+//
+// return res;
+// }
+// //-----------------------------------------------------------------------
+// private final void addNode( MetadataTreeNode node )
+// throws ContradictionException, SatException
+// {
+// if( node == null )
+// return;
+//
+// if( node.getMd() == null )
+// throw new SatException("found a node without metadata");
+//
+// // this one is a must :)
+// if( node.getParent() == null )
+// _helper.setTrue( node, node.getName() );
+//
+// if( ! node.hasChildren() )
+// return;
+//
+// Map<ArtifactMetadata,List<MetadataTreeNode>> kids = processChildren( node.getQueries(), node.getChildren() );
+//
+// // leaf node in this scope
+// if( kids == null )
+// return;
+//
+// for( Map.Entry<ArtifactMetadata,List<MetadataTreeNode>> kid : kids.entrySet() )
+// {
+// ArtifactMetadata query = kid.getKey();
+//
+// List<MetadataTreeNode> range = kid.getValue();
+//
+// if( range.size() > 1 )
+// {
+// addRange( nodeLit.getLiteral(), range, query.isOptional() );
+// for( MetadataTreeNode tn : range )
+// {
+// addNode( tn );
+// }
+// }
+// else
+// {
+// MetadataTreeNode child = range.get(0);
+// SatVar kidLit = _context.findOrAdd( child );
//
-// addPB( SatHelper.getSmallOnes( new int [] { nodeLit.getLiteral(), kidLit.getLiteral() } )
-// , SatHelper.getBigOnes( 1, -1 )
-// , true, BigInteger.ZERO
-// );
-//// addRange( nodeLit.getLiteral(), range, query.isOptional() );
-// addNode( child );
-// }
-//
-// }
-// }
-// //-----------------------------------------------------------------------
-// private final int [] addRange( int parentLiteral, List<MetadataTreeNode> range, boolean optional )
-// throws ContradictionException, SatException
-// {
-// SatVar literal;
-//
-// int [] literals = new int[ range.size() ];
-//
-// int count = 0;
-//
-// for( MetadataTreeNode tn : range )
-// {
-// literal = _context.findOrAdd( tn );
-// literals[count++] = literal.getLiteral();
-//
-// // implication to parent
-// addPB( SatHelper.getSmallOnes( new int [] { parentLiteral, literal.getLiteral() } )
-// , SatHelper.getBigOnes( 1, -1 )
-// , true, BigInteger.ZERO
-// );
-// }
-//
-// IVecInt rangeVector = SatHelper.getSmallOnes( literals );
-//
-// if( optional ) // Sxi >= 0
-// {
-//if( LOG.isDebugEnabled() )
-// LOG.debug( "optional range: atMost 1: "+ SatHelper.vectorToString( rangeVector) );
-//
-// _solver.addAtMost( rangeVector, 1 );
-// }
-// else // Sxi = 1
-// {
-//if( LOG.isDebugEnabled() )
-// LOG.debug( "range: " + SatHelper.vectorToString( rangeVector) );
-//
-// IConstr atLeast = _solver.addAtLeast( rangeVector, 1 );
-// if( LOG.isDebugEnabled() )
-// LOG.debug( "atLeast: " + SatHelper.vectorToString( atLeast) );
-//
-// IConstr atMost = _solver.addAtMost( rangeVector, 1 );
-// if( LOG.isDebugEnabled() )
-// LOG.debug( "atMost: " + SatHelper.vectorToString( atMost) );
-//
-// }
-//
-// return literals;
-// }
-// //-----------------------------------------------------------------------
-// public final List<ArtifactMetadata> solve()
-// throws SatException
-// {
-// List<ArtifactMetadata> res = null;
-// GenericEvent event = null;
-//
-// try
-// {
-// if( _eventManager != null )
-// event = new GenericEvent( EventTypeEnum.satSolver, EVENT_SOLVE, _root.toString() );
-//
-// if( _solver.isSatisfiable() )
-// {
-// res = new ArrayList<ArtifactMetadata>( _root.countNodes() );
+// addPB( SatHelper.getSmallOnes( new int [] { nodeLit.getLiteral(), kidLit.getLiteral() } )
+// , SatHelper.getBigOnes( 1, -1 )
+// , true, BigInteger.ZERO
+// );
+// // addRange( nodeLit.getLiteral(), range, query.isOptional() );
+// addNode( child );
+// }
+//
+// }
+// }
+// //-----------------------------------------------------------------------
+// private final int [] addRange( int parentLiteral, List<MetadataTreeNode> range, boolean optional )
+// throws ContradictionException, SatException
+// {
+// SatVar literal;
+//
+// int [] literals = new int[ range.size() ];
+//
+// int count = 0;
+//
+// for( MetadataTreeNode tn : range )
+// {
+// literal = _context.findOrAdd( tn );
+// literals[count++] = literal.getLiteral();
+//
+// // implication to parent
+// addPB( SatHelper.getSmallOnes( new int [] { parentLiteral, literal.getLiteral() } )
+// , SatHelper.getBigOnes( 1, -1 )
+// , true, BigInteger.ZERO
+// );
+// }
+//
+// IVecInt rangeVector = SatHelper.getSmallOnes( literals );
+//
+// if( optional ) // Sxi >= 0
+// {
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "optional range: atMost 1: "+ SatHelper.vectorToString( rangeVector) );
+//
+// _solver.addAtMost( rangeVector, 1 );
+// }
+// else // Sxi = 1
+// {
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "range: " + SatHelper.vectorToString( rangeVector) );
+//
+// IConstr atLeast = _solver.addAtLeast( rangeVector, 1 );
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "atLeast: " + SatHelper.vectorToString( atLeast) );
+//
+// IConstr atMost = _solver.addAtMost( rangeVector, 1 );
+// if( LOG.isDebugEnabled() )
+// LOG.debug( "atMost: " + SatHelper.vectorToString( atMost) );
+//
+// }
+//
+// return literals;
+// }
+// //-----------------------------------------------------------------------
+// public final List<ArtifactMetadata> solve()
+// throws SatException
+// {
+// List<ArtifactMetadata> res = null;
+// GenericEvent event = null;
+//
+// try
+// {
+// if( _eventManager != null )
+// event = new GenericEvent( EventTypeEnum.satSolver, EVENT_SOLVE, _root.toString() );
+//
+// if( _solver.isSatisfiable() )
+// {
+// res = new ArrayList<ArtifactMetadata>( _root.countNodes() );
//
-// int [] model = _solver.model();
+// int [] model = _solver.model();
//
-//if( LOG.isDebugEnabled() )
-// if( model != null )
-// {
-// StringBuilder sb = new StringBuilder();
-// String comma = "";
-// for( int m : model )
-// {
-// sb.append( comma+m );
-// comma = ", ";
-// }
-// LOG.debug( '['+sb.toString()+']' );
-// }
-// else
-// LOG.debug( "model is null" );
-//
-// for( int i : model )
-// if( i > 0 )
-// res.add( _context.getMd( i ) );
-// }
-// }
-// catch (TimeoutException e)
-// {
-// throw new SatException( e );
-// }
-// finally
-// {
-// if( _eventManager != null )
-// {
-// event.stop();
-// _eventManager.fireEvent( event );
-// }
-// }
-// return res;
-// }
-// //-----------------------------------------------------------------------
-// public final MetadataTreeNode solveAsTree()
-// throws SatException
-// {
-// try
-// {
-// if( _helper.hasASolution() )
-// {
+// if( LOG.isDebugEnabled() )
+// if( model != null )
+// {
+// StringBuilder sb = new StringBuilder();
+// String comma = "";
+// for( int m : model )
+// {
+// sb.append( comma+m );
+// comma = ", ";
+// }
+// LOG.debug( '['+sb.toString()+']' );
+// }
+// else
+// LOG.debug( "model is null" );
+//
+// for( int i : model )
+// if( i > 0 )
+// res.add( _context.getMd( i ) );
+// }
+// }
+// catch (TimeoutException e)
+// {
+// throw new SatException( e );
+// }
+// finally
+// {
+// if( _eventManager != null )
+// {
+// event.stop();
+// _eventManager.fireEvent( event );
+// }
+// }
+// return res;
+// }
+// //-----------------------------------------------------------------------
+// public final MetadataTreeNode solveAsTree()
+// throws SatException
+// {
+// try
+// {
+// if( _helper.hasASolution() )
+// {
//
-// IVec<MetadataTreeNode> solution = _helper.getSolution();
+// IVec<MetadataTreeNode> solution = _helper.getSolution();
//
-// if( solution == null )
-// return null;
+// if( solution == null )
+// return null;
//
-// for( Iterator<MetadataTreeNode> i = solution.iterator(); i.hasNext(); )
-// {
-// MetadataTreeNode mtn = i.next();
+// for( Iterator<MetadataTreeNode> i = solution.iterator(); i.hasNext(); )
+// {
+// MetadataTreeNode mtn = i.next();
//
-// if( mtn.getParent() == null )
-// return mtn;
-// }
+// if( mtn.getParent() == null )
+// return mtn;
+// }
//
-// return null;
-// }
-// }
-// catch (TimeoutException e)
-// {
-// throw new SatException( e );
-// }
-//
-// }
-// //-----------------------------------------------------------------------
-// public void register( MercuryEventListener listener )
-// {
-// if( _eventManager == null )
-// _eventManager = new EventManager();
-//
-// _eventManager.register( listener );
-// }
-//
-// public void setEventManager( EventManager eventManager )
-// {
-// _eventManager = eventManager;
-// }
-//
-// public void unRegister( MercuryEventListener listener )
-// {
-// if( _eventManager != null )
-// _eventManager.unRegister( listener );
-// }
-// //-----------------------------------------------------------------------
-//}
+// return null;
+// }
+// }
+// catch (TimeoutException e)
+// {
+// throw new SatException( e );
+// }
+//
+// }
+// //-----------------------------------------------------------------------
+// public void register( MercuryEventListener listener )
+// {
+// if( _eventManager == null )
+// _eventManager = new EventManager();
+//
+// _eventManager.register( listener );
+// }
+//
+// public void setEventManager( EventManager eventManager )
+// {
+// _eventManager = eventManager;
+// }
+//
+// public void unRegister( MercuryEventListener listener )
+// {
+// if( _eventManager != null )
+// _eventManager.unRegister( listener );
+// }
+// //-----------------------------------------------------------------------
+// }
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java Mon Apr 27 23:12:25 2009
@@ -30,131 +30,138 @@
import org.codehaus.plexus.lang.DefaultLanguage;
import org.codehaus.plexus.lang.Language;
- /**
- * This class hold all variables fed to the SAT solver. Because of the
- * tree unwinding algorithm all pivots (optional nodes) should be supplied first
- *
- * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
- */
+/**
+ * This class hold all variables fed to the SAT solver. Because of the tree unwinding algorithm all pivots (optional
+ * nodes) should be supplied first
+ *
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
class SatContext
{
- private static final Language LANG = new DefaultLanguage(SatContext.class);
- private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( SatContext.class );
+ private static final Language LANG = new DefaultLanguage( SatContext.class );
- Map<MetadataTreeNode,SatVar> variables;
- //-----------------------------------------------------------------------
- public SatContext( int estimatedTreeSize )
- {
- variables = new HashMap<MetadataTreeNode,SatVar>( estimatedTreeSize );
- }
- //-----------------------------------------------------------------------
- public SatVar findOrAdd( MetadataTreeNode n )
- throws SatException
- {
- if( n == null )
- throw new SatException( "cannot create a literal out of a null metadata: "+n );
-
- SatVar var = variables.get( n );
-
- if( var != null )
- {
- if( LOG.isDebugEnabled() )
- LOG.debug( var.toString() );
- return var;
- }
-
- var = new SatVar( n );
- variables.put( n, var );
-
- if( LOG.isDebugEnabled() )
- LOG.debug( var.toString() );
-
- return var;
- }
- //-----------------------------------------------------------------------
- public ArtifactMetadata getMd( int literal )
- {
- for( SatVar v : variables.values() )
- if( v._literal == literal )
- return v.getMd();
-
- return null;
- }
- //-----------------------------------------------------------------------
- private static final boolean isSolution( int m, int [] model )
- {
- for( int mm : model )
- if( mm == m )
- return true;
-
- return false;
- }
- //-----------------------------------------------------------------------
- public MetadataTreeNode getSolutionSubtree( MetadataTreeNode tree, int [] model )
- {
- if( tree == null )
- throw new IllegalArgumentException( LANG.getMessage( "null.tree" ) );
-
- if( tree.getMd() == null )
- throw new IllegalArgumentException( LANG.getMessage( "null.tree.md" ) );
-
- if( model == null )
- throw new IllegalArgumentException( LANG.getMessage( "null.model" ) );
-
- if( model.length < 1 )
- throw new IllegalArgumentException( LANG.getMessage( "empty.model" ) );
-
- int sz = 0;
-
- for( int m : model )
- if( m > 0 )
- ++sz;
-
- if( sz == 0)
- return null;
-
- MetadataTreeNode res = MetadataTreeNode.deepCopy( tree );
-
- cleanTree( res, model );
-
- return res;
- }
- //-----------------------------------------------------------------------
- private static final void cleanTree( MetadataTreeNode tn, int [] model )
- {
- if( ! tn.hasChildren() )
- return;
-
- List<MetadataTreeNode> badKids = new ArrayList<MetadataTreeNode>();
-
- for( MetadataTreeNode kid : tn.getChildren() )
- if( ! isSolution( kid.getId(), model ) )
- badKids.add( kid );
-
- tn.getChildren().removeAll( badKids );
-
- if( ! tn.hasChildren() )
- return;
-
- for( MetadataTreeNode kid : tn.getChildren() )
- cleanTree( kid, model );
- }
- //-----------------------------------------------------------------------
-// @Override
-// public String toString()
-// {
-// if(varCount < 1)
-// return "";
-// StringBuilder sb = new StringBuilder( 32*varCount );
-// char comma = '[';
-//
-// for( SatVar var : variables )
-// {
-// sb.append(comma+" x"+var._literal+"="+var._md.toString() );
-// comma = ',';
-// }
-// return sb.toString()+']';
-// }
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
+ private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( SatContext.class );
+
+ Map<MetadataTreeNode, SatVar> variables;
+
+ // -----------------------------------------------------------------------
+ public SatContext( int estimatedTreeSize )
+ {
+ variables = new HashMap<MetadataTreeNode, SatVar>( estimatedTreeSize );
+ }
+
+ // -----------------------------------------------------------------------
+ public SatVar findOrAdd( MetadataTreeNode n )
+ throws SatException
+ {
+ if ( n == null )
+ throw new SatException( "cannot create a literal out of a null metadata: " + n );
+
+ SatVar var = variables.get( n );
+
+ if ( var != null )
+ {
+ if ( LOG.isDebugEnabled() )
+ LOG.debug( var.toString() );
+ return var;
+ }
+
+ var = new SatVar( n );
+ variables.put( n, var );
+
+ if ( LOG.isDebugEnabled() )
+ LOG.debug( var.toString() );
+
+ return var;
+ }
+
+ // -----------------------------------------------------------------------
+ public ArtifactMetadata getMd( int literal )
+ {
+ for ( SatVar v : variables.values() )
+ if ( v._literal == literal )
+ return v.getMd();
+
+ return null;
+ }
+
+ // -----------------------------------------------------------------------
+ private static final boolean isSolution( int m, int[] model )
+ {
+ for ( int mm : model )
+ if ( mm == m )
+ return true;
+
+ return false;
+ }
+
+ // -----------------------------------------------------------------------
+ public MetadataTreeNode getSolutionSubtree( MetadataTreeNode tree, int[] model )
+ {
+ if ( tree == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.tree" ) );
+
+ if ( tree.getMd() == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.tree.md" ) );
+
+ if ( model == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.model" ) );
+
+ if ( model.length < 1 )
+ throw new IllegalArgumentException( LANG.getMessage( "empty.model" ) );
+
+ int sz = 0;
+
+ for ( int m : model )
+ if ( m > 0 )
+ ++sz;
+
+ if ( sz == 0 )
+ return null;
+
+ MetadataTreeNode res = MetadataTreeNode.deepCopy( tree );
+
+ cleanTree( res, model );
+
+ return res;
+ }
+
+ // -----------------------------------------------------------------------
+ private static final void cleanTree( MetadataTreeNode tn, int[] model )
+ {
+ if ( !tn.hasChildren() )
+ return;
+
+ List<MetadataTreeNode> badKids = new ArrayList<MetadataTreeNode>();
+
+ for ( MetadataTreeNode kid : tn.getChildren() )
+ if ( !isSolution( kid.getId(), model ) )
+ badKids.add( kid );
+
+ tn.getChildren().removeAll( badKids );
+
+ if ( !tn.hasChildren() )
+ return;
+
+ for ( MetadataTreeNode kid : tn.getChildren() )
+ cleanTree( kid, model );
+ }
+ // -----------------------------------------------------------------------
+ // @Override
+ // public String toString()
+ // {
+ // if(varCount < 1)
+ // return "";
+ // StringBuilder sb = new StringBuilder( 32*varCount );
+ // char comma = '[';
+ //
+ // for( SatVar var : variables )
+ // {
+ // sb.append(comma+" x"+var._literal+"="+var._md.toString() );
+ // comma = ',';
+ // }
+ // return sb.toString()+']';
+ // }
+ // -----------------------------------------------------------------------
+ // -----------------------------------------------------------------------
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatException.java Mon Apr 27 23:12:25 2009
@@ -24,25 +24,25 @@
public class SatException
extends Exception
{
- private static final long serialVersionUID = -2461839690564604496L;
+ private static final long serialVersionUID = -2461839690564604496L;
- public SatException()
- {
- }
+ public SatException()
+ {
+ }
- public SatException(String message)
- {
- super(message);
- }
+ public SatException( String message )
+ {
+ super( message );
+ }
- public SatException(Throwable cause)
- {
- super(cause);
- }
+ public SatException( Throwable cause )
+ {
+ super( cause );
+ }
- public SatException(String message, Throwable cause)
- {
- super(message, cause);
- }
+ public SatException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatHelper.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatHelper.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatHelper.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatHelper.java Mon Apr 27 23:12:25 2009
@@ -36,112 +36,121 @@
*/
public class SatHelper
{
- //-----------------------------------------------------------------------
- public static final List<ArtifactMetadata> createList( String... uris )
- {
- List<ArtifactMetadata> aml = new ArrayList<ArtifactMetadata>( uris.length );
- for( String uri : uris )
- {
- aml.add( new ArtifactMetadata(uri) );
- }
- return aml;
- }
- //-----------------------------------------------------------------------
- public static final IVecInt getSmallOnes( int... ints )
- {
- VecInt res = new VecInt( ints );
- return new ReadOnlyVecInt(res);
- }
- //-----------------------------------------------------------------------
- public static final IVecInt getSmallOnes( int first, int second )
- {
- return getSmallOnes( new int [] {first, second} );
- }
- //-----------------------------------------------------------------------
- public static int [] toIntArray( int first, int... ints )
- {
- int [] lits = new int[ ints.length+1 ];
- lits[0] = first;
- int ptr = 1;
-
- for( int i : ints )
- lits[ptr++] = i;
-
- return lits;
- }
- //-----------------------------------------------------------------------
- private static final IVec<BigInteger> toVec( BigInteger... bis )
- {
- return new ReadOnlyVec<BigInteger>( new Vec<BigInteger>( bis ) );
- }
- //-----------------------------------------------------------------------
- public static final IVec<BigInteger> getBigOnes( int... ones )
- {
- BigInteger [] res = new BigInteger[ ones.length ];
-
- for( int i=0; i<ones.length; i++ )
- res[ i ] = BigInteger.valueOf( ones[i] );
-
- return toVec( res );
- }
- //-----------------------------------------------------------------------
- public static final IVec<BigInteger> getBigOnes( int nOnes, boolean negate )
- {
- BigInteger [] res = new BigInteger[ nOnes ];
- BigInteger bi = negate ? BigInteger.ONE.negate() : BigInteger.ONE;
-
- for( int i=0; i<nOnes; i++ )
- res[i] = bi;
-
- return toVec(res);
- }
- //-----------------------------------------------------------------------
- public static final IVec<BigInteger> getBigOnes( int first, int nOnes, boolean negateOnes )
- {
- int len = nOnes + 1;
-
- BigInteger [] res = new BigInteger[ len ];
- res[ 0 ] = BigInteger.valueOf(first);
-
- BigInteger bi = negateOnes ? BigInteger.ONE.negate() : BigInteger.ONE;
-
- for( int i=0; i<nOnes; i++ )
- res[i+1] = bi;
-
- return toVec(res);
- }
- //-----------------------------------------------------------------------
- public static final String vectorToString( IVecInt vec )
- {
- if( vec == null || vec.size() < 1 )
- return "[]";
-
- StringBuilder sb = new StringBuilder();
- String comma = "";
-
- for( int i=0; i<vec.size(); i++ )
- {
- sb.append( comma+"x"+vec.get( i ) );
- comma = ", ";
- }
- return "["+sb.toString()+"]";
- }
- //-----------------------------------------------------------------------
- public static final String vectorToString( IConstr vec )
- {
- if( vec == null || vec.size() < 1 )
- return "[]";
-
- StringBuilder sb = new StringBuilder();
- String comma = "";
-
- for( int i=0; i<vec.size(); i++ )
- {
- sb.append( comma+"x"+vec.get( i ) );
- comma = ", ";
- }
- return "["+sb.toString()+"]";
- }
- //-----------------------------------------------------------------------
- //-----------------------------------------------------------------------
+ // -----------------------------------------------------------------------
+ public static final List<ArtifactMetadata> createList( String... uris )
+ {
+ List<ArtifactMetadata> aml = new ArrayList<ArtifactMetadata>( uris.length );
+ for ( String uri : uris )
+ {
+ aml.add( new ArtifactMetadata( uri ) );
+ }
+ return aml;
+ }
+
+ // -----------------------------------------------------------------------
+ public static final IVecInt getSmallOnes( int... ints )
+ {
+ VecInt res = new VecInt( ints );
+ return new ReadOnlyVecInt( res );
+ }
+
+ // -----------------------------------------------------------------------
+ public static final IVecInt getSmallOnes( int first, int second )
+ {
+ return getSmallOnes( new int[] { first, second } );
+ }
+
+ // -----------------------------------------------------------------------
+ public static int[] toIntArray( int first, int... ints )
+ {
+ int[] lits = new int[ints.length + 1];
+ lits[0] = first;
+ int ptr = 1;
+
+ for ( int i : ints )
+ lits[ptr++] = i;
+
+ return lits;
+ }
+
+ // -----------------------------------------------------------------------
+ private static final IVec<BigInteger> toVec( BigInteger... bis )
+ {
+ return new ReadOnlyVec<BigInteger>( new Vec<BigInteger>( bis ) );
+ }
+
+ // -----------------------------------------------------------------------
+ public static final IVec<BigInteger> getBigOnes( int... ones )
+ {
+ BigInteger[] res = new BigInteger[ones.length];
+
+ for ( int i = 0; i < ones.length; i++ )
+ res[i] = BigInteger.valueOf( ones[i] );
+
+ return toVec( res );
+ }
+
+ // -----------------------------------------------------------------------
+ public static final IVec<BigInteger> getBigOnes( int nOnes, boolean negate )
+ {
+ BigInteger[] res = new BigInteger[nOnes];
+ BigInteger bi = negate ? BigInteger.ONE.negate() : BigInteger.ONE;
+
+ for ( int i = 0; i < nOnes; i++ )
+ res[i] = bi;
+
+ return toVec( res );
+ }
+
+ // -----------------------------------------------------------------------
+ public static final IVec<BigInteger> getBigOnes( int first, int nOnes, boolean negateOnes )
+ {
+ int len = nOnes + 1;
+
+ BigInteger[] res = new BigInteger[len];
+ res[0] = BigInteger.valueOf( first );
+
+ BigInteger bi = negateOnes ? BigInteger.ONE.negate() : BigInteger.ONE;
+
+ for ( int i = 0; i < nOnes; i++ )
+ res[i + 1] = bi;
+
+ return toVec( res );
+ }
+
+ // -----------------------------------------------------------------------
+ public static final String vectorToString( IVecInt vec )
+ {
+ if ( vec == null || vec.size() < 1 )
+ return "[]";
+
+ StringBuilder sb = new StringBuilder();
+ String comma = "";
+
+ for ( int i = 0; i < vec.size(); i++ )
+ {
+ sb.append( comma + "x" + vec.get( i ) );
+ comma = ", ";
+ }
+ return "[" + sb.toString() + "]";
+ }
+
+ // -----------------------------------------------------------------------
+ public static final String vectorToString( IConstr vec )
+ {
+ if ( vec == null || vec.size() < 1 )
+ return "[]";
+
+ StringBuilder sb = new StringBuilder();
+ String comma = "";
+
+ for ( int i = 0; i < vec.size(); i++ )
+ {
+ sb.append( comma + "x" + vec.get( i ) );
+ comma = ", ";
+ }
+ return "[" + sb.toString() + "]";
+ }
+ // -----------------------------------------------------------------------
+ // -----------------------------------------------------------------------
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatOptimizer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatOptimizer.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatOptimizer.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatOptimizer.java Mon Apr 27 23:12:25 2009
@@ -22,22 +22,20 @@
import org.sat4j.pb.ObjectiveFunction;
/**
- * Sat solver optimizer - calculates and returns the minimization function
+ * Sat solver optimizer - calculates and returns the minimization function
*
* @author Oleg Gusakov
- *
*/
public interface SatOptimizer
{
- /**
- * returns the function to be minimized
- *
- * @param tn
- * @param context
- * @return
- * @throws SatException
- */
- public ObjectiveFunction getOptimizer( MetadataTreeNode tn, SatContext context )
- throws SatException
- ;
+ /**
+ * returns the function to be minimized
+ *
+ * @param tn
+ * @param context
+ * @return
+ * @throws SatException
+ */
+ public ObjectiveFunction getOptimizer( MetadataTreeNode tn, SatContext context )
+ throws SatException;
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatSolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatSolver.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatSolver.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatSolver.java Mon Apr 27 23:12:25 2009
@@ -29,26 +29,25 @@
* @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
*/
public interface SatSolver
-extends EventGenerator
+ extends EventGenerator
{
- public static final int DEFAULT_TREE_SIZE = 128; //nodes
-
- public static final String EVENT_SOLVE = "solve";
- public static final String EVENT_CREATE_SOLVER = "create.sat.solver";
-
- /**
- *
- * @param sorts - policies expressed as sorted list of node sorters - from most important to the least
- * @throws SatException
- */
- public void applyPolicies( List< Comparator<MetadataTreeNode> > comparators )
- throws SatException;
-
- /**
- *
- * @return list of ArtifactMetedata's in the solution
- * @throws SatException
- */
- public List<ArtifactMetadata> solve()
- throws SatException;
+ public static final int DEFAULT_TREE_SIZE = 128; // nodes
+
+ public static final String EVENT_SOLVE = "solve";
+
+ public static final String EVENT_CREATE_SOLVER = "create.sat.solver";
+
+ /**
+ * @param sorts - policies expressed as sorted list of node sorters - from most important to the least
+ * @throws SatException
+ */
+ public void applyPolicies( List<Comparator<MetadataTreeNode>> comparators )
+ throws SatException;
+
+ /**
+ * @return list of ArtifactMetedata's in the solution
+ * @throws SatException
+ */
+ public List<ArtifactMetadata> solve()
+ throws SatException;
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java Mon Apr 27 23:12:25 2009
@@ -26,47 +26,45 @@
*/
class SatVar
{
- MetadataTreeNode _node;
- int _literal;
- boolean _optional;
- //---------------------------------------------------------------------
- public SatVar( MetadataTreeNode n )
- throws SatException
- {
- if( n == null
- || n.getMd() == null
- )
- throw new SatException("Cannot create SatVar from a null MetadataTreeNode: "+n);
-
- ArtifactMetadata md = n.getMd();
- if(
- md == null
- || md.getGroupId() == null
- || md.getArtifactId() == null
- || md.getVersion() == null
- )
- throw new SatException("Cannot create SatVar from a null Metadata: "+md);
-
- this._node = n;
- this._literal = n.getId();
- }
- //---------------------------------------------------------------------
- public ArtifactMetadata getMd()
- {
- return _node.getMd();
- }
-
- public int getLiteral()
- {
- return _literal;
- }
- //---------------------------------------------------------------------
- @Override
- public String toString()
- {
- return _node.toString()+" -> X"+_literal;
- }
-
- //---------------------------------------------------------------------
- //---------------------------------------------------------------------
+ MetadataTreeNode _node;
+
+ int _literal;
+
+ boolean _optional;
+
+ // ---------------------------------------------------------------------
+ public SatVar( MetadataTreeNode n )
+ throws SatException
+ {
+ if ( n == null || n.getMd() == null )
+ throw new SatException( "Cannot create SatVar from a null MetadataTreeNode: " + n );
+
+ ArtifactMetadata md = n.getMd();
+ if ( md == null || md.getGroupId() == null || md.getArtifactId() == null || md.getVersion() == null )
+ throw new SatException( "Cannot create SatVar from a null Metadata: " + md );
+
+ this._node = n;
+ this._literal = n.getId();
+ }
+
+ // ---------------------------------------------------------------------
+ public ArtifactMetadata getMd()
+ {
+ return _node.getMd();
+ }
+
+ public int getLiteral()
+ {
+ return _literal;
+ }
+
+ // ---------------------------------------------------------------------
+ @Override
+ public String toString()
+ {
+ return _node.toString() + " -> X" + _literal;
+ }
+
+ // ---------------------------------------------------------------------
+ // ---------------------------------------------------------------------
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/AbstractRepository.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/AbstractRepository.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/AbstractRepository.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/AbstractRepository.java Mon Apr 27 23:12:25 2009
@@ -73,7 +73,7 @@
protected DependencyProcessor dependencyProcessor;
protected Server server;
-
+
protected boolean isSufficient = false;
private static final byte[] __HEX_DIGITS = "0123456789abcdef".getBytes();
@@ -271,12 +271,12 @@
{
return repositoryQualityRange.isAcceptedQuality( quality );
}
-
+
public boolean isSufficient()
{
return isSufficient;
}
-
+
public void setSufficient( boolean isSufficient )
{
this.isSufficient = isSufficient;
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/MetadataResults.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/MetadataResults.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/MetadataResults.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/MetadataResults.java Mon Apr 27 23:12:25 2009
@@ -55,8 +55,7 @@
{
}
- public static MetadataResults add( final MetadataResults res, final ArtifactMetadata key,
- final Exception err )
+ public static MetadataResults add( final MetadataResults res, final ArtifactMetadata key, final Exception err )
{
MetadataResults ret = res;
if ( res == null )
@@ -68,7 +67,7 @@
}
public static MetadataResults add( final MetadataResults res, final ArtifactMetadata key,
- final List<ArtifactMetadata> result )
+ final List<ArtifactMetadata> result )
{
MetadataResults ret = res;
if ( res == null )
@@ -80,7 +79,7 @@
}
public static MetadataResults add( final MetadataResults res, final ArtifactMetadata key,
- final ArtifactMetadata result )
+ final ArtifactMetadata result )
{
MetadataResults ret = res;
if ( res == null )
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/Repository.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/Repository.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/Repository.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/Repository.java Mon Apr 27 23:12:25 2009
@@ -65,13 +65,13 @@
public boolean isSnapshots();
/**
- * indicates that any version or artifact, found in the repository
- * is sufficient and VirtualRepositoryReader should look no further
- *
+ * indicates that any version or artifact, found in the repository is sufficient and VirtualRepositoryReader should
+ * look no further
*/
boolean isSufficient();
+
void setSufficient( boolean isSufficient );
-
+
/**
* indicates if the supplied code quality is served by this repository
*/
@@ -81,18 +81,18 @@
* defines the code quality range for this repository
*/
public QualityRange getRepositoryQualityRange();
+
void setRepositoryQualityRange( QualityRange qualityRange );
/**
* defines how VersionRnage treats upper boundary - which Artifacts should be treated as belonging to the vicinity -
- * http://docs.codehaus.org/x/twDPBQ
- *
- * note: don't mix this with repository quality range - this one is for version range calculations only!
- *
+ * http://docs.codehaus.org/x/twDPBQ note: don't mix this with repository quality range - this one is for version
+ * range calculations only!
*/
public QualityRange getVersionRangeQualityRange();
+
public void setVersionRangeQualityRange( QualityRange qualityRange );
-
+
/**
* get default reader, if any
*
@@ -125,7 +125,7 @@
* @param protocol
* @return writer instance for the specified protocol
* @throws NonExistentProtocolException if protocol not supported
- * @throws RepositoryException
+ * @throws RepositoryException
*/
RepositoryWriter getWriter( String protocol )
throws NonExistentProtocolException, RepositoryException;
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryGAMetadata.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryGAMetadata.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryGAMetadata.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryGAMetadata.java Mon Apr 27 23:12:25 2009
@@ -146,5 +146,5 @@
{
this.negativeResult = negativeResult;
}
-
+
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryMetadataCache.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryMetadataCache.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryMetadataCache.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryMetadataCache.java Mon Apr 27 23:12:25 2009
@@ -95,17 +95,16 @@
* @throws MetadataCacheException
*/
public void saveRaw( ArtifactMetadata bmd, byte[] rawBytes )
- throws MetadataCacheException;
-
+ throws MetadataCacheException;
+
/**
- * clears all session data (in-memory cache). Only on-disk data should remain and it
- * complies with expiration policies. Session data is different in this regard and once in
- * memory - ignores expiration time; this is done for faster access of the same data if
- * expiration is set to "always" - first time data is read from remote repository, cached in
- * the session, and all subsequent call use this data.
+ * clears all session data (in-memory cache). Only on-disk data should remain and it complies with expiration
+ * policies. Session data is different in this regard and once in memory - ignores expiration time; this is done for
+ * faster access of the same data if expiration is set to "always" - first time data is read from remote repository,
+ * cached in the session, and all subsequent call use this data.
*
* @throws MetadataCacheException
*/
public void clearSession()
- throws MetadataCacheException;
+ throws MetadataCacheException;
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdateIntervalPolicy.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdateIntervalPolicy.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdateIntervalPolicy.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdateIntervalPolicy.java Mon Apr 27 23:12:25 2009
@@ -67,7 +67,7 @@
private static final long NEVER = -1L;
private static final long ALWAYS = 0L;
-
+
private static final long DAYLY = 3600000L * 24L;
protected long interval = DAYLY;
@@ -124,7 +124,7 @@
public boolean timestampExpired( long lastUpdateMillis, Quality quality )
{
- // save a couple of nannos
+ // save a couple of nannos
if ( interval == NEVER )
return false;
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicy.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicy.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicy.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicy.java Mon Apr 27 23:12:25 2009
@@ -29,6 +29,7 @@
public interface RepositoryUpdatePolicy
{
public static final String SYSTEM_PROPERTY_UPDATE_POLICY = "mercury.repository.update.policy";
+
/**
* initialize this calculator
*
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyFactory.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyFactory.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/api/RepositoryUpdatePolicyFactory.java Mon Apr 27 23:12:25 2009
@@ -15,23 +15,22 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-*/
+ */
package org.apache.maven.mercury.repository.api;
/**
* creates repository update policy out of strings
- *
+ *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class RepositoryUpdatePolicyFactory
{
public static RepositoryUpdatePolicy create( String policy )
{
RepositoryUpdateIntervalPolicy up = new RepositoryUpdateIntervalPolicy( policy );
-
+
return up;
}
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAMetadata.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAMetadata.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAMetadata.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAMetadata.java Mon Apr 27 23:12:25 2009
@@ -31,85 +31,84 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class CachedGAMetadata
-extends RepositoryGAMetadata
+ extends RepositoryGAMetadata
{
- public static final String ELEM_COORDINATES = "coordinates";
- public static final String ATTR_GROUP_ID = "groupId";
- public static final String ATTR_ARTIFACT_ID = "artifactId";
- public static final String ATTR_VERSION = "version";
- public static final String ATTR_NEGATIVE = "negative";
-
- public static final String ELEM_VERSIONS = "versions";
-
- CachedMetadata cm;
-
- public CachedGAMetadata( File mdFile )
- throws FileNotFoundException, IOException, XmlPullParserException, MetadataCorruptionException
- {
- cm = new CachedMetadata( mdFile );
- fromXml();
- }
-
- public CachedGAMetadata( RepositoryGAMetadata md )
- throws MetadataException
- {
- super( md );
-
- cm = new CachedMetadata();
-
- toXml();
- }
-
- /**
- * fill GA with data from cm
- *
- * @throws MetadataCorruptionException
- */
- private void fromXml()
- throws MetadataCorruptionException
- {
- ga = new ArtifactCoordinates(
- cm.getAttribute( ELEM_COORDINATES, ATTR_GROUP_ID, true )
- , cm.getAttribute( ELEM_COORDINATES, ATTR_ARTIFACT_ID, true )
- , null
- );
-
- List<String> verList = cm.findAttributes( ELEM_VERSIONS, ATTR_VERSION );
-
- if( ! Util.isEmpty( verList ) )
- this.versions.addAll( verList );
-
- String lChk = cm.getLastUpdate();
-
- String negative = cm.getAttribute( ELEM_COORDINATES, ATTR_NEGATIVE, false );
-
- if( !Util.isEmpty( negative ) )
- setNegativeResult( Boolean.parseBoolean( negative ) );
-
- lastCheck = Long.parseLong( lChk );
- }
-
- private void toXml()
- {
- cm.clean();
-
- cm.setAttribute( ELEM_COORDINATES, ATTR_GROUP_ID, ga.getGroupId() );
- cm.setAttribute( ELEM_COORDINATES, ATTR_ARTIFACT_ID, ga.getArtifactId() );
-
- if( isNegativeResult() )
- cm.setAttribute( ELEM_COORDINATES, ATTR_NEGATIVE, "true" );
-
- if( !Util.isEmpty( versions ) )
- cm.setAttribute( ELEM_VERSIONS, ATTR_VERSION, versions );
-
- cm.setLastUpdate( ""+lastCheck );
- }
-
+ public static final String ELEM_COORDINATES = "coordinates";
+
+ public static final String ATTR_GROUP_ID = "groupId";
+
+ public static final String ATTR_ARTIFACT_ID = "artifactId";
+
+ public static final String ATTR_VERSION = "version";
+
+ public static final String ATTR_NEGATIVE = "negative";
+
+ public static final String ELEM_VERSIONS = "versions";
+
+ CachedMetadata cm;
+
+ public CachedGAMetadata( File mdFile )
+ throws FileNotFoundException, IOException, XmlPullParserException, MetadataCorruptionException
+ {
+ cm = new CachedMetadata( mdFile );
+ fromXml();
+ }
+
+ public CachedGAMetadata( RepositoryGAMetadata md )
+ throws MetadataException
+ {
+ super( md );
+
+ cm = new CachedMetadata();
+
+ toXml();
+ }
+
+ /**
+ * fill GA with data from cm
+ *
+ * @throws MetadataCorruptionException
+ */
+ private void fromXml()
+ throws MetadataCorruptionException
+ {
+ ga =
+ new ArtifactCoordinates( cm.getAttribute( ELEM_COORDINATES, ATTR_GROUP_ID, true ),
+ cm.getAttribute( ELEM_COORDINATES, ATTR_ARTIFACT_ID, true ), null );
+
+ List<String> verList = cm.findAttributes( ELEM_VERSIONS, ATTR_VERSION );
+
+ if ( !Util.isEmpty( verList ) )
+ this.versions.addAll( verList );
+
+ String lChk = cm.getLastUpdate();
+
+ String negative = cm.getAttribute( ELEM_COORDINATES, ATTR_NEGATIVE, false );
+
+ if ( !Util.isEmpty( negative ) )
+ setNegativeResult( Boolean.parseBoolean( negative ) );
+
+ lastCheck = Long.parseLong( lChk );
+ }
+
+ private void toXml()
+ {
+ cm.clean();
+
+ cm.setAttribute( ELEM_COORDINATES, ATTR_GROUP_ID, ga.getGroupId() );
+ cm.setAttribute( ELEM_COORDINATES, ATTR_ARTIFACT_ID, ga.getArtifactId() );
+
+ if ( isNegativeResult() )
+ cm.setAttribute( ELEM_COORDINATES, ATTR_NEGATIVE, "true" );
+
+ if ( !Util.isEmpty( versions ) )
+ cm.setAttribute( ELEM_VERSIONS, ATTR_VERSION, versions );
+
+ cm.setLastUpdate( "" + lastCheck );
+ }
+
}
Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVMetadata.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVMetadata.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVMetadata.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/repository/cache/fs/CachedGAVMetadata.java Mon Apr 27 23:12:25 2009
@@ -31,81 +31,82 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
- *
- *
* @author Oleg Gusakov
* @version $Id$
- *
*/
public class CachedGAVMetadata
-extends RepositoryGAVMetadata
+ extends RepositoryGAVMetadata
{
- public static final String ELEM_SNAPSHOTS = "snapshots";
- public static final String ATTR_SNAPSHOT = "snapshot";
+ public static final String ELEM_SNAPSHOTS = "snapshots";
- public static final String ELEM_CLASSIFIERS = "classifiers";
- public static final String ATTR_CLASSIFIER = "classifier";
+ public static final String ATTR_SNAPSHOT = "snapshot";
+
+ public static final String ELEM_CLASSIFIERS = "classifiers";
+
+ public static final String ATTR_CLASSIFIER = "classifier";
+
+ CachedMetadata cm;
+
+ public CachedGAVMetadata( File mdFile )
+ throws FileNotFoundException, IOException, XmlPullParserException, MetadataCorruptionException
+ {
+ cm = new CachedMetadata( mdFile );
+ fromXml();
+ }
+
+ public CachedGAVMetadata( RepositoryGAVMetadata gavm )
+ throws MetadataException
+ {
+ super( gavm );
+
+ cm = new CachedMetadata();
+
+ toXml();
+ }
+
+ /**
+ * fill GA with data from cm
+ *
+ * @throws MetadataCorruptionException
+ */
+ private void fromXml()
+ throws MetadataCorruptionException
+ {
+ gav =
+ new ArtifactCoordinates( cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES,
+ CachedGAMetadata.ATTR_GROUP_ID, true ),
+ cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES,
+ CachedGAMetadata.ATTR_ARTIFACT_ID, true ),
+ cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_VERSION,
+ true ) );
+
+ List<String> snList = cm.findAttributes( ELEM_SNAPSHOTS, ATTR_SNAPSHOT );
+
+ if ( !Util.isEmpty( snList ) )
+ this.snapshots.addAll( snList );
+
+ List<String> clList = cm.findAttributes( ELEM_CLASSIFIERS, ATTR_CLASSIFIER );
+
+ if ( !Util.isEmpty( clList ) )
+ this.classifiers.addAll( clList );
+
+ String lChk = cm.getLastUpdate();
+
+ lastCheck = Long.parseLong( lChk );
+ }
+
+ private void toXml()
+ {
+ cm.clean();
+
+ cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_GROUP_ID, gav.getGroupId() );
+ cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_ARTIFACT_ID, gav.getArtifactId() );
+ cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_VERSION, gav.getVersion() );
+
+ if ( !Util.isEmpty( snapshots ) )
+ cm.setAttribute( ELEM_SNAPSHOTS, ATTR_SNAPSHOT, snapshots );
+
+ cm.setLastUpdate( "" + lastCheck );
+ }
- CachedMetadata cm;
-
- public CachedGAVMetadata( File mdFile )
- throws FileNotFoundException, IOException, XmlPullParserException, MetadataCorruptionException
- {
- cm = new CachedMetadata( mdFile );
- fromXml();
- }
-
- public CachedGAVMetadata( RepositoryGAVMetadata gavm )
- throws MetadataException
- {
- super( gavm );
-
- cm = new CachedMetadata();
-
- toXml();
- }
-
- /**
- * fill GA with data from cm
- *
- * @throws MetadataCorruptionException
- */
- private void fromXml()
- throws MetadataCorruptionException
- {
- gav = new ArtifactCoordinates(
- cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_GROUP_ID, true )
- , cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_ARTIFACT_ID, true )
- , cm.getAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_VERSION, true )
- );
-
- List<String> snList = cm.findAttributes( ELEM_SNAPSHOTS, ATTR_SNAPSHOT );
-
- if( ! Util.isEmpty( snList ) )
- this.snapshots.addAll( snList );
-
- List<String> clList = cm.findAttributes( ELEM_CLASSIFIERS, ATTR_CLASSIFIER );
-
- if( ! Util.isEmpty( clList ) )
- this.classifiers.addAll( clList );
-
- String lChk = cm.getLastUpdate();
-
- lastCheck = Long.parseLong( lChk );
- }
-
- private void toXml()
- {
- cm.clean();
-
- cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_GROUP_ID, gav.getGroupId() );
- cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_ARTIFACT_ID, gav.getArtifactId() );
- cm.setAttribute( CachedGAMetadata.ELEM_COORDINATES, CachedGAMetadata.ATTR_VERSION, gav.getVersion() );
-
- if( !Util.isEmpty( snapshots ) )
- cm.setAttribute( ELEM_SNAPSHOTS, ATTR_SNAPSHOT, snapshots );
-
- cm.setLastUpdate( ""+lastCheck );
- }
-
}