diff --git a/maven-shared-model/README.txt b/maven-shared-model/README.txt deleted file mode 100644 index 3641e254c4..0000000000 --- a/maven-shared-model/README.txt +++ /dev/null @@ -1 +0,0 @@ -This module is not part of the shared build due to JDK 1.5 requirement. \ No newline at end of file diff --git a/maven-shared-model/pom.xml b/maven-shared-model/pom.xml deleted file mode 100644 index 9c55cab477..0000000000 --- a/maven-shared-model/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - 4.0.0 - - org.apache.maven.shared - maven-shared-components - 9 - - maven-shared-model - 1.0-SNAPSHOT - Maven Shared Model - - - org.codehaus.woodstox - wstx-asl - 3.2.6 - - - stax - stax-api - 1.0.1 - - - junit - junit - 4.4 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - - - - - scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model - scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model - http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model - - diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java deleted file mode 100644 index c33cf3059b..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DataSourceException.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.IOException; - -/** - * Exception class whose instance is thrown if there is an illegal state within a data source. - */ -public class DataSourceException - extends IOException -{ - static final long serialVersionUID = 8738495672439L; - - /** - * Default constructor - */ - public DataSourceException() - { - super(); - } - - /** - * Constructor - * - * @param message exception message - */ - public DataSourceException( String message ) - { - super( message ); - } - -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java deleted file mode 100644 index 4ed410a45f..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModel.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.shared.model; - -import java.util.List; - -/* - * 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. - */ - -/** - * Extensions or implementations of this interface can be used to provide wrappers around existing models or can be - * used to expose model elements directly. Each respective ModelTransformer implementation should know how to cast to - * the appropriate domain model type(s). - */ -public interface DomainModel -{ - - List getModelProperties(); - - /** - * Returns event history of joins and deletes used in constructing this domain model. - * - * @return event history of joins and deletes used in constructing this domain model - */ - String getEventHistory(); - - /** - * Sets event history of joins and deletes used in constructing this domain model - * - * @param history history of joins and deletes used in constructing this domain model - */ - void setEventHistory( String history ); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModelFactory.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModelFactory.java deleted file mode 100644 index 06c9361cd5..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/DomainModelFactory.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.apache.maven.shared.model; - -import java.util.List; -import java.io.IOException; - -public interface DomainModelFactory { - - DomainModel createDomainModel(List modelProperties) throws IOException; -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java deleted file mode 100644 index 12d966a492..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ImportModel.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.List; - -public interface ImportModel { - - String getId(); - - List getModelProperties(); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java deleted file mode 100644 index ca888a95bd..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/InputStreamDomainModel.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.InputStream; - -/** - * Provides service for obtaining input stream of domain model. - */ -public interface InputStreamDomainModel - extends DomainModel -{ - - /** - * Returns input stream of domain model. - * - * @return input stream of domain model - */ - InputStream getInputStream(); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java deleted file mode 100644 index f61bfed1fa..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/InterpolatorProperty.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.apache.maven.shared.model; - -import java.util.*; - -/* - * 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. - */ - -/** - * Provides interpolator property information. - */ -public final class InterpolatorProperty -{ - /** - * The key (or name) of the property - */ - private final String key; - - /** - * The value of the property - */ - private final String value; - - /** - * Metadata tag (general use) - */ - private String tag; - - - /** - * Constructor - * - * @param key the key (or name) of the property. May not be null - * @param value the value of the property. May not be null. - */ - public InterpolatorProperty( String key, String value ) - { - this(key, value, null); - } - - public InterpolatorProperty( String key, String value, String tag ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "key: null" ); - } - - if ( value == null ) - { - throw new IllegalArgumentException( "value: null" ); - } - this.key = key; - this.value = value; - this.tag = tag; - - } - - /** - * Returns key (or name) of property. - * - * @return key (or name) of property - */ - public String getKey() - { - return key; - } - - /** - * Returns value of property. - * - * @return value of property - */ - public String getValue() - { - return value; - } - - public String getTag() - { - return tag; - } - - public void setTag(String tag) - { - this.tag = tag; - } - public static List toInterpolatorProperties( Map properties, String tag ) - { - if( properties == null ) - { - throw new IllegalArgumentException( "properties: null" ); - } - - List interpolatorProperties = new ArrayList(); - for ( Map.Entry e : properties.entrySet() ) - { - interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", e.getValue(), tag) ); - } - return interpolatorProperties; - } - - /** - * Returns true if key values match, otherwise returns false. - * - * @param o interpolator property to compare - * @return true if key values match, otherwise returns false - */ - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - InterpolatorProperty that = (InterpolatorProperty) o; - - if ( !key.equals( that.key ) ) - { - return false; - } - - return true; - } - - /** - * Returns hash code of interpolator property key. - * - * @return hash code of interpolator property key - */ - public int hashCode() - { - return key.hashCode(); - } - - public String toString() - { - return "Key = " + key + ", Value = " + value + ", Hash = " + - this.hashCode(); - } - - public static List toInterpolatorProperties( Properties properties, String tag ) - { - if( properties == null ) - { - throw new IllegalArgumentException( "properties: null" ); - } - - List interpolatorProperties = new ArrayList(); - for ( Map.Entry e : properties.entrySet() ) - { - interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) ); - } - return interpolatorProperties; - } -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java deleted file mode 100644 index e9e362405e..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainer.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.List; - -/** - * Provides services for determining actions to take: noop, delete, join. For example, say containers with the same ids - * are joined, otherwise one must be deleted. - *
- * ModelContainerA.id = "foo" and
- * ModelContainerB.id = "foobar"
- * 
- * then ModelContainerA.containerAction(ModelContainerB) would return delete action for ModelContainerB. - */ -public interface ModelContainer -{ - - /** - * Returns the model properties contained within the model container. This list must be unmodifiable. - * - * @return the model properties contained within the model container - */ - List getProperties(); - - /** - * Returns model container action (noop, delete, join) for the specified model container. - * - * @param modelContainer the model container to determine the action of - * @return model container action (noop, delete, join) for the specified model container - */ - ModelContainerAction containerAction( ModelContainer modelContainer ); - - /** - * Creates new instance of model container. - * - * @param modelProperties - * @return new instance of model container - */ - ModelContainer createNewInstance( List modelProperties ); - -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java deleted file mode 100644 index 95a6717261..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerAction.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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. - */ - -/** - * Model container actions - */ -public enum ModelContainerAction -{ - /** - * Join two containers - */ - JOIN, - - /** - * Delete container - */ - DELETE, - - /** - * No operation - */ - NOP -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java deleted file mode 100644 index abb2d6b107..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelContainerFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.Collection; -import java.util.List; - -/** - * Factory for returning model container instances. Unlike most factories, implementations of this class are meant to - * create only one type of model container instance. - */ -public interface ModelContainerFactory -{ - - /** - * Returns collection of URIs associated with this factory. - * - * @return collection of URIs associated with this factory - */ - Collection getUris(); - - /** - * Creates a model container instance that contains the specified model properties. The implementing class instance may - * modify, add, delete or reorder the list of model properties before placing them into the returned model - * container. - * - * @param modelProperties the model properties to be contained within the model container - * @return the model container - */ - ModelContainer create( List modelProperties ); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java deleted file mode 100644 index 4040b93f37..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelDataSource.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.Collection; -import java.util.List; - -/** - * Provides services for joining, deleting and querying model containers. - */ -public interface ModelDataSource -{ - /** - * Join model properties of the specified container a with the specified container b. Any elements of model container - * a must take precedence over model container b. All elements of model container A must exist in the data source; - * elements of model container b may or may not exist. - * - * @param a model container with precedence - * @param b model container without precedence - * @return joined model container - */ - ModelContainer join( ModelContainer a, ModelContainer b ) - throws DataSourceException; - - /** - * Deletes properties of the specified model container from the data source. - * - * @param modelContainer the model container that holds the properties to be deleted - */ - void delete( ModelContainer modelContainer ); - - - /** - * Return copy of underlying model properties. No changes in this list will be reflected in the data source. - * - * @return copy of underlying model properties - */ - List getModelProperties(); - - /** - * Returns model containers for the specified URI. - * - * @param uri - * @return - */ - List queryFor( String uri ) - throws DataSourceException; - - - /** - * Initializes the object with model properties. - * - * @param modelProperties the model properties that back the data source - */ - void init( List modelProperties, Collection modelContainerFactories ); - - /** - * Return history of all joins and deletes - * - * @return history of all joins and deletes - */ - String getEventHistory(); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java deleted file mode 100644 index d068e8e5c5..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelEventListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.apache.maven.shared.model; - -import java.util.List; -import java.util.Collection; - -public interface ModelEventListener { - - public void fire(List modelContainers); - - List getUris(); - - Collection getModelContainerFactories(); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java deleted file mode 100644 index 95f90cd862..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelMarshaller.java +++ /dev/null @@ -1,412 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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 javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Provides methods for marshalling and unmarshalling XML that does not contain attributes. - */ -public final class ModelMarshaller -{ - - /** - * Private Constructor - */ - private ModelMarshaller() - { - } - - /** - * Returns list of model properties transformed from the specified input stream. - * - * @param inputStream input stream containing the xml document. May not be null. - * @param baseUri the base uri of every model property. May not be null or empty. - * @param collections set of uris that are to be treated as a collection (multiple entries). May be null. - * @return list of model properties transformed from the specified input stream. - * @throws IOException if there was a problem doing the transform - */ - public static List marshallXmlToModelProperties( InputStream inputStream, String baseUri, - Set collections ) - throws IOException - { - if ( inputStream == null ) - { - throw new IllegalArgumentException( "inputStream: null" ); - } - - if ( baseUri == null || baseUri.trim().length() == 0 ) - { - throw new IllegalArgumentException( "baseUri: null" ); - } - - if ( collections == null ) - { - collections = Collections.emptySet(); - } - - List modelProperties = new ArrayList(); - XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); - xmlInputFactory.setProperty( XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE ); - xmlInputFactory.setProperty( XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE ); - - Uri uri = new Uri( baseUri ); - String tagName = baseUri; - StringBuilder tagValue = new StringBuilder( 256 ); - - int depth = 0; - int depthOfTagValue = depth; - XMLStreamReader xmlStreamReader = null; - try - { - xmlStreamReader = xmlInputFactory.createXMLStreamReader( inputStream ); - - Map attributes = new HashMap(); - for ( ; ; xmlStreamReader.next() ) - { - int type = xmlStreamReader.getEventType(); - switch ( type ) - { - - case XMLStreamConstants.CDATA: - case XMLStreamConstants.CHARACTERS: - { - if ( depth == depthOfTagValue ) - { - tagValue.append( xmlStreamReader.getTextCharacters(), xmlStreamReader.getTextStart(), - xmlStreamReader.getTextLength() ); - } - break; - } - - case XMLStreamConstants.START_ELEMENT: - { - if ( !tagName.equals( baseUri ) ) - { - String value = null; - if ( depth < depthOfTagValue ) - { - value = tagValue.toString(); - } - modelProperties.add( new ModelProperty( tagName, value ) ); - if ( !attributes.isEmpty() ) - { - for ( Map.Entry e : attributes.entrySet() ) - { - modelProperties.add( new ModelProperty( e.getKey(), e.getValue() ) ); - } - attributes.clear(); - } - } - - depth++; - tagName = uri.getUriFor( xmlStreamReader.getName().getLocalPart(), depth ); - if ( collections.contains( tagName + "#collection" ) ) - { - tagName = tagName + "#collection"; - uri.addTag( xmlStreamReader.getName().getLocalPart() + "#collection" ); - } - else if(collections.contains( tagName + "#set" )) - { - tagName = tagName + "#set"; - uri.addTag( xmlStreamReader.getName().getLocalPart() + "#set" ); - } - else - { - uri.addTag( xmlStreamReader.getName().getLocalPart() ); - } - tagValue.setLength( 0 ); - depthOfTagValue = depth; - } - case XMLStreamConstants.ATTRIBUTE: - { - for ( int i = 0; i < xmlStreamReader.getAttributeCount(); i++ ) - { - - attributes.put( - tagName + "#property/" + xmlStreamReader.getAttributeName( i ).getLocalPart(), - xmlStreamReader.getAttributeValue( i ) ); - } - break; - } - case XMLStreamConstants.END_ELEMENT: - { - depth--; - break; - } - case XMLStreamConstants.END_DOCUMENT: - { - modelProperties.add( new ModelProperty( tagName, tagValue.toString() ) ); - if ( !attributes.isEmpty() ) - { - for ( Map.Entry e : attributes.entrySet() ) - { - modelProperties.add( new ModelProperty( e.getKey(), e.getValue() ) ); - } - attributes.clear(); - } - return modelProperties; - } - } - } - } - catch ( XMLStreamException e ) - { - throw new IOException( ":" + e.toString() ); - } - finally - { - if ( xmlStreamReader != null ) - { - try - { - xmlStreamReader.close(); - } - catch ( XMLStreamException e ) - { - e.printStackTrace(); - } - } - try - { - inputStream.close(); - } - catch ( IOException e ) - { - - } - } - } - - /** - * Returns XML string unmarshalled from the specified list of model properties - * - * @param modelProperties the model properties to unmarshal. May not be null or empty - * @param baseUri the base uri of every model property. May not be null or empty. - * @return XML string unmarshalled from the specified list of model properties - * @throws IOException if there was a problem with unmarshalling - */ - public static String unmarshalModelPropertiesToXml( List modelProperties, String baseUri ) - throws IOException - { - if ( modelProperties == null || modelProperties.isEmpty() ) - { - throw new IllegalArgumentException( "modelProperties: null or empty" ); - } - - if ( baseUri == null || baseUri.trim().length() == 0 ) - { - throw new IllegalArgumentException( "baseUri: null or empty" ); - } - - final int basePosition = baseUri.length(); - - StringBuffer sb = new StringBuffer(); - List lastUriTags = new ArrayList(); - int n = 1; - for ( ModelProperty mp : modelProperties ) - { - String uri = mp.getUri(); - if ( uri.contains( "#property" ) ) - { - continue; - } - - //String val = (mp.getResolvedValue() != null) ? "\"" + mp.getResolvedValue() + "\"" : null; - // System.out.println("new ModelProperty(\"" + mp.getUri() +"\" , " + val +"),"); - if ( !uri.startsWith( baseUri ) ) - { - throw new IllegalArgumentException( - "Passed in model property that does not match baseUri: Property URI = " + uri + ", Base URI = " + - baseUri ); - } - List tagNames = getTagNamesFromUri( basePosition, uri ); - if ( lastUriTags.size() > tagNames.size() ) - { - for ( int i = lastUriTags.size() - 1; i >= tagNames.size(); i-- ) - { - sb.append( toEndTag( lastUriTags.get( i - 1 ) ) ); - } - } - String tag = tagNames.get( tagNames.size() - 1 ); - - List attributes = new ArrayList(); - for(int peekIndex = modelProperties.indexOf( mp ) + 1; peekIndex < modelProperties.size(); peekIndex++) - { - if ( peekIndex <= modelProperties.size() - 1 ) - { - ModelProperty peekProperty = modelProperties.get( peekIndex ); - if ( peekProperty.getUri().contains( "#property" ) ) - { - attributes.add(peekProperty); - } - else - { - break; - } - } - else - { - break; - } - } - - sb.append( toStartTag( tag, attributes ) ); - if ( mp.getResolvedValue() != null ) - { - sb.append( mp.getResolvedValue() ); - sb.append( toEndTag( tag ) ); - n = 2; - } - else if(!attributes.isEmpty()) - { - int pi = modelProperties.indexOf( mp ) + attributes.size() + 1; - if ( pi <= modelProperties.size() - 1 ) - { - ModelProperty peekProperty = modelProperties.get( pi ); - if ( !peekProperty.getUri().startsWith(mp.getUri()) ) - { - if( mp.getResolvedValue() != null ) - { - sb.append( mp.getResolvedValue() ); - } - sb.append( toEndTag( tag ) ); - n = 2; - } - } - } - else - { - n = 1; - } - lastUriTags = tagNames; - } - for ( int i = lastUriTags.size() - n; i >= 1; i-- ) - { - sb.append( toEndTag( lastUriTags.get( i ) ) ); - } - return sb.toString(); - } - - /** - * Returns list of tag names parsed from the specified uri. All #collection parts of the tag are removed from the - * tag names. - * - * @param basePosition the base position in the specified URI to start the parse - * @param uri the uri to parse for tag names - * @return list of tag names parsed from the specified uri - */ - private static List getTagNamesFromUri( int basePosition, String uri ) - { - return Arrays.asList( uri.substring( basePosition ).replaceAll( "#collection", "" ) - .replaceAll("#set", "").split( "/" ) ); - } - - /** - * Returns the XML formatted start tag for the specified value and the specified attribute. - * - * @param value the value to use for the start tag - * @param attributes the attribute to use in constructing of start tag - * @return the XML formatted start tag for the specified value and the specified attribute - */ - private static String toStartTag( String value, List attributes ) - { - StringBuffer sb = new StringBuffer(); //TODO: Support more than one attribute - sb.append( "\r\n<" ).append( value ); - if ( attributes != null ) - { - for(ModelProperty attribute : attributes) - { - sb.append( " " ).append( - attribute.getUri().substring( attribute.getUri().indexOf( "#property/" ) + 10 ) ).append( "=\"" ) - .append( attribute.getResolvedValue() ).append( "\" " ); - } - } - sb.append( ">" ); - return sb.toString(); - } - - /** - * Returns XML formatted end tag for the specified value. - * - * @param value the value to use for the end tag - * @return xml formatted end tag for the specified value - */ - private static String toEndTag( String value ) - { - if ( value.trim().length() == 0 ) - { - return ""; - } - StringBuffer sb = new StringBuffer(); - sb.append( "" ); - return sb.toString(); - } - - /** - * Class for storing information about URIs. - */ - private static class Uri - { - - List uris; - - Uri( String baseUri ) - { - uris = new LinkedList(); - uris.add( baseUri ); - } - - String getUriFor( String tag, int depth ) - { - setUrisToDepth( depth ); - StringBuffer sb = new StringBuffer(); - for ( String tagName : uris ) - { - sb.append( tagName ).append( "/" ); - } - sb.append( tag ); - return sb.toString(); - } - - void addTag( String tag ) - { - uris.add( tag ); - } - - void setUrisToDepth( int depth ) - { - uris = new LinkedList( uris.subList( 0, depth ) ); - } - } -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java deleted file mode 100644 index 8f942ae51f..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelProperty.java +++ /dev/null @@ -1,247 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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 java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Maps a URI to a string value, which may be null. This class is immutable. - */ -public final class ModelProperty -{ - - /** - * A pattern used for finding pom, project and env properties - */ - private static final Pattern EXPRESSION_PATTERN = Pattern.compile( "\\$\\{(pom\\.|project\\.|env\\.)?([^}]+)\\}" ); - - /** - * URI of the resource - */ - private final String uri; - - /** - * Value associated with the uri - */ - private final String value; - - /** - * The count of '/' within this model property's uri, which is the depth of its XML nodes. - */ - private final int depth; - - /** - * Value of this model property after interpolation - */ - private String resolvedValue; - - /** - * List of unresolved expressions within this model property's value - */ - private final List unresolvedExpressions; - - /** - * Constructor - * - * @param uri URI of the resource. May not be null - * @param value Value associated with specified uri. Value may be null if uri does not map to primitive type. - */ - public ModelProperty( String uri, String value ) - { - if ( uri == null ) - { - throw new IllegalArgumentException( "uri" ); - } - this.uri = uri; - this.value = value; - resolvedValue = value; - - unresolvedExpressions = new ArrayList(); - if ( value != null ) - { - Matcher matcher = EXPRESSION_PATTERN.matcher( value ); - while ( matcher.find() ) - { - unresolvedExpressions.add( matcher.group( 0 ) ); - } - } - - String uriWithoutProperty; - int index = uri.lastIndexOf( "/" ); - if(index > -1) { - uriWithoutProperty = uri.substring( 0, uri.lastIndexOf( "/" ) ); - if(uriWithoutProperty.endsWith("#property") || uriWithoutProperty.endsWith("combine.children") ) - { - uriWithoutProperty = uriWithoutProperty.substring( 0, uriWithoutProperty.lastIndexOf( "/" ) ); - } - } - else - { - uriWithoutProperty = uri; - } - - depth = uriWithoutProperty.split( "/" ).length; - } - - /** - * Returns URI key - * - * @return URI key - */ - public String getUri() - { - return uri; - } - - /** - * Returns value for the URI key. Value may be null. - * - * @return value for the URI key. Value may be null - */ - public String getValue() - { - return value; - } - - /** - * Value of this model property after interpolation. CDATA section will be added if needed. - * - * @return value of this model property after interpolation - */ - public String getResolvedValue() - { - if( !uri.contains("#property") && resolvedValue != null && !resolvedValue.startsWith (""; - } - return resolvedValue; - } - - /** - * Returns true if model property is completely interpolated, otherwise returns false. - * - * @return true if model property is completely interpolated, otherwise returns false - */ - public boolean isResolved() - { - return unresolvedExpressions.isEmpty(); - } - - /** - * Returns copy of the uninterpolated model property - * - * @return copy of the uninterpolated model property - */ - public ModelProperty createCopyOfOriginal() - { - return new ModelProperty( uri, value ); - } - - /** - * Returns the count of '/' within this model property's uri, which is the depth of its XML nodes. - * - * @return the count of '/' within this model property's uri, which is the depth of its XML nodes - */ - public int getDepth() - { - return depth; - } - - /** - * Returns true if this model property is a direct parent of the specified model property, otherwise returns false. - * - * @param modelProperty the model property - * @return true if this model property is a direct parent of the specified model property, otherwise returns false - */ - public boolean isParentOf( ModelProperty modelProperty ) - { - if ( Math.abs( depth - modelProperty.getDepth() ) > 1 ) - { - return false; - } - if ( uri.equals( modelProperty.getUri() ) || uri.startsWith( modelProperty.getUri() ) ) - { - return false; - } - return ( modelProperty.getUri().startsWith( uri ) ); - } - - /** - * Returns this model property as an interpolator property, allowing the interpolation of model elements within - * other model elements. - * - * @param baseUri the base uri of the model property - * @return this model property as an interpolator property, allowing the interpolation of model elements within - * other model elements - */ - public InterpolatorProperty asInterpolatorProperty( String baseUri ) - { - if ( uri.contains( "#collection" ) || uri.contains("#set") || value == null ) - { - return null; - } - String key = "${" + uri.replace( baseUri + "/", "" ).replace( "/", "." ) + "}"; - return new InterpolatorProperty( key, value ); - } - - /** - * Resolves any unresolved model property expressions using the specified interpolator property - * - * @param property the interpolator property used to resolve - */ - public boolean resolveWith( InterpolatorProperty property ) - { - if ( property == null ) - { - throw new IllegalArgumentException( "property: null" ); - } - if ( isResolved() ) - { - return false; - } - boolean resolved = false; - for ( String expression : unresolvedExpressions ) - { - if ( property.getKey().equals( expression ) ) - { - resolved = true; - resolvedValue = resolvedValue.replace( property.getKey(), property.getValue() ); - unresolvedExpressions.clear(); - Matcher matcher = EXPRESSION_PATTERN.matcher( resolvedValue ); - while ( matcher.find() ) - { - unresolvedExpressions.add( matcher.group( 0 ) ); - } - break; - } - } - return resolved; - } - - public String toString() - { - return "Uri = " + uri + ", Value = " + value + ", Resolved Value = " + resolvedValue + ", Hash = " + - this.hashCode(); - } -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java deleted file mode 100644 index 8ed0073502..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelPropertyTransformer.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.List; - -public interface ModelPropertyTransformer { - - List transform(List modelProperties); - - String getBaseUri(); -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java deleted file mode 100644 index d57de6ce4e..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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.IOException; -import java.util.List; - -/** - * Provides services for transforming domain models to property lists and vice versa. - * ModelTransformer.transformToDomainModel == ModelTransformer.transformToModelProperties if list of model - * properties specified in transformToDomainModel contains only one property with a uri of http://apache.org/model/project. - */ -public interface ModelTransformer -{ - - List preprocessModelProperties(List modelProperties); - - String getBaseUri(); - - /** - * Transforms specified list of model properties into a single domain model. The list may contain a hierarchy (inheritance) of - * model information. - * - * @param properties list of model properties to transform into domain model. List may not be null. - * @return domain model - */ - DomainModel transformToDomainModel( List properties, List eventListeners) - throws IOException; - - /** - * Transforms specified list of domain models to a property list. The list of domain models should be in order of - * most specialized to least specialized model. - * - * @param domainModels list of domain models to transform to a list of model properties. List may not be null. - * @return list of model properties - */ - List transformToModelProperties(List domainModels ) - throws IOException; - - /** - * - * @param modelProperties - * @param interpolatorProperties - * @param domainModel - * @throws IOException - */ - void interpolateModelProperties(List modelProperties, - List interpolatorProperties, - DomainModel domainModel) - throws IOException; -} diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java deleted file mode 100644 index 403a0b55eb..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java +++ /dev/null @@ -1,443 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.shared.model.impl.DefaultModelDataSource; - -import java.io.IOException; -import java.util.*; - - -/** - * Primary context for this package. Provides methods for doing transforms. - */ -public final class ModelTransformerContext -{ - /** - * Factories to use for construction of model containers - */ - private final Collection factories; - - /** - * List of system and environmental properties to use during interpolation - */ - private final static List systemInterpolatorProperties = - new ArrayList(); - - private final static List environmentInterpolatorProperties = - new ArrayList(); - - static - { - for ( Map.Entry e : System.getProperties().entrySet() ) - { - systemInterpolatorProperties.add( - new InterpolatorProperty( "${" + e.getKey() + "}", (String) e.getValue() ) ); - } - - for ( Map.Entry e : System.getenv().entrySet() ) - { - environmentInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) ); - } - } - - /** - * Default constructor - * - * @param factories model container factories. Value may be null. - */ - public ModelTransformerContext( Collection factories ) - { - if ( factories == null ) - { - this.factories = Collections.emptyList(); - } - else - { - this.factories = factories; - } - } - - public static List createInterpolatorProperties(List modelProperties, - String baseUriForModel, - Map aliases, - String interpolatorTag, - boolean includeSystemProperties, - boolean includeEnvironmentProperties) - { - if(modelProperties == null) - { - throw new IllegalArgumentException("modelProperties: null"); - } - - if(baseUriForModel == null) - { - throw new IllegalArgumentException( "baseUriForModel: null"); - } - - List interpolatorProperties - = new ArrayList( ); - - if( includeSystemProperties ) - { - interpolatorProperties.addAll( systemInterpolatorProperties ); - } - - if( includeEnvironmentProperties ) - { - interpolatorProperties.addAll( environmentInterpolatorProperties ); - } - - for ( ModelProperty mp : modelProperties ) - { - InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel ); - if ( ip != null ) - { ip.setTag( interpolatorTag ); - interpolatorProperties.add( ip ); - for ( Map.Entry a : aliases.entrySet() ) - { - interpolatorProperties.add( new InterpolatorProperty( - ip.getKey().replaceAll( a.getKey(), a.getValue()), - ip.getValue().replaceAll( a.getKey(), a.getValue()), - interpolatorTag) ); - } - } - } - - List ips = new ArrayList(); - for(InterpolatorProperty ip : interpolatorProperties) { - if(!ips.contains(ip)) { - ips.add(ip); - } - } - return ips; - } - - public static void interpolateModelProperties(List modelProperties, - List interpolatorProperties ) - { - if( modelProperties == null ) - { - throw new IllegalArgumentException("modelProperties: null"); - } - - if( interpolatorProperties == null ) - { - throw new IllegalArgumentException("interpolatorProperties: null"); - } - - List unresolvedProperties = new ArrayList(); - for ( ModelProperty mp : modelProperties ) - { - if ( !mp.isResolved() ) - { - unresolvedProperties.add( mp ); - } - } - - LinkedHashSet ips = new LinkedHashSet(); - ips.addAll(interpolatorProperties); - boolean continueInterpolation = true; - while(continueInterpolation) - { - continueInterpolation = false; - for ( InterpolatorProperty ip : ips) - { - for ( ModelProperty mp : unresolvedProperties ) - { - if(mp.resolveWith(ip) && !continueInterpolation ) - { - continueInterpolation = true; - } - } - } - } - } - - - /** - * Transforms the specified model properties using the specified transformers. - * - * @param modelProperties - * @param modelPropertyTransformers - * @return transformed model properties - */ - public static List transformModelProperties(List modelProperties, - List modelPropertyTransformers) - { - if(modelProperties == null) { - throw new IllegalArgumentException("modelProperties: null"); - } - if(modelPropertyTransformers == null) { - throw new IllegalArgumentException("modelPropertyTransformers: null"); - } - - List properties = new ArrayList(modelProperties); - List transformers = new ArrayList(modelPropertyTransformers); - for(ModelPropertyTransformer mpt : transformers) { - properties = sort(mpt.transform(sort(properties, mpt.getBaseUri())), mpt.getBaseUri()); - if(transformers.indexOf(mpt) == transformers.size() - 1) { - properties = sort(sort(properties, mpt.getBaseUri()), mpt.getBaseUri()); - } - } - - return properties; - } - - /** - * Transforms and interpolates specified hierarchical list of domain models (inheritence) to target domain model. - * Unlike ModelTransformerContext#transform(java.util.List, ModelTransformer, ModelTransformer), this method requires - * the user to add interpolator properties. It's intended to be used by IDEs. - * - * @param domainModels the domain model list to transform - * @param fromModelTransformer transformer that transforms from specified domain models to canonical data model - * @param toModelTransformer transformer that transforms from canonical data model to returned domain model - * @param importModels - * @param interpolatorProperties properties to use during interpolation. @return processed domain model - * @throws IOException if there was a problem with the transform - */ - public DomainModel transform(List domainModels, - ModelTransformer fromModelTransformer, - ModelTransformer toModelTransformer, - Collection importModels, - List interpolatorProperties, - List eventListeners) - throws IOException - { - - if( eventListeners == null ) - { - eventListeners = new ArrayList(); - } - else - { - eventListeners = new ArrayList(eventListeners); - } - - if(interpolatorProperties == null) - { - interpolatorProperties = new ArrayList(); - } - - - List transformedProperties = - importModelProperties(importModels, fromModelTransformer.transformToModelProperties( domainModels)); - transformedProperties = fromModelTransformer.preprocessModelProperties(transformedProperties); - - String baseUriForModel = fromModelTransformer.getBaseUri(); - List modelProperties = - sort( transformedProperties, baseUriForModel ); - - modelProperties = determineLeafNodes(modelProperties); - ModelDataSource modelDataSource = new DefaultModelDataSource(); - modelDataSource.init( modelProperties, factories ); - - for ( ModelContainerFactory factory : factories ) - { - for ( String uri : factory.getUris() ) - { - List modelContainers; - try - { - modelContainers = modelDataSource.queryFor( uri ); - } - catch ( IllegalArgumentException e ) - { - System.out.println( modelDataSource.getEventHistory() ); - throw new IllegalArgumentException( e ); - } - List removedModelContainers = new ArrayList(); - Collections.reverse( modelContainers ); - for ( int i = 0; i < modelContainers.size(); i++ ) - { - ModelContainer mcA = modelContainers.get( i ); - if ( removedModelContainers.contains( mcA ) ) - { - continue; - } - for ( ModelContainer mcB : modelContainers.subList( i + 1, modelContainers.size() ) ) - { - ModelContainerAction action = mcA.containerAction( mcB ); - - if ( ModelContainerAction.DELETE.equals( action ) ) - { - modelDataSource.delete( mcB ); - removedModelContainers.add( mcB ); - } - else if ( ModelContainerAction.JOIN.equals( action ) ) - { - try - { - mcA = modelDataSource.join( mcA, mcB ); - removedModelContainers.add( mcB ); - } - catch ( DataSourceException e ) - { - System.out.println( modelDataSource.getEventHistory() ); - e.printStackTrace(); - throw new IOException( "Failed to join model containers: URI = " + uri + - ", Factory = " + factory.getClass().getName() ); - } - } - } - } - } - } - - - List mps = modelDataSource.getModelProperties(); - mps = sort( mps, baseUriForModel ); - - fromModelTransformer.interpolateModelProperties( mps, interpolatorProperties, domainModels.get(0)); - - try - { - DomainModel domainModel = toModelTransformer.transformToDomainModel( mps, eventListeners ); - domainModel.setEventHistory(modelDataSource.getEventHistory()); - return domainModel; - } - catch ( IOException e ) - { - System.out.println( modelDataSource.getEventHistory() ); - e.printStackTrace(); - throw new IOException( e.getMessage() ); - } - } - - /** - * Transforms and interpolates specified hierarchical list of domain models (inheritence) to target domain model. - * Uses standard environmental and system properties for intepolation. - * - * @param domainModels the domain model list to transform - * @param fromModelTransformer transformer that transforms from specified domain models to canonical data model - * @param toModelTransformer transformer that transforms from canonical data model to returned domain model - * @return processed domain model - * @throws IOException if there was a problem with the transform - */ - public DomainModel transform( List domainModels, ModelTransformer fromModelTransformer, - ModelTransformer toModelTransformer ) - throws IOException - { - return this.transform( domainModels, fromModelTransformer, toModelTransformer, null, systemInterpolatorProperties, null ); - } - - private static List importModelProperties(Collection importModels, - List modelProperties) { - List properties = new ArrayList(); - for(ModelProperty mp: modelProperties) { - if(mp.getUri().endsWith("importModel")) { - for(ImportModel im : importModels) { - if(im.getId().equals(mp.getResolvedValue())) { - properties.addAll(im.getModelProperties()); - } - } - } else { - properties.add(mp); - } - } - return properties; - } - - /** - * Sorts specified list of model properties. Typically the list contain property information from the entire - * hierarchy of models, with most specialized model first in the list. - *

- * Define Sorting Rules: Sorting also removes duplicate values (same URI) unless the value contains a parent with - * a #collection (http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency) - * - * @param properties unsorted list of model properties. List may not be null. - * @param baseUri the base URI of every model property - * @return sorted list of model properties - */ - public static List sort( List properties, String baseUri ) - { - if ( properties == null ) - { - throw new IllegalArgumentException( "properties" ); - } - LinkedList processedProperties = new LinkedList(); - List position = new ArrayList(); - boolean projectIsContained = false; - - for ( ModelProperty p : properties ) - { - String uri = p.getUri(); - String parentUri = uri.substring( 0, uri.lastIndexOf( "/" ) ); - - if ( !projectIsContained && uri.equals( baseUri ) ) - { - projectIsContained = true; - processedProperties.add( p ); - position.add( 0, uri ); - } - else if ( !position.contains( uri ) || parentUri.contains( "#collection" ) || parentUri.contains( "#set" ) ) - { - int pst = (parentUri.endsWith("#property")) - ? (position.indexOf( parentUri.replaceAll("#property", "") ) + 1) : (position.indexOf( parentUri ) + 1); - if(pst == 0 && !uri.equals(properties.get(0).getUri()) ) - { - for(ModelProperty mp : properties) - { - System.out.println(mp); - } - throw new IllegalArgumentException("Could not locate parent: Parent URI = " + parentUri - + ": Child - " + p.toString()); - } - processedProperties.add( pst, p ); - position.add( pst, uri ); - } - } - return processedProperties; - } - - private static List determineLeafNodes(List modelProperties) - { - List mps = new ArrayList(); - for(ModelProperty mp : modelProperties) - { - if(mp.getResolvedValue() != null && mp.getResolvedValue().trim().equals("") && isLeafNode( mp, modelProperties) ) - { - mps.add( new ModelProperty(mp.getUri(), null) ); - } - else - { - mps.add(mp); - } - } - return mps; - } - - private static boolean isLeafNode(ModelProperty modelProperty, List modelProperties) - { - for(int i = modelProperties.indexOf(modelProperty); i < modelProperties.size() - 1 ; i++) - { - ModelProperty peekProperty = modelProperties.get( i + 1 ); - if(modelProperty.isParentOf( peekProperty ) && !peekProperty.getUri().contains( "#property") ) - { - return true; - } - else if(!modelProperty.isParentOf( peekProperty ) ) - { - return modelProperty.getDepth() < peekProperty.getDepth(); - } - } - return true; - } -} \ No newline at end of file diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java deleted file mode 100644 index 80a9f49b66..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java +++ /dev/null @@ -1,590 +0,0 @@ -package org.apache.maven.shared.model.impl; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.shared.model.DataSourceException; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelContainerFactory; -import org.apache.maven.shared.model.ModelDataSource; -import org.apache.maven.shared.model.ModelProperty; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * Default implementation of the ModelDataSource. - */ -public final class DefaultModelDataSource - implements ModelDataSource -{ - - /** - * List of current model properties underlying the data source - */ - private List modelProperties; - - /** - * Copy of the model properties used during initialization of the data source - */ - private List originalModelProperties; - - /** - * History of joins and deletes - */ - private List dataEvents; - - /** - * Map of model container factories used in creation of model containers - */ - private Map modelContainerFactoryMap; - - /** - * Default constructor - */ - public DefaultModelDataSource() - { - } - - /** - * @see ModelDataSource#join(org.apache.maven.shared.model.ModelContainer, org.apache.maven.shared.model.ModelContainer) - */ - public ModelContainer join( ModelContainer a, ModelContainer b ) - throws DataSourceException - { - if ( a == null || a.getProperties() == null || a.getProperties().size() == 0 ) - { - throw new IllegalArgumentException( "a or a.properties: empty" ); - } - if ( b == null || b.getProperties() == null ) - { - throw new IllegalArgumentException( "b: null or b.properties: empty" ); - } - /* - if ( !modelProperties.containsAll( a.getProperties() ) ) - { - List unknownProperties = new ArrayList(); - for ( ModelProperty mp : a.getProperties() ) - { - if ( !modelProperties.contains( mp ) ) - { - unknownProperties.add( mp ); - } - } - - List des = new ArrayList(); - for ( DataEvent de : dataEvents ) - { - if ( aContainsAnyOfB( de.getRemovedModelProperties(), unknownProperties ) ) - { - des.add( de ); - } - } - //output - StringBuffer sb = new StringBuffer(); - sb.append( "Found unknown properties in container 'a': Name = " ).append( a.getClass().getName() ).append( - "\r\n" ); - for ( ModelProperty mp : unknownProperties ) - { - sb.append( mp ).append( "\r\n" ); - } - - System.out.println( sb ); - throw new DataSourceException( "ModelContainer 'a' contains elements not within datasource" ); - } - */ - if ( a.equals( b ) || b.getProperties().size() == 0 ) - { - return a; - } - - int startIndex = modelProperties.indexOf( b.getProperties().get( 0 ) ); - if(startIndex == -1) - { - startIndex = modelProperties.indexOf( a.getProperties().get( 0 ) ); - if(startIndex == -1) { - return null; - } - } - delete( a ); - delete( b ); - - List joinedProperties = mergeModelContainers( a, b ); - if ( modelProperties.size() == 0 ) - { - startIndex = 0; - } - joinedProperties = sort(joinedProperties, findBaseUriFrom(joinedProperties)); - - modelProperties.addAll( startIndex, joinedProperties ); - /* - List deletedProperties = new ArrayList(); - deletedProperties.addAll( a.getProperties() ); - deletedProperties.addAll( b.getProperties() ); - deletedProperties.removeAll( joinedProperties ); - if ( deletedProperties.size() > 0 ) - { - dataEvents.add( new DataEvent( a, b, deletedProperties, "join" ) ); - } - */ - return a.createNewInstance( joinedProperties ); - } - - /** - * @see ModelDataSource#delete(org.apache.maven.shared.model.ModelContainer) - */ - public void delete( ModelContainer modelContainer ) - { - if ( modelContainer == null ) - { - throw new IllegalArgumentException( "modelContainer: null" ); - } - if ( modelContainer.getProperties() == null ) - { - throw new IllegalArgumentException( "modelContainer.properties: null" ); - } - modelProperties.removeAll( modelContainer.getProperties() ); - //dataEvents.add( new DataEvent( modelContainer, null, modelContainer.getProperties(), "delete" ) ); - } - - /** - * @see org.apache.maven.shared.model.ModelDataSource#getModelProperties() - */ - public List getModelProperties() - { - return new ArrayList( modelProperties ); - } - - /** - * @see ModelDataSource#queryFor(String) - */ - public List queryFor( String uri ) - throws DataSourceException - { - if ( uri == null ) - { - throw new IllegalArgumentException( "uri" ); - } - - if ( modelProperties.isEmpty() ) - { - return Collections.emptyList(); - } - - ModelContainerFactory factory = modelContainerFactoryMap.get( uri ); - if ( factory == null ) - { - throw new DataSourceException( "Unable to find factory for uri: URI = " + uri ); - } - - List modelContainers = new LinkedList(); - - final int NO_TAG = 0; - final int START_TAG = 1; - final int END_START_TAG = 2; - final int END_TAG = 3; - int state = NO_TAG; - - List tmp = new ArrayList(); - - for ( Iterator i = modelProperties.iterator(); i.hasNext(); ) - { - ModelProperty mp = i.next(); - if ( state == START_TAG && ( !i.hasNext() || !mp.getUri().startsWith( uri ) ) ) - { - state = END_TAG; - } - else if ( state == START_TAG && mp.getUri().equals( uri ) ) - { - state = END_START_TAG; - } - else if ( mp.getUri().startsWith( uri ) ) - { - state = START_TAG; - } - else - { - state = NO_TAG; - } - switch ( state ) - { - case START_TAG: - { - tmp.add( mp ); - if ( !i.hasNext() ) - { - modelContainers.add( factory.create( tmp ) ); - } - break; - } - case END_START_TAG: - { - modelContainers.add( factory.create( tmp ) ); - tmp.clear(); - tmp.add( mp ); - state = START_TAG; - break; - } - case END_TAG: - { - if ( !i.hasNext() && mp.getUri().startsWith(uri)) - { - tmp.add( mp ); - } - modelContainers.add( factory.create( tmp ) ); - tmp.clear(); - state = NO_TAG; - } - } - } - - //verify data source integrity - List unknownProperties = findUnknownModelPropertiesFrom( modelContainers ); - if ( !unknownProperties.isEmpty() ) - { - for ( ModelProperty mp : unknownProperties ) - { - System.out.println( "Missing property from ModelContainer: " + mp ); - } - throw new DataSourceException( - "Unable to query datasource. ModelContainer contains elements not within datasource" ); - } - - return modelContainers; - } - - /** - * @see ModelDataSource#init(java.util.List, java.util.Collection) - */ - public void init( List modelProperties, Collection modelContainerFactories ) - { - if ( modelProperties == null ) - { - throw new IllegalArgumentException( "modelProperties: null" ); - } - if ( modelContainerFactories == null ) - { - throw new IllegalArgumentException( "modeContainerFactories: null" ); - } - this.modelProperties = new LinkedList( modelProperties ); - this.modelContainerFactoryMap = new HashMap(); - this.dataEvents = new ArrayList(); - this.originalModelProperties = new ArrayList( modelProperties ); - - for ( ModelContainerFactory factory : modelContainerFactories ) - { - Collection uris = factory.getUris(); - if ( uris == null ) - { - throw new IllegalArgumentException( "factory.uris: null" ); - } - - for ( String uri : uris ) - { - modelContainerFactoryMap.put( uri, factory ); - } - } - } - - /** - * @see org.apache.maven.shared.model.ModelDataSource#getEventHistory() - */ - public String getEventHistory() - { - StringBuffer sb = new StringBuffer(); - /* - sb.append( "Original Model Properties\r\n" ); - for ( ModelProperty mp : originalModelProperties ) - { - sb.append( mp ).append( "\r\n" ); - } - - for ( DataEvent de : dataEvents ) - { - sb.append( de.toString() ); - } - - sb.append( "Processed Model Properties\r\n" ); - for ( ModelProperty mp : modelProperties ) - { - sb.append( mp ).append( "\r\n" ); - } - */ - return sb.toString(); - } - - /** - * Removes duplicate model properties from the containers and return list. - * - * @param a container A - * @param b container B - * @return list of merged properties - */ - protected static List mergeModelContainers( ModelContainer a, ModelContainer b ) - { - List m = new ArrayList(); - m.addAll( a.getProperties() ); - m.addAll( b.getProperties() ); - - List combineChildrenUris = new ArrayList(); - for ( ModelProperty mp : m ) - { - String x = mp.getUri(); - if ( x.endsWith( "#property/combine.children" ) && mp.getResolvedValue().equals( "append" ) ) - { - combineChildrenUris.add( x.substring( 0, x.length() - 26 ) ); - } - } - - LinkedList processedProperties = new LinkedList(); - List uris = new ArrayList(); - String baseUri = a.getProperties().get( 0 ).getUri(); - for ( ModelProperty p : m ) - { - int modelPropertyLength = p.getUri().length(); - if ( baseUri.length() > modelPropertyLength ) - { - throw new IllegalArgumentException( - "Base URI is longer than model property uri: Base URI = " + baseUri + ", ModelProperty = " + p ); - } - - String subUri = p.getUri().substring( baseUri.length(), modelPropertyLength ); - if ( !uris.contains( p.getUri() ) || ( (subUri.contains( "#collection" ) || subUri.contains("#set")) && - (!subUri.endsWith( "#collection" ) && !subUri.endsWith("#set")) && !isParentASet(subUri) && combineChildrenRule(p, combineChildrenUris) ) - ) - { - processedProperties.add( findLastIndexOfParent( p, processedProperties ) + 1, p ); - uris.add( p.getUri() ); - } - //if parentUri ends in set and uri is contained don't include it - } - return processedProperties; - } - - private static boolean combineChildrenRule(ModelProperty mp, List combineChildrenUris) { - return !combineChildrenUris.contains( mp.getUri() ) || mp.getUri().endsWith( "#property/combine.children" ) ; - } - - private static boolean isParentASet(String uri) - { - String x = uri.replaceAll("#property", "").replaceAll("/combine.children", ""); - String parentUri = (x.lastIndexOf( "/" ) > 0) - ? x.substring( 0, x.lastIndexOf( "/" ) ) : ""; - return parentUri.endsWith("#set"); - } - - /** - * Returns list of model properties (from the specified list of model containers) that are not contained in the data - * source - * - * @param modelContainers the model containers (containing model properties) to check for unknown model properties - * @return list of model properties (from the specified list of model containers) that are not contained in the data - * source - */ - private List findUnknownModelPropertiesFrom( List modelContainers ) - { - List unknownProperties = new ArrayList(); - for ( ModelContainer mc : modelContainers ) - { - if ( !modelProperties.containsAll( mc.getProperties() ) ) - { - for ( ModelProperty mp : mc.getProperties() ) - { - if ( !modelProperties.contains( mp ) ) - { - unknownProperties.add( mp ); - } - } - } - } - return unknownProperties; - } - - /** - * Returns the last position of the uri of the specified model property (ModelProperty.getUri) from within the specified - * list of model properties. - * - * @param modelProperty the model property - * @param modelProperties the list of model properties used in determining the returned index - * @return the last position of the uri of the specified model property (ModelProperty.getUri) from within the specified - * list of model properties. - */ - private static int findLastIndexOfParent( ModelProperty modelProperty, List modelProperties ) - { - for ( int i = modelProperties.size() - 1; i >= 0; i-- ) - { - if ( modelProperties.get( i ).getUri().equals( modelProperty.getUri() ) ) - { - for ( int j = i; j < modelProperties.size(); j++ ) - { - if ( !modelProperties.get( j ).getUri().startsWith( modelProperty.getUri() ) ) - { - return j - 1; - } - } - return modelProperties.size() - 1; - } - else if ( modelProperties.get( i ).isParentOf( modelProperty ) ) - { - return i; - } - } - return -1; - } - - /** - * Returns true if specified list 'a' contains one or more elements of specified list 'b', otherwise returns false. - * - * @param a list of model containers - * @param b list of model containers - * @return true if specified list 'a' contains one or more elements of specified list 'b', otherwise returns false. - */ - private static boolean aContainsAnyOfB( List a, List b ) - { - for ( ModelProperty mp : b ) - { - if ( a.contains( mp ) ) - { - return true; - } - } - return false; - } - - /** - * Join or delete event - */ - private static class DataEvent - { - - private List removedModelProperties; - - private ModelContainer mcA; - - private ModelContainer mcB; - - private String methodName; - - DataEvent( ModelContainer mcA, ModelContainer mcB, List removedModelProperties, - String methodName ) - { - this.mcA = mcA; - this.mcB = mcB; - this.removedModelProperties = removedModelProperties; - this.methodName = methodName; - } - - public ModelContainer getMcA() - { - return mcA; - } - - public ModelContainer getMcB() - { - return mcB; - } - - public List getRemovedModelProperties() - { - return removedModelProperties; - } - - public String getMethodName() - { - return methodName; - } - - public String toString() - { - StringBuffer sb = new StringBuffer(); - sb.append( "Delete Event: " ).append( methodName ).append( "\r\n" ); - sb.append( "Model Container A:\r\n" ); - for ( ModelProperty mp : mcA.getProperties() ) - { - sb.append( mp ).append( "\r\n" ); - } - if ( mcB != null ) - { - sb.append( "Model Container B:\r\n" ); - for ( ModelProperty mp : mcB.getProperties() ) - { - sb.append( mp ).append( "\r\n" ); - } - } - - sb.append( "Removed Properties:\r\n" ); - for ( ModelProperty mp : removedModelProperties ) - { - sb.append( mp ).append( "\r\n" ); - } - return sb.toString(); - } - } - - protected static List sort( List properties, String baseUri ) - { - if ( properties == null ) - { - throw new IllegalArgumentException( "properties" ); - } - LinkedList processedProperties = new LinkedList(); - List position = new ArrayList(); - boolean projectIsContained = false; - - for ( ModelProperty p : properties ) - { - String uri = p.getUri(); - String parentUri = uri.substring( 0, uri.lastIndexOf( "/" ) ); - - if ( !projectIsContained && uri.equals( baseUri ) ) - { - projectIsContained = true; - processedProperties.add( p ); - position.add( 0, uri ); - } - else if ( !position.contains( uri ) || parentUri.contains( "#collection" ) || parentUri.contains( "#set" ) ) - { - int pst = (parentUri.endsWith("#property")) - ? (position.indexOf( parentUri.replaceAll("#property", "") ) + 1) : (position.indexOf( parentUri ) + 1); - processedProperties.add( pst, p ); - position.add( pst, uri ); - } - } - return processedProperties; - } - - private static String findBaseUriFrom(List modelProperties) - { - String baseUri = null; - for(ModelProperty mp : modelProperties) - { - if(baseUri == null || mp.getUri().length() < baseUri.length()) - { - baseUri = mp.getUri(); - } - } - return baseUri; - } -} \ No newline at end of file diff --git a/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/XmlImportModel.java b/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/XmlImportModel.java deleted file mode 100644 index 0866fd21b6..0000000000 --- a/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/XmlImportModel.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.apache.maven.shared.model.impl; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.shared.model.ImportModel; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.ModelMarshaller; - -import java.util.List; -import java.io.InputStream; -import java.io.IOException; - -public class XmlImportModel implements ImportModel { - - private String id; - - private List modelProperties; - - public XmlImportModel(String id, InputStream inputStream, String baseUri) throws IOException { - if(id == null) { - throw new IllegalArgumentException("id: null"); - } - this.id = id; - modelProperties = ModelMarshaller.marshallXmlToModelProperties(inputStream, baseUri, null); - } - - public String getId() { - return id; - } - - public List getModelProperties() { - return modelProperties; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - XmlImportModel that = (XmlImportModel) o; - - if (id != null ? !id.equals(that.id) : that.id != null) return false; - - return true; - } - - public int hashCode() { - int result; - result = (id != null ? id.hashCode() : 0); - result = 31 * result + (modelProperties != null ? modelProperties.hashCode() : 0); - return result; - } -} diff --git a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java b/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java deleted file mode 100644 index bc1f86e6ab..0000000000 --- a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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 static org.junit.Assert.assertEquals; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ModelMarshallerTest -{ - - @Test - public void unmarshalWithEmptyCollectionTags() - throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://apache.org/maven/project/dependencies#collection", null ) ); - String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, "http://apache.org/maven" ); - // System.out.println( "COMPLETE:" + xml ); //TODO: Verify proper xml - } - - @Test - public void unmarshalWithSingleProperty() - throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://apache.org/maven/project/modelVersion", "4.0.0" ) ); - String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, "http://apache.org/maven" ); - // System.out.println( "COMPLETE:" + xml ); //TODO: Verify proper xml - } - - @Test - public void unmarshalWithEmptyTags111() - throws IOException - { - List modelProperties = ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream( - "1.24".getBytes() ), - "http://apache.org/maven", - null ); - - String xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, "http://apache.org/maven" ); - // System.out.println( "COMPLETE:" + xml ); //TODO: Verify proper xml - } - - @Test - public void marshal() - throws IOException - { - List modelProperties = ModelMarshaller.marshallXmlToModelProperties( - new ByteArrayInputStream( "1.1".getBytes() ), - "http://apache.org/maven", null ); - - assertEquals( 2, modelProperties.size() ); - assertEquals( "http://apache.org/maven/project", modelProperties.get( 0 ).getUri() ); - assertEquals( "http://apache.org/maven/project/version", modelProperties.get( 1 ).getUri() ); - assertEquals( "1.1", modelProperties.get( 1 ).getResolvedValue() ); - } - - /* - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithBadBaseUri() throws IOException, XmlPullParserException { - List modelProperties = Arrays.asList( - new ModelProperty("http://apache.org/maven/project", null), - new ModelProperty("http://apache.org/maven/project/version", "1.1") - ); - - ModelMarshaller.unmarshalModelPropertiesToXml(modelProperties, "http://apache.org"); - } - */ - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithNullBaseUri() - throws IOException - { - List modelProperties = - Arrays.asList( new ModelProperty( "http://apache.org/maven/project", null ) ); - - ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, null ); - } - - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithEmptyBaseUri() - throws IOException - { - List modelProperties = - Arrays.asList( new ModelProperty( "http://apache.org/maven/project", null ) ); - - ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, "" ); - } - - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithEmptyModelProperties() - throws IOException - { - ModelMarshaller.unmarshalModelPropertiesToXml( new ArrayList(), - "http://apache.org/maven/project" ); - } - - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithNullModelProperties() - throws IOException - { - ModelMarshaller.unmarshalModelPropertiesToXml( null, "http://apache.org/maven/project" ); - } - - @Test(expected = IllegalArgumentException.class) - public void unmarshalWithIncorrectModelPropertyUri() - throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://bogus.org/maven", "1.1" ) ); - - ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, "http://apache.org/maven" ); - } -} diff --git a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java b/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java deleted file mode 100644 index 57248a7643..0000000000 --- a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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 static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class ModelPropertyTest -{ - - @Test - public void isParent() - { - ModelProperty mp0 = new ModelProperty( "http://apache.org/maven/project/profiles#collection/profile/id", "1" ); - ModelProperty mp1 = new ModelProperty( - "http://apache.org/maven/project/profiles#collection/profile/build/plugins/plugin/groupId", "org" ); - assertFalse( mp0.isParentOf( mp1 ) ); - assertTrue( mp0.getDepth() < mp1.getDepth() ); - } - - @Test - public void isParent1() - { - ModelProperty mp0 = new ModelProperty( "http://apache.org/maven/project/profiles#collection/profile/id", "1" ); - ModelProperty mp1 = - new ModelProperty( "http://apache.org/maven/project/profiles#collection/profile/id/a/b", "org" ); - assertFalse( mp0.isParentOf( mp1 ) ); - } -} diff --git a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelTransformerContextTest.java b/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelTransformerContextTest.java deleted file mode 100644 index bb3ab43593..0000000000 --- a/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelTransformerContextTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.apache.maven.shared.model; - -/* - * 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 static org.junit.Assert.*; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ModelTransformerContextTest -{ - - - @Test - public void sortWithDuplicateProperty1() - { - ModelProperty dup0 = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty dup1 = new ModelProperty( "http://apache.org/maven/project/build", null ); - ModelProperty dup2 = new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ); - ModelProperty dup3 = - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ); - ModelProperty dup4 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ); - ModelProperty dup5 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration", null ); - ModelProperty dup6 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration/tagBase", - "tag" ); - ModelProperty dup7 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "1.1" ); - - ModelProperty dup10 = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty dup11 = new ModelProperty( "http://apache.org/maven/project/build", null ); - ModelProperty dup12 = new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ); - ModelProperty dup13 = - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ); - ModelProperty dup14 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ); - ModelProperty dup15 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration", null ); - ModelProperty dup16 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration/tagBase", - "tag" ); - ModelProperty dup17 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "1.1" ); - - List modelProperties = Arrays.asList( dup0, dup1, dup2, dup3, dup4, dup5, dup6, dup7, dup10, - dup11, dup12, dup13, dup14, dup15, dup16, dup17 ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - for ( ModelProperty mp : sortedProperties ) - { - System.out.println( mp ); - } - // assertTrue(sortedProperties.contains(dup0)); - // assertFalse(sortedProperties.contains(dup1)); - } - - @Test - public void sortWithDuplicateProperty() - { - ModelProperty dup0 = new ModelProperty( "http://apache.org/maven/project/version", "1.1" ); - ModelProperty dup1 = new ModelProperty( "http://apache.org/maven/project/version", "1.2" ); - List modelProperties = Arrays.asList( dup0, dup1 ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - assertTrue( sortedProperties.contains( dup0 ) ); - assertFalse( sortedProperties.contains( dup1 ) ); - } - - @Test - public void sortWithDuplicateCollectionProperty() - { - ModelProperty dup0 = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.1" ); - ModelProperty dup1 = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.2" ); - List modelProperties = Arrays.asList( dup0, dup1 ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - assertTrue( sortedProperties.contains( dup0 ) ); - assertTrue( sortedProperties.contains( dup1 ) ); - } - - @Test - public void sortCollection() - { - ModelProperty a = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty b = new ModelProperty( "http://apache.org/maven/project/test#collection", null ); - ModelProperty c = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.1" ); - ModelProperty d = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.2" ); - List modelProperties = Arrays.asList( a, b, c, d ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - assertEquals( a, sortedProperties.get( 0 ) ); - assertEquals( b, sortedProperties.get( 1 ) ); - assertEquals( d, sortedProperties.get( 2 ) ); - assertEquals( c, sortedProperties.get( 3 ) ); - } - - @Test - public void sortCollectionWithDualBaseUris() - { - ModelProperty a = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty b = new ModelProperty( "http://apache.org/maven/project/test#collection", null ); - ModelProperty c = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.1" ); - ModelProperty d = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty e = new ModelProperty( "http://apache.org/maven/project/test#collection", null ); - ModelProperty f = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.2" ); - List modelProperties = Arrays.asList( a, b, c, d, e, f ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - assertEquals( a, sortedProperties.get( 0 ) ); - assertEquals( b, sortedProperties.get( 1 ) ); - assertEquals( f, sortedProperties.get( 2 ) ); - assertEquals( c, sortedProperties.get( 3 ) ); - } - - @Test - public void sortCollectionWithSubcollections() - { - ModelProperty a = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty b = new ModelProperty( "http://apache.org/maven/project/test#collection", null ); - ModelProperty c = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.1" ); - ModelProperty d = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection", null ); - ModelProperty e = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection/a", "a" ); - ModelProperty f = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection/b", "b" ); - - ModelProperty g = new ModelProperty( "http://apache.org/maven/project/test#collection/version", "1.2" ); - ModelProperty h = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection", null ); - ModelProperty i = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection/c", "c" ); - ModelProperty j = - new ModelProperty( "http://apache.org/maven/project/test#collection/version/test2#collection/d", "d" ); - List modelProperties = Arrays.asList( a, b, c, d, e, f, g, h, i, j ); - - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - List sortedProperties = ctx.sort( modelProperties, "http://apache.org/maven" ); - - assertEquals( a, sortedProperties.get( 0 ) ); - assertEquals( b, sortedProperties.get( 1 ) ); - - assertEquals( g, sortedProperties.get( 2 ) ); - assertEquals( h, sortedProperties.get( 3 ) ); - assertEquals( j, sortedProperties.get( 4 ) ); - assertEquals( i, sortedProperties.get( 5 ) ); - - assertEquals( c, sortedProperties.get( 6 ) ); - assertEquals( d, sortedProperties.get( 7 ) ); - assertEquals( f, sortedProperties.get( 8 ) ); - assertEquals( e, sortedProperties.get( 9 ) ); - } - - @Test(expected = IllegalArgumentException.class) - public void sortWithNullProperties() - { - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - ctx.sort( null, "http://apache.org/maven" ); - } - - @Test - public void sortWithEmptyProperties() - { - ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList() ); - assertEquals( 0, ctx.sort( new ArrayList(), "http://apache.org/maven" ).size() ); - } -} diff --git a/maven-shared-model/src/test/java/org/apache/maven/shared/model/impl/DefaultModelDataSourceTest.java b/maven-shared-model/src/test/java/org/apache/maven/shared/model/impl/DefaultModelDataSourceTest.java deleted file mode 100644 index 384533d373..0000000000 --- a/maven-shared-model/src/test/java/org/apache/maven/shared/model/impl/DefaultModelDataSourceTest.java +++ /dev/null @@ -1,499 +0,0 @@ -package org.apache.maven.shared.model.impl; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.shared.model.DataSourceException; -import org.apache.maven.shared.model.ModelContainer; -import org.apache.maven.shared.model.ModelContainerAction; -import org.apache.maven.shared.model.ModelContainerFactory; -import org.apache.maven.shared.model.ModelDataSource; -import org.apache.maven.shared.model.ModelProperty; -import static org.junit.Assert.*; -import org.junit.Test; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class DefaultModelDataSourceTest -{ - - private static List factories = new ArrayList(); - - static - { - factories.add( new DummyModelContainerFactory() ); - } - - @Test - public void mergeModelContainersSetWithAppendChild() { - ModelProperty dup0 = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty dup1 = new ModelProperty( "http://apache.org/maven/project/build", null ); - ModelProperty dup2 = - new ModelProperty( "http://apache.org/maven/project/build/plugins#collection", null ); - ModelProperty dup3 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin", null ); - ModelProperty dup4 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set", null ); - ModelProperty dup5 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList", null ); - ModelProperty dup6 = new ModelProperty( "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList#property/combine.children", "append" ); - ModelProperty dup6a = new ModelProperty( "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList#property/combine.children/a", "x" ); - ModelProperty dup7 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/version", "1.1" ); - ModelProperty dup8 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin", null ); - ModelProperty dup9 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set", null ); - ModelProperty dup10 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList", null ); - ModelProperty dup11 = new ModelProperty( "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList#property/combine.children", "append" ); - ModelProperty dup11a = new ModelProperty( "http://apache.org/maven/project/build/plugins#collection/plugin/configuration#set/myList#property/combine.children/b", "y" ); - ModelProperty dup12 = new ModelProperty( - "http://apache.org/maven/project/build/plugins#collection/plugin/version", "1.1" ); - - List modelProperties = Arrays.asList( dup0, dup1, dup2, dup3, dup4, dup5, dup6, dup6a, dup7, dup8, - dup9, dup10, dup11, dup11a, dup12 ); - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - DefaultModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List mps = datasource.mergeModelContainers( - factory.create( new ArrayList( modelProperties.subList( 3, 9 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 9, 14 ) ) ) ); - // for(ModelProperty mp : mps) { - // System.out.println(mp); - // } - assertTrue(mps.contains(dup6a)); - assertTrue(mps.contains(dup11a)); - } - - - @Test - public void mergeModelContainersSet() { - ModelProperty dup0 = new ModelProperty( "http://apache.org/maven/project", null ); - ModelProperty dup1 = new ModelProperty( "http://apache.org/maven/project/build", null ); - ModelProperty dup2 = new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ); - ModelProperty dup3 = - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ); - ModelProperty dup4 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ); - ModelProperty dup5 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration#set", null ); - ModelProperty dup6 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration#set/jdk", - "1.5" ); - ModelProperty dup7 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "1.1" ); - ModelProperty dup8 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ); - ModelProperty dup9 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration#set", null ); - ModelProperty dup10 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/configuration#set/jdk", - "1.4" ); - ModelProperty dup11 = new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "1.1" ); - - List modelProperties = Arrays.asList( dup0, dup1, dup2, dup3, dup4, dup5, dup6, dup7, dup8, - dup9, dup10, dup11 ); - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - DefaultModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List mps = datasource.mergeModelContainers( - factory.create( new ArrayList( modelProperties.subList( 4, 8 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 8, 11 ) ) ) ); - assertFalse(mps.contains(dup10)); - } - - @Test - public void mergeModelContainersCollectionsOfCollections() - throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://apache.org/maven/project/build", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "2.0.2" ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", "maven-compiler-plugin" ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", "org.apache.maven.plugins" ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency", null ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/groupId", - "gid1" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/artifactId", - "art1" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/version", - "2.0" ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", - "2.0.2" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", - "maven-compiler-plugin" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", - "org.apache.maven.plugins" ), - - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection", - null ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency", - null ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/groupId", - "gid1" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/artifactId", - "art1" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/dependencies#collection/dependency/version", - "1.0" ) ); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - DefaultModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List mps = datasource.mergeModelContainers( - factory.create( new ArrayList( modelProperties.subList( 4, 13 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 13, 21 ) ) ) ); - assertTrue( mps.containsAll( new ArrayList( modelProperties.subList( 4, 8 ) ) ) ); - } - - @Test - public void mergeModelContainers() - throws IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://apache.org/maven/project/build", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ), - - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", - null ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "2.0.2" ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", - "maven-compiler-plugin" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", - "org.apache.maven.plugins" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", - "2.0.2" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", - "maven-compiler-plugin" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", - "org.apache.maven.plugins" ) ); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - DefaultModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List mps = datasource.mergeModelContainers( - factory.create( new ArrayList( modelProperties.subList( 4, 8 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 8, 12 ) ) ) ); - assertTrue( mps.containsAll( new ArrayList( modelProperties.subList( 4, 8 ) ) ) ); - } - - @Test - public void join1() - throws DataSourceException, IOException - { - List modelProperties = Arrays.asList( - new ModelProperty( "http://apache.org/maven/project", null ), - new ModelProperty( "http://apache.org/maven/project/build", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection", null ), - new ModelProperty( "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", - null ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", "2.0.2" ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", - "maven-compiler-plugin" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", - "org.apache.maven.plugins" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin", null ), - new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/version", - "2.0.2" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/artifactId", - "maven-compiler-plugin" ), new ModelProperty( - "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/groupId", - "org.apache.maven.plugins" ), new ModelProperty( "http://apache.org/maven/project/version", - "2.0.10-SNAPSHOT" ), - new ModelProperty( "http://apache.org/maven/project/artifactId", "maven" ), - new ModelProperty( "http://apache.org/maven/project/groupId", - "org.apache.maven" ), new ModelProperty( - "http://apache.org/maven/project/modelVersion", "4.0.0" ) ); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - ModelContainer joinedModelContainer = datasource.join( - factory.create( new ArrayList( modelProperties.subList( 4, 8 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 8, 12 ) ) ) ); - - if ( !datasource.getModelProperties().containsAll( joinedModelContainer.getProperties() ) ) - { - throw new IOException(); - } - } - - - @Test - public void query() - throws DataSourceException - { - ModelProperty mpA = new ModelProperty( "container-marker/a", null ); - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "container-marker", null ) ); - modelProperties.add( mpA ); - - modelProperties.add( new ModelProperty( "container-marker", null ) ); - modelProperties.add( new ModelProperty( "container-marker/b", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List containers = datasource.queryFor( "container-marker" ); - assertEquals( "Number of containers: ", 2, containers.size() ); - assertEquals( "Properties for container 'a':", 2, containers.get( 0 ).getProperties().size() ); - assertEquals( mpA, containers.get( 0 ).getProperties().get( 1 ) ); - } - - @Test - public void queryWithOneContainerMarker() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "container-marker", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List containers = datasource.queryFor( "container-marker" ); - assertEquals( "Number of containers: ", 1, containers.size() ); - assertEquals( "Properties for container 'a':", 1, containers.get( 0 ).getProperties().size() ); - } - - @Test - public void queryWithMultipleContainerMarkers() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "container-marker", null ) ); - modelProperties.add( new ModelProperty( "container-marker", null ) ); - modelProperties.add( new ModelProperty( "acontainer-marker-1", null ) ); - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - List containers = datasource.queryFor( "container-marker" ); - assertEquals( "Number of containers: ", 2, containers.size() ); - assertEquals( "Properties for container 'a':", 1, containers.get( 0 ).getProperties().size() ); - } - - @Test(expected = DataSourceException.class) - public void queryWithUriNotInContainerFactory() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "a", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - datasource.queryFor( "bogus" ); - } - - @Test - public void joinEmptyContainer() - throws DataSourceException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "a", null ) ); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - ModelContainer modelContainerA = factory.create( new ArrayList( modelProperties ) ); - ModelContainer modelContainer = - datasource.join( modelContainerA, factory.create( new ArrayList() ) ); - assertEquals( modelContainer, modelContainerA ); - } - - /* - @Test(expected = DataSourceException.class) - public void joinContainerWithElementsNotInDataSource() throws DataSourceException { - ModelProperty mpA = new ModelProperty("a", null); - ModelProperty mpB = new ModelProperty("b", null); - ModelProperty mpC = new ModelProperty("c", null); - - List modelProperties = new ArrayList(); - modelProperties.add(mpA); - modelProperties.add(mpB); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init(modelProperties, factories); - modelProperties.add(mpC); - datasource.join( - factory.create(new ArrayList(modelProperties.subList(0, 3))), - factory.create(new ArrayList(modelProperties.subList(1, 2)))); - } - */ - - @Test - public void cannotModifyDataSourceFromInitializedList() - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "a", null ) ); - modelProperties.add( new ModelProperty( "b", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - modelProperties.remove( 0 ); - - assertEquals( 2, datasource.getModelProperties().size() ); - } - - @Test - public void cannotModifyDataSourceFromReturnedList() - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "a", null ) ); - modelProperties.add( new ModelProperty( "b", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - - datasource.getModelProperties().remove( 0 ); - - assertEquals( 2, datasource.getModelProperties().size() ); - } - - @Test - public void join() - throws DataSourceException - { - ModelProperty mpA = new ModelProperty( "maven/a", null ); - ModelProperty mpB = new ModelProperty( "maven/b", null ); - ModelProperty mpC = new ModelProperty( "maven/a", null ); - - List modelProperties = Arrays.asList( mpA, mpB, mpC ); - - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - ModelContainer joinedModelContainer = datasource.join( - factory.create( new ArrayList( modelProperties.subList( 0, 1 ) ) ), - factory.create( new ArrayList( modelProperties.subList( 1, 3 ) ) ) ); - - assertEquals( 2, joinedModelContainer.getProperties().size() ); - assertFalse( joinedModelContainer.getProperties().contains( mpC ) ); - } - - @Test - public void delete() - { - ModelProperty mpA = new ModelProperty( "a", null ); - ModelProperty mpB = new ModelProperty( "b", null ); - ModelProperty mpC = new ModelProperty( "a", null ); - - List modelProperties = Arrays.asList( mpA, mpB, mpC ); - DummyModelContainerFactory factory = new DummyModelContainerFactory(); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - datasource.delete( factory.create( new ArrayList( modelProperties.subList( 0, 1 ) ) ) ); - - assertEquals( 2, datasource.getModelProperties().size() ); - assertFalse( datasource.getModelProperties().contains( mpA ) ); - } - - @Test(expected = IllegalArgumentException.class) - public void deleteNullModelContainer() - throws IllegalArgumentException - { - List modelProperties = new ArrayList(); - modelProperties.add( new ModelProperty( "a", null ) ); - - ModelDataSource datasource = new DefaultModelDataSource(); - datasource.init( modelProperties, factories ); - datasource.delete( null ); - } - - private static class DummyModelContainerFactory - implements ModelContainerFactory - { - - public Collection getUris() - { - return Arrays.asList( "container-marker" ); - } - - public ModelContainer create( final List modelProperties ) - { - return new DummyModelContainer( modelProperties ); - } - - private static class DummyModelContainer - implements ModelContainer - { - - private List modelProperties; - - private DummyModelContainer( List modelProperties ) - { - this.modelProperties = new ArrayList( modelProperties ); - } - - public List getProperties() - { - return modelProperties; - } - - public ModelContainerAction containerAction( ModelContainer modelContainer ) - { - return ModelContainerAction.NOP; - } - - public ModelContainer createNewInstance( List modelProperties ) - { - return new DummyModelContainer( modelProperties ); - } - - } - } -} diff --git a/pom.xml b/pom.xml index 4ccd52d6f1..2c4400b6a3 100644 --- a/pom.xml +++ b/pom.xml @@ -275,7 +275,6 @@ under the License. maven-project-builder maven-mercury maven-embedder - maven-shared-model maven-toolchain maven-compat