o Formatted code

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@729501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2008-12-26 15:33:38 +00:00
parent 2bb74899fe
commit 5952595d24
1 changed files with 187 additions and 133 deletions

View File

@ -31,148 +31,202 @@
import org.apache.maven.project.builder.PomClassicDomainModel; import org.apache.maven.project.builder.PomClassicDomainModel;
import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelProperty;
public class PomTestWrapper { public class PomTestWrapper
{
private PomClassicDomainModel domainModel; private PomClassicDomainModel domainModel;
private JXPathContext context; private JXPathContext context;
public PomTestWrapper(PomClassicDomainModel domainModel) throws IOException { public PomTestWrapper( PomClassicDomainModel domainModel )
if(domainModel == null) { throws IOException
throw new IllegalArgumentException("domainModel: null"); {
} if ( domainModel == null )
this.domainModel = domainModel; {
context = JXPathContext.newContext(domainModel.getModel()); throw new IllegalArgumentException( "domainModel: null" );
} }
this.domainModel = domainModel;
public PomTestWrapper(File file) throws IOException { context = JXPathContext.newContext( domainModel.getModel() );
if(file == null) { }
throw new IllegalArgumentException("file: null");
} public PomTestWrapper( File file )
throws IOException
this.domainModel = new PomClassicDomainModel(file); {
context = JXPathContext.newContext(domainModel.getModel()); if ( file == null )
} {
throw new IllegalArgumentException( "file: null" );
public PomTestWrapper(Model model) throws IOException { }
if(model == null) {
throw new IllegalArgumentException("model: null"); this.domainModel = new PomClassicDomainModel( file );
} context = JXPathContext.newContext( domainModel.getModel() );
}
this.domainModel = new PomClassicDomainModel(model);
context = JXPathContext.newContext(domainModel.getModel()); public PomTestWrapper( Model model )
} throws IOException
{
if ( model == null )
{
throw new IllegalArgumentException( "model: null" );
}
this.domainModel = new PomClassicDomainModel( model );
context = JXPathContext.newContext( domainModel.getModel() );
}
public PomClassicDomainModel getDomainModel() public PomClassicDomainModel getDomainModel()
{ {
return this.domainModel; return this.domainModel;
} }
public String getValueOfProjectUri(String projectUri, boolean withResolvedValue) throws IOException { public String getValueOfProjectUri( String projectUri, boolean withResolvedValue )
if(projectUri.contains("#collection") || projectUri.contains("#set")) { throws IOException
throw new IllegalArgumentException("projectUri: contains a collection or set"); {
} if ( projectUri.contains( "#collection" ) || projectUri.contains( "#set" ) )
return asMap(withResolvedValue).get(projectUri); {
} throw new IllegalArgumentException( "projectUri: contains a collection or set" );
}
public void setValueOnModel(String expression, Object value) { return asMap( withResolvedValue ).get( projectUri );
context.setValue(expression, value); }
}
/* public void setValueOnModel( String expression, Object value )
public int containerCountForUri(String uri) throws IOException { {
if(uri == null || uri.trim().equals("")) { context.setValue( expression, value );
throw new IllegalArgumentException("uri: null or empty"); }
}
ModelDataSource source = new DefaultModelDataSource(); /*
source.init(domainModel.getModelProperties(), null); public int containerCountForUri( String uri )
return source.queryFor(uri).size(); throws IOException
} {
if ( uri == null || uri.trim().equals( "" ) )
{
throw new IllegalArgumentException( "uri: null or empty" );
}
ModelDataSource source = new DefaultModelDataSource();
source.init( domainModel.getModelProperties(), null );
return source.queryFor( uri ).size();
}
*/ */
public Iterator<?> getIteratorForXPathExpression(String expression) {
return context.iterate(expression);
}
public boolean containsXPathExpression(String expression) {
return context.getValue(expression) != null;
}
public Object getValue(String expression) { public Iterator<?> getIteratorForXPathExpression( String expression )
return context.getValue(expression); {
} return context.iterate( expression );
}
public boolean xPathExpressionEqualsValue(String expression, String value) {
return context.getValue(expression) != null && context.getValue(expression).equals(value);
}
public Map<String, String> asMap(boolean withResolvedValues) throws IOException { public boolean containsXPathExpression( String expression )
Map<String, String> map = new HashMap<String, String>(); {
for(ModelProperty mp : domainModel.getModelProperties()) { return context.getValue( expression ) != null;
if(withResolvedValues) { }
map.put(mp.getUri(), mp.getResolvedValue());
} else { public Object getValue( String expression )
map.put(mp.getUri(), mp.getValue()); {
} return context.getValue( expression );
}
}
return map; public boolean xPathExpressionEqualsValue( String expression, String value )
} {
return context.getValue( expression ) != null && context.getValue( expression ).equals( value );
public boolean containsModelProperty(ModelProperty modelProperty) throws IOException { }
return domainModel.getModelProperties().contains(modelProperty);
} public Map<String, String> asMap( boolean withResolvedValues )
throws IOException
public boolean containsAllModelPropertiesOf(List<ModelProperty> modelProperties) throws IOException { {
for(ModelProperty mp : modelProperties) { Map<String, String> map = new HashMap<String, String>();
if(!containsModelProperty(mp)) { for ( ModelProperty mp : domainModel.getModelProperties() )
return false; {
} if ( withResolvedValues )
} {
return true; map.put( mp.getUri(), mp.getResolvedValue() );
} }
else
public boolean matchModelProperties(List<ModelProperty> hasProperties, List<ModelProperty> doesNotHaveProperties) throws IOException { {
return containsAllModelPropertiesOf(hasProperties) && containNoModelPropertiesOf(doesNotHaveProperties); map.put( mp.getUri(), mp.getValue() );
} }
public boolean matchUris(List<String> hasAllUris, List<String> doesNotHaveUris) throws IOException { }
return hasAllUris(hasAllUris) && hasNoUris(doesNotHaveUris); return map;
} }
public boolean containNoModelPropertiesOf(List<ModelProperty> modelProperties) throws IOException { public boolean containsModelProperty( ModelProperty modelProperty )
for(ModelProperty mp : modelProperties) { throws IOException
if(containsModelProperty(mp)) { {
return false; return domainModel.getModelProperties().contains( modelProperty );
} }
}
return true; public boolean containsAllModelPropertiesOf( List<ModelProperty> modelProperties )
} throws IOException
{
for ( ModelProperty mp : modelProperties )
{
if ( !containsModelProperty( mp ) )
{
return false;
}
}
return true;
}
public boolean matchModelProperties( List<ModelProperty> hasProperties, List<ModelProperty> doesNotHaveProperties )
throws IOException
{
return containsAllModelPropertiesOf( hasProperties ) && containNoModelPropertiesOf( doesNotHaveProperties );
}
public boolean matchUris( List<String> hasAllUris, List<String> doesNotHaveUris )
throws IOException
{
return hasAllUris( hasAllUris ) && hasNoUris( doesNotHaveUris );
}
public boolean containNoModelPropertiesOf( List<ModelProperty> modelProperties )
throws IOException
{
for ( ModelProperty mp : modelProperties )
{
if ( containsModelProperty( mp ) )
{
return false;
}
}
return true;
}
public boolean hasUri( String uri )
throws IOException
{
for ( ModelProperty mp : domainModel.getModelProperties() )
{
if ( mp.getValue().equals( uri ) )
{
return true;
}
}
return false;
}
public boolean hasAllUris( List<String> uris )
throws IOException
{
for ( String s : uris )
{
if ( !hasUri( s ) )
{
return false;
}
}
return true;
}
public boolean hasNoUris( List<String> uris )
throws IOException
{
for ( String s : uris )
{
if ( hasUri( s ) )
{
return false;
}
}
return true;
}
public boolean hasUri(String uri) throws IOException {
for(ModelProperty mp : domainModel.getModelProperties()) {
if(mp.getValue().equals(uri)) {
return true;
}
}
return false;
}
public boolean hasAllUris(List<String> uris) throws IOException {
for(String s : uris) {
if(!hasUri(s)) {
return false;
}
}
return true;
}
public boolean hasNoUris(List<String> uris) throws IOException {
for(String s : uris) {
if(hasUri(s)) {
return false;
}
}
return true;
}
} }