Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

For new models, the framework developer will need to create a class that implements the ModelTransformer interface. The ModelTransformer.transformToDomainModel instance transforms a specified list of model properties (the canonical data model) into a single domain model. The list may contain a hierarchy (inheritance) of model information. In the case of PomClassicDomainModel, the returned DomainModel instance is a wrapper for the maven model. ModelTransformer.transformToModelProperties instance reverses the process of transforming the domain models to the canonical format of model properties. Thus the framework developer is responsible for doing bi-directional transform between data models and the canonical data model.

Code Block
borderStylesolid
titleModelTransformer Interface
borderStylesolid
DomainModel transformToDomainModel(List<ModelProperty> properties);

List<ModelProperty> transformToModelProperties(List<DomainModel> domainModels);

The second interface that the framework developer is required to implement is the ModelContainer. This is implemented for any part of the model which is a collection.

Code Block
borderStylesolid
titleModelContainer Interface
borderStylesolid
ModelContainerAction containerAction(ModelContainer modelContainer);
List<ModelProperty> getProperties();

The ModelContainer.containerAction implementation instance is required to return model container action (noop, delete, join) for the specified model container. For example, the following implementation says that if the group id and artifact id are the same but the version is different then delete the passed in container. If the group id, artifact id and version are the same, then join the containers. If the group id or artifact id are different, the don't do anything. 

Code Block
borderStylesolid
titleModelContainer.ContainerAction
borderStylesolid
public ModelContainerAction containerAction(ModelContainer modelContainer) {
  ArtifactManagementModelContainer c = (ArtifactManagementModelContainer) modelContainer;
  if (c.groupId.equals(groupId) && c.artifactId.equals(artifactId)) {
    return (c.version.equals(version)) ? ModelContainerAction.JOIN : ModelContainerAction.DELETE;
  } else {
    return ModelContainerAction.NOP;
  }
 }

...

The user only needs to concern themselves with three classes: DomainModel, ModelTransformer and ModelTransformerContext. The DomainModel and ModelTransformer are implemented by framework developers so the user needs to obtain these instances through whatever means the framework developer has specified. They then use the ModelTransformerContext passing in the transformers and domain models to the ModelTransformerContext.transform method. They will get back the fully processed domain model.

Code Block
titleModelTransformerContext
borderStylesolid
titleModelTransformerContext
DomainModel transform(List<DomainModel> domainModels, ModelTransformer fromModelTransformer, ModelTransformer toModelTransformer)

...

The framework assigns each field within the pom a URI key and a value, which may be null. The following is an example of a model property list where the ordering from parent to child model is: [C, B, A]. All processing is done on this canonical model.

