mirror of https://github.com/apache/maven.git
o Added a factory to manually wire/setup a model builder for convenient use in non-ioc envs
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@963073 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f8c8aa5fa1
commit
4bc3491706
|
@ -0,0 +1,242 @@
|
||||||
|
package org.apache.maven.model.building;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.model.Model;
|
||||||
|
import org.apache.maven.model.composition.DefaultDependencyManagementImporter;
|
||||||
|
import org.apache.maven.model.composition.DependencyManagementImporter;
|
||||||
|
import org.apache.maven.model.inheritance.DefaultInheritanceAssembler;
|
||||||
|
import org.apache.maven.model.inheritance.InheritanceAssembler;
|
||||||
|
import org.apache.maven.model.interpolation.ModelInterpolator;
|
||||||
|
import org.apache.maven.model.interpolation.StringSearchModelInterpolator;
|
||||||
|
import org.apache.maven.model.io.DefaultModelReader;
|
||||||
|
import org.apache.maven.model.io.ModelReader;
|
||||||
|
import org.apache.maven.model.locator.DefaultModelLocator;
|
||||||
|
import org.apache.maven.model.locator.ModelLocator;
|
||||||
|
import org.apache.maven.model.management.DefaultDependencyManagementInjector;
|
||||||
|
import org.apache.maven.model.management.DefaultPluginManagementInjector;
|
||||||
|
import org.apache.maven.model.management.DependencyManagementInjector;
|
||||||
|
import org.apache.maven.model.management.PluginManagementInjector;
|
||||||
|
import org.apache.maven.model.normalization.DefaultModelNormalizer;
|
||||||
|
import org.apache.maven.model.normalization.ModelNormalizer;
|
||||||
|
import org.apache.maven.model.path.DefaultModelPathTranslator;
|
||||||
|
import org.apache.maven.model.path.DefaultModelUrlNormalizer;
|
||||||
|
import org.apache.maven.model.path.DefaultPathTranslator;
|
||||||
|
import org.apache.maven.model.path.DefaultUrlNormalizer;
|
||||||
|
import org.apache.maven.model.path.ModelPathTranslator;
|
||||||
|
import org.apache.maven.model.path.ModelUrlNormalizer;
|
||||||
|
import org.apache.maven.model.path.PathTranslator;
|
||||||
|
import org.apache.maven.model.path.UrlNormalizer;
|
||||||
|
import org.apache.maven.model.plugin.DefaultPluginConfigurationExpander;
|
||||||
|
import org.apache.maven.model.plugin.DefaultReportConfigurationExpander;
|
||||||
|
import org.apache.maven.model.plugin.DefaultReportingConverter;
|
||||||
|
import org.apache.maven.model.plugin.LifecycleBindingsInjector;
|
||||||
|
import org.apache.maven.model.plugin.PluginConfigurationExpander;
|
||||||
|
import org.apache.maven.model.plugin.ReportConfigurationExpander;
|
||||||
|
import org.apache.maven.model.plugin.ReportingConverter;
|
||||||
|
import org.apache.maven.model.profile.DefaultProfileInjector;
|
||||||
|
import org.apache.maven.model.profile.DefaultProfileSelector;
|
||||||
|
import org.apache.maven.model.profile.ProfileInjector;
|
||||||
|
import org.apache.maven.model.profile.ProfileSelector;
|
||||||
|
import org.apache.maven.model.profile.activation.FileProfileActivator;
|
||||||
|
import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
|
||||||
|
import org.apache.maven.model.profile.activation.OperatingSystemProfileActivator;
|
||||||
|
import org.apache.maven.model.profile.activation.ProfileActivator;
|
||||||
|
import org.apache.maven.model.profile.activation.PropertyProfileActivator;
|
||||||
|
import org.apache.maven.model.superpom.DefaultSuperPomProvider;
|
||||||
|
import org.apache.maven.model.superpom.SuperPomProvider;
|
||||||
|
import org.apache.maven.model.validation.DefaultModelValidator;
|
||||||
|
import org.apache.maven.model.validation.ModelValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory to create model builder instances when no dependency injection is available. <em>Note:</em> This class is
|
||||||
|
* only meant as a utility for developers that want to employ the model builder outside of the Maven build system, Maven
|
||||||
|
* plugins should always acquire model builder instances via dependency injection. Developers might want to subclass
|
||||||
|
* this factory to provide custom implementations for some of the components used by the model builder.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class DefaultModelBuilderFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
protected ModelProcessor newModelProcessor()
|
||||||
|
{
|
||||||
|
DefaultModelProcessor processor = new DefaultModelProcessor();
|
||||||
|
processor.setModelLocator( newModelLocator() );
|
||||||
|
processor.setModelReader( newModelReader() );
|
||||||
|
return processor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelLocator newModelLocator()
|
||||||
|
{
|
||||||
|
return new DefaultModelLocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelReader newModelReader()
|
||||||
|
{
|
||||||
|
return new DefaultModelReader();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProfileSelector newProfileSelector()
|
||||||
|
{
|
||||||
|
DefaultProfileSelector profileSelector = new DefaultProfileSelector();
|
||||||
|
|
||||||
|
for ( ProfileActivator activator : newProfileActivators() )
|
||||||
|
{
|
||||||
|
profileSelector.addProfileActivator( activator );
|
||||||
|
}
|
||||||
|
|
||||||
|
return profileSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProfileActivator[] newProfileActivators()
|
||||||
|
{
|
||||||
|
return new ProfileActivator[] { new JdkVersionProfileActivator(), new OperatingSystemProfileActivator(),
|
||||||
|
new PropertyProfileActivator(), new FileProfileActivator() };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected UrlNormalizer newUrlNormalizer()
|
||||||
|
{
|
||||||
|
return new DefaultUrlNormalizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PathTranslator newPathTranslator()
|
||||||
|
{
|
||||||
|
return new DefaultPathTranslator();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelInterpolator newModelInterpolator()
|
||||||
|
{
|
||||||
|
UrlNormalizer urlNormalizer = newUrlNormalizer();
|
||||||
|
PathTranslator pathTranslator = newPathTranslator();
|
||||||
|
return new StringSearchModelInterpolator().setPathTranslator( pathTranslator ).setUrlNormalizer( urlNormalizer );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelValidator newModelValidator()
|
||||||
|
{
|
||||||
|
return new DefaultModelValidator();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelNormalizer newModelNormalizer()
|
||||||
|
{
|
||||||
|
return new DefaultModelNormalizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelPathTranslator newModelPathTranslator()
|
||||||
|
{
|
||||||
|
return new DefaultModelPathTranslator().setPathTranslator( newPathTranslator() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ModelUrlNormalizer newModelUrlNormalizer()
|
||||||
|
{
|
||||||
|
return new DefaultModelUrlNormalizer().setUrlNormalizer( newUrlNormalizer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InheritanceAssembler newInheritanceAssembler()
|
||||||
|
{
|
||||||
|
return new DefaultInheritanceAssembler();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProfileInjector newProfileInjector()
|
||||||
|
{
|
||||||
|
return new DefaultProfileInjector();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SuperPomProvider newSuperPomProvider()
|
||||||
|
{
|
||||||
|
return new DefaultSuperPomProvider().setModelProcessor( newModelProcessor() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DependencyManagementImporter newDependencyManagementImporter()
|
||||||
|
{
|
||||||
|
return new DefaultDependencyManagementImporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DependencyManagementInjector newDependencyManagementInjector()
|
||||||
|
{
|
||||||
|
return new DefaultDependencyManagementInjector();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected LifecycleBindingsInjector newLifecycleBindingsInjector()
|
||||||
|
{
|
||||||
|
return new StubLifecycleBindingsInjector();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PluginManagementInjector newPluginManagementInjector()
|
||||||
|
{
|
||||||
|
return new DefaultPluginManagementInjector();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PluginConfigurationExpander newPluginConfigurationExpander()
|
||||||
|
{
|
||||||
|
return new DefaultPluginConfigurationExpander();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReportConfigurationExpander newReportConfigurationExpander()
|
||||||
|
{
|
||||||
|
return new DefaultReportConfigurationExpander();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ReportingConverter newReportingConverter()
|
||||||
|
{
|
||||||
|
return new DefaultReportingConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new model builder instance.
|
||||||
|
*
|
||||||
|
* @return The new model builder instance, never {@code null}.
|
||||||
|
*/
|
||||||
|
public DefaultModelBuilder newInstance()
|
||||||
|
{
|
||||||
|
DefaultModelBuilder modelBuilder = new DefaultModelBuilder();
|
||||||
|
|
||||||
|
modelBuilder.setModelProcessor( newModelProcessor() );
|
||||||
|
modelBuilder.setModelValidator( newModelValidator() );
|
||||||
|
modelBuilder.setModelNormalizer( newModelNormalizer() );
|
||||||
|
modelBuilder.setModelPathTranslator( newModelPathTranslator() );
|
||||||
|
modelBuilder.setModelUrlNormalizer( newModelUrlNormalizer() );
|
||||||
|
modelBuilder.setModelInterpolator( newModelInterpolator() );
|
||||||
|
modelBuilder.setInheritanceAssembler( newInheritanceAssembler() );
|
||||||
|
modelBuilder.setProfileInjector( newProfileInjector() );
|
||||||
|
modelBuilder.setProfileSelector( newProfileSelector() );
|
||||||
|
modelBuilder.setSuperPomProvider( newSuperPomProvider() );
|
||||||
|
modelBuilder.setDependencyManagementImporter( newDependencyManagementImporter() );
|
||||||
|
modelBuilder.setDependencyManagementInjector( newDependencyManagementInjector() );
|
||||||
|
modelBuilder.setLifecycleBindingsInjector( newLifecycleBindingsInjector() );
|
||||||
|
modelBuilder.setPluginManagementInjector( newPluginManagementInjector() );
|
||||||
|
modelBuilder.setPluginConfigurationExpander( newPluginConfigurationExpander() );
|
||||||
|
modelBuilder.setReportConfigurationExpander( newReportConfigurationExpander() );
|
||||||
|
modelBuilder.setReportingConverter( newReportingConverter() );
|
||||||
|
|
||||||
|
return modelBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class StubLifecycleBindingsInjector
|
||||||
|
implements LifecycleBindingsInjector
|
||||||
|
{
|
||||||
|
|
||||||
|
public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,6 +22,8 @@ package org.apache.maven.model.building;
|
||||||
/**
|
/**
|
||||||
* Defines events that the model builder fires during construction of the effective model. When a listener encounteres
|
* Defines events that the model builder fires during construction of the effective model. When a listener encounteres
|
||||||
* errors while processing the event, it can report these problems via {@link ModelBuildingEvent#getProblems()}.
|
* errors while processing the event, it can report these problems via {@link ModelBuildingEvent#getProblems()}.
|
||||||
|
* <em>Note:</em> To cope with future extensions to this interface, it is strongly recommended to extend
|
||||||
|
* {@link AbstractModelBuildingListener} rather than to directly implement this interface.
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.apache.maven.model.building;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.File;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class DefaultModelBuilderFactoryTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private File getPom( String name )
|
||||||
|
{
|
||||||
|
return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCompleteWiring()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
|
||||||
|
assertNotNull( builder );
|
||||||
|
|
||||||
|
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
|
||||||
|
request.setProcessPlugins( true );
|
||||||
|
request.setPomFile( getPom( "simple" ) );
|
||||||
|
|
||||||
|
ModelBuildingResult result = builder.build( request );
|
||||||
|
assertNotNull( result );
|
||||||
|
assertNotNull( result.getEffectiveModel() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?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/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>test</groupId>
|
||||||
|
<artifactId>test</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.5</source>
|
||||||
|
<target>1.5</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>test</id>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>test</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
Loading…
Reference in New Issue