From 8a31c1a381b59c1d22d0b112d0c212dd489ea0a5 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Mon, 30 Mar 2009 22:33:11 +0000 Subject: [PATCH] Setup test classes for testing of pom construction with settings. Tried to use test-jar type to reuse classes but the causes some lost dependencies in eclipse. Just duping classes for now. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@760207 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/project/harness/PomTestWrapper.java | 332 ++++++++++++++++++ .../harness/Xpp3DomAttributeIterator.java | 90 +++++ .../harness/Xpp3DomAttributePointer.java | 105 ++++++ .../project/harness/Xpp3DomNodeIterator.java | 161 +++++++++ .../project/harness/Xpp3DomNodePointer.java | 156 ++++++++ .../harness/Xpp3DomPointerFactory.java | 62 ++++ .../PomConstructionWithSettingsTest.java | 95 +++++ .../settings-no-pom/pom.xml | 13 + .../settings-no-pom/settings.xml | 20 ++ 9 files changed, 1034 insertions(+) create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributeIterator.java create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributePointer.java create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodeIterator.java create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodePointer.java create mode 100644 maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomPointerFactory.java create mode 100644 maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java create mode 100644 maven-core/src/test/resources-settings/settings-no-pom/pom.xml create mode 100644 maven-core/src/test/resources-settings/settings-no-pom/settings.xml diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java new file mode 100644 index 0000000000..fcb83417ae --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java @@ -0,0 +1,332 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.io.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.jxpath.JXPathNotFoundException; +import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.model.ModelProperty; +import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +public class PomTestWrapper +{ + + private PomClassicDomainModel domainModel; + + private File pomFile; + + private JXPathContext context; + + private MavenProject mavenProject; + + static + { + JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() ); + } + + public PomTestWrapper( PomClassicDomainModel domainModel ) + throws IOException + { + this( null, domainModel ); + } + + public PomTestWrapper( File pomFile, PomClassicDomainModel domainModel ) + throws IOException + { + if ( domainModel == null ) + { + throw new IllegalArgumentException( "domainModel: null" ); + } + this.domainModel = domainModel; + this.pomFile = pomFile; + try { + context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream())); + } catch (XmlPullParserException e) { + throw new IOException(e.getMessage()); + } + } + + public PomTestWrapper( File pomFile, MavenProject mavenProject ) + throws IOException + { + if ( mavenProject == null ) + { + throw new IllegalArgumentException( "mavenProject: null" ); + } + this.mavenProject = mavenProject; + this.pomFile = pomFile; + context = JXPathContext.newContext( mavenProject.getModel() ); + } + + public PomTestWrapper( MavenProject mavenProject ) + throws IOException + { + if ( mavenProject == null ) + { + throw new IllegalArgumentException( "mavenProject: null" ); + } + this.mavenProject = mavenProject; + context = JXPathContext.newContext( mavenProject.getModel() ); + } + + public PomTestWrapper( File file ) + throws IOException + { + if ( file == null ) + { + throw new IllegalArgumentException( "file: null" ); + } + + this.domainModel = new PomClassicDomainModel( file ); + try { + context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream())); + } catch (XmlPullParserException e) { + throw new IOException(e.getMessage()); + } + } + + public MavenProject getMavenProject() + { + return mavenProject; + } + + public PomClassicDomainModel getDomainModel() + { + if ( domainModel == null && mavenProject != null ) + { + try + { + domainModel = convertToDomainModel( mavenProject.getModel() ); + int lineageCount = 1; + for ( MavenProject parent = mavenProject.getParent(); parent != null; parent = parent.getParent() ) + { + lineageCount++; + } + domainModel.setLineageCount( lineageCount ); + } + catch ( IOException e ) + { + + } + } + + return this.domainModel; + } + + private PomClassicDomainModel convertToDomainModel(Model model) throws IOException + { + if ( model == null ) + { + throw new IllegalArgumentException( "model: null" ); + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Writer out = null; + MavenXpp3Writer writer = new MavenXpp3Writer(); + try + { + out = WriterFactory.newXmlWriter( baos ); + writer.write( out, model ); + } + finally + { + if ( out != null ) + { + out.close(); + } + } + return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray())); + } + + public File getBasedir() + { + return ( pomFile != null ) ? pomFile.getParentFile() : null; + } + + public String getValueOfProjectUri( String projectUri, boolean withResolvedValue ) + throws IOException + { + if ( projectUri.contains( "#collection" ) || projectUri.contains( "#set" ) ) + { + throw new IllegalArgumentException( "projectUri: contains a collection or set" ); + } + return asMap( withResolvedValue ).get( projectUri ); + } + + public void setValueOnModel( String expression, Object value ) + { + context.setValue( expression, value ); + } + + /* + public int containerCountForUri( String uri ) + 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 ) + { + try + { + return context.getValue( expression ); + } + catch ( JXPathNotFoundException e ) + { + return null; + } + } + + public boolean xPathExpressionEqualsValue( String expression, String value ) + { + return context.getValue( expression ) != null && context.getValue( expression ).equals( value ); + } + + public Map asMap( boolean withResolvedValues ) + throws IOException + { + Map map = new HashMap(); + for ( ModelProperty mp : domainModel.getModelProperties() ) + { + if ( withResolvedValues ) + { + map.put( mp.getUri(), mp.getResolvedValue() ); + } + else + { + map.put( mp.getUri(), mp.getValue() ); + } + + } + return map; + } + + public boolean containsModelProperty( ModelProperty modelProperty ) + throws IOException + { + return domainModel.getModelProperties().contains( modelProperty ); + } + + public boolean containsAllModelPropertiesOf( List modelProperties ) + throws IOException + { + for ( ModelProperty mp : modelProperties ) + { + if ( !containsModelProperty( mp ) ) + { + return false; + } + } + return true; + } + + public boolean matchModelProperties( List hasProperties, List doesNotHaveProperties ) + throws IOException + { + return containsAllModelPropertiesOf( hasProperties ) && containNoModelPropertiesOf( doesNotHaveProperties ); + } + + public boolean matchUris( List hasAllUris, List doesNotHaveUris ) + throws IOException + { + return hasAllUris( hasAllUris ) && hasNoUris( doesNotHaveUris ); + } + + public boolean containNoModelPropertiesOf( List 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 uris ) + throws IOException + { + for ( String s : uris ) + { + if ( !hasUri( s ) ) + { + return false; + } + } + return true; + } + + public boolean hasNoUris( List uris ) + throws IOException + { + for ( String s : uris ) + { + if ( hasUri( s ) ) + { + return false; + } + } + return true; + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributeIterator.java b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributeIterator.java new file mode 100644 index 0000000000..73faa7d0bd --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributeIterator.java @@ -0,0 +1,90 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.jxpath.ri.QName; +import org.apache.commons.jxpath.ri.model.NodeIterator; +import org.apache.commons.jxpath.ri.model.NodePointer; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * An attribute iterator for JXPath to support Xpp3Dom. + * + * @author Benjamin Bentmann + * @version $Id: Xpp3DomAttributeIterator.java 747943 2009-02-25 22:28:48Z bentmann $ + */ +class Xpp3DomAttributeIterator + implements NodeIterator +{ + + private NodePointer parent; + + private Xpp3Dom node; + + private List> attributes; + + private Map.Entry attribute; + + private int position; + + public Xpp3DomAttributeIterator( NodePointer parent, QName qname ) + { + this.parent = parent; + this.node = (Xpp3Dom) parent.getNode(); + + Map map = new LinkedHashMap(); + for ( String name : this.node.getAttributeNames() ) + { + if ( name.equals( qname.getName() ) || "*".equals( qname.getName() ) ) + { + String value = this.node.getAttribute( name ); + map.put( name, value ); + } + } + this.attributes = new ArrayList>( map.entrySet() ); + } + + public NodePointer getNodePointer() + { + if ( position == 0 ) + { + setPosition( 1 ); + } + return ( attribute == null ) ? null : new Xpp3DomAttributePointer( parent, attribute ); + } + + public int getPosition() + { + return position; + } + + public boolean setPosition( int position ) + { + this.position = position; + attribute = ( position > 0 && position <= attributes.size() ) ? attributes.get( position - 1 ) : null; + return attribute != null; + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributePointer.java b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributePointer.java new file mode 100644 index 0000000000..e1aa29f36b --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomAttributePointer.java @@ -0,0 +1,105 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.util.Map; + +import org.apache.commons.jxpath.ri.QName; +import org.apache.commons.jxpath.ri.model.NodePointer; + +/** + * An attribute pointer for JXPath to support Xpp3Dom. + * + * @author Benjamin Bentmann + */ +class Xpp3DomAttributePointer + extends NodePointer +{ + + private Map.Entry attrib; + + public Xpp3DomAttributePointer( NodePointer parent, Map.Entry attrib ) + { + super( parent ); + this.attrib = attrib; + } + + @Override + public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2 ) + { + // should never happen because attributes have no children + return 0; + } + + @Override + public Object getValue() + { + return attrib.getValue(); + } + + @Override + public Object getBaseValue() + { + return attrib; + } + + @Override + public Object getImmediateNode() + { + return attrib; + } + + @Override + public int getLength() + { + return 1; + } + + @Override + public QName getName() + { + return new QName( null, attrib.getKey() ); + } + + @Override + public boolean isActual() + { + return true; + } + + @Override + public boolean isCollection() + { + return false; + } + + @Override + public boolean isLeaf() + { + return true; + } + + @Override + public void setValue( Object value ) + { + throw new UnsupportedOperationException(); + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodeIterator.java b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodeIterator.java new file mode 100644 index 0000000000..d34e2a9a04 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodeIterator.java @@ -0,0 +1,161 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.commons.jxpath.ri.Compiler; +import org.apache.commons.jxpath.ri.compiler.NodeNameTest; +import org.apache.commons.jxpath.ri.compiler.NodeTest; +import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; +import org.apache.commons.jxpath.ri.model.NodeIterator; +import org.apache.commons.jxpath.ri.model.NodePointer; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * A node iterator for JXPath to support Xpp3Dom. + * + * @author Benjamin Bentmann + * @version $Id: Xpp3DomNodeIterator.java 737056 2009-01-23 15:35:43Z bentmann $ + */ +class Xpp3DomNodeIterator + implements NodeIterator +{ + + private NodePointer parent; + + private NodeTest test; + + private Xpp3Dom node; + + private Xpp3Dom[] children; + + private List filteredChildren = new ArrayList(); + + private int filteredIndex; + + private Xpp3Dom child; + + private int position; + + public Xpp3DomNodeIterator( NodePointer parent, NodeTest test, boolean reverse, NodePointer startWith ) + { + this.parent = parent; + this.node = (Xpp3Dom) parent.getNode(); + this.children = this.node.getChildren(); + if ( startWith != null ) + { + for ( ; filteredIndex < children.length; filteredIndex++ ) + { + if ( startWith.equals( children[filteredIndex] ) ) + { + filteredIndex++; + break; + } + } + } + this.test = test; + if ( reverse ) + { + throw new UnsupportedOperationException(); + } + } + + public NodePointer getNodePointer() + { + if ( position == 0 ) + { + setPosition( 1 ); + } + return ( child == null ) ? null : new Xpp3DomNodePointer( parent, child ); + } + + public int getPosition() + { + return position; + } + + public boolean setPosition( int position ) + { + this.position = position; + filterChildren( position ); + child = ( position > 0 && position <= filteredChildren.size() ) ? filteredChildren.get( position - 1 ) : null; + return child != null; + } + + private void filterChildren( int position ) + { + for ( ; position > filteredChildren.size() && filteredIndex < children.length; filteredIndex++ ) + { + Xpp3Dom child = children[filteredIndex]; + if ( testNode( child ) ) + { + filteredChildren.add( child ); + } + } + } + + private boolean testNode( Xpp3Dom node ) + { + if ( test == null ) + { + return true; + } + if ( test instanceof NodeNameTest ) + { + String nodeName = node.getName(); + if ( StringUtils.isEmpty( nodeName ) ) + { + return false; + } + + NodeNameTest nodeNameTest = (NodeNameTest) test; + String namespaceURI = nodeNameTest.getNamespaceURI(); + boolean wildcard = nodeNameTest.isWildcard(); + String testName = nodeNameTest.getNodeName().getName(); + String testPrefix = nodeNameTest.getNodeName().getPrefix(); + if ( wildcard && testPrefix == null ) + { + return true; + } + if ( wildcard || testName.equals( nodeName ) ) + { + return StringUtils.isEmpty( namespaceURI ) || StringUtils.isEmpty( testPrefix ); + } + return false; + } + if ( test instanceof NodeTypeTest ) + { + switch ( ( (NodeTypeTest) test ).getNodeType() ) + { + case Compiler.NODE_TYPE_NODE: + return true; + case Compiler.NODE_TYPE_TEXT: + return node.getValue() != null; + default: + return false; + } + } + return false; + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodePointer.java b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodePointer.java new file mode 100644 index 0000000000..46b87c110c --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomNodePointer.java @@ -0,0 +1,156 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.util.ArrayList; +import java.util.List; + +import org.apache.commons.jxpath.ri.QName; +import org.apache.commons.jxpath.ri.compiler.NodeTest; +import org.apache.commons.jxpath.ri.model.NodeIterator; +import org.apache.commons.jxpath.ri.model.NodePointer; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * A node pointer for JXPath to support Xpp3Dom. + * + * @author Benjamin Bentmann + * @version $Id: Xpp3DomNodePointer.java 747943 2009-02-25 22:28:48Z bentmann $ + */ +class Xpp3DomNodePointer + extends NodePointer +{ + + private Xpp3Dom node; + + public Xpp3DomNodePointer( Xpp3Dom node ) + { + super( null ); + this.node = node; + } + + public Xpp3DomNodePointer( NodePointer parent, Xpp3Dom node ) + { + super( parent ); + this.node = node; + } + + @Override + public int compareChildNodePointers( NodePointer pointer1, NodePointer pointer2 ) + { + Xpp3Dom node1 = (Xpp3Dom) pointer1.getBaseValue(); + Xpp3Dom node2 = (Xpp3Dom) pointer2.getBaseValue(); + if ( node1 == node2 ) + { + return 0; + } + for ( int i = 0; i < node.getChildCount(); i++ ) + { + Xpp3Dom child = node.getChild( i ); + if ( child == node1 ) + { + return -1; + } + if ( child == node2 ) + { + return 1; + } + } + return 0; + } + + @Override + public Object getValue() + { + return getValue(node); + } + + private static Object getValue( Xpp3Dom node ) + { + if ( node.getValue() != null ) + { + return node.getValue().trim(); + } + else + { + List children = new ArrayList(); + for ( int i = 0; i < node.getChildCount(); i++ ) + { + children.add( getValue( node.getChild( i ) ) ); + } + return children; + } + } + + @Override + public Object getBaseValue() + { + return node; + } + + @Override + public Object getImmediateNode() + { + return node; + } + + @Override + public int getLength() + { + return 1; + } + + @Override + public QName getName() + { + return new QName( null, node.getName() ); + } + + @Override + public boolean isCollection() + { + return false; + } + + @Override + public boolean isLeaf() + { + return node.getChildCount() <= 0; + } + + @Override + public void setValue( Object value ) + { + throw new UnsupportedOperationException(); + } + + @Override + public NodeIterator childIterator( NodeTest test, boolean reverse, NodePointer startWith ) + { + return new Xpp3DomNodeIterator( this, test, reverse, startWith ); + } + + @Override + public NodeIterator attributeIterator( QName qname ) + { + return new Xpp3DomAttributeIterator( this, qname ); + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomPointerFactory.java b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomPointerFactory.java new file mode 100644 index 0000000000..8262c95562 --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/harness/Xpp3DomPointerFactory.java @@ -0,0 +1,62 @@ +package org.apache.maven.project.harness; + +/* + * 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 java.util.Locale; + +import org.apache.commons.jxpath.ri.QName; +import org.apache.commons.jxpath.ri.model.NodePointer; +import org.apache.commons.jxpath.ri.model.NodePointerFactory; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * A node pointer factory for JXPath to support Xpp3Dom. + * + * @author Benjamin Bentmann + * @version $Id: Xpp3DomPointerFactory.java 737056 2009-01-23 15:35:43Z bentmann $ + */ +class Xpp3DomPointerFactory + implements NodePointerFactory +{ + + public int getOrder() + { + return 200; + } + + public NodePointer createNodePointer( QName name, Object object, Locale locale ) + { + if ( object instanceof Xpp3Dom ) + { + return new Xpp3DomNodePointer( (Xpp3Dom) object ); + } + return null; + } + + public NodePointer createNodePointer( NodePointer parent, QName name, Object object ) + { + if ( object instanceof Xpp3Dom ) + { + return new Xpp3DomNodePointer( parent, (Xpp3Dom) object ); + } + return null; + } + +} diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java new file mode 100644 index 0000000000..d86b9123bb --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -0,0 +1,95 @@ +package org.apache.maven.settings; + +import java.io.File; +import java.io.IOException; +import java.io.Reader; + +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.model.Profile; +import org.apache.maven.profiles.DefaultProfileManager; +import org.apache.maven.profiles.ProfileActivationContext; +import org.apache.maven.profiles.ProfileManager; +import org.apache.maven.project.DefaultMavenProjectBuilder; +import org.apache.maven.project.DefaultProjectBuilderConfiguration; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuilderConfiguration; +import org.apache.maven.project.harness.PomTestWrapper; +import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +public class PomConstructionWithSettingsTest + extends PlexusTestCase +{ + private static String BASE_DIR = "src/test"; + + private static String BASE_POM_DIR = BASE_DIR + "/resources-settings"; + + private DefaultMavenProjectBuilder mavenProjectBuilder; + + private File testDirectory; + + protected void setUp() + throws Exception + { + testDirectory = new File( getBasedir(), BASE_POM_DIR ); + mavenProjectBuilder = (DefaultMavenProjectBuilder) lookup( MavenProjectBuilder.class ); + } + + public void testA() throws Exception + { + PomTestWrapper pom = buildPom( "settings-no-pom" ); + System.out.println(pom.getDomainModel().asString()); + } + + private PomTestWrapper buildPom( String pomPath ) + throws Exception + { + File pomFile = new File( testDirectory + File.separator + pomPath , "pom.xml" ); + File settingsFile = new File( testDirectory + File.separator + pomPath, "settings.xml" ); + + Settings settings = readSettingsFile(settingsFile); + + ProfileActivationContext pCtx = new ProfileActivationContext(null, true); + ProfileManager profileManager = new DefaultProfileManager(getContainer(), pCtx); + + for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) + { + Profile profile = SettingsUtils.convertFromSettingsProfile( rawProfile ); + + profileManager.addProfile( profile ); + } + + ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration(); + config.setLocalRepository(new DefaultArtifactRepository("default", "", new DefaultRepositoryLayout())); + + config.setGlobalProfileManager(profileManager); + return new PomTestWrapper( pomFile, mavenProjectBuilder.build( pomFile, config ) ); + } + + private static Settings readSettingsFile(File settingsFile) + throws IOException, XmlPullParserException + { + Settings settings = null; + + Reader reader = null; + + try + { + reader = ReaderFactory.newXmlReader( settingsFile ); + + SettingsXpp3Reader modelReader = new SettingsXpp3Reader(); + + settings = modelReader.read( reader ); + } + finally + { + IOUtil.close( reader ); + } + + return settings; + } +} diff --git a/maven-core/src/test/resources-settings/settings-no-pom/pom.xml b/maven-core/src/test/resources-settings/settings-no-pom/pom.xml new file mode 100644 index 0000000000..ee62782619 --- /dev/null +++ b/maven-core/src/test/resources-settings/settings-no-pom/pom.xml @@ -0,0 +1,13 @@ + + + + 4.0.0 + + org.apache.maven.its.mng3099 + maven-mng3099-plugin + 1 + maven-plugin + + maven-mng3099-plugin + Tests properties injected as a result of active profiles in the user settings file. + \ No newline at end of file diff --git a/maven-core/src/test/resources-settings/settings-no-pom/settings.xml b/maven-core/src/test/resources-settings/settings-no-pom/settings.xml new file mode 100644 index 0000000000..b03bb53f85 --- /dev/null +++ b/maven-core/src/test/resources-settings/settings-no-pom/settings.xml @@ -0,0 +1,20 @@ + + + + + + local-profile + + local-profile-prop-value + + + + + + local-profile + + +