Code Block
titleA
borderStylesolid
titleA
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-a
Uri = [http://apache.org/model/project/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.bogus
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = bogus-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.0
Code Block
titleB
borderStylesolid
titleB
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-b
Uri = [http://apache.org/model/project/version], Value = 1.2
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/scope], Value = compile
Code Block
titleC
borderStylesolid
titleC
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-c
Uri = [http://apache.org/model/project/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.4

...

In the sort, (3) will reverse the dependency list of collections so that the most general model element will be first under the collection. For example, org.apache.maven.dep:artificat-dep:1.4, which is from pom C, would first in the dependency management collection.

Code Block
title
borderStylesolidtitle
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-a
Uri = [http://apache.org/model/project/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.4
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/scope], Value = compile
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.bogus
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = bogus-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.0
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencyManagement/dependencies#collection/dependency/version], Value = 1.1

...

The ModelDataSource contains the underlying list of ModelProperties (canonical data model). After the initial sort (above), all modifications of the data model go though the ModelDataSource class implementation instance. The ModelDataSource handles deleting and joining of ModelContainers, more specifically the deleting and joining of the ModelProperties that the ModelContainers contain.

Code Block
titleModelDataSource
borderStylesolid
titleModelDataSource
/**
 * 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 precendence over model container b.
     *
     * @param a model container with precedence
     * @param b model container without precedence
     * @return joined model container
     */
    ModelContainer join(ModelContainer a, ModelContainer b);

    /**
     * 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();

    List<ModelContainer> queryFor(String uri);

    /**
     * Initializes the object with model properties.
     *
     * @param modelProperties the model properties that back the data source
     */
    void init(List<ModelProperty> modelProperties, Collection<ModelContainerFactory> modelContainerFactories);
}

...

There are 43 collections within the pom model that are sorted according to the general collection rules

Code Block
borderStylesolid
titleCollections (Pom)
borderStylesolid
http://apache.org/maven/project/build/resources#collection
http://apache.org/maven/project/build/testResources#collection
http://apache.org/maven/project/build/extensions#collection
http://apache.org/maven/project/build/plugins#collection
http://apache.org/maven/project/build/plugins/plugin/dependencies#collection
http://apache.org/maven/project/build/plugins/plugin/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/build/plugins/plugin/executions#collection
http://apache.org/maven/project/build/pluginManagement/plugins#collection
http://apache.org/maven/project/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/build/pluginManagement/plugins/plugin/executions#collection
http://apache.org/maven/project/build/pluginManagement/plugins/plugin/dependencies#collection
http://apache.org/maven/project/dependencyManagement/dependencies#collection
http://apache.org/maven/project/dependencyManagement/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/dependencies#collection
http://apache.org/maven/project/pluginRepositories#collection
http://apache.org/maven/project/repositories#collection
http://apache.org/maven/project/licenses#collection
http://apache.org/maven/project/reporting/plugins#collection
http://apache.org/maven/project/reporting/plugins/plugin/reportSets#collection
http://apache.org/maven/project/contributors#collection
http://apache.org/maven/project/developers#collection
http://apache.org/maven/project/mailingLists#collection
http://apache.org/maven/project/ciManagement/notifiers#collection
http://apache.org/maven/project/profiles#collection
http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection
http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/profiles/profile/reporting/plugins#collection
http://apache.org/maven/project/profiles/profile/build/testResources#collection
http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection
http://apache.org/maven/project/profiles/profile/build/resources#collection
http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies#collection
http://apache.org/maven/project/profiles/profile/pluginRepositories#collection
http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection
http://apache.org/maven/project/profiles/profile/dependencies#collection
http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies#collection
http://apache.org/maven/project/profiles/profile/repositories#collection
http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection
http://apache.org/maven/project/profiles/profile/build/plugins#collection
http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection
http://apache.org/maven/project/profiles/profile/dependencies/dependency/exclusions#collection
http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection

...

Transforming between XML based models involves changing the URIs. For example to change between the canonical model (which is based on the pom) and a C# project file, you would rename the URIs.

Code Block
borderStylesolid
titleCanonical Model (Pom)
borderStylesolid
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-a
Uri = [http://apache.org/model/project/version], Value = 1.1
Uri = [http://apache.org/model/project/dependencies#collection/dependency], Value = null
Uri = [http://apache.org/model/project/dependencies#collection/dependency/groupId], Value = org.apache.maven.dep
Uri = [http://apache.org/model/project/dependencies#collection/dependency/artifactId], Value = artifact-dep
Uri = [http://apache.org/model/project/dependencies#collection/dependency/version], Value = 1.4
Code Block
borderStylesolid
titleC# Project File
borderStylesolid
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/Project#collection/PropertyGroup], Value = null
Uri = [http://apache.org/model/Project#collection/PropertyGroup/AssemblyName], Value = maven-a
Uri = [http://apache.org/model/Project#collection/ItemGroup#collection/Reference], Value = null
Uri = [http://apache.org/model/Project#collection/ItemGroup#collection/Reference/Include], Value = artifact-dep

...

You can easily add information to the canonical model by defining new URIs. For example, we could introduce toolchains:

Code Block
borderStylesolid
titleToolchain Extension
borderStylesolid
Uri = [http://apache.org/model/project], Value = null
Uri = [http://apache.org/model/project/groupId], Value = org.apache.maven
Uri = [http://apache.org/model/project/artifactId], Value = maven-a
Uri = [http://apache.org/model/project/version], Value = 1.1
Uri = [http://apache.org/model/project/toolchain], Value = null
Uri = [http://apache.org/model/project/toolchain/type], Value = jdk
Uri = [http://apache.org/model/project/toolchain/provides], Value = null
Uri = [http://apache.org/model/project/toolchain/provides/jdkVersion], Value = 1.5

...