You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/07/25 10:28:23 UTC
svn commit: r679701 [2/3] - in /maven/shared/trunk/maven-shared-model: ./
src/main/java/org/apache/maven/shared/model/
src/main/java/org/apache/maven/shared/model/impl/
src/test/java/org/apache/maven/shared/model/
src/test/java/org/apache/maven/shared/...
Modified: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java?rev=679701&r1=679700&r2=679701&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java (original)
+++ maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java Fri Jul 25 01:28:22 2008
@@ -1,55 +1,55 @@
-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
-{
-
- 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<ModelProperty> properties )
- 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<ModelProperty> transformToModelProperties( List<DomainModel> domainModels )
- throws IOException;
-
-}
+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
+{
+
+ 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<ModelProperty> properties )
+ 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<ModelProperty> transformToModelProperties( List<DomainModel> domainModels )
+ throws IOException;
+
+}
Propchange: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java?rev=679701&r1=679700&r2=679701&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java (original)
+++ maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java Fri Jul 25 01:28:22 2008
@@ -1,256 +1,256 @@
-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.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * 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<ModelContainerFactory> factories;
-
- /**
- * List of system and environmental properties to use during interpolation
- */
- private final static List<InterpolatorProperty> systemInterpolatorProperties =
- new ArrayList<InterpolatorProperty>();
-
- static
- {
- for ( Map.Entry<Object, Object> e : System.getProperties().entrySet() )
- {
- systemInterpolatorProperties.add(
- new InterpolatorProperty( "${" + e.getKey() + "}", (String) e.getValue() ) );
- }
-
- for ( Map.Entry<String, String> e : System.getenv().entrySet() )
- {
- systemInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) );
- }
- }
-
- /**
- * Default constructor
- *
- * @param factories model container factories. Value may be null.
- */
- public ModelTransformerContext( Collection<ModelContainerFactory> factories )
- {
- this.factories = ( factories == null ) ? Collections.EMPTY_LIST : factories;
- }
-
- /**
- * 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 interpolatorProperties properties to use during interpolation.
- * @return processed domain model
- * @throws IOException if there was a problem with the transform
- */
- public DomainModel transform( List<DomainModel> domainModels, ModelTransformer fromModelTransformer,
- ModelTransformer toModelTransformer,
- Collection<InterpolatorProperty> interpolatorProperties )
- throws IOException
- {
- List<InterpolatorProperty> properties = new ArrayList<InterpolatorProperty>( interpolatorProperties );
-
- String baseUriForModel = fromModelTransformer.getBaseUri();
- List<ModelProperty> modelProperties =
- sort( fromModelTransformer.transformToModelProperties( domainModels ), baseUriForModel );
- ModelDataSource modelDataSource = new DefaultModelDataSource();
- modelDataSource.init( modelProperties, factories );
-
- for ( ModelContainerFactory factory : factories )
- {
- for ( String uri : factory.getUris() )
- {
- List<ModelContainer> modelContainers;
- try
- {
- modelContainers = modelDataSource.queryFor( uri );
- }
- catch ( IllegalArgumentException e )
- {
- System.out.println( modelDataSource.getEventHistory() );
- throw new IllegalArgumentException( e );
- }
- List<ModelContainer> removedModelContainers = new ArrayList<ModelContainer>();
- 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() );
- }
- }
- }
- }
- }
- }
-
- //interpolator
- List<ModelProperty> mps = modelDataSource.getModelProperties();
-
- for ( ModelProperty mp : mps )
- {
- InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel );
- if ( ip != null )
- {
- properties.add( ip );
- }
- }
-
- List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
- for ( ModelProperty mp : mps )
- {
- if ( !mp.isResolved() )
- {
- unresolvedProperties.add( mp );
- }
- }
-
- /*
- for ( InterpolatorProperty ip : properties )
- {
- for ( ModelProperty mp : unresolvedProperties )
- {
- mp.resolveWith(ip);
- System.out.println(mp);
- System.out.println("-------------------");
- }
- }
- */
- mps = sort( mps, baseUriForModel );
-
- try
- {
- DomainModel domainModel = toModelTransformer.transformToDomainModel( mps );
- //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<DomainModel> domainModels, ModelTransformer fromModelTransformer,
- ModelTransformer toModelTransformer )
- throws IOException
- {
- return this.transform( domainModels, fromModelTransformer, toModelTransformer, systemInterpolatorProperties );
- }
-
- /**
- * 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.
- * <p/>
- * 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
- */
- protected List<ModelProperty> sort( List<ModelProperty> properties, String baseUri )
- {
- if ( properties == null )
- {
- throw new IllegalArgumentException( "properties" );
- }
- LinkedList<ModelProperty> processedProperties = new LinkedList<ModelProperty>();
- List<String> position = new ArrayList<String>();
- boolean projectIsContained = false;
-
- for ( ModelProperty p : properties )
- {
- String uri = p.getUri();
- String parentUri = uri.substring( 0, uri.lastIndexOf( "/" ) ).replaceAll( "#property", "" );
- if ( !projectIsContained && uri.equals( baseUri ) )
- {
- projectIsContained = true;
- processedProperties.add( p );
- position.add( 0, uri );
- }
- else if ( !position.contains( uri ) || parentUri.contains( "#collection" ) )
- {
- int pst = position.indexOf( parentUri ) + 1;
- processedProperties.add( pst, p );
- position.add( pst, uri );
- }
- }
- return processedProperties;
- }
-}
+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.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 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<ModelContainerFactory> factories;
+
+ /**
+ * List of system and environmental properties to use during interpolation
+ */
+ private final static List<InterpolatorProperty> systemInterpolatorProperties =
+ new ArrayList<InterpolatorProperty>();
+
+ static
+ {
+ for ( Map.Entry<Object, Object> e : System.getProperties().entrySet() )
+ {
+ systemInterpolatorProperties.add(
+ new InterpolatorProperty( "${" + e.getKey() + "}", (String) e.getValue() ) );
+ }
+
+ for ( Map.Entry<String, String> e : System.getenv().entrySet() )
+ {
+ systemInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) );
+ }
+ }
+
+ /**
+ * Default constructor
+ *
+ * @param factories model container factories. Value may be null.
+ */
+ public ModelTransformerContext( Collection<ModelContainerFactory> factories )
+ {
+ this.factories = ( factories == null ) ? Collections.EMPTY_LIST : factories;
+ }
+
+ /**
+ * 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 interpolatorProperties properties to use during interpolation.
+ * @return processed domain model
+ * @throws IOException if there was a problem with the transform
+ */
+ public DomainModel transform( List<DomainModel> domainModels, ModelTransformer fromModelTransformer,
+ ModelTransformer toModelTransformer,
+ Collection<InterpolatorProperty> interpolatorProperties )
+ throws IOException
+ {
+ List<InterpolatorProperty> properties = new ArrayList<InterpolatorProperty>( interpolatorProperties );
+
+ String baseUriForModel = fromModelTransformer.getBaseUri();
+ List<ModelProperty> modelProperties =
+ sort( fromModelTransformer.transformToModelProperties( domainModels ), baseUriForModel );
+ ModelDataSource modelDataSource = new DefaultModelDataSource();
+ modelDataSource.init( modelProperties, factories );
+
+ for ( ModelContainerFactory factory : factories )
+ {
+ for ( String uri : factory.getUris() )
+ {
+ List<ModelContainer> modelContainers;
+ try
+ {
+ modelContainers = modelDataSource.queryFor( uri );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ System.out.println( modelDataSource.getEventHistory() );
+ throw new IllegalArgumentException( e );
+ }
+ List<ModelContainer> removedModelContainers = new ArrayList<ModelContainer>();
+ 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() );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //interpolator
+ List<ModelProperty> mps = modelDataSource.getModelProperties();
+
+ for ( ModelProperty mp : mps )
+ {
+ InterpolatorProperty ip = mp.asInterpolatorProperty( baseUriForModel );
+ if ( ip != null )
+ {
+ properties.add( ip );
+ }
+ }
+
+ List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
+ for ( ModelProperty mp : mps )
+ {
+ if ( !mp.isResolved() )
+ {
+ unresolvedProperties.add( mp );
+ }
+ }
+
+ /*
+ for ( InterpolatorProperty ip : properties )
+ {
+ for ( ModelProperty mp : unresolvedProperties )
+ {
+ mp.resolveWith(ip);
+ System.out.println(mp);
+ System.out.println("-------------------");
+ }
+ }
+ */
+ mps = sort( mps, baseUriForModel );
+
+ try
+ {
+ DomainModel domainModel = toModelTransformer.transformToDomainModel( mps );
+ //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<DomainModel> domainModels, ModelTransformer fromModelTransformer,
+ ModelTransformer toModelTransformer )
+ throws IOException
+ {
+ return this.transform( domainModels, fromModelTransformer, toModelTransformer, systemInterpolatorProperties );
+ }
+
+ /**
+ * 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.
+ * <p/>
+ * 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
+ */
+ protected List<ModelProperty> sort( List<ModelProperty> properties, String baseUri )
+ {
+ if ( properties == null )
+ {
+ throw new IllegalArgumentException( "properties" );
+ }
+ LinkedList<ModelProperty> processedProperties = new LinkedList<ModelProperty>();
+ List<String> position = new ArrayList<String>();
+ boolean projectIsContained = false;
+
+ for ( ModelProperty p : properties )
+ {
+ String uri = p.getUri();
+ String parentUri = uri.substring( 0, uri.lastIndexOf( "/" ) ).replaceAll( "#property", "" );
+ if ( !projectIsContained && uri.equals( baseUri ) )
+ {
+ projectIsContained = true;
+ processedProperties.add( p );
+ position.add( 0, uri );
+ }
+ else if ( !position.contains( uri ) || parentUri.contains( "#collection" ) )
+ {
+ int pst = position.indexOf( parentUri ) + 1;
+ processedProperties.add( pst, p );
+ position.add( pst, uri );
+ }
+ }
+ return processedProperties;
+ }
+}
Propchange: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/ModelTransformerContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java?rev=679701&r1=679700&r2=679701&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java (original)
+++ maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java Fri Jul 25 01:28:22 2008
@@ -1,522 +1,522 @@
-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<ModelProperty> modelProperties;
-
- /**
- * Copy of the model properties used during initialization of the data source
- */
- private List<ModelProperty> originalModelProperties;
-
- /**
- * History of joins and deletes
- */
- private List<DataEvent> dataEvents;
-
- /**
- * Map of model container factories used in creation of model containers
- */
- private Map<String, ModelContainerFactory> 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<ModelProperty> unknownProperties = new ArrayList<ModelProperty>();
- for ( ModelProperty mp : a.getProperties() )
- {
- if ( !modelProperties.contains( mp ) )
- {
- unknownProperties.add( mp );
- }
- }
-
- List<DataEvent> des = new ArrayList<DataEvent>();
- 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 ) );
- delete( a );
- delete( b );
-
- List<ModelProperty> joinedProperties = mergeModelContainers( a, b );
-
- if ( modelProperties.size() == 0 )
- {
- startIndex = 0;
- }
- modelProperties.addAll( startIndex, joinedProperties );
-
- List<ModelProperty> deletedProperties = new ArrayList<ModelProperty>();
- 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<ModelProperty> getModelProperties()
- {
- return new ArrayList<ModelProperty>( modelProperties );
- }
-
- /**
- * @see ModelDataSource#queryFor(String)
- */
- public List<ModelContainer> queryFor( String uri )
- throws DataSourceException
- {
- if ( uri == null )
- {
- throw new IllegalArgumentException( "uri" );
- }
-
- if ( modelProperties.isEmpty() )
- {
- return Collections.EMPTY_LIST;
- }
-
- ModelContainerFactory factory = modelContainerFactoryMap.get( uri );
- if ( factory == null )
- {
- throw new DataSourceException( "Unable to find factory for uri: URI = " + uri );
- }
-
- List<ModelContainer> modelContainers = new LinkedList<ModelContainer>();
-
- 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<ModelProperty> tmp = new ArrayList<ModelProperty>();
-
- for ( Iterator<ModelProperty> 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() )
- {
- tmp.add( mp );
- }
- modelContainers.add( factory.create( tmp ) );
- tmp.clear();
- state = NO_TAG;
- }
- }
- }
-
- //verify data source integrity
- List<ModelProperty> 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<ModelProperty> modelProperties, Collection<ModelContainerFactory> modelContainerFactories )
- {
- if ( modelProperties == null )
- {
- throw new IllegalArgumentException( "modelProperties: null" );
- }
- if ( modelContainerFactories == null )
- {
- throw new IllegalArgumentException( "modeContainerFactories: null" );
- }
- this.modelProperties = new LinkedList<ModelProperty>( modelProperties );
- this.modelContainerFactoryMap = new HashMap<String, ModelContainerFactory>();
- this.dataEvents = new ArrayList<DataEvent>();
- this.originalModelProperties = new ArrayList<ModelProperty>( modelProperties );
-
- for ( ModelContainerFactory factory : modelContainerFactories )
- {
- Collection<String> 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<ModelProperty> mergeModelContainers( ModelContainer a, ModelContainer b )
- {
- List<ModelProperty> m = new ArrayList<ModelProperty>();
- m.addAll( a.getProperties() );
- m.addAll( b.getProperties() );
-
- List<String> combineChildrenUris = new ArrayList<String>();
- for ( ModelProperty mp : m )
- {
- String x = mp.getUri();
- if ( x.endsWith( "#property/combine.children" ) && mp.getValue().equals( "append" ) )
- {
- combineChildrenUris.add( x.substring( 0, x.length() - 26 ) );
- }
- }
-
- LinkedList<ModelProperty> processedProperties = new LinkedList<ModelProperty>();
- List<String> uris = new ArrayList<String>();
- 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.endsWith( "#collection" ) ) &&
- ( !combineChildrenUris.contains( p.getUri() ) || p.getUri().endsWith( "#property/combine.children" ) ) )
- {
- processedProperties.add( findLastIndexOfParent( p, processedProperties ) + 1, p );
- uris.add( p.getUri() );
- }
- }
- return processedProperties;
- }
-
- /**
- * 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<ModelProperty> findUnknownModelPropertiesFrom( List<ModelContainer> modelContainers )
- {
- List<ModelProperty> unknownProperties = new ArrayList<ModelProperty>();
- 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<ModelProperty> 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<ModelProperty> a, List<ModelProperty> b )
- {
- for ( ModelProperty mp : b )
- {
- if ( a.contains( mp ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Join or delete event
- */
- private static class DataEvent
- {
-
- private List<ModelProperty> removedModelProperties;
-
- private ModelContainer mcA;
-
- private ModelContainer mcB;
-
- private String methodName;
-
- DataEvent( ModelContainer mcA, ModelContainer mcB, List<ModelProperty> 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<ModelProperty> 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();
- }
- }
-}
+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<ModelProperty> modelProperties;
+
+ /**
+ * Copy of the model properties used during initialization of the data source
+ */
+ private List<ModelProperty> originalModelProperties;
+
+ /**
+ * History of joins and deletes
+ */
+ private List<DataEvent> dataEvents;
+
+ /**
+ * Map of model container factories used in creation of model containers
+ */
+ private Map<String, ModelContainerFactory> 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<ModelProperty> unknownProperties = new ArrayList<ModelProperty>();
+ for ( ModelProperty mp : a.getProperties() )
+ {
+ if ( !modelProperties.contains( mp ) )
+ {
+ unknownProperties.add( mp );
+ }
+ }
+
+ List<DataEvent> des = new ArrayList<DataEvent>();
+ 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 ) );
+ delete( a );
+ delete( b );
+
+ List<ModelProperty> joinedProperties = mergeModelContainers( a, b );
+
+ if ( modelProperties.size() == 0 )
+ {
+ startIndex = 0;
+ }
+ modelProperties.addAll( startIndex, joinedProperties );
+
+ List<ModelProperty> deletedProperties = new ArrayList<ModelProperty>();
+ 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<ModelProperty> getModelProperties()
+ {
+ return new ArrayList<ModelProperty>( modelProperties );
+ }
+
+ /**
+ * @see ModelDataSource#queryFor(String)
+ */
+ public List<ModelContainer> queryFor( String uri )
+ throws DataSourceException
+ {
+ if ( uri == null )
+ {
+ throw new IllegalArgumentException( "uri" );
+ }
+
+ if ( modelProperties.isEmpty() )
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ ModelContainerFactory factory = modelContainerFactoryMap.get( uri );
+ if ( factory == null )
+ {
+ throw new DataSourceException( "Unable to find factory for uri: URI = " + uri );
+ }
+
+ List<ModelContainer> modelContainers = new LinkedList<ModelContainer>();
+
+ 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<ModelProperty> tmp = new ArrayList<ModelProperty>();
+
+ for ( Iterator<ModelProperty> 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() )
+ {
+ tmp.add( mp );
+ }
+ modelContainers.add( factory.create( tmp ) );
+ tmp.clear();
+ state = NO_TAG;
+ }
+ }
+ }
+
+ //verify data source integrity
+ List<ModelProperty> 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<ModelProperty> modelProperties, Collection<ModelContainerFactory> modelContainerFactories )
+ {
+ if ( modelProperties == null )
+ {
+ throw new IllegalArgumentException( "modelProperties: null" );
+ }
+ if ( modelContainerFactories == null )
+ {
+ throw new IllegalArgumentException( "modeContainerFactories: null" );
+ }
+ this.modelProperties = new LinkedList<ModelProperty>( modelProperties );
+ this.modelContainerFactoryMap = new HashMap<String, ModelContainerFactory>();
+ this.dataEvents = new ArrayList<DataEvent>();
+ this.originalModelProperties = new ArrayList<ModelProperty>( modelProperties );
+
+ for ( ModelContainerFactory factory : modelContainerFactories )
+ {
+ Collection<String> 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<ModelProperty> mergeModelContainers( ModelContainer a, ModelContainer b )
+ {
+ List<ModelProperty> m = new ArrayList<ModelProperty>();
+ m.addAll( a.getProperties() );
+ m.addAll( b.getProperties() );
+
+ List<String> combineChildrenUris = new ArrayList<String>();
+ for ( ModelProperty mp : m )
+ {
+ String x = mp.getUri();
+ if ( x.endsWith( "#property/combine.children" ) && mp.getValue().equals( "append" ) )
+ {
+ combineChildrenUris.add( x.substring( 0, x.length() - 26 ) );
+ }
+ }
+
+ LinkedList<ModelProperty> processedProperties = new LinkedList<ModelProperty>();
+ List<String> uris = new ArrayList<String>();
+ 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.endsWith( "#collection" ) ) &&
+ ( !combineChildrenUris.contains( p.getUri() ) || p.getUri().endsWith( "#property/combine.children" ) ) )
+ {
+ processedProperties.add( findLastIndexOfParent( p, processedProperties ) + 1, p );
+ uris.add( p.getUri() );
+ }
+ }
+ return processedProperties;
+ }
+
+ /**
+ * 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<ModelProperty> findUnknownModelPropertiesFrom( List<ModelContainer> modelContainers )
+ {
+ List<ModelProperty> unknownProperties = new ArrayList<ModelProperty>();
+ 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<ModelProperty> 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<ModelProperty> a, List<ModelProperty> b )
+ {
+ for ( ModelProperty mp : b )
+ {
+ if ( a.contains( mp ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Join or delete event
+ */
+ private static class DataEvent
+ {
+
+ private List<ModelProperty> removedModelProperties;
+
+ private ModelContainer mcA;
+
+ private ModelContainer mcB;
+
+ private String methodName;
+
+ DataEvent( ModelContainer mcA, ModelContainer mcB, List<ModelProperty> 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<ModelProperty> 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();
+ }
+ }
+}
Propchange: maven/shared/trunk/maven-shared-model/src/main/java/org/apache/maven/shared/model/impl/DefaultModelDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java?rev=679701&r1=679700&r2=679701&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java (original)
+++ maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java Fri Jul 25 01:28:22 2008
@@ -1,157 +1,157 @@
-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 aaa() throws IOException {
- List<ModelProperty> properties =
- ModelMarshaller.marshallXmlToModelProperties(
- new FileInputStream("/home/shane/checkout/SI_MAVEN_2_1_A/maven-core-it-runner/target/it-working-folder/it0060/subproject/pom.xml"),
- "http://apache.org/maven", null);
- for(ModelProperty mp : properties) {
- // System.out.println(mp);
- }
- ModelTransformerContext ctx = new ModelTransformerContext(new ArrayList());
-
-
- for(ModelProperty mp : properties) {
- System.out.println(mp);
- }
- System.out.println(ModelMarshaller.unmarshalModelPropertiesToXml(properties, "http://apache.org/maven"));
- }
- */
- @Test
- public void unmarshalWithEmptyCollectionTags()
- throws IOException
- {
- List<ModelProperty> 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<ModelProperty> 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<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream(
- "<project><S></S><version>1.2</version><developers><developer><organization></organization></developer></developers><modelVersion>4</modelVersion></project>".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<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties(
- new ByteArrayInputStream( "<project><version>1.1</version></project>".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 ).getValue() );
- }
-
- /*
- @Test(expected = IllegalArgumentException.class)
- public void unmarshalWithBadBaseUri() throws IOException, XmlPullParserException {
- List<ModelProperty> 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<ModelProperty> 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<ModelProperty> 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<ModelProperty>(),
- "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<ModelProperty> 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" );
- }
-}
+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 aaa() throws IOException {
+ List<ModelProperty> properties =
+ ModelMarshaller.marshallXmlToModelProperties(
+ new FileInputStream("/home/shane/checkout/SI_MAVEN_2_1_A/maven-core-it-runner/target/it-working-folder/it0060/subproject/pom.xml"),
+ "http://apache.org/maven", null);
+ for(ModelProperty mp : properties) {
+ // System.out.println(mp);
+ }
+ ModelTransformerContext ctx = new ModelTransformerContext(new ArrayList());
+
+
+ for(ModelProperty mp : properties) {
+ System.out.println(mp);
+ }
+ System.out.println(ModelMarshaller.unmarshalModelPropertiesToXml(properties, "http://apache.org/maven"));
+ }
+ */
+ @Test
+ public void unmarshalWithEmptyCollectionTags()
+ throws IOException
+ {
+ List<ModelProperty> 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<ModelProperty> 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<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream(
+ "<project><S></S><version>1.2</version><developers><developer><organization></organization></developer></developers><modelVersion>4</modelVersion></project>".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<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties(
+ new ByteArrayInputStream( "<project><version>1.1</version></project>".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 ).getValue() );
+ }
+
+ /*
+ @Test(expected = IllegalArgumentException.class)
+ public void unmarshalWithBadBaseUri() throws IOException, XmlPullParserException {
+ List<ModelProperty> 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<ModelProperty> 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<ModelProperty> 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<ModelProperty>(),
+ "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<ModelProperty> 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" );
+ }
+}
Propchange: maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelMarshallerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java?rev=679701&r1=679700&r2=679701&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java (original)
+++ maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java Fri Jul 25 01:28:22 2008
@@ -1,47 +1,47 @@
-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 ) );
- }
-}
+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 ) );
+ }
+}
Propchange: maven/shared/trunk/maven-shared-model/src/test/java/org/apache/maven/shared/model/ModelPropertyTest.java
------------------------------------------------------------------------------
svn:eol-style = native