mirror of https://github.com/apache/maven.git
Removed maven-shared model. It is now located in shared trunk.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@719516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d78042d0d2
commit
5d0a16c182
|
@ -1 +0,0 @@
|
|||
This module is not part of the shared build due to JDK 1.5 requirement.
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-shared-components</artifactId>
|
||||
<version>9</version>
|
||||
</parent>
|
||||
<artifactId>maven-shared-model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Maven Shared Model</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.woodstox</groupId>
|
||||
<artifactId>wstx-asl</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>stax</groupId>
|
||||
<artifactId>stax-api</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.5</source>
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<scm>
|
||||
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model</connection>
|
||||
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/shared/trunk/maven-shared-model</developerConnection>
|
||||
<url>http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-model</url>
|
||||
</scm>
|
||||
</project>
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
|
@ -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<ModelProperty> 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 );
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package org.apache.maven.shared.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface DomainModelFactory {
|
||||
|
||||
DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException;
|
||||
}
|
|
@ -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<ModelProperty> getModelProperties();
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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<InterpolatorProperty> toInterpolatorProperties( Map<String, String> properties, String tag )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "properties: null" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<String, String> 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<InterpolatorProperty> toInterpolatorProperties( Properties properties, String tag )
|
||||
{
|
||||
if( properties == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "properties: null" );
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
for ( Map.Entry<Object, Object> e : properties.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty( "${" + e.getKey() +"}", (String) e.getValue(), tag) );
|
||||
}
|
||||
return interpolatorProperties;
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <pre>
|
||||
* ModelContainerA.id = "foo" and
|
||||
* ModelContainerB.id = "foobar"
|
||||
* </pre>
|
||||
* 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<ModelProperty> 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<ModelProperty> modelProperties );
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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<String> 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<ModelProperty> modelProperties );
|
||||
}
|
|
@ -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<ModelProperty> getModelProperties();
|
||||
|
||||
/**
|
||||
* Returns model containers for the specified URI.
|
||||
*
|
||||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
List<ModelContainer> queryFor( String uri )
|
||||
throws DataSourceException;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the object with model properties.
|
||||
*
|
||||
* @param modelProperties the model properties that back the data source
|
||||
*/
|
||||
void init( List<ModelProperty> modelProperties, Collection<ModelContainerFactory> modelContainerFactories );
|
||||
|
||||
/**
|
||||
* Return history of all joins and deletes
|
||||
*
|
||||
* @return history of all joins and deletes
|
||||
*/
|
||||
String getEventHistory();
|
||||
}
|
|
@ -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<ModelContainer> modelContainers);
|
||||
|
||||
List<String> getUris();
|
||||
|
||||
Collection<ModelContainerFactory> getModelContainerFactories();
|
||||
}
|
|
@ -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<ModelProperty> marshallXmlToModelProperties( InputStream inputStream, String baseUri,
|
||||
Set<String> 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<String, String> attributes = new HashMap<String, String>();
|
||||
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<String, String> 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<String, String> 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<ModelProperty> 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<String> lastUriTags = new ArrayList<String>();
|
||||
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<String> 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<ModelProperty> attributes = new ArrayList<ModelProperty>();
|
||||
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<String> 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<ModelProperty> 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( "</" ).append( value ).append( ">" );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for storing information about URIs.
|
||||
*/
|
||||
private static class Uri
|
||||
{
|
||||
|
||||
List<String> uris;
|
||||
|
||||
Uri( String baseUri )
|
||||
{
|
||||
uris = new LinkedList<String>();
|
||||
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<String>( uris.subList( 0, depth ) );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String> 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<String>();
|
||||
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 ("<![CDATA[")
|
||||
&& (resolvedValue.contains( "=" ) || resolvedValue.contains( "<" ) || resolvedValue.contains( "&" )))
|
||||
{
|
||||
resolvedValue = "<![CDATA[" + resolvedValue + "]]>";
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> transform(List<ModelProperty> modelProperties);
|
||||
|
||||
String getBaseUri();
|
||||
}
|
|
@ -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<ModelProperty> preprocessModelProperties(List<ModelProperty> 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<ModelProperty> properties, List<ModelEventListener> 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<ModelProperty> transformToModelProperties(List<DomainModel> domainModels )
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param modelProperties
|
||||
* @param interpolatorProperties
|
||||
* @param domainModel
|
||||
* @throws IOException
|
||||
*/
|
||||
void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
DomainModel domainModel)
|
||||
throws IOException;
|
||||
}
|
|
@ -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<ModelContainerFactory> factories;
|
||||
|
||||
/**
|
||||
* List of system and environmental properties to use during interpolation
|
||||
*/
|
||||
private final static List<InterpolatorProperty> systemInterpolatorProperties =
|
||||
new ArrayList<InterpolatorProperty>();
|
||||
|
||||
private final static List<InterpolatorProperty> environmentInterpolatorProperties =
|
||||
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() )
|
||||
{
|
||||
environmentInterpolatorProperties.add( new InterpolatorProperty( "${env." + e.getKey() + "}", e.getValue() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param factories model container factories. Value may be null.
|
||||
*/
|
||||
public ModelTransformerContext( Collection<ModelContainerFactory> factories )
|
||||
{
|
||||
if ( factories == null )
|
||||
{
|
||||
this.factories = Collections.emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.factories = factories;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<InterpolatorProperty> createInterpolatorProperties(List<ModelProperty> modelProperties,
|
||||
String baseUriForModel,
|
||||
Map<String, String> aliases,
|
||||
String interpolatorTag,
|
||||
boolean includeSystemProperties,
|
||||
boolean includeEnvironmentProperties)
|
||||
{
|
||||
if(modelProperties == null)
|
||||
{
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if(baseUriForModel == null)
|
||||
{
|
||||
throw new IllegalArgumentException( "baseUriForModel: null");
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> interpolatorProperties
|
||||
= new ArrayList<InterpolatorProperty>( );
|
||||
|
||||
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<String, String> a : aliases.entrySet() )
|
||||
{
|
||||
interpolatorProperties.add( new InterpolatorProperty(
|
||||
ip.getKey().replaceAll( a.getKey(), a.getValue()),
|
||||
ip.getValue().replaceAll( a.getKey(), a.getValue()),
|
||||
interpolatorTag) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>();
|
||||
for(InterpolatorProperty ip : interpolatorProperties) {
|
||||
if(!ips.contains(ip)) {
|
||||
ips.add(ip);
|
||||
}
|
||||
}
|
||||
return ips;
|
||||
}
|
||||
|
||||
public static void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
if( modelProperties == null )
|
||||
{
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
|
||||
if( interpolatorProperties == null )
|
||||
{
|
||||
throw new IllegalArgumentException("interpolatorProperties: null");
|
||||
}
|
||||
|
||||
List<ModelProperty> unresolvedProperties = new ArrayList<ModelProperty>();
|
||||
for ( ModelProperty mp : modelProperties )
|
||||
{
|
||||
if ( !mp.isResolved() )
|
||||
{
|
||||
unresolvedProperties.add( mp );
|
||||
}
|
||||
}
|
||||
|
||||
LinkedHashSet<InterpolatorProperty> ips = new LinkedHashSet<InterpolatorProperty>();
|
||||
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<ModelProperty> transformModelProperties(List<ModelProperty> modelProperties,
|
||||
List<ModelPropertyTransformer> modelPropertyTransformers)
|
||||
{
|
||||
if(modelProperties == null) {
|
||||
throw new IllegalArgumentException("modelProperties: null");
|
||||
}
|
||||
if(modelPropertyTransformers == null) {
|
||||
throw new IllegalArgumentException("modelPropertyTransformers: null");
|
||||
}
|
||||
|
||||
List<ModelProperty> properties = new ArrayList<ModelProperty>(modelProperties);
|
||||
List<ModelPropertyTransformer> transformers = new ArrayList<ModelPropertyTransformer>(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<DomainModel> domainModels,
|
||||
ModelTransformer fromModelTransformer,
|
||||
ModelTransformer toModelTransformer,
|
||||
Collection<ImportModel> importModels,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
List<ModelEventListener> eventListeners)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
if( eventListeners == null )
|
||||
{
|
||||
eventListeners = new ArrayList<ModelEventListener>();
|
||||
}
|
||||
else
|
||||
{
|
||||
eventListeners = new ArrayList<ModelEventListener>(eventListeners);
|
||||
}
|
||||
|
||||
if(interpolatorProperties == null)
|
||||
{
|
||||
interpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
}
|
||||
|
||||
|
||||
List<ModelProperty> transformedProperties =
|
||||
importModelProperties(importModels, fromModelTransformer.transformToModelProperties( domainModels));
|
||||
transformedProperties = fromModelTransformer.preprocessModelProperties(transformedProperties);
|
||||
|
||||
String baseUriForModel = fromModelTransformer.getBaseUri();
|
||||
List<ModelProperty> 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<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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<ModelProperty> 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<DomainModel> domainModels, ModelTransformer fromModelTransformer,
|
||||
ModelTransformer toModelTransformer )
|
||||
throws IOException
|
||||
{
|
||||
return this.transform( domainModels, fromModelTransformer, toModelTransformer, null, systemInterpolatorProperties, null );
|
||||
}
|
||||
|
||||
private static List<ModelProperty> importModelProperties(Collection<ImportModel> importModels,
|
||||
List<ModelProperty> modelProperties) {
|
||||
List<ModelProperty> properties = new ArrayList<ModelProperty>();
|
||||
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.
|
||||
* <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
|
||||
*/
|
||||
public static 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( "/" ) );
|
||||
|
||||
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<ModelProperty> determineLeafNodes(List<ModelProperty> modelProperties)
|
||||
{
|
||||
List<ModelProperty> mps = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty> 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;
|
||||
}
|
||||
}
|
|
@ -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<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 ) );
|
||||
if(startIndex == -1)
|
||||
{
|
||||
startIndex = modelProperties.indexOf( a.getProperties().get( 0 ) );
|
||||
if(startIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
delete( a );
|
||||
delete( b );
|
||||
|
||||
List<ModelProperty> joinedProperties = mergeModelContainers( a, b );
|
||||
if ( modelProperties.size() == 0 )
|
||||
{
|
||||
startIndex = 0;
|
||||
}
|
||||
joinedProperties = sort(joinedProperties, findBaseUriFrom(joinedProperties));
|
||||
|
||||
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.emptyList();
|
||||
}
|
||||
|
||||
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() && mp.getUri().startsWith(uri))
|
||||
{
|
||||
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.getResolvedValue().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.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<String> 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<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();
|
||||
}
|
||||
}
|
||||
|
||||
protected static 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( "/" ) );
|
||||
|
||||
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<ModelProperty> modelProperties)
|
||||
{
|
||||
String baseUri = null;
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(baseUri == null || mp.getUri().length() < baseUri.length())
|
||||
{
|
||||
baseUri = mp.getUri();
|
||||
}
|
||||
}
|
||||
return baseUri;
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> 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<ModelProperty> 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;
|
||||
}
|
||||
}
|
|
@ -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<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 ).getResolvedValue() );
|
||||
}
|
||||
|
||||
/*
|
||||
@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" );
|
||||
}
|
||||
}
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> 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<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties = Arrays.asList( dup0, dup1 );
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties = Arrays.asList( dup0, dup1 );
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties = Arrays.asList( a, b, c, d );
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties = Arrays.asList( a, b, c, d, e, f );
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties = Arrays.asList( a, b, c, d, e, f, g, h, i, j );
|
||||
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
List<ModelProperty> 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<ModelContainerFactory>() );
|
||||
ctx.sort( null, "http://apache.org/maven" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortWithEmptyProperties()
|
||||
{
|
||||
ModelTransformerContext ctx = new ModelTransformerContext( new ArrayList<ModelContainerFactory>() );
|
||||
assertEquals( 0, ctx.sort( new ArrayList<ModelProperty>(), "http://apache.org/maven" ).size() );
|
||||
}
|
||||
}
|
|
@ -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<ModelContainerFactory> factories = new ArrayList<ModelContainerFactory>();
|
||||
|
||||
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<ModelProperty> 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<ModelProperty> mps = datasource.mergeModelContainers(
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 3, 9 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( 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<ModelProperty> 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<ModelProperty> mps = datasource.mergeModelContainers(
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 4, 8 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 8, 11 ) ) ) );
|
||||
assertFalse(mps.contains(dup10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeModelContainersCollectionsOfCollections()
|
||||
throws IOException
|
||||
{
|
||||
List<ModelProperty> 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<ModelProperty> mps = datasource.mergeModelContainers(
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 4, 13 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 13, 21 ) ) ) );
|
||||
assertTrue( mps.containsAll( new ArrayList<ModelProperty>( modelProperties.subList( 4, 8 ) ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeModelContainers()
|
||||
throws IOException
|
||||
{
|
||||
List<ModelProperty> 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<ModelProperty> mps = datasource.mergeModelContainers(
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 4, 8 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 8, 12 ) ) ) );
|
||||
assertTrue( mps.containsAll( new ArrayList<ModelProperty>( modelProperties.subList( 4, 8 ) ) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void join1()
|
||||
throws DataSourceException, IOException
|
||||
{
|
||||
List<ModelProperty> 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<ModelProperty>( modelProperties.subList( 4, 8 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelContainer> 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( "container-marker", null ) );
|
||||
|
||||
ModelDataSource datasource = new DefaultModelDataSource();
|
||||
datasource.init( modelProperties, factories );
|
||||
|
||||
List<ModelContainer> 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelContainer> 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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( "a", null ) );
|
||||
|
||||
ModelDataSource datasource = new DefaultModelDataSource();
|
||||
datasource.init( modelProperties, factories );
|
||||
|
||||
datasource.queryFor( "bogus" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinEmptyContainer()
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
modelProperties.add( new ModelProperty( "a", null ) );
|
||||
|
||||
DummyModelContainerFactory factory = new DummyModelContainerFactory();
|
||||
|
||||
ModelDataSource datasource = new DefaultModelDataSource();
|
||||
datasource.init( modelProperties, factories );
|
||||
|
||||
ModelContainer modelContainerA = factory.create( new ArrayList<ModelProperty>( modelProperties ) );
|
||||
ModelContainer modelContainer =
|
||||
datasource.join( modelContainerA, factory.create( new ArrayList<ModelProperty>() ) );
|
||||
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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty>(modelProperties.subList(0, 3))),
|
||||
factory.create(new ArrayList<ModelProperty>(modelProperties.subList(1, 2))));
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void cannotModifyDataSourceFromInitializedList()
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty> 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<ModelProperty>( modelProperties.subList( 0, 1 ) ) ),
|
||||
factory.create( new ArrayList<ModelProperty>( 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<ModelProperty> modelProperties = Arrays.asList( mpA, mpB, mpC );
|
||||
DummyModelContainerFactory factory = new DummyModelContainerFactory();
|
||||
|
||||
ModelDataSource datasource = new DefaultModelDataSource();
|
||||
datasource.init( modelProperties, factories );
|
||||
datasource.delete( factory.create( new ArrayList<ModelProperty>( modelProperties.subList( 0, 1 ) ) ) );
|
||||
|
||||
assertEquals( 2, datasource.getModelProperties().size() );
|
||||
assertFalse( datasource.getModelProperties().contains( mpA ) );
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void deleteNullModelContainer()
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<String> getUris()
|
||||
{
|
||||
return Arrays.asList( "container-marker" );
|
||||
}
|
||||
|
||||
public ModelContainer create( final List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new DummyModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
private static class DummyModelContainer
|
||||
implements ModelContainer
|
||||
{
|
||||
|
||||
private List<ModelProperty> modelProperties;
|
||||
|
||||
private DummyModelContainer( List<ModelProperty> modelProperties )
|
||||
{
|
||||
this.modelProperties = new ArrayList<ModelProperty>( modelProperties );
|
||||
}
|
||||
|
||||
public List<ModelProperty> getProperties()
|
||||
{
|
||||
return modelProperties;
|
||||
}
|
||||
|
||||
public ModelContainerAction containerAction( ModelContainer modelContainer )
|
||||
{
|
||||
return ModelContainerAction.NOP;
|
||||
}
|
||||
|
||||
public ModelContainer createNewInstance( List<ModelProperty> modelProperties )
|
||||
{
|
||||
return new DummyModelContainer( modelProperties );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